h5mage-commerceapi - Version 0.0.3

Version Notes

Reference API

Download this release

Release Info

Developer H5mag
Extension h5mage-commerceapi
Version 0.0.3
Comparing to
See all releases


Code changes from version 0.0.2 to 0.0.3

app/code/community/H5mag/ShopApi/Model/Generic.php CHANGED
@@ -12,7 +12,7 @@
12
  * obtain it through the world-wide-web, please send an email
13
  * to license@h5mag.com so we can send you a copy immediately.
14
  *
15
- * @copyright Copyright (c) 2013 H5mag Inc. (http://www.h5mag.com)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
@@ -69,30 +69,18 @@ class H5mag_ShopApi_Model_Generic extends H5mag_ShopApi_Model_Product {
69
 
70
  if ($product->getId()) {
71
  // Add product description to data
72
- $this->data = array(
73
- 'id' => $product->getId(),
74
- 'name' => $product->getName(),
75
- 'text' => $product->getDescription(),
76
- );
77
- $this->data['locale'] = (!empty($this->locale)) ? $this->locale : Mage::app()->getStore()->getConfig('general/locale/code');
78
-
79
- // Get variants of this product
80
  $variants = array();
 
81
  if ($product->isConfigurable()) {
82
  $variants = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
83
- $this->data['variants'] = array();
84
  } else if ($product->getTypeId() == 'simple') {
85
- $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
86
- if(!$parentIds) {
87
  $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
88
- if(isset($parentIds[0])){
89
- $parent = Mage::getModel('catalog/product')->load($parentIds[0]);
90
- $variants = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$parent);
91
- $variants_list = array();
92
- foreach($variants as $variant) {
93
- array_push($variants_list, Mage::getModel('catalog/product')->load($variant->getId()));
94
- }
95
- $variants = $variants_list;
96
  } else {
97
  $variants[] = $product;
98
  }
@@ -100,16 +88,48 @@ class H5mag_ShopApi_Model_Generic extends H5mag_ShopApi_Model_Product {
100
  $variants[] = $product;
101
  }
102
  }
 
 
 
 
 
 
 
 
103
 
104
  // Add variants to data
105
  foreach ($variants as $variant) {
106
  $store = Mage::getModel('core/store')->load($variant->getStoreId());
107
  $data = array();
108
  $data['currency'] = $store->getCurrentCurrencyCode();
109
- $data['id'] = $variant->getSku(); // Send the SKU instead of the actual database id
110
- $data['name'] = $variant->getName();
111
- var_dump($variant);
112
- $data['price'] = $variant->getPrice() * 100; // H5mag uses cents
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  $data['pictures'] = array();
114
  $data['stock'] = 0;
115
  $data['available'] = false;
@@ -122,18 +142,14 @@ class H5mag_ShopApi_Model_Generic extends H5mag_ShopApi_Model_Product {
122
  if ($image = $variant->getImageUrl()) $data['pictures'][] = $image;
123
  if ($image = $variant->getSmallImageUrl()) $data['pictures'][] = $image;
124
  if ($image = $variant->getThumbnailUrl()) $data['pictures'][] = $image;
125
-
126
- // Optional properties
127
- // TODO: Move these to config.xml and make an admin panel where these can be configured
128
- /*if ($variant->offsetExists('color') && $color = $variant->getAttributeText('color') ) {
129
- $data['color'] = $color;
130
- }
131
- if ($variant->offsetExists('hexcolor') && $hex_color = $variant->getAttributeText('hexcolor') ) {
132
- $data['display-color'] = "#{$hex_color}";
133
- }*/
134
 
135
  if ($dimensions = $variant->getDimensions()) $data['dimensions'] = $dimensions;
136
- $this->data['variants'][] = $data;
 
 
 
 
 
137
  }
138
  }
139
  }
12
  * obtain it through the world-wide-web, please send an email
13
  * to license@h5mag.com so we can send you a copy immediately.
14
  *
15
+ * @copyright Copyright (c) 2015 H5mag Inc. (http://www.h5mag.com)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
69
 
70
  if ($product->getId()) {
71
  // Add product description to data
72
+
 
 
 
 
 
 
 
73
  $variants = array();
74
+
75
  if ($product->isConfigurable()) {
76
  $variants = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
 
77
  } else if ($product->getTypeId() == 'simple') {
78
+ $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getTypeId);
79
+ if (empty($parentIds)) {
80
  $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
81
+ if (isset($parentIds[0])) {
82
+ $product = Mage::getModel('catalog/product')->load($parentIds[0]);
83
+ $variants = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);
 
 
 
 
 
84
  } else {
85
  $variants[] = $product;
86
  }
88
  $variants[] = $product;
89
  }
90
  }
91
+
92
+ $this->data = array(
93
+ 'id' => $product->getId(),
94
+ 'name' => $product->getName(),
95
+ 'text' => $product->getDescription(),
96
+ );
97
+ $this->data['locale'] = (!empty($this->locale)) ? $this->locale : Mage::app()->getStore()->getConfig('general/locale/code');
98
+
99
 
100
  // Add variants to data
101
  foreach ($variants as $variant) {
102
  $store = Mage::getModel('core/store')->load($variant->getStoreId());
103
  $data = array();
104
  $data['currency'] = $store->getCurrentCurrencyCode();
105
+ $data['id'] = $variant->getSKU(); // Send the SKU instead of the actual database id
106
+ if ($product->isConfigurable()) {
107
+ if ($variant->getName() == null) {
108
+ $nameSuffix = '';
109
+ $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
110
+ $attributeOptions = array();
111
+ foreach ($productAttributeOptions as $productAttribute) {
112
+ $nameSuffix .= ' ' . $variant->getAttributeText(strtolower($productAttribute['label']));
113
+ }
114
+
115
+ $data['name'] = $product->getName() . $nameSuffix;
116
+ $data['price'] = $product->getPrice() * 100;
117
+ } else {
118
+ $nameSuffix = '';
119
+ $nameSuffix = '';
120
+ $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
121
+ $attributeOptions = array();
122
+ foreach ($productAttributeOptions as $productAttribute) {
123
+ $nameSuffix .= ' ' . $variant->getAttributeText(strtolower($productAttribute['label']));
124
+ }
125
+ $data['name'] = $variant->getName() . $nameSuffix;
126
+ $data['price'] = $variant->getPrice() * 100; // H5mag uses cents
127
+ }
128
+ } else {
129
+ $data['name'] = $variant->getName();
130
+ $data['price'] = $variant->getPrice() * 100;
131
+ }
132
+
133
  $data['pictures'] = array();
134
  $data['stock'] = 0;
135
  $data['available'] = false;
142
  if ($image = $variant->getImageUrl()) $data['pictures'][] = $image;
143
  if ($image = $variant->getSmallImageUrl()) $data['pictures'][] = $image;
144
  if ($image = $variant->getThumbnailUrl()) $data['pictures'][] = $image;
 
 
 
 
 
 
 
 
 
145
 
146
  if ($dimensions = $variant->getDimensions()) $data['dimensions'] = $dimensions;
147
+
148
+ if ($id == $variant->getId()) {
149
+ array_unshift($this->data['variants'], $data);
150
+ } else {
151
+ $this->data['variants'][] = $data;
152
+ }
153
  }
154
  }
155
  }
app/code/community/H5mag/ShopApi/Model/Order/Observer.php CHANGED
@@ -12,7 +12,7 @@
12
  * obtain it through the world-wide-web, please send an email
13
  * to license@h5mag.com so we can send you a copy immediately.
14
  *
15
- * @copyright Copyright (c) 2013 H5mag Inc. (http://www.h5mag.com)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
12
  * obtain it through the world-wide-web, please send an email
13
  * to license@h5mag.com so we can send you a copy immediately.
14
  *
15
+ * @copyright Copyright (c) 2015 H5mag Inc. (http://www.h5mag.com)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
app/code/community/H5mag/ShopApi/Model/Product.php CHANGED
@@ -12,7 +12,7 @@
12
  * obtain it through the world-wide-web, please send an email
13
  * to license@h5mag.com so we can send you a copy immediately.
14
  *
15
- * @copyright Copyright (c) 2013 H5mag Inc. (http://www.h5mag.com)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
12
  * obtain it through the world-wide-web, please send an email
13
  * to license@h5mag.com so we can send you a copy immediately.
14
  *
15
+ * @copyright Copyright (c) 2015 H5mag Inc. (http://www.h5mag.com)
16
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
  */
18
 
app/code/community/H5mag/ShopApi/controllers/CheckoutController.php CHANGED
@@ -14,7 +14,7 @@
14
  *
15
  * @category H5mag ShopApi
16
  * @package H5mag_ShopApi
17
- * @copyright Copyright (c) 2013 H5mag (http://www.h5mag.com)
18
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
  */
20
  class H5mag_ShopApi_CheckoutController extends Mage_Core_Controller_Front_Action {
@@ -42,10 +42,9 @@
42
  // Update cart in session
43
  if ($cart->getItemsCount() > 0) {
44
  $empty_cart = $this->getRequest()->getParam('cart');
45
- $url = strtolower(Mage::app()->getStore()->getConfig('h5mag_shopapi_magazine/general/url'));
46
- if (preg_match('/^http:\/\//', $url) == false) $url = "http://{$url}";
47
- if (preg_match('\/$') == false) $url .= '/';
48
- Mage::getSingleton('core/session')->setH5magShopApiCartUrl("{$url}system/shop/empty-cart?cart={$empty_cart}");
49
  $this->_redirect('checkout/cart');
50
  } else {
51
  echo 'Products out-of-stock.';
14
  *
15
  * @category H5mag ShopApi
16
  * @package H5mag_ShopApi
17
+ * @copyright Copyright (c) 2015 H5mag (http://www.h5mag.com)
18
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
  */
20
  class H5mag_ShopApi_CheckoutController extends Mage_Core_Controller_Front_Action {
42
  // Update cart in session
43
  if ($cart->getItemsCount() > 0) {
44
  $empty_cart = $this->getRequest()->getParam('cart');
45
+ $url = Mage::app()->getStore()->getConfig('h5mag_shopapi_magazine/general/url');
46
+ $url = rtrim($url, '/');
47
+ Mage::getSingleton('core/session')->setH5magShopApiCartUrl("{$url}/system/shop/empty-cart?cart={$empty_cart}");
 
48
  $this->_redirect('checkout/cart');
49
  } else {
50
  echo 'Products out-of-stock.';
app/code/community/H5mag/ShopApi/controllers/IndexController.php CHANGED
@@ -14,7 +14,7 @@
14
  *
15
  * @category H5mag ShopApi
16
  * @package H5mag_ShopApi
17
- * @copyright Copyright (c) 2013 H5mag (http://www.h5mag.com)
18
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
  */
20
  class H5mag_ShopApi_IndexController extends Mage_Core_Controller_Front_Action {
@@ -40,7 +40,8 @@ class H5mag_ShopApi_IndexController extends Mage_Core_Controller_Front_Action {
40
  private function send($data){
41
  header('Content-Type: application/json; charset=utf-8');
42
  header('Content-Length: '.strlen($data));
43
- die($data);
 
44
  }
45
 
46
  }
14
  *
15
  * @category H5mag ShopApi
16
  * @package H5mag_ShopApi
17
+ * @copyright Copyright (c) 2015 H5mag (http://www.h5mag.com)
18
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
  */
20
  class H5mag_ShopApi_IndexController extends Mage_Core_Controller_Front_Action {
40
  private function send($data){
41
  header('Content-Type: application/json; charset=utf-8');
42
  header('Content-Length: '.strlen($data));
43
+ echo ($data);
44
+ exit;
45
  }
46
 
47
  }
app/code/community/H5mag/ShopApi/etc/system.xml CHANGED
@@ -28,6 +28,7 @@
28
  <comment>The URL of the H5mag magazine</comment>
29
  <frontend_type>text</frontend_type>
30
  <sort_order>10</sort_order>
 
31
  <show_in_default>1</show_in_default>
32
  <show_in_website>1</show_in_website>
33
  <show_in_store>1</show_in_store>
28
  <comment>The URL of the H5mag magazine</comment>
29
  <frontend_type>text</frontend_type>
30
  <sort_order>10</sort_order>
31
+ <validate>validate-url</validate>
32
  <show_in_default>1</show_in_default>
33
  <show_in_website>1</show_in_website>
34
  <show_in_store>1</show_in_store>
app/design/frontend/base/default/template/h5mag/shopapi/emptycart.phtml CHANGED
@@ -1,6 +1,9 @@
1
- <?php $url = Mage::getSingleton('core/session')->getH5magShopApiCartUrl();?>
2
- <?php error_log($url);?>
3
- <?php if (!empty($url)) :?>
4
- <iframe src="<?php echo $url?>" width="1" height="1" scrolling="no" frameborder="0" border="0"></iframe>
5
- <?php Mage::getSingleton('core/session')->unsH5magShopApiCartUrl() ?>
6
- <?php endif;?>
 
 
 
1
+ <?php
2
+ $url = Mage::getSingleton('core/session')->getH5magShopApiCartUrl();
3
+ if (!empty($url)):?>
4
+ <iframe src="<?php echo $url; ?>" width="1" height="1" scrolling="no" frameborder="0" border="0"></iframe>
5
+ <?php
6
+ Mage::getSingleton('core/session')->unsH5magShopApiCartUrl();
7
+ endif;
8
+
9
+ ?>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>h5mage-commerceapi</name>
4
- <version>0.0.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.h5mag.com">Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
@@ -10,9 +10,9 @@
10
  <description>Sell your products through your H5mag online magazine</description>
11
  <notes>Reference API</notes>
12
  <authors><author><name>H5mag</name><user>h5mag</user><email>info@h5mag.com</email></author></authors>
13
- <date>2015-08-20</date>
14
- <time>13:57:35</time>
15
- <contents><target name="mageetc"><dir><dir name="modules"><file name="H5mag_ShopApi.xml" hash="a7f3540be0ca960e3c4342c97ff10611"/></dir></dir></target><target name="magecommunity"><dir><dir name="H5mag"><dir name="ShopApi"><dir name="Model"><file name="Generic.php" hash="9e22a439073e15e2da7c66f9ba6e31f2"/><dir name="Order"><file name="Observer.php" hash="d6d859b3d426db207a0f26b9c09dc8cf"/></dir><file name="Product.php" hash="61fc08e108376c890e4ad4cb60aba130"/></dir><dir name="controllers"><file name="CheckoutController.php" hash="4198c5faf44b0d5896948cb9e3f48a14"/><file name="IndexController.php" hash="48f95ac755532b43f22b04dde8e85f19"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4d5313c01a1c7eb331ec9e14b05de9a3"/><file name="config.xml" hash="49001110e909ff73da3765fb9e6195a7"/><file name="system.xml" hash="87c0aa8a8201293ce9d3aa762ea37707"/></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="h5mag"><dir name="shopapi"><file name="emptycart.phtml" hash="858809d6c1b4f3301f7716fcc751ef05"/></dir></dir></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.10</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>h5mage-commerceapi</name>
4
+ <version>0.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.h5mag.com">Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
10
  <description>Sell your products through your H5mag online magazine</description>
11
  <notes>Reference API</notes>
12
  <authors><author><name>H5mag</name><user>h5mag</user><email>info@h5mag.com</email></author></authors>
13
+ <date>2015-09-02</date>
14
+ <time>09:49:05</time>
15
+ <contents><target name="mageetc"><dir><dir name="modules"><file name="H5mag_ShopApi.xml" hash="a7f3540be0ca960e3c4342c97ff10611"/></dir></dir></target><target name="magecommunity"><dir><dir name="H5mag"><dir name="ShopApi"><dir name="Model"><file name="Generic.php" hash="7913f49f76747753b6cc001315150b4e"/><dir name="Order"><file name="Observer.php" hash="feeb4b145711fda6d0c62d7b8bda8ba7"/></dir><file name="Product.php" hash="2d02f892f12a774081072779e61e91a6"/></dir><dir name="controllers"><file name="CheckoutController.php" hash="703ee86056c7d5a5be99b8e856400046"/><file name="IndexController.php" hash="c1bef5e7e2dc9eb3fd1f13deeae73eda"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4d5313c01a1c7eb331ec9e14b05de9a3"/><file name="config.xml" hash="49001110e909ff73da3765fb9e6195a7"/><file name="system.xml" hash="0e1e2da2b22ea05098ebd2138b201c23"/></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="h5mag"><dir name="shopapi"><file name="emptycart.phtml" hash="d25f087f78a205332406373418880531"/></dir></dir></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.10</min><max>6.0.0</max></php></required></dependencies>
18
  </package>