flowecommerce_resultadosdigitais - Version 0.1.5

Version Notes

Bugfix - Quando um lead não havia sido ainda processado pelo RD a conversão em venda não estava sendo processada com sucesso (a conversão do lead leva alguns segundos)

Adicionadas conversões para adição de produtos ao carrinho, bem como os observers para pagamentos recorrentes.

Download this release

Release Info

Developer Flow eCommerce
Extension flowecommerce_resultadosdigitais
Version 0.1.5
Comparing to
See all releases


Code changes from version 0.1.4 to 0.1.5

app/code/local/Flowecommerce/Resultadosdigitais/Model/Api.php CHANGED
@@ -11,6 +11,7 @@ class Flowecommerce_Resultadosdigitais_Model_Api
11
 
12
  public function markSale($email, $value)
13
  {
 
14
  try {
15
  $data = array(
16
  'status' => 'won',
@@ -26,14 +27,16 @@ class Flowecommerce_Resultadosdigitais_Model_Api
26
  ->setMethod(Zend_Http_Client::POST)
27
  ->setParameterPost($data);
28
  $response = $leadHttpClient->request();
29
- $responseBody = $response->getBody();
30
  } catch (Exception $e) {
31
  Mage::logException($e);
32
  }
 
33
  }
34
 
35
  public function addLeadConversion($conversionIdentifier, Flowecommerce_Resultadosdigitais_Model_Requestdata $data)
36
  {
 
37
  try {
38
  if ($this->validateLead($conversionIdentifier, $data)) {
39
  $data_query = http_build_query($data);
@@ -47,11 +50,12 @@ class Flowecommerce_Resultadosdigitais_Model_Api
47
  ->setParameterPost($this->_prepareParams($conversionIdentifier, $data));
48
 
49
  $response = $leadHttpClient->request();
50
- $responseBody = $response->getBody();
51
  }
52
  } catch (Exception $e) {
53
  Mage::logException($e);
54
  }
 
55
  }
56
 
57
  protected function _getHelper() {
11
 
12
  public function markSale($email, $value)
13
  {
14
+ $return = false;
15
  try {
16
  $data = array(
17
  'status' => 'won',
27
  ->setMethod(Zend_Http_Client::POST)
28
  ->setParameterPost($data);
29
  $response = $leadHttpClient->request();
30
+ $return = $response;
31
  } catch (Exception $e) {
32
  Mage::logException($e);
33
  }
34
+ return $return;
35
  }
36
 
37
  public function addLeadConversion($conversionIdentifier, Flowecommerce_Resultadosdigitais_Model_Requestdata $data)
38
  {
39
+ $return = false;
40
  try {
41
  if ($this->validateLead($conversionIdentifier, $data)) {
42
  $data_query = http_build_query($data);
50
  ->setParameterPost($this->_prepareParams($conversionIdentifier, $data));
51
 
52
  $response = $leadHttpClient->request();
53
+ $return = $response;
54
  }
55
  } catch (Exception $e) {
56
  Mage::logException($e);
57
  }
58
+ return $return;
59
  }
60
 
61
  protected function _getHelper() {
app/code/local/Flowecommerce/Resultadosdigitais/Model/Observer.php CHANGED
@@ -12,7 +12,10 @@ class Flowecommerce_Resultadosdigitais_Model_Observer {
12
  const LEAD_ORDERPLACE = 'order-place';
13
  const LEAD_ACCOUNTCREATE = 'account-create';
14
  const LEAD_NEWSLETTERSUBSCRIBE = 'newsletter-subscribe';
15
-
 
 
 
16
  /**
17
  * Cliente tipo pessoa juridica - Compatibilidade com módulo PJ Flow
18
  */
@@ -62,7 +65,7 @@ class Flowecommerce_Resultadosdigitais_Model_Observer {
62
  $data->setEmail($post['email']);
63
  $data->setNome($post['name']);
64
  $data->setTelefone($post['telephone']);
65
-
66
  $data->setData('store_name', $this->_getStoreDataObject()->getName());
67
 
68
  $this->_getApi()->addLeadConversion(self::LEAD_CONTACTFORM, $data);
@@ -71,6 +74,9 @@ class Flowecommerce_Resultadosdigitais_Model_Observer {
71
 
72
  public function orderPlace(Varien_Event_Observer $observer) {
73
  if ($this->_getHelper()->isEnabled()) {
 
 
 
74
  /* @var Mage_Sales_Model_Order $order */
75
  $order = $observer->getOrder();
76
  /* @var Mage_Customer_Model_Customer $customer */
@@ -156,7 +162,14 @@ class Flowecommerce_Resultadosdigitais_Model_Observer {
156
  $data->setData('store_name', $this->_getStoreDataObject()->getName());
157
 
158
  $this->_getApi()->addLeadConversion(self::LEAD_ORDERPLACE, $data);
159
- $this->_getApi()->markSale($customer->getEmail(), $order_value);
 
 
 
 
 
 
 
160
  }
161
  }
162
 
@@ -174,7 +187,7 @@ class Flowecommerce_Resultadosdigitais_Model_Observer {
174
  $data->setAniversario($customer->getDob());
175
  $data->setGender($this->_getGenderLabel($customer->getGender()));
176
  $data->setCpfCnpj($customer->getTaxvat());
177
-
178
  $data->setData('store_name', $this->_getStoreDataObject()->getName());
179
 
180
  $this->_getApi()->addLeadConversion(self::LEAD_ACCOUNTCREATE, $data);
@@ -184,17 +197,68 @@ class Flowecommerce_Resultadosdigitais_Model_Observer {
184
  public function newsletterSubscribe(Varien_Event_Observer $observer) {
185
  if ($this->_getHelper()->isEnabled()) {
186
  $subscriber = $observer->getEvent()->getSubscriber();
187
- if ($subscriber->isSubscribed()) {
188
- /*
189
- * Dados da conta
190
- */
191
  $data = $this->_getRequestDataObject();
192
  $data->setEmail($subscriber->getEmail());
193
-
194
  $data->setData('store_name', $this->_getStoreDataObject()->getName());
 
 
 
 
 
 
 
 
 
195
 
196
- $this->_getApi()->addLeadConversion(self::LEAD_NEWSLETTERSUBSCRIBE, $data);
 
 
 
 
 
 
 
 
 
 
 
 
197
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  }
199
  }
200
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  const LEAD_ORDERPLACE = 'order-place';
13
  const LEAD_ACCOUNTCREATE = 'account-create';
14
  const LEAD_NEWSLETTERSUBSCRIBE = 'newsletter-subscribe';
15
+ const LEAD_NEWSLETTERUNSUBSCRIBE= 'newsletter-unsubscribe';
16
+ const LEAD_RECURRINGPAYMENT = 'recurring-payment-subscription-processed';
17
+ const LEAD_RECURRINGPAYMENTPLANCHANGE = 'recurring-payment-plan-change';
18
+ const LEAD_PRODUCTADDEDTOCART = 'product-added-to-cart';
19
  /**
20
  * Cliente tipo pessoa juridica - Compatibilidade com módulo PJ Flow
21
  */
65
  $data->setEmail($post['email']);
66
  $data->setNome($post['name']);
67
  $data->setTelefone($post['telephone']);
68
+
69
  $data->setData('store_name', $this->_getStoreDataObject()->getName());
70
 
71
  $this->_getApi()->addLeadConversion(self::LEAD_CONTACTFORM, $data);
74
 
75
  public function orderPlace(Varien_Event_Observer $observer) {
76
  if ($this->_getHelper()->isEnabled()) {
77
+ if(Mage::registry('rdstation_do_not_create_order')){
78
+ return false;
79
+ }
80
  /* @var Mage_Sales_Model_Order $order */
81
  $order = $observer->getOrder();
82
  /* @var Mage_Customer_Model_Customer $customer */
162
  $data->setData('store_name', $this->_getStoreDataObject()->getName());
163
 
164
  $this->_getApi()->addLeadConversion(self::LEAD_ORDERPLACE, $data);
165
+
166
+ for ($i = 0; $i <=10; $i++) {
167
+ $response = $this->_getApi()->markSale($customer->getEmail(), $order_value);
168
+ $statusResponse = $response->getHeader('Status');
169
+ if ($statusResponse == "200 OK") {
170
+ break;
171
+ }
172
+ }
173
  }
174
  }
175
 
187
  $data->setAniversario($customer->getDob());
188
  $data->setGender($this->_getGenderLabel($customer->getGender()));
189
  $data->setCpfCnpj($customer->getTaxvat());
190
+
191
  $data->setData('store_name', $this->_getStoreDataObject()->getName());
192
 
193
  $this->_getApi()->addLeadConversion(self::LEAD_ACCOUNTCREATE, $data);
197
  public function newsletterSubscribe(Varien_Event_Observer $observer) {
198
  if ($this->_getHelper()->isEnabled()) {
199
  $subscriber = $observer->getEvent()->getSubscriber();
200
+ $statusChange = $subscriber->getIsStatusChanged();
201
+ if($statusChange)
202
+ {
 
203
  $data = $this->_getRequestDataObject();
204
  $data->setEmail($subscriber->getEmail());
 
205
  $data->setData('store_name', $this->_getStoreDataObject()->getName());
206
+ if($subscriber->getSubscriberStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED)
207
+ {
208
+ $this->_getApi()->addLeadConversion(self::LEAD_NEWSLETTERSUBSCRIBE, $data);
209
+ }elseif($subscriber->getSubscriberStatus() == Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED) {
210
+ $this->_getApi()->addLeadConversion(self::LEAD_NEWSLETTERUNSUBSCRIBE,$data);
211
+ }
212
+ }
213
+ }
214
+ }
215
 
216
+ public function registerRecurringPayment(Varien_Event_Observer $observer)
217
+ {
218
+
219
+ if ($this->_getHelper()->isEnabled() && Mage::registry('rdstation_do_not_create_order')) {
220
+
221
+ $data = $this->_getRequestDataObject();
222
+ $data->setEmail($observer->getEmail());
223
+ $items = $observer->getOrder()->getItemsCollection()->getItems();
224
+ foreach($items as $item)
225
+ {
226
+ $sku = $item->getSku();
227
+ $price = $item->getPrice();
228
+ break;
229
  }
230
+ $data->setProductSku($sku);
231
+ $data->setProductPrice($price);
232
+ $this->_getApi()->addLeadConversion(self::LEAD_RECURRINGPAYMENT, $data);
233
+ }
234
+ }
235
+
236
+ public function changeRecurringPaymentPlan(Varien_Event_Observer $observer)
237
+ {
238
+ if ($this->_getHelper()->isEnabled()) {
239
+
240
+ $data = $this->_getRequestDataObject();
241
+ $data->setEmail($observer->getEmail());
242
+ $data->setOldProductSku($observer->getOldSku());
243
+ $data->setOldProductPrice($observer->getOldPrice());
244
+ $data->setNewProductSku($observer->getNewSku());
245
+ $data->setNewProductPrice($observer->getNewPrice());
246
+ $this->_getApi()->addLeadConversion(self::LEAD_RECURRINGPAYMENTPLANCHANGE, $data);
247
  }
248
  }
249
+
250
+
251
+ public function catchAddToCart(Varien_Event_Observer $observer)
252
+ {
253
+ if ($this->_getHelper()->isEnabled() && Mage::getSingleton('customer/session')->isLoggedIn()) {
254
+ $data = $this->_getRequestDataObject();
255
+ $data->setEmail(Mage::getSingleton('customer/session')->getCustomer()->getEmail());
256
+ $data->setSku($observer->getProduct()->getSku());
257
+ $data->setQty($observer->getQuoteItem()->getQty());
258
+ $data->setPrice($observer->getProduct()->getPrice());
259
+ $this->_getApi()->addLeadConversion(self::LEAD_PRODUCTADDEDTOCART, $data);
260
+ }
261
+
262
+ }
263
+
264
+ }
app/code/local/Flowecommerce/Resultadosdigitais/etc/config.xml CHANGED
@@ -27,7 +27,7 @@
27
  </observers>
28
  </controller_action_postdispatch_contacts_index_post>
29
 
30
- <!-- formulário de contato enviado - fileform -->
31
  <controller_action_postdispatch_fileform_index_post>
32
  <observers>
33
  <flowecommerce_resultadosdigitais_fileform_post>
@@ -37,6 +37,25 @@
37
  </observers>
38
  </controller_action_postdispatch_fileform_index_post>
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  <!-- criação de pedido -->
41
  <sales_order_place_after>
42
  <observers>
@@ -66,6 +85,18 @@
66
  </flowecommerce_resultadosdigitais_newsletter_subscribe>
67
  </observers>
68
  </newsletter_subscriber_save_after>
 
 
 
 
 
 
 
 
 
 
 
 
69
  </events>
70
  </global>
71
  </config>
27
  </observers>
28
  </controller_action_postdispatch_contacts_index_post>
29
 
30
+ <!-- formulário de contato enviado - fileform - Extensão Exclusiva Flow -->
31
  <controller_action_postdispatch_fileform_index_post>
32
  <observers>
33
  <flowecommerce_resultadosdigitais_fileform_post>
37
  </observers>
38
  </controller_action_postdispatch_fileform_index_post>
39
 
40
+ <!-- Recurring payments - Extensão Exclusiva Flow -->
41
+ <recurringpayments_subscription_processed>
42
+ <observers>
43
+ <flowecommerce_resultadosdigitais_register_recurring_payment>
44
+ <class>resultadosdigitais/observer</class>
45
+ <method>registerRecurringPayment</method>
46
+ </flowecommerce_resultadosdigitais_register_recurring_payment>
47
+ </observers>
48
+ </recurringpayments_subscription_processed>
49
+
50
+ <recurringpayments_subscription_plan_changed>
51
+ <observers>
52
+ <flowecommerce_resultadosdigitais_change_recurring_payment_plan>
53
+ <class>resultadosdigitais/observer</class>
54
+ <method>changeRecurringPaymentPlan</method>
55
+ </flowecommerce_resultadosdigitais_change_recurring_payment_plan>
56
+ </observers>
57
+ </recurringpayments_subscription_plan_changed>
58
+
59
  <!-- criação de pedido -->
60
  <sales_order_place_after>
61
  <observers>
85
  </flowecommerce_resultadosdigitais_newsletter_subscribe>
86
  </observers>
87
  </newsletter_subscriber_save_after>
88
+
89
+ <!-- adicionar produto ao carrinho -->
90
+ <checkout_cart_product_add_after>
91
+ <observers>
92
+ <flowecommerce_resultadosdigitais_add_to_cart>
93
+ <class>resultadosdigitais/observer</class>
94
+ <method>catchAddToCart</method>
95
+ </flowecommerce_resultadosdigitais_add_to_cart>
96
+ </observers>
97
+ </checkout_cart_product_add_after>
98
+
99
+
100
  </events>
101
  </global>
102
  </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>flowecommerce_resultadosdigitais</name>
4
- <version>0.1.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
@@ -14,19 +14,15 @@ Este m&#xF3;dulo executa chamadas para a API do RDStation quando:&#xD;
14
  Um formul&#xE1;rio de contato &#xE9; enviado&#xD;
15
  Uma nova conta de cliente &#xE9; criada&#xD;
16
  Um novo pedido &#xE9; criado&#xD;
17
- Um cliente assina a newsletter da loja virtual</description>
18
- <notes>M&#xF3;dulo de integra&#xE7;&#xE3;o entre o magento e a plataforma RD Station da Resultados Digitais para cria&#xE7;&#xE3;o e qualifica&#xE7;&#xE3;o de leads.&#xD;
 
19
  &#xD;
20
- Este m&#xF3;dulo executa chamadas para a API do RDStation quando:&#xD;
21
- &#xD;
22
- Um formul&#xE1;rio de contato &#xE9; enviado&#xD;
23
- Uma nova conta de cliente &#xE9; criada&#xD;
24
- Um novo pedido &#xE9; criado&#xD;
25
- Um cliente assina a newsletter da loja virtual</notes>
26
  <authors><author><name>Flow eCommerce</name><user>flowecommerce</user><email>contato@flowecommerce.com</email></author><author><name>Gabriel Queiroz Silva</name><user>gabrielqs</user><email>gabriel@flowecommerce.com</email></author></authors>
27
- <date>2015-07-28</date>
28
- <time>09:59:10</time>
29
- <contents><target name="magelocal"><dir name="Flowecommerce"><dir name="Resultadosdigitais"><dir name="Helper"><file name="Data.php" hash="00d2ae49825e162eb99dd72a98895a61"/></dir><dir name="Model"><file name="Api.php" hash="e9657c111243ba10c79b32949f6f4d29"/><dir name="Googleanalytics"><file name="Customvar.php" hash="d163ebb5bb590dd7553ed1356c033a2c"/><file name="Tracker.php" hash="be95e10bd1df9ca5319f5a50967f2eed"/><dir name="Utm"><file name="A.php" hash="7604206d87189c56f109231c4a95f00f"/><file name="B.php" hash="e710a66f3c061f4da69e9f468c2eaf5c"/><file name="C.php" hash="27c99ca82b05b11bcba01e88f9a3e5c6"/><file name="V.php" hash="9c77ced8175034ac42b89878e26844f5"/><file name="Z.php" hash="1bb0821f8752993b737a923fcbd4b314"/></dir></dir><file name="Observer.php" hash="238f47383f5d1ff054a0b30469ebc082"/><file name="Requestdata.php" hash="d97634793fae544f18e5ffda617ed745"/></dir><dir name="etc"><file name="adminhtml.xml" hash="be9b06eed9df502e9759b5cd397f9fa2"/><file name="config.xml" hash="895bd2d9a76ff3bc31811dd2129c0b9f"/><file name="system.xml" hash="da64ea97bc98fe6f42988df79c2ace1f"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Flowecommerce_Resultadosdigitais.xml" hash="5d476dea8a51bda77126fa637c5f29f2"/></dir></target></contents>
30
  <compatible/>
31
  <dependencies><required><php><min>5.3.0</min><max>5.6.3</max></php></required></dependencies>
32
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>flowecommerce_resultadosdigitais</name>
4
+ <version>0.1.5</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
14
  Um formul&#xE1;rio de contato &#xE9; enviado&#xD;
15
  Uma nova conta de cliente &#xE9; criada&#xD;
16
  Um novo pedido &#xE9; criado&#xD;
17
+ Um cliente assina a newsletter da loja virtual&#xD;
18
+ Um produto &#xE9; adicionado ao carrinho quando o cliente est&#xE1; logado</description>
19
+ <notes>Bugfix - Quando um lead n&#xE3;o havia sido ainda processado pelo RD a convers&#xE3;o em venda n&#xE3;o estava sendo processada com sucesso (a convers&#xE3;o do lead leva alguns segundos)&#xD;
20
  &#xD;
21
+ Adicionadas convers&#xF5;es para adi&#xE7;&#xE3;o de produtos ao carrinho, bem como os observers para pagamentos recorrentes.</notes>
 
 
 
 
 
22
  <authors><author><name>Flow eCommerce</name><user>flowecommerce</user><email>contato@flowecommerce.com</email></author><author><name>Gabriel Queiroz Silva</name><user>gabrielqs</user><email>gabriel@flowecommerce.com</email></author></authors>
23
+ <date>2015-10-05</date>
24
+ <time>13:43:16</time>
25
+ <contents><target name="magelocal"><dir name="Flowecommerce"><dir name="Resultadosdigitais"><dir name="Helper"><file name="Data.php" hash="00d2ae49825e162eb99dd72a98895a61"/></dir><dir name="Model"><file name="Api.php" hash="0aa520776e63e4785c9f9862ef4ecef3"/><dir name="Googleanalytics"><file name="Customvar.php" hash="d163ebb5bb590dd7553ed1356c033a2c"/><file name="Tracker.php" hash="be95e10bd1df9ca5319f5a50967f2eed"/><dir name="Utm"><file name="A.php" hash="7604206d87189c56f109231c4a95f00f"/><file name="B.php" hash="e710a66f3c061f4da69e9f468c2eaf5c"/><file name="C.php" hash="27c99ca82b05b11bcba01e88f9a3e5c6"/><file name="V.php" hash="9c77ced8175034ac42b89878e26844f5"/><file name="Z.php" hash="1bb0821f8752993b737a923fcbd4b314"/></dir></dir><file name="Observer.php" hash="4c810af6288f49a4702006db81060c00"/><file name="Requestdata.php" hash="d97634793fae544f18e5ffda617ed745"/></dir><dir name="etc"><file name="adminhtml.xml" hash="be9b06eed9df502e9759b5cd397f9fa2"/><file name="config.xml" hash="4e39d0e74bb0f89a3212bd3fe18ac385"/><file name="system.xml" hash="da64ea97bc98fe6f42988df79c2ace1f"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Flowecommerce_Resultadosdigitais.xml" hash="5d476dea8a51bda77126fa637c5f29f2"/></dir></target></contents>
26
  <compatible/>
27
  <dependencies><required><php><min>5.3.0</min><max>5.6.3</max></php></required></dependencies>
28
  </package>