-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade extension to use latest api endpoints and Fera/Ai namespace.
- Loading branch information
1 parent
104b754
commit 74b0423
Showing
19 changed files
with
379 additions
and
163 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
2 changes: 1 addition & 1 deletion
2
...nnector/Block/Footer/Checkout/Success.php → ...Fera/Ai/Block/Footer/Checkout/Success.php
100644 → 100755
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
103 changes: 103 additions & 0 deletions
103
src/app/code/community/Fera/Ai/Block/Footer/Product/View.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,103 @@ | ||
<?php | ||
|
||
class Fera_Ai_Block_Footer_Product_View extends Mage_Core_Block_Template | ||
{ | ||
protected $_product; | ||
/** | ||
* Retrieve current product model | ||
* | ||
* @return Mage_Catalog_Model_Product | ||
*/ | ||
public function getProduct() | ||
{ | ||
if (!$this->_product) { | ||
if ($this->getData('product_id')) { | ||
$this->_product = Mage::getModel('catalog/product')->load($this->getData('product_id')); | ||
} else { | ||
$this->_product = Mage::registry('product'); | ||
} | ||
} | ||
return $this->_product; | ||
} | ||
|
||
public function getProductJson() | ||
{ | ||
$p = $this->getProduct(); | ||
|
||
$thumb = $p->getThumbnailUrl(); | ||
$productData = [ | ||
"id" => $p->getId(), // String | ||
"name" => $p->getName(), // String | ||
"price" => $p->getFinalPrice(), // Float | ||
"status" => $p->getStatus() == 1 ? 'published' : 'draft', // (Optional) String | ||
"created_at" => (new DateTime($p->getCreatedAt()))->format(DateTime::ATOM), // (Optional) String (ISO 8601 format DateTime) | ||
"modified_at" => (new DateTime($p->getUpdatedAt()))->format(DateTime::ATOM), // (Optional) String (ISO 8601 format DateTime) | ||
"stock" => $p->getStockItem()->getQty(), // (Optional) Integer, If null assumed to be infinite. | ||
"in_stock" => $p->isInStock(), // (Optional) Boolean | ||
"url" => $p->getUrl(), // String | ||
"thumbnail_url" => $thumb, // String | ||
"needs_shipping" => $p->getTypeId() != 'virtual', // (Optional) Boolean | ||
"hidden" => $p->getVisibility() == '1', // (Optional) Boolean | ||
'tags' => [], | ||
"variants" => [], // (Optional) Array<Variant>: Variants that are applicable to this product. | ||
"platform_data" => [ // (Optional) Hash/Object of attributes to store about the product specific to the integration platform (can be used in future filters) | ||
"sku" => $p->getSku(), | ||
"type" => $p->getTypeId(), | ||
"regular_price" => $p->getPrice() | ||
] | ||
]; | ||
|
||
$tags = Mage::getModel('tag/tag')->getResourceCollection() | ||
->addPopularity() | ||
->addStatusFilter(Mage::getModel('tag/tag')->getApprovedStatus()) | ||
->addProductFilter($p->getId()); | ||
foreach($tags as $tag) { | ||
$productData['tags'][] = $tag->getName(); | ||
} | ||
|
||
if ($p->getTypeId() == 'configurable') { | ||
$cfgAttr = $p->getTypeInstance()->getConfigurableAttributesAsArray(); | ||
foreach ($p->getTypeInstance()->getUsedProducts() as $subProduct) { | ||
$variant = [ | ||
"id" => $subProduct->getId(), | ||
"name" => $subProduct->getName(), // String | ||
"status" => $subProduct->getStatus() == 1 ? 'published' : 'draft', // (Optional) String | ||
"created_at" => (new DateTime($subProduct->getCreatedAt()))->format(DateTime::ATOM), // (Optional) String (ISO 8601 format DateTime) | ||
"modified_at" => (new DateTime($subProduct->getUpdatedAt()))->format(DateTime::ATOM), // (Optional) String (ISO 8601 format DateTime) | ||
"stock" => $subProduct->getStockItem()->getQty(), // (Optional) Integer, If null assumed to be infinite. | ||
"in_stock" => $subProduct->isInStock(), // (Optional) Boolean | ||
"price" => $subProduct->getPrice(), // Float | ||
"platform_data" => [ // (Optional) Hash/Object of attributes to store about the product specific to the integration platform (can be used in future filters) | ||
"sku" => $subProduct->getSku() | ||
] | ||
]; | ||
|
||
$variantImage = $subProduct->getThumbnailUrl(); | ||
if ($variantImage != $thumb && stripos($variantImage, '/placeholder') === false){ | ||
$variant['thumbnail_url'] = $subProduct->getThumbnailUrl(); | ||
} | ||
|
||
$variantAttrVals = []; | ||
foreach ($cfgAttr as $attr) { | ||
$attrValIndex = $subProduct->getData($attr['attribute_code']); | ||
foreach ($attr['values'] as $attrVal) { | ||
if ($attrVal['value_index'] == $attrValIndex) { | ||
$variantAttrVals[] = $attrVal['label']; | ||
} | ||
} | ||
# code... | ||
} | ||
$variant['name'] = implode(' / ', $variantAttrVals); | ||
|
||
$productData['variants'][] = $variant; | ||
} | ||
} | ||
|
||
return json_encode($productData); | ||
} | ||
|
||
public function getProductId() | ||
{ | ||
return $this->getProduct()->getId(); | ||
} | ||
} |
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
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,68 @@ | ||
<?php | ||
/** | ||
* This client handles the creation of order JSON for sending to Fera | ||
*/ | ||
class Fera_Ai_Model_Order extends Varien_Object | ||
{ | ||
|
||
protected $order; | ||
|
||
/** | ||
* Set the order for this model | ||
* @param Mage_Sales_Model_Order $order | ||
* @return $this | ||
*/ | ||
public function loadFromMageOrder($order) | ||
{ | ||
$this->order = $order; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Format our mage order object into JSON for sending VIA js api | ||
* @return JSON | ||
*/ | ||
public function getJson() | ||
{ | ||
$order = $this->order; | ||
|
||
$customerId = $order->getCustomerId(); | ||
if (!empty($customerId)) { | ||
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId()); | ||
$addressObj = $customer->getPrimaryShippingAddress(); | ||
$address; | ||
if (!empty($addressObj)) { | ||
$address = $addressObj->getData(); | ||
} | ||
$customer = array( | ||
'id' => $customerId, | ||
'first_name' => $customer->getFirstname(), | ||
'email' => $customer->getEmail(), | ||
'address' => $address | ||
); | ||
} | ||
|
||
$currencyCode = $order->getOrderCurrencyCode(); | ||
$total = $order->getGrandTotal(); | ||
$totalUsd = Mage::helper('directory')->currencyConvert($total, $currencyCode, 'USD'); | ||
|
||
$orderData = array( | ||
'id' => $order->getId(), | ||
'number' => $order->getIncrementId(), | ||
|
||
'total' => $total, | ||
'total_usd' => $totalUsd, | ||
|
||
'created_at' => (new DateTime($order->getCreatedAt()))->format(DateTime::ATOM), | ||
'modified_at' => (new DateTime($order->getUpdatedAt()))->format(DateTime::ATOM), | ||
|
||
'line_items' => Mage::helper('fera_ai')->serializeQuoteItems($order->getItemsCollection()), | ||
|
||
'customer' => $customer, | ||
'source_name' => 'web' | ||
); | ||
|
||
return json_encode($orderData); | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/app/code/community/Fera/Ai/controllers/InstallationController.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,74 @@ | ||
<?php | ||
class Fera_Ai_InstallationController extends Mage_Core_Controller_Front_Action | ||
{ | ||
protected function _getHelper() | ||
{ | ||
return Mage::helper('fera_ai'); | ||
} | ||
|
||
|
||
public function checkAction() | ||
{ | ||
try { | ||
$params = $this->getRequest()->getParams(); | ||
|
||
if (Mage::getStoreConfig('fera_ai/fera_ai_group/secret_key') != $params['sk']) { | ||
die("Invalid key"); | ||
} | ||
|
||
Mage::app()->cleanCache(); | ||
|
||
$responseData = [ | ||
"version" => ((array)Mage::getConfig()->getNode('modules/Fera_Ai/version'))[0], | ||
"public_key" => $this->_getHelper()->getPublicKey(), | ||
"api_url" => $this->_getHelper()->getApiUrl(), | ||
"js_url" => $this->_getHelper()->getJsUrl() | ||
]; | ||
|
||
$response = json_encode($responseData); | ||
} catch (Mage_Core_Exception $e) { | ||
$response = $e->getMessage(); | ||
} catch (Exception $e) { | ||
$response = 'Error: System error during request'; | ||
} | ||
|
||
$this->getResponse()->setBody($response); | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
*/ | ||
public function autoconfigureAction() | ||
{ | ||
try { | ||
$params = $this->getRequest()->getParams(); | ||
|
||
if (Mage::getStoreConfig('fera_ai/fera_ai_group/secret_key')) { | ||
die("This account has already been auto-configured and cannot be auto-configured again. If you want to update the API credentials please go to the System settings and enter in the API credentials manually."); | ||
} | ||
|
||
Mage::getConfig()->saveConfig('fera_ai/fera_ai_group/secret_key', $params['sk']); | ||
Mage::getConfig()->saveConfig('fera_ai/fera_ai_group/public_key', $params['pk']); | ||
|
||
if ($params['api_url']) { | ||
Mage::getConfig()->saveConfig('fera_ai/fera_ai_group/api_url', $params['api_url']); | ||
} | ||
|
||
if ($params['js_url']) { | ||
Mage::getConfig()->saveConfig('fera_ai/fera_ai_group/js_url', $params['js_url']); | ||
} | ||
|
||
Mage::app()->cleanCache(); | ||
|
||
$response = "Automatic confiuration was successful. You may now close this window."; | ||
} catch (Mage_Core_Exception $e) { | ||
$response = $e->getMessage(); | ||
} catch (Exception $e) { | ||
$response = 'Error: System error during request'; | ||
} | ||
$this->getResponse()->setBody($response); | ||
return $this; | ||
} | ||
|
||
} |
Oops, something went wrong.