diff --git a/README.md b/README.md new file mode 100644 index 0000000..fa70541 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +Everlytic Magento 1.9 Extension +===================== +![Maintenance](https://img.shields.io/maintenance/yes/2019) +---------- +This repo contains the Magento Extension that allows connection to the Everlytic App . + +###### Features: +- Custom route to allow Everlytic to read product data from a Magento 1.9 installation. + +#### Installation + +##### Manually: +- You can copy the files from the folders of this repository to the same folders structure of your installation + +###### Post Installation: +- Clear your cache, see the menu System > Cache Management +- Visit, System > Web Services > Rest Roles > Role API Resources to give access to the role to be used. Click on the Resource access drop-down and give access to Everlytic +- Visit, System > Web Services > Rest Attributes. Choose the User Type, advisably Admin and choose the attributes to give access to. + +##### Compatibility + Compatibility: 1.9 + +Support +------- +You are welcome to log any issues you find. + +Licence +------- +TBD + +Copyright +--------- +(c) 2019 Everlytic \ No newline at end of file diff --git a/app/code/local/Everlytic/Productapi/Helper/Data.php b/app/code/local/Everlytic/Productapi/Helper/Data.php new file mode 100644 index 0000000..efa7a28 --- /dev/null +++ b/app/code/local/Everlytic/Productapi/Helper/Data.php @@ -0,0 +1,9 @@ + + */ +class Everlytic_Productapi_Model_Api2_Product extends Mage_Api2_Model_Resource +{ + +} diff --git a/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php b/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php new file mode 100644 index 0000000..b7d9c79 --- /dev/null +++ b/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php @@ -0,0 +1,91 @@ + + */ +class Everlytic_Productapi_Model_Api2_Product_Rest_Admin_V1 extends Mage_Catalog_Model_Api2_Product_Rest +{ + /** + * The greatest decimal value which could be stored. Corresponds to DECIMAL (12,4) SQL type + */ + const MAX_DECIMAL_VALUE = 99999999.9999; + + /** + * Add special fields to product get response + * + * @param Mage_Catalog_Model_Product $product + */ + protected function _prepareProductForResponse(Mage_Catalog_Model_Product $product) + { + $productData = $product->getData(); + $productData['price'] = Mage::helper('core')->currency($product->getPrice()); + $productData['gallery'] = $this->getGalleryFromProduct($product); + $productData['product_url'] = $product->getProductUrl(); + $productData['add_to_cart_url'] = Mage::getBaseUrl() . "add-to-cart/index/index/product/" . $product->getId(); + + $product->addData($productData); + } + + /** + * Retrieve list of products + * + * @return array + */ + protected function _retrieveCollection() + { + /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */ + $collection = Mage::getResourceModel('catalog/product_collection'); + $collection->addAttributeToSelect(array_keys( + $this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ) + )); + $products = $collection->load(); + + foreach ($products as $product) { + $this->_prepareProductForResponse($product); + } + + return $products->toArray(); + } + + /** + * @param Mage_Catalog_Model_Product $product + * @return array + */ + private function getGalleryFromProduct(Mage_Catalog_Model_Product $product) + { + $gallery = []; + $galleryImages = Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages(); + foreach ($galleryImages as $_image) { + $gallery[] = $_image->getUrl(); + } + return $gallery; + } +} diff --git a/app/code/local/Everlytic/Productapi/controllers/IndexController.php b/app/code/local/Everlytic/Productapi/controllers/IndexController.php new file mode 100644 index 0000000..70d5bd5 --- /dev/null +++ b/app/code/local/Everlytic/Productapi/controllers/IndexController.php @@ -0,0 +1,14 @@ +getRequest()->getParam('product'); + $key = Mage::getSingleton('core/session')->getFormKey();; + if (empty($product)){ + $this->_redirect(''); + } + else{ + $this->_redirect('checkout/cart/add', array('product'=>$product, 'form_key'=>$key)); + } + } +} \ No newline at end of file diff --git a/app/code/local/Everlytic/Productapi/etc/api2.xml b/app/code/local/Everlytic/Productapi/etc/api2.xml new file mode 100644 index 0000000..acdec9d --- /dev/null +++ b/app/code/local/Everlytic/Productapi/etc/api2.xml @@ -0,0 +1,47 @@ + + + + + + Everlytic + 10 + + + + + everlytic_productapi + everlytic_productapi/api2_product + catalog/product + Everlytic Products + 10 + + + 1 + + + 1 + + + + Product ID + Product Name + Product Description + Price + Special Price + SKU + URL + Add to Cart URL + Product Gallery + Product Image + + + + /everlytic/v1/products + collection + + + 1 + + + + \ No newline at end of file diff --git a/app/code/local/Everlytic/Productapi/etc/config.xml b/app/code/local/Everlytic/Productapi/etc/config.xml new file mode 100644 index 0000000..f7c751e --- /dev/null +++ b/app/code/local/Everlytic/Productapi/etc/config.xml @@ -0,0 +1,31 @@ + + + + + 0.1.0 + + + + + + Everlytic_Productapi_Helper + + + + + Everlytic_Productapi_Model + + + + + + + standard + + Everlytic_Productapi + add-to-cart + + + + + \ No newline at end of file diff --git a/app/etc/modules/Mage_Everlytic.xml b/app/etc/modules/Mage_Everlytic.xml new file mode 100644 index 0000000..070d285 --- /dev/null +++ b/app/etc/modules/Mage_Everlytic.xml @@ -0,0 +1,13 @@ + + + + + true + local + 0.1.0 + + + + + + \ No newline at end of file