Aplazame_Aplazame - Version 0.3.2

Version Notes

* Order cancellation improvements.

Download this release

Release Info

Developer Aplazame
Extension Aplazame_Aplazame
Version 0.3.2
Comparing to
See all releases


Code changes from version 0.2.2 to 0.3.2

app/code/community/Aplazame/Aplazame/Block/AdminHtml/ProductCampaigns.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method void setArticlesId(string[] $articlesId)
5
+ * @method string[] getArticlesId()
6
+ * @method array[] getArticlesId()
7
+ */
8
+ class Aplazame_Aplazame_Block_AdminHtml_ProductCampaigns extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ $this->setTemplate('aplazame/productCampaigns.phtml');
15
+ }
16
+
17
+ public function getArticles()
18
+ {
19
+ $articlesId = $this->getArticlesId();
20
+ $products = Mage::getModel('catalog/product');
21
+
22
+ $articles = array();
23
+ foreach ($articlesId as $articleId) {
24
+ /** @var Mage_Catalog_Model_Product $product */
25
+ $product = $products->load($articleId);
26
+
27
+ $article = array(
28
+ "id" => $product->getId(),
29
+ "name" => $product->getName(),
30
+ "description" => substr($product->getDescription(), 0, 255),
31
+ "url" => $product->getProductUrl(),
32
+ );
33
+ if (isset($product->_data['media_gallery']['images'][0]['file'])) {
34
+ $article["image_url"] = $product->getMediaConfig()->getMediaUrl($product->_data['media_gallery']['images'][0]['file']);
35
+ }
36
+
37
+ $articles[] = $article;
38
+ }
39
+
40
+ return $articles;
41
+ }
42
+ }
app/code/community/Aplazame/Aplazame/Block/AdminHtml/ProductsCampaigns.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Aplazame_Block_AdminHtml_ProductsCampaigns extends Aplazame_Aplazame_Block_AdminHtml_ProductCampaigns
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->setTemplate('aplazame/productsCampaigns.phtml');
10
+ }
11
+ }
app/code/community/Aplazame/Aplazame/Block/Payment/Redirect.php CHANGED
@@ -7,6 +7,9 @@ class Aplazame_Aplazame_Block_Payment_Redirect extends Mage_Core_Block_Abstract
7
  {
8
  $aplazameJsUri = getenv('APLAZAME_JS_URI') ? getenv('APLAZAME_JS_URI') : 'https://aplazame.com/static/aplazame.js';
9
 
 
 
 
10
  /** @var Aplazame_Aplazame_Model_Payment $payment */
11
  $payment = Mage::getModel('aplazame/payment');
12
 
@@ -17,7 +20,8 @@ class Aplazame_Aplazame_Block_Payment_Redirect extends Mage_Core_Block_Abstract
17
  <script
18
  type="text/javascript"
19
  src="'. $aplazameJsUri . '"
20
- data-aplazame="publicKey: '. Mage::getStoreConfig('payment/aplazame/public_api_key') . '"
 
21
  data-sandbox="'. (Mage::getStoreConfig('payment/aplazame/sandbox')?'true':'false') . '">
22
  </script>
23
 
7
  {
8
  $aplazameJsUri = getenv('APLAZAME_JS_URI') ? getenv('APLAZAME_JS_URI') : 'https://aplazame.com/static/aplazame.js';
9
 
10
+ /** @var Aplazame_Aplazame_Model_Api_Client $client */
11
+ $client = Mage::getModel('aplazame/api_client');
12
+
13
  /** @var Aplazame_Aplazame_Model_Payment $payment */
14
  $payment = Mage::getModel('aplazame/payment');
15
 
20
  <script
21
  type="text/javascript"
22
  src="'. $aplazameJsUri . '"
23
+ data-api-host="' . $client->apiBaseUri . '"
24
+ data-aplazame="'. Mage::getStoreConfig('payment/aplazame/public_api_key') . '"
25
  data-sandbox="'. (Mage::getStoreConfig('payment/aplazame/sandbox')?'true':'false') . '">
26
  </script>
27
 
app/code/community/Aplazame/Aplazame/Model/Api/Client.php CHANGED
@@ -9,7 +9,7 @@ class Aplazame_Aplazame_Model_Api_Client extends Varien_Object
9
  /**
10
  * @var string
11
  */
12
- private $apiBaseUri;
13
 
14
  public function __construct()
15
  {
@@ -80,7 +80,7 @@ class Aplazame_Aplazame_Model_Api_Client extends Varien_Object
80
  */
81
  public function authorize($orderId)
82
  {
83
- return $this->request(Varien_Http_Client::POST, "/" . $orderId . "/authorize");
84
  }
85
 
86
  /**
9
  /**
10
  * @var string
11
  */
12
+ public $apiBaseUri;
13
 
14
  public function __construct()
15
  {
80
  */
81
  public function authorize($orderId)
82
  {
83
+ return $this->request(Varien_Http_Client::POST, '/orders/' . $orderId . "/authorize");
84
  }
85
 
86
  /**
app/code/community/Aplazame/Aplazame/Model/Api/Serializers.php CHANGED
@@ -86,7 +86,7 @@ class Aplazame_Aplazame_Model_Api_Serializers extends Varien_Object
86
  "name"=>$order->getShippingMethod()
87
  ));
88
 
89
- if ($order->getShippingAmount()) {
90
  $shipping["tax_rate"] = 100 * $order->getShippingTaxAmount() / $order->getShippingAmount();
91
  }
92
  }
@@ -109,17 +109,16 @@ class Aplazame_Aplazame_Model_Api_Serializers extends Varien_Object
109
  protected function getArticles($order)
110
  {
111
  $articles = array();
112
- $products = Mage::getModel('catalog/product');
113
 
114
  /** @var Mage_Sales_Model_Order_Item $order_item */
115
  foreach ($order->getAllVisibleItems() as $order_item) {
116
  $productId = $order_item->getProductId();
117
  /** @var Mage_Catalog_Model_Product $product */
118
- $product = $products->load($productId);
119
  $discounts = $product->getPrice() - $product->getFinalPrice();
120
 
121
  $articles[] = array(
122
- "id" => $order_item->getId(),
123
  "sku" => $order_item->getSku(),
124
  "name" => $order_item->getName(),
125
  "description" => substr($product->getDescription(), 0, 255),
86
  "name"=>$order->getShippingMethod()
87
  ));
88
 
89
+ if ($order->getShippingAmount() > 0) {
90
  $shipping["tax_rate"] = 100 * $order->getShippingTaxAmount() / $order->getShippingAmount();
91
  }
92
  }
109
  protected function getArticles($order)
110
  {
111
  $articles = array();
 
112
 
113
  /** @var Mage_Sales_Model_Order_Item $order_item */
114
  foreach ($order->getAllVisibleItems() as $order_item) {
115
  $productId = $order_item->getProductId();
116
  /** @var Mage_Catalog_Model_Product $product */
117
+ $product = Mage::getModel('catalog/product')->load($productId);
118
  $discounts = $product->getPrice() - $product->getFinalPrice();
119
 
120
  $articles[] = array(
121
+ "id" => $productId,
122
  "sku" => $order_item->getSku(),
123
  "name" => $order_item->getName(),
124
  "description" => substr($product->getDescription(), 0, 255),
app/code/community/Aplazame/Aplazame/Model/CampaignsObserver.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Aplazame_Aplazame_Model_CampaignsObserver extends Mage_Core_Model_Abstract
5
+ {
6
+ /**
7
+ * @param Varien_Event_Observer $observer
8
+ */
9
+ public function campaignsMassActions($observer)
10
+ {
11
+ $block = $observer->getEvent()->getBlock();
12
+ if (!($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction)) {
13
+ return;
14
+ }
15
+
16
+ if ($block->getRequest()->getControllerName() !== 'catalog_product') {
17
+ return;
18
+ }
19
+
20
+ $helper = Mage::helper('aplazame');
21
+ /** @var Mage_Adminhtml_Model_Url $adminUrl */
22
+ $adminUrl = Mage::getModel('adminhtml/url');
23
+
24
+ $block->addItem(
25
+ 'associateProductsToAplazameCampaigns',
26
+ array(
27
+ 'label' => $helper->__('Associate to Aplazame Campaigns'),
28
+ 'url' => $adminUrl->getUrl('adminhtml/aplazame/productsCampaigns'),
29
+ )
30
+ );
31
+ $block->addItem(
32
+ 'removeProductsFromAplazameCampaigns',
33
+ array(
34
+ 'label' => $helper->__('Remove from Aplazame Campaigns'),
35
+ 'url' => $adminUrl->getUrl('adminhtml/aplazame/productsCampaigns'),
36
+ )
37
+ );
38
+ }
39
+
40
+ /**
41
+ * @param Varien_Event_Observer $observer
42
+ */
43
+ public function productCampaigns($observer)
44
+ {
45
+ $block = $observer->getEvent()->getBlock();
46
+ if (!($block instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs)) {
47
+ return;
48
+ }
49
+
50
+ /** @var Mage_Adminhtml_Block_Catalog_Product $product */
51
+ $product = Mage::registry('product');
52
+ if (!$this->_canAddTab($product)) {
53
+ return;
54
+ }
55
+
56
+ $helper = Mage::helper('aplazame');
57
+ /** @var Mage_Adminhtml_Model_Url $adminUrl */
58
+ $adminUrl = Mage::getModel('adminhtml/url');
59
+
60
+ $block->addTabAfter(
61
+ 'aplazameCampaigns',
62
+ array(
63
+ 'label' => $helper->__('Aplazame Campaigns'),
64
+ 'url' => $adminUrl->getUrl(
65
+ 'adminhtml/aplazame/productCampaigns',
66
+ array('id' => $product->getId())
67
+ ),
68
+ 'class' => 'ajax',
69
+ ),
70
+ 'categories'
71
+ );
72
+ }
73
+
74
+ /**
75
+ * @param Mage_Adminhtml_Block_Catalog_Product $product
76
+ * @return bool
77
+ */
78
+ protected function _canAddTab($product)
79
+ {
80
+ if ($product->getId()) {
81
+ return true;
82
+ }
83
+ if (!$product->getAttributeSetId()) {
84
+ return false;
85
+ }
86
+ $request = Mage::app()->getRequest();
87
+ if ($request->getParam('type') == 'configurable') {
88
+ if ($request->getParam('attributes')) {
89
+ return true;
90
+ }
91
+ }
92
+ return false;
93
+ }
94
+ }
app/code/community/Aplazame/Aplazame/Model/Observer.php CHANGED
@@ -61,19 +61,19 @@ class Aplazame_Aplazame_Model_Observer extends Mage_Core_Model_Abstract
61
  */
62
  public function salesOrderPaymentCancel($observer)
63
  {
64
- $code = Aplazame_Aplazame_Model_Payment::METHOD_CODE;
65
-
66
  /** @var Mage_Sales_Model_Order|null $order */
67
  $order = $observer->getOrder();
68
 
69
  $orderId = explode("-", $order->getIncrementId());
70
-
71
- /** @var Mage_Sales_Model_Order $nextOrder */
72
- $nextOrder = Mage::getModel('sales/order')->loadByIncrementId(
73
- $orderId[0] . '-' . ((int)$orderId[1] + 1));
74
-
75
- if ($nextOrder->getId()) {
76
- return $this;
 
 
77
  }
78
 
79
  if (!$this->is_aplazame_payment($order)) {
@@ -82,13 +82,21 @@ class Aplazame_Aplazame_Model_Observer extends Mage_Core_Model_Abstract
82
 
83
  /** @var Aplazame_Aplazame_Model_Api_Client $client */
84
  $client = Mage::getModel('aplazame/api_client');
85
- $client->cancelOrder($order);
 
 
 
 
 
 
 
 
86
 
87
  return $this;
88
  }
89
 
90
  /**
91
- * Method to send a parcial (refund) or total (cancel) refund to aplazame when a creditmemo is created
92
  *
93
  * @param Varien_Event_Observer $observer
94
  * @return $this
61
  */
62
  public function salesOrderPaymentCancel($observer)
63
  {
 
 
64
  /** @var Mage_Sales_Model_Order|null $order */
65
  $order = $observer->getOrder();
66
 
67
  $orderId = explode("-", $order->getIncrementId());
68
+ if (isset($orderId[1])) {
69
+ /** @var Mage_Sales_Model_Order $nextOrder */
70
+ $nextOrder = Mage::getModel('sales/order')->loadByIncrementId(
71
+ $orderId[0] . '-' . ((int)$orderId[1] + 1)
72
+ );
73
+
74
+ if ($nextOrder->getId()) {
75
+ return $this;
76
+ }
77
  }
78
 
79
  if (!$this->is_aplazame_payment($order)) {
82
 
83
  /** @var Aplazame_Aplazame_Model_Api_Client $client */
84
  $client = Mage::getModel('aplazame/api_client');
85
+ try {
86
+ $client->cancelOrder($order);
87
+ } catch (Mage_Core_Exception $e) {
88
+ if ($e->getMessage() === 'Aplazame error code 404: Not found') {
89
+ return $this;
90
+ }
91
+
92
+ throw $e;
93
+ }
94
 
95
  return $this;
96
  }
97
 
98
  /**
99
+ * Method to send a partial (refund) or total (cancel) refund to aplazame when a creditmemo is created
100
  *
101
  * @param Varien_Event_Observer $observer
102
  * @return $this
app/code/community/Aplazame/Aplazame/controllers/AdminHtml/AplazameController.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Aplazame_AdminHtml_AplazameController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /** @var Aplazame_Aplazame_Model_Api_Client */
6
+ private $aplazameClient;
7
+
8
+ public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
9
+ {
10
+ parent::__construct($request, $response, $invokeArgs);
11
+
12
+ $this->aplazameClient = Mage::getModel('aplazame/api_client');
13
+ }
14
+
15
+ public function proxyAction()
16
+ {
17
+ $request = $this->getRequest();
18
+
19
+ $data = json_decode($request->getParam('data'));
20
+
21
+ $response = $this->aplazameClient->request(
22
+ $request->getParam('method'),
23
+ $request->getParam('path'),
24
+ $data
25
+ );
26
+
27
+ $this->getResponse()->setHeader('Content-Type', 'application/json');
28
+
29
+ echo json_encode($response);
30
+ }
31
+
32
+ public function productCampaignsAction()
33
+ {
34
+ $productId = $this->getRequest()->getParam('id');
35
+
36
+ $this->loadLayout();
37
+
38
+ $block = $this->getLayout()->createBlock('aplazame/adminHtml_productCampaigns');
39
+ if (!($block instanceof Aplazame_Aplazame_Block_AdminHtml_ProductCampaigns)) {
40
+ throw new LogicException('Expected Aplazame_Aplazame_Block_AdminHtml_ProductCampaigns');
41
+ }
42
+ $block->setArticlesId(array($productId));
43
+
44
+ $this->getResponse()->setBody($block->toHtml());
45
+ }
46
+
47
+ public function productsCampaignsAction()
48
+ {
49
+ $products = $this->getRequest()->getParam('product');
50
+
51
+ $this->loadLayout();
52
+
53
+ $block = $this->getLayout()->createBlock('aplazame/adminHtml_productsCampaigns');
54
+ if (!($block instanceof Aplazame_Aplazame_Block_AdminHtml_ProductsCampaigns)) {
55
+ throw new LogicException('Expected Aplazame_Aplazame_Block_AdminHtml_ProductsCampaigns');
56
+ }
57
+ $block->setArticlesId($products);
58
+
59
+ $this->getLayout()->getBlock('content')->append($block);
60
+
61
+ $this->renderLayout();
62
+ }
63
+ }
app/code/community/Aplazame/Aplazame/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Aplazame_Aplazame>
5
- <version>0.2.2</version>
6
  </Aplazame_Aplazame>
7
  </modules>
8
  <global>
@@ -28,7 +28,36 @@
28
  </aplazame>
29
  </helpers>
30
  </global>
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  <adminhtml>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  <events>
33
  <sales_order_place_after>
34
  <observers>
@@ -66,6 +95,20 @@
66
  </Aplazame>
67
  </observers>
68
  </sales_order_payment_refund>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  </events>
70
  </adminhtml>
71
 
2
  <config>
3
  <modules>
4
  <Aplazame_Aplazame>
5
+ <version>0.3.2</version>
6
  </Aplazame_Aplazame>
7
  </modules>
8
  <global>
28
  </aplazame>
29
  </helpers>
30
  </global>
31
+
32
+ <admin>
33
+ <routers>
34
+ <adminhtml>
35
+ <args>
36
+ <modules>
37
+ <Aplazame_Aplazame after="Mage_Adminhtml">Aplazame_Aplazame_AdminHtml</Aplazame_Aplazame>
38
+ </modules>
39
+ </args>
40
+ </adminhtml>
41
+ </routers>
42
+ </admin>
43
+
44
  <adminhtml>
45
+ <layout>
46
+ <updates>
47
+ <aplazame>
48
+ <file>aplazame.xml</file>
49
+ </aplazame>
50
+ </updates>
51
+ </layout>
52
+ <translate>
53
+ <modules>
54
+ <Aplazame_Aplazame>
55
+ <files>
56
+ <default>Aplazame_Aplazame.csv</default>
57
+ </files>
58
+ </Aplazame_Aplazame>
59
+ </modules>
60
+ </translate>
61
  <events>
62
  <sales_order_place_after>
63
  <observers>
95
  </Aplazame>
96
  </observers>
97
  </sales_order_payment_refund>
98
+ <core_block_abstract_prepare_layout_after>
99
+ <observers>
100
+ <campaignsMassActions>
101
+ <type>singleton</type>
102
+ <class>aplazame/campaignsObserver</class>
103
+ <method>campaignsMassActions</method>
104
+ </campaignsMassActions>
105
+ <productCampaigns>
106
+ <type>singleton</type>
107
+ <class>aplazame/campaignsObserver</class>
108
+ <method>productCampaigns</method>
109
+ </productCampaigns>
110
+ </observers>
111
+ </core_block_abstract_prepare_layout_after>
112
  </events>
113
  </adminhtml>
114
 
app/code/community/Aplazame/Aplazame/etc/system.xml CHANGED
@@ -31,7 +31,7 @@
31
  <show_in_store>1</show_in_store>
32
  </sandbox>
33
  <secret_api_key translate="label">
34
- <label>Secret API Key</label>
35
  <frontend_type>obscure</frontend_type>
36
  <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
37
  <sort_order>30</sort_order>
@@ -48,7 +48,7 @@
48
  <show_in_store>1</show_in_store>
49
  </public_api_key>
50
  <button>
51
- <label>Button CSS Selector</label>
52
  <frontend_type>text</frontend_type>
53
  <sort_order>50</sort_order>
54
  <show_in_default>1</show_in_default>
@@ -56,7 +56,7 @@
56
  <show_in_store>1</show_in_store>
57
  </button>
58
  <button_img>
59
- <label>Button Image</label>
60
  <frontend_type>text</frontend_type>
61
  <sort_order>60</sort_order>
62
  <show_in_default>1</show_in_default>
31
  <show_in_store>1</show_in_store>
32
  </sandbox>
33
  <secret_api_key translate="label">
34
+ <label>Private API Key</label>
35
  <frontend_type>obscure</frontend_type>
36
  <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
37
  <sort_order>30</sort_order>
48
  <show_in_store>1</show_in_store>
49
  </public_api_key>
50
  <button>
51
+ <label>Aplazame Button CSS Selector</label>
52
  <frontend_type>text</frontend_type>
53
  <sort_order>50</sort_order>
54
  <show_in_default>1</show_in_default>
56
  <show_in_store>1</show_in_store>
57
  </button>
58
  <button_img>
59
+ <label>Aplazame Button Image</label>
60
  <frontend_type>text</frontend_type>
61
  <sort_order>60</sort_order>
62
  <show_in_default>1</show_in_default>
app/design/adminhtml/default/default/layout/aplazame.xml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <layout>
2
+ </layout>
app/design/adminhtml/default/default/template/aplazame/productCampaigns.phtml ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** @var Aplazame_Aplazame_Block_AdminHtml_ProductCampaigns $this */
4
+
5
+ ?>
6
+
7
+ <div class="entry-edit">
8
+ <div class="entry-edit-head">
9
+ <h4 class="icon-head head-edit-form fieldset-legend">
10
+ <?php echo $this->__('Aplazame Campaigns'); ?>
11
+ </h4>
12
+ </div>
13
+
14
+ <fieldset>
15
+ <legend>
16
+ <?php echo $this->__('Campaigns'); ?>
17
+ </legend>
18
+
19
+ <table cellspacing="0" class="form-list">
20
+ <tbody id="aplazame_campaigns_container">
21
+ </tbody>
22
+ </table>
23
+ </fieldset>
24
+ </div>
25
+
26
+ <script>
27
+ var apiProxyEndpoint = "<?php echo $this->getUrl('adminhtml/aplazame/proxy') ?>";
28
+ var campaignsContainer = document.getElementById("aplazame_campaigns_container");
29
+
30
+ var articles = <?php echo json_encode($this->getArticles()) ?>;
31
+
32
+ function associateArticlesToCampaign(articles, campaignId) {
33
+ apiRequest("POST", "/me/campaigns/" + campaignId + "/articles", articles, function() {});
34
+ }
35
+
36
+ function removeArticlesFromCampaign(articles, campaignId) {
37
+ var articleIds = articles.map(function (article) {
38
+ return article.id;
39
+ });
40
+
41
+ apiRequest("DELETE", "/me/campaigns/" + campaignId + "/articles?article-mid=" + articleIds.join(","), null, function() {});
42
+ }
43
+
44
+ /**
45
+ * @param {MouseEvent} event
46
+ */
47
+ function campaignToggle(event)
48
+ {
49
+ /**
50
+ * @type {HTMLInputElement|EventTarget}
51
+ */
52
+ var checkbox = event.target;
53
+
54
+ var campaignId = checkbox["data-campaignId"];
55
+ if (checkbox.checked) {
56
+ associateArticlesToCampaign(articles, campaignId);
57
+ } else {
58
+ removeArticlesFromCampaign(articles, campaignId);
59
+ }
60
+ }
61
+
62
+ function insertCampaign(campaign) {
63
+
64
+ var inputId = "campaign_" + campaign.id;
65
+ /**
66
+ * @type {HTMLInputElement|Element}
67
+ */
68
+ var checkbox = document.createElement("input");
69
+ checkbox.type = "checkbox";
70
+ checkbox.name = "campaigns[]";
71
+ checkbox.value = campaign.id;
72
+ checkbox.id = inputId;
73
+ checkbox["data-campaignId"] = campaign.id;
74
+ checkbox.addEventListener("click", campaignToggle, false);
75
+
76
+ /**
77
+ * @type {HTMLLabelElement|Element}
78
+ */
79
+ var label = document.createElement("label");
80
+ label.htmlFor = inputId;
81
+
82
+ label.appendChild(document.createTextNode(campaign.name));
83
+
84
+ var tr = document.createElement("tr");
85
+
86
+ var tdLabel = document.createElement("td");
87
+ tdLabel.className = "label";
88
+ tdLabel.appendChild(label);
89
+
90
+ var tdValue = document.createElement("td");
91
+ tdValue.className = "value";
92
+ tdValue.appendChild(checkbox);
93
+
94
+ tr.appendChild(tdLabel);
95
+ tr.appendChild(tdValue);
96
+
97
+ campaignsContainer.appendChild(tr);
98
+ }
99
+
100
+ function displayCampaigns(campaigns) {
101
+ campaigns.forEach(insertCampaign);
102
+ }
103
+
104
+ function selectCampaigns(campaigns) {
105
+ campaigns.forEach(function (campaign) {
106
+ var inputId = "campaign_" + campaign.id;
107
+ document.getElementById(inputId).checked = true;
108
+ });
109
+
110
+ }
111
+
112
+ function apiRequest(method, path, data, callback) {
113
+ new Ajax.Request(apiProxyEndpoint, {
114
+ method: "POST",
115
+ parameters: {
116
+ method: method,
117
+ path: path,
118
+ data: JSON.stringify(data)
119
+ },
120
+ onComplete: function (transport) {
121
+ var payload = JSON.parse(transport.responseText);
122
+
123
+ callback(payload);
124
+ }
125
+ });
126
+ }
127
+
128
+ apiRequest("GET", "/me/campaigns", null, function(payload) {
129
+ var campaigns = payload.results;
130
+
131
+ apiRequest("GET", "/me/campaigns?articles-mid=" + articles[0].id, null, function(payload) {
132
+ var selectedCampaigns = payload.results;
133
+
134
+ displayCampaigns(campaigns);
135
+ selectCampaigns(selectedCampaigns);
136
+ });
137
+ });
138
+ </script>
app/design/adminhtml/default/default/template/aplazame/productsCampaigns.phtml ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** @var Aplazame_Aplazame_Block_AdminHtml_ProductCampaigns $this */
4
+
5
+ ?>
6
+
7
+ <div class="entry-edit">
8
+ <div class="entry-edit-head">
9
+ <h4 class="icon-head head-edit-form fieldset-legend">
10
+ <?php echo $this->__('Aplazame Campaigns'); ?>
11
+ </h4>
12
+ </div>
13
+
14
+ <fieldset>
15
+ <legend>
16
+ <?php echo $this->__('Campaigns'); ?>
17
+ </legend>
18
+
19
+ <table cellspacing="0" class="form-list">
20
+ <tbody id="aplazame_campaigns_container">
21
+ </tbody>
22
+ </table>
23
+ </fieldset>
24
+
25
+ <button type="button" name="associateProductsToCampaigns" id="associateProductsToCampaigns" onclick="associateArticlesToCampaigns()">
26
+ <?php echo $this->__('Associate products to selected campaigns'); ?>
27
+ </button>
28
+
29
+ <button type="button" name="removeProductsFromCampaigns" id="removeProductsFromCampaigns" onclick="removeArticlesFromCampaigns()">
30
+ <?php echo $this->__('Remove products from selected campaigns'); ?>
31
+ </button>
32
+ </div>
33
+
34
+ <script>
35
+ var apiProxyEndpoint = "<?php echo $this->getUrl('adminhtml/aplazame/proxy') ?>";
36
+ var campaignsContainer = document.getElementById("aplazame_campaigns_container");
37
+
38
+ var articles = <?php echo json_encode($this->getArticles()) ?>;
39
+
40
+ function associateArticlesToCampaign(articles, campaignId) {
41
+ apiRequest("POST", "/me/campaigns/" + campaignId + "/articles", articles, function() {});
42
+ }
43
+
44
+ function removeArticlesFromCampaign(articles, campaignId) {
45
+ var articleIds = articles.map(function (article) {
46
+ return article.id;
47
+ });
48
+
49
+ apiRequest("DELETE", "/me/campaigns/" + campaignId + "/articles?article-mid=" + articleIds.join(","), null, function() {});
50
+ }
51
+
52
+ function associateArticlesToCampaigns() {
53
+ var campaignsId = getSelectedCampaigns();
54
+
55
+ campaignsId.forEach(function (campaignId) {
56
+ associateArticlesToCampaign(articles, campaignId);
57
+ });
58
+ }
59
+
60
+ function removeArticlesFromCampaigns() {
61
+ var campaignsId = getSelectedCampaigns();
62
+
63
+ campaignsId.forEach(function (campaignId) {
64
+ removeArticlesFromCampaign(articles, campaignId);
65
+ });
66
+ }
67
+
68
+ function getSelectedCampaigns()
69
+ {
70
+ var checkboxes = document.getElementsByName("campaigns");
71
+ var selected = [];
72
+ for (var i = 0; i < checkboxes.length; ++i) {
73
+ var checkbox = checkboxes[i];
74
+ if (checkbox.checked) {
75
+ selected.push(checkbox["data-campaignId"]);
76
+ }
77
+ }
78
+
79
+ return selected;
80
+ }
81
+
82
+ function insertCampaign(campaign) {
83
+
84
+ var inputId = "campaign_" + campaign.id;
85
+ /**
86
+ * @type {HTMLInputElement|Element}
87
+ */
88
+ var checkbox = document.createElement("input");
89
+ checkbox.type = "checkbox";
90
+ checkbox.name = "campaigns";
91
+ checkbox.value = campaign.id;
92
+ checkbox.id = inputId;
93
+ checkbox["data-campaignId"] = campaign.id;
94
+
95
+ /**
96
+ * @type {HTMLLabelElement|Element}
97
+ */
98
+ var label = document.createElement("label");
99
+ label.htmlFor = inputId;
100
+
101
+ label.appendChild(document.createTextNode(campaign.name));
102
+
103
+ var tr = document.createElement("tr");
104
+
105
+ var tdLabel = document.createElement("td");
106
+ tdLabel.className = "label";
107
+ tdLabel.appendChild(label);
108
+
109
+ var tdValue = document.createElement("td");
110
+ tdValue.className = "value";
111
+ tdValue.appendChild(checkbox);
112
+
113
+ tr.appendChild(tdLabel);
114
+ tr.appendChild(tdValue);
115
+
116
+ campaignsContainer.appendChild(tr);
117
+ }
118
+
119
+ function displayCampaigns(campaigns) {
120
+ campaigns.forEach(insertCampaign);
121
+ }
122
+
123
+ function apiRequest(method, path, data, callback) {
124
+ new Ajax.Request(apiProxyEndpoint, {
125
+ method: "POST",
126
+ parameters: {
127
+ method: method,
128
+ path: path,
129
+ data: JSON.stringify(data)
130
+ },
131
+ onComplete: function (transport) {
132
+ var payload = JSON.parse(transport.responseText);
133
+
134
+ callback(payload);
135
+ }
136
+ });
137
+ }
138
+
139
+ apiRequest("GET", "/me/campaigns", null, function(payload) {
140
+ var campaigns = payload.results;
141
+
142
+ displayCampaigns(campaigns);
143
+ });
144
+ </script>
app/design/frontend/base/default/template/aplazame/payment/common.phtml CHANGED
@@ -1,8 +1,14 @@
1
- <?php $aplazameJsUri = getenv('APLAZAME_JS_URI') ? getenv('APLAZAME_JS_URI') : 'https://aplazame.com/static/aplazame.js'; ?>
 
 
 
 
 
2
 
3
  <script
4
  type="text/javascript"
5
  src="<?php echo $aplazameJsUri; ?>"
 
6
  data-aplazame="publicKey: <?php echo Mage::getStoreConfig('payment/aplazame/public_api_key') ?>"
7
  data-sandbox="<?php echo Mage::getStoreConfig('payment/aplazame/sandbox')?'true':'false' ?>"
8
  ></script>
1
+ <?php
2
+ /** @var Aplazame_Aplazame_Model_Api_Client $client */
3
+ $client = Mage::getModel('aplazame/api_client');
4
+
5
+ $aplazameJsUri = getenv('APLAZAME_JS_URI') ? getenv('APLAZAME_JS_URI') : 'https://aplazame.com/static/aplazame.js';
6
+ ?>
7
 
8
  <script
9
  type="text/javascript"
10
  src="<?php echo $aplazameJsUri; ?>"
11
+ data-api-host="<?php echo $client->apiBaseUri; ?>"
12
  data-aplazame="publicKey: <?php echo Mage::getStoreConfig('payment/aplazame/public_api_key') ?>"
13
  data-sandbox="<?php echo Mage::getStoreConfig('payment/aplazame/sandbox')?'true':'false' ?>"
14
  ></script>
app/locale/es_ES/Aplazame_Aplazame.csv CHANGED
@@ -1,2 +1,24 @@
 
 
 
 
1
  "Automatic invoice generation","Facturar automáticamente"
2
- "Applicable only if the payment was successful.","Genera factura si el pago es correcto."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Private API Key","Clave API privada"
2
+ "Public API Key","Clave API pública"
3
+ "Aplazame Button CSS Selector","Selector CSS del botón de Aplazame"
4
+ "Aplazame Button Image","Imagen del botón de Aplazame"
5
  "Automatic invoice generation","Facturar automáticamente"
6
+ "Applicable only if the payment was successful.","Genera factura si el pago es correcto."
7
+ "Authentication header format is invalid.","La cabecera Authentication es inválida."
8
+ "Authentication header is absent.","La cabecera Authentication está ausente."
9
+ "Your order has expired.","Tu compra ha expirado."
10
+ "Confirm has no checkout token.","Confirm no tiene el token de checkout."
11
+ "History has no checkout token.","History no tiene el token de checkout."
12
+ "Order not found.","Compra no encontrada."
13
+ "You don\'t have permissions.","No tienes permisos."
14
+ "Cannot add the item to shopping cart.","No se puede añadir el producto al carro de compra."
15
+ "Aplazame error code ","Aplazame error código "
16
+ "Invalid amount for authorization.","Cantidad inválida para autorizar."
17
+ "Aplazame charge id not returned from call.","ID de cargo aplazame no devuelto."
18
+ "Associate to Aplazame Campaigns","Asociar a las campañas Aplazame"
19
+ "Remove from Aplazame Campaigns","Eliminar de las campañas Aplazame"
20
+ "Aplazame Campaigns","Aplazame Campaigns"
21
+ "Campaigns","Campañas"
22
+ "Aplazame Campaigns","Campañas Aplazame"
23
+ "Associate products to selected campaigns","Asociar productos a las campañas seleccionadas"
24
+ "Remove products from selected campaigns","Eliminar productos de las campañas seleccionadas"
package.xml CHANGED
@@ -1,20 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Aplazame_Aplazame</name>
4
- <version>0.2.2</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Aplazame, a consumer credit company, offers a payment system that can be used by online buyers to receive funding for their purchases.</summary>
10
  <description>Aplazame, a consumer credit company, offers a payment system that can be used by online buyers to receive funding for their purchases.</description>
11
- <notes>* Widget cart&#xD;
12
- * Refund observer&#xD;
13
- * Widget data view</notes>
14
  <authors><author><name>Aplazame</name><user>aplazame</user><email>dev@aplazame.com</email></author></authors>
15
- <date>2016-07-06</date>
16
- <time>18:19:52</time>
17
- <contents><target name="magecommunity"><dir name="Aplazame"><dir name="Aplazame"><dir name="Block"><dir name="Checkout"><dir name="Cart"><file name="Widget.php" hash="3942489d065d22d356ce3ffcef1a801f"/></dir><dir name="Onepage"><file name="Billing.php" hash="d908bf39c8555f436f8841ff30b520f1"/><file name="Shipping.php" hash="8968979cc9140f2f6236ee9f2fbafc98"/></dir></dir><dir name="Payment"><file name="Form.php" hash="d23f592da9ed9ac11b4432f49c2783ac"/><file name="Info.php" hash="eeadafff816256593595d261c9e3b5f8"/><file name="Redirect.php" hash="43810d5a8a3201bc8263cddf01156732"/></dir><dir name="Product"><file name="Widget.php" hash="672f3ce4f644fa93206bbbf908a38b15"/></dir></dir><dir name="Helper"><file name="Cart.php" hash="f95a90db86fb4732f7d3ef1fb6a2322a"/><file name="Data.php" hash="35cc7eb331ff48912492cce397918270"/></dir><dir name="Model"><dir name="Api"><file name="Client.php" hash="af66459f7c0abdd97fcde9fd279757cb"/><file name="Serializers.php" hash="b70f21d4e8beeda9f015c0eb18f513ac"/></dir><file name="Config.php" hash="ecff6c7d937b86802dc6c98139b1d7c4"/><file name="Observer.php" hash="c3f0d2877615142f99a5d872363107f5"/><file name="Payment.php" hash="5026810ce6ccb7a44ac682af899e3d51"/></dir><dir name="controllers"><file name="PaymentController.php" hash="66fa5f442de6ba7f9c95f3a49fddeb9f"/></dir><dir name="etc"><file name="config.xml" hash="a34136dabe19ac238f523deaad9b5d5e"/><file name="system.xml" hash="4b6a34f80670427799ebaca4c11d0cb4"/></dir></dir></dir></target><target name="magelib"><dir name="Aplazame"><dir name="Aplazame"><file name="Util.php" hash="039c093cbf8c1859cd7e159829ec8e82"/></dir><file name="Aplazame.php" hash="e67f083f4079693da19cd634d7e5bae9"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="aplazame.xml" hash=""/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="aplazame.xml" hash="e56ae75dc4088c1590d986904ecee676"/></dir><dir name="template"><dir name="aplazame"><dir name="checkout"><dir name="cart"><file name="widget.phtml" hash="d81d7b50e0289f54bd653f9c865712c5"/></dir></dir><dir name="payment"><file name="common.phtml" hash="4832e7710b4c43dad8bb2dcd81e4737d"/><file name="form.phtml" hash="47d03cc30037d3136790a7e88942c8b9"/></dir><dir name="product"><file name="widget.phtml" hash="381b9f5d90cfe4eb5394a862838d7993"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir><dir name="es_ES"><file name="Aplazame_Aplazame.csv" hash="01ee93633a293309873bbba03b3c2a8f"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Aplazame_Aplazame.xml" hash="d816c618a1829401ca0314c3406482a1"/></dir></target></contents>
18
  <compatible/>
19
  <dependencies><required><php><min>5.2.0</min><max>7.0.0</max></php></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Aplazame_Aplazame</name>
4
+ <version>0.3.2</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Aplazame, a consumer credit company, offers a payment system that can be used by online buyers to receive funding for their purchases.</summary>
10
  <description>Aplazame, a consumer credit company, offers a payment system that can be used by online buyers to receive funding for their purchases.</description>
11
+ <notes>* Order cancellation improvements.</notes>
 
 
12
  <authors><author><name>Aplazame</name><user>aplazame</user><email>dev@aplazame.com</email></author></authors>
13
+ <date>2016-09-15</date>
14
+ <time>09:20:03</time>
15
+ <contents><target name="magecommunity"><dir name="Aplazame"><dir name="Aplazame"><dir name="Block"><dir name="AdminHtml"><file name="ProductCampaigns.php" hash="c2cb087af982d7ed40cecc1cba48db00"/><file name="ProductsCampaigns.php" hash="4e654f2a4b65979229e2adcedda2f287"/></dir><dir name="Checkout"><dir name="Cart"><file name="Widget.php" hash="3942489d065d22d356ce3ffcef1a801f"/></dir><dir name="Onepage"><file name="Billing.php" hash="d908bf39c8555f436f8841ff30b520f1"/><file name="Shipping.php" hash="8968979cc9140f2f6236ee9f2fbafc98"/></dir></dir><dir name="Payment"><file name="Form.php" hash="d23f592da9ed9ac11b4432f49c2783ac"/><file name="Info.php" hash="eeadafff816256593595d261c9e3b5f8"/><file name="Redirect.php" hash="ad0b51fba8eb624c215680d19678df30"/></dir><dir name="Product"><file name="Widget.php" hash="672f3ce4f644fa93206bbbf908a38b15"/></dir></dir><dir name="Helper"><file name="Cart.php" hash="f95a90db86fb4732f7d3ef1fb6a2322a"/><file name="Data.php" hash="35cc7eb331ff48912492cce397918270"/></dir><dir name="Model"><dir name="Api"><file name="Client.php" hash="a6ac5731d75daee8d2e96a1c052778c5"/><file name="Serializers.php" hash="564d5ee885e3bbb9d2c623ed57dba52e"/></dir><file name="CampaignsObserver.php" hash="8fad045c72f366897e41d571ac9290f5"/><file name="Config.php" hash="ecff6c7d937b86802dc6c98139b1d7c4"/><file name="Observer.php" hash="1d418013ae7fc2c68cdd99c931b2c7e6"/><file name="Payment.php" hash="5026810ce6ccb7a44ac682af899e3d51"/></dir><dir name="controllers"><dir name="AdminHtml"><file name="AplazameController.php" hash="455ef1ac99ae9b43902ad65f408a95ef"/></dir><file name="PaymentController.php" hash="66fa5f442de6ba7f9c95f3a49fddeb9f"/></dir><dir name="etc"><file name="config.xml" hash="26ad10bf4bc5f12ae998a27318ad793b"/><file name="system.xml" hash="714e49e7b52a305c7f8ceebefe34adcb"/></dir></dir></dir></target><target name="magelib"><dir name="Aplazame"><dir name="Aplazame"><file name="Util.php" hash="039c093cbf8c1859cd7e159829ec8e82"/></dir><file name="Aplazame.php" hash="e67f083f4079693da19cd634d7e5bae9"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="aplazame.xml" hash="79024c230729c2757d9b372278411308"/></dir><dir name="template"><dir name="aplazame"><file name="productCampaigns.phtml" hash="9d9f685a918b8f7a7042ba531332991a"/><file name="productsCampaigns.phtml" hash="25e22d4540ebbb7cbb87a516b66393c6"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="aplazame.xml" hash="e56ae75dc4088c1590d986904ecee676"/></dir><dir name="template"><dir name="aplazame"><dir name="checkout"><dir name="cart"><file name="widget.phtml" hash="d81d7b50e0289f54bd653f9c865712c5"/></dir></dir><dir name="payment"><file name="common.phtml" hash="128898cf9895997954ea62da3ce091c9"/><file name="form.phtml" hash="47d03cc30037d3136790a7e88942c8b9"/></dir><dir name="product"><file name="widget.phtml" hash="381b9f5d90cfe4eb5394a862838d7993"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir><dir name="es_ES"><file name="Aplazame_Aplazame.csv" hash="2bbbffece8ee09579e94c8e810bfde6a"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Aplazame_Aplazame.xml" hash="d816c618a1829401ca0314c3406482a1"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>7.0.0</max></php></required></dependencies>
18
  </package>