Version Notes
Reference API
Added API key and url validation
Download this release
Release Info
| Developer | H5mag |
| Extension | h5mage-commerceapi |
| Version | 0.0.4 |
| Comparing to | |
| See all releases | |
Code changes from version 0.0.3 to 0.0.4
app/code/community/H5mag/ShopApi/Model/Generic.php
CHANGED
|
@@ -153,7 +153,30 @@ class H5mag_ShopApi_Model_Generic extends H5mag_ShopApi_Model_Product {
|
|
| 153 |
}
|
| 154 |
}
|
| 155 |
}
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
/**
|
| 158 |
* Get the JSON representation of this product
|
| 159 |
*
|
| 153 |
}
|
| 154 |
}
|
| 155 |
}
|
| 156 |
+
/**
|
| 157 |
+
* Get the JSON representation of this product
|
| 158 |
+
*
|
| 159 |
+
* @return string json encoded string
|
| 160 |
+
*/
|
| 161 |
+
public function fetchAll() {
|
| 162 |
+
|
| 163 |
+
// Use locale to set current store or use the default one
|
| 164 |
+
if (empty($this->storeId)) $this->storeId = Mage::app()->getStore()->getId();
|
| 165 |
+
Mage::app()->setCurrentStore($this->storeId);
|
| 166 |
+
|
| 167 |
+
// Fetch our product
|
| 168 |
+
$products = Mage::getModel('catalog/product')->getCollection()->getData();
|
| 169 |
+
$productList = array();
|
| 170 |
+
foreach($products as $product) {
|
| 171 |
+
if ($product['type_id'] == 'simple') {
|
| 172 |
+
$prod = Mage::getModel('catalog/product')->load($product['entity_id']);
|
| 173 |
+
$store = Mage::getModel('core/store')->load($prod->getStoreId());
|
| 174 |
+
array_push($productList, array("name" => $prod->name, "description" => $prod->description, "sku" => $prod->sku, "currency" => $store->getCurrentCurrencyCode(), "image"=> $prod->getSmallImageUrl(), "price" => $prod->price));
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
$this->data = $productList;
|
| 179 |
+
}
|
| 180 |
/**
|
| 181 |
* Get the JSON representation of this product
|
| 182 |
*
|
app/code/community/H5mag/ShopApi/Model/Product.php
CHANGED
|
@@ -52,7 +52,13 @@ abstract class H5mag_ShopApi_Model_Product extends Mage_Core_Model_Abstract {
|
|
| 52 |
* @return void
|
| 53 |
*/
|
| 54 |
abstract public function fetch($id);
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
/**
|
| 57 |
* Get the JSON representation of this product
|
| 58 |
*
|
| 52 |
* @return void
|
| 53 |
*/
|
| 54 |
abstract public function fetch($id);
|
| 55 |
+
/**
|
| 56 |
+
* Load the product.
|
| 57 |
+
*
|
| 58 |
+
* @param integer $id product ID
|
| 59 |
+
* @return void
|
| 60 |
+
*/
|
| 61 |
+
abstract public function fetchAll();
|
| 62 |
/**
|
| 63 |
* Get the JSON representation of this product
|
| 64 |
*
|
app/code/community/H5mag/ShopApi/controllers/IndexController.php
CHANGED
|
@@ -18,20 +18,54 @@
|
|
| 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 {
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
/**
|
| 23 |
* Get product and variants
|
| 24 |
*/
|
| 25 |
public function indexAction() {
|
| 26 |
-
$product_id = $this->getRequest()->getParam('id');
|
| 27 |
$callback = $this->getRequest()->getParam('callback');
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
/**
|
| 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 {
|
| 21 |
+
private function testHash($hash) {
|
| 22 |
+
$previousHashTime = floor((time()-300)/300);
|
| 23 |
+
$currentHashTime = floor(time()/300);
|
| 24 |
+
$apiKey = Mage::app()->getStore()->getConfig('h5mag_shopapi_magazine/general/apikey');
|
| 25 |
+
$previousHash = sha1($apiKey . $previousHashTime);
|
| 26 |
+
$currentHash = sha1($apiKey . $currentHashTime);
|
| 27 |
+
if (strlen($currentHash) === strlen($hash) && $currentHash === $hash) {
|
| 28 |
+
return true;
|
| 29 |
+
} else if (strlen($previousHash) === strlen($hash) && $previousHash === $hash) {
|
| 30 |
+
return true;
|
| 31 |
+
}
|
| 32 |
+
return false;
|
| 33 |
+
}
|
| 34 |
/**
|
| 35 |
* Get product and variants
|
| 36 |
*/
|
| 37 |
public function indexAction() {
|
|
|
|
| 38 |
$callback = $this->getRequest()->getParam('callback');
|
| 39 |
+
$hash = $this->getRequest()->getParam('key');
|
| 40 |
+
if (Mage::app()->getStore()->getConfig('h5mag_shopapi_magazine/general/apikey') != "" && $this->testHash($hash)) {
|
| 41 |
+
$product_id = $this->getRequest()->getParam('id');
|
| 42 |
+
if (empty($product_id)) throw new Exception(E_NO_PRODUCT_ID_SPECIFIED);
|
| 43 |
+
$product = Mage::getModel('h5mag_shopapi/'. Mage::app()->getStore()->getConfig('h5mag_shopapi_developer/general/model'));
|
| 44 |
+
if (!$product) $product = Mage::getModel('h5mag_shopapi/generic');
|
| 45 |
+
$locale = $this->getRequest()->getParam('locale');
|
| 46 |
+
if (!empty($locale)) $product->setLocale($locale);
|
| 47 |
+
$product->fetch($product_id);
|
| 48 |
+
$this->send($callback.'('.$product->json().')');
|
| 49 |
+
} else {
|
| 50 |
+
$this->send($callback.'([])');
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Get product and variants
|
| 56 |
+
*/
|
| 57 |
+
public function productsAction() {
|
| 58 |
+
$hash = $this->getRequest()->getParam('key');
|
| 59 |
+
if (Mage::app()->getStore()->getConfig('h5mag_shopapi_magazine/general/apikey') != "" && $this->testHash($hash)) {
|
| 60 |
+
$product = Mage::getModel('h5mag_shopapi/'. Mage::app()->getStore()->getConfig('h5mag_shopapi_developer/general/model'));
|
| 61 |
+
if (!$product) $product = Mage::getModel('h5mag_shopapi/generic');
|
| 62 |
+
$locale = $this->getRequest()->getParam('locale');
|
| 63 |
+
if (!empty($locale)) $product->setLocale($locale);
|
| 64 |
+
$product->fetchAll($product_id);
|
| 65 |
+
$this->send($callback.'('.$product->json().')');
|
| 66 |
+
} else {
|
| 67 |
+
$this->send($callback.'([])');
|
| 68 |
+
}
|
| 69 |
}
|
| 70 |
|
| 71 |
/**
|
app/code/community/H5mag/ShopApi/etc/system.xml
CHANGED
|
@@ -33,6 +33,15 @@
|
|
| 33 |
<show_in_website>1</show_in_website>
|
| 34 |
<show_in_store>1</show_in_store>
|
| 35 |
</url>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
</fields>
|
| 37 |
</general>
|
| 38 |
</groups>
|
| 33 |
<show_in_website>1</show_in_website>
|
| 34 |
<show_in_store>1</show_in_store>
|
| 35 |
</url>
|
| 36 |
+
<apikey translate="label comment">
|
| 37 |
+
<label>API Key</label>
|
| 38 |
+
<comment>H5mag magazine user API key</comment>
|
| 39 |
+
<frontend_type>text</frontend_type>
|
| 40 |
+
<sort_order>10</sort_order>
|
| 41 |
+
<show_in_default>1</show_in_default>
|
| 42 |
+
<show_in_website>1</show_in_website>
|
| 43 |
+
<show_in_store>1</show_in_store>
|
| 44 |
+
</apikey>
|
| 45 |
</fields>
|
| 46 |
</general>
|
| 47 |
</groups>
|
package.xml
CHANGED
|
@@ -1,18 +1,20 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>h5mage-commerceapi</name>
|
| 4 |
-
<version>0.0.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.h5mag.com">Open Software License (OSL 3.0)</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Connect your store with H5mag</summary>
|
| 10 |
<description>Sell your products through your H5mag online magazine</description>
|
| 11 |
-
<notes>Reference API
|
|
|
|
|
|
|
| 12 |
<authors><author><name>H5mag</name><user>h5mag</user><email>info@h5mag.com</email></author></authors>
|
| 13 |
-
<date>2015-09-
|
| 14 |
-
<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="
|
| 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.4</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.h5mag.com">Open Software License (OSL 3.0)</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Connect your store with H5mag</summary>
|
| 10 |
<description>Sell your products through your H5mag online magazine</description>
|
| 11 |
+
<notes>Reference API
|
| 12 |
+

|
| 13 |
+
Added API key and url validation</notes>
|
| 14 |
<authors><author><name>H5mag</name><user>h5mag</user><email>info@h5mag.com</email></author></authors>
|
| 15 |
+
<date>2015-09-15</date>
|
| 16 |
+
<time>14:45:39</time>
|
| 17 |
+
<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="ee7230ea0371be754c017a4dbbe370d6"/><dir name="Order"><file name="Observer.php" hash="feeb4b145711fda6d0c62d7b8bda8ba7"/></dir><file name="Product.php" hash="711ce6b1c57e5781f43a812394303cb1"/></dir><dir name="controllers"><file name="CheckoutController.php" hash="703ee86056c7d5a5be99b8e856400046"/><file name="IndexController.php" hash="cf68fb47a4ffe82bf25aacec815c55f6"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4d5313c01a1c7eb331ec9e14b05de9a3"/><file name="config.xml" hash="49001110e909ff73da3765fb9e6195a7"/><file name="system.xml" hash="751a05e3cd64d5dac4798e128d4cb3dc"/></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>
|
| 18 |
<compatible/>
|
| 19 |
<dependencies><required><php><min>5.3.10</min><max>6.0.0</max></php></required></dependencies>
|
| 20 |
</package>
|
