This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ade
committed
Sep 26, 2019
1 parent
3f42b03
commit 2fd7bb5
Showing
7 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
app/code/local/Everlytic/Productapi/Model/Api2/Product.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/code/local/Everlytic/Productapi/controllers/IndexController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |