Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Initial Commit, ready to go
Browse files Browse the repository at this point in the history
  • Loading branch information
ade committed Sep 26, 2019
0 parents commit a192dfc
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions app/code/local/Everlytic/Productapi/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Everlytic\Extension\Helper;

use Mage_Core_Helper_Abstract;

class Data extends Mage_Core_Helper_Abstract
{

}
37 changes: 37 additions & 0 deletions app/code/local/Everlytic/Productapi/Model/Api2/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Catalog
* @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Abstract Api2 model for product instance
*
* @category Mage
* @package Mage_Catalog
* @author Magento Core Team <[email protected]>
*/
class Everlytic_Productapi_Model_Api2_Product extends Mage_Api2_Model_Resource
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Catalog
* @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* API2 for catalog_product (Admin)
*
* @category Mage
* @package Mage_Catalog
* @author Magento Core Team <[email protected]>
*/
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

class Everlytic_Productapi_IndexController extends Mage_Core_Controller_Front_Action{
public function indexAction(){
$product = $this->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));
}
}
}
47 changes: 47 additions & 0 deletions app/code/local/Everlytic/Productapi/etc/api2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0"?>
<config>
<api2>
<resource_groups>
<everlytic_productapi translate="title" module="everlytic_productapi">
<title>Everlytic</title>
<sort_order>10</sort_order>
</everlytic_productapi>
</resource_groups>
<resources>
<everlytic_productapi translate="title" module="everlytic_productapi">
<group>everlytic_productapi</group>
<model>everlytic_productapi/api2_product</model>
<working_model>catalog/product</working_model>
<title>Everlytic Products</title>
<sort_order>10</sort_order>
<privileges>
<guest>
<retrieve>1</retrieve>
</guest>
<admin>
<retrieve>1</retrieve>
</admin>
</privileges>
<attributes translate="" module="everlytic_productapi">
<entity_id>Product ID</entity_id>
<name>Product Name</name>
<description>Product Description</description>
<price>Price</price>
<special_price>Special Price</special_price>
<sku>SKU</sku>
<product_url>URL</product_url>
<add_to_cart_url>Add to Cart URL</add_to_cart_url>
<gallery>Product Gallery</gallery>
<image>Product Image</image>
</attributes>
<routes>
<route_collection>
<route>/everlytic/v1/products</route>
<action_type>collection</action_type>
</route_collection>
</routes>
<versions>1</versions>
</everlytic_productapi>
</resources>
</api2>
</config>
31 changes: 31 additions & 0 deletions app/code/local/Everlytic/Productapi/etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<config>
<modules>
<Everlytic_Productapi>
<version>0.1.0</version>
</Everlytic_Productapi>
</modules>
<global>
<helpers>
<everlytic_productapi>
<class>Everlytic_Productapi_Helper</class>
</everlytic_productapi>
</helpers>
<models>
<everlytic_productapi>
<class>Everlytic_Productapi_Model</class>
</everlytic_productapi>
</models>
</global>
<frontend>
<routers>
<everlytic_productapi>
<use>standard</use>
<args>
<module>Everlytic_Productapi</module>
<frontName>add-to-cart</frontName>
</args>
</everlytic_productapi>
</routers>
</frontend>
</config>
13 changes: 13 additions & 0 deletions app/etc/modules/Mage_Everlytic.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<config>
<modules>
<Everlytic_Productapi>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
<depends>
<Mage_Checkout />
</depends>
</Everlytic_Productapi>
</modules>
</config>

0 comments on commit a192dfc

Please sign in to comment.