Version Notes
Choice AI plugin
Download this release
Release Info
Developer | BrainSINS |
Extension | choiceai |
Version | 1.1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.12 to 1.1.1
- app/code/community/ChoiceAI/Personalisation/Block/Base/Script.php +10 -4
- app/code/community/ChoiceAI/Personalisation/Block/Event/Analytics/Listpage.php +6 -3
- app/code/community/ChoiceAI/Personalisation/Block/Event/Analytics/Search.php +6 -3
- app/code/community/ChoiceAI/Personalisation/Block/Event/Catalog/Product/View.php +45 -39
- app/code/community/ChoiceAI/Personalisation/Block/Event/Checkout/Cart/Index.php +37 -32
- app/code/community/ChoiceAI/Personalisation/Block/Event/Checkout/Onepage/Success.php +119 -118
- app/code/community/ChoiceAI/Personalisation/Block/Searchpage/Addparam.php +6 -3
- app/code/community/ChoiceAI/Personalisation/Helper/Data.php +23 -10
- app/code/community/ChoiceAI/Personalisation/Model/Observer.php +109 -110
- app/code/community/ChoiceAI/Personalisation/controllers/ApiController.php +1030 -305
- app/code/community/ChoiceAI/Personalisation/etc/config.xml +1 -1
- app/code/community/ChoiceAI/Personalisation/sql/personalisation_setup/install-1.0.12.php +0 -31
- app/code/community/ChoiceAI/Personalisation/sql/personalisation_setup/install-1.1.1.php +37 -0
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Attribute.php +46 -45
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Boolean.php +21 -20
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Category.php +34 -33
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Decimal.php +46 -45
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/Filter/Price.php +50 -50
- app/code/local/ChoiceAI/Search/Block/Catalog/Layer/View.php +112 -109
- app/code/local/ChoiceAI/Search/Block/Catalog/Product/List.php +1 -0
- app/code/local/ChoiceAI/Search/Block/Catalog/Product/List/Toolbar.php +10 -7
- app/code/local/ChoiceAI/Search/Block/Catalogsearch/Enterprise/Layer.php +4 -3
- app/code/local/ChoiceAI/Search/Block/Catalogsearch/Layer.php +116 -115
- app/code/local/ChoiceAI/Search/Block/Catalogsearch/Layer/Filter/Attribute.php +47 -46
- app/code/local/ChoiceAI/Search/Block/Catalogsearch/Result.php +5 -3
- app/code/local/ChoiceAI/Search/Helper/Choiceaisearch.php +16 -15
- app/code/local/ChoiceAI/Search/Helper/Data.php +450 -425
- app/code/local/ChoiceAI/Search/Helper/Productimg.php +5 -5
- app/code/local/ChoiceAI/Search/Model/Catalog/Category.php +8 -8
- app/code/local/ChoiceAI/Search/Model/Catalog/Config.php +125 -121
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer.php +38 -37
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer/Filter/Attribute.php +173 -168
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer/Filter/Boolean.php +43 -41
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer/Filter/Category.php +138 -132
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer/Filter/Decimal.php +191 -190
- app/code/local/ChoiceAI/Search/Model/Catalog/Layer/Filter/Price.php +162 -154
- app/code/local/ChoiceAI/Search/Model/Catalog/Product/Url.php +4 -4
- app/code/local/ChoiceAI/Search/Model/Catalogsearch/Layer.php +31 -31
- app/code/local/ChoiceAI/Search/Model/Catalogsearch/Layer/Filter/Attribute.php +17 -16
- app/code/local/ChoiceAI/Search/Model/Resource/Catalog/Product/Collection.php +383 -373
- app/code/local/ChoiceAI/Search/Model/Resource/Engine/Abstract.php +13 -11
- app/code/local/ChoiceAI/Search/Model/Resource/Engine/Choiceaisearch.php +288 -276
- app/code/local/ChoiceAI/Search/Model/Resource/Engine/Choiceaisearch/Client.php +5 -4
- app/code/local/ChoiceAI/Search/etc/config.xml +2 -2
- app/code/local/ChoiceAI/Searchcore/Helper/Constants.php +6 -5
- app/code/local/ChoiceAI/Searchcore/Helper/Data.php +37 -22
- app/code/local/ChoiceAI/Searchcore/etc/config.xml +1 -1
- app/design/frontend/base/default/template/choiceai/personalisation/analytics/listpage.phtml +20 -23
- app/design/frontend/base/default/template/choiceai/personalisation/analytics/search.phtml +20 -23
- app/design/frontend/base/default/template/choiceai/personalisation/base/addparam.phtml +3 -24
- app/design/frontend/base/default/template/choiceai/personalisation/base/script.phtml +39 -39
- app/design/frontend/default/default/template/choiceai/personalisation/base/script.phtml +38 -38
- lib/ChoiceAI/Client.php +312 -291
- lib/ChoiceAI/Service.php +174 -181
- package.xml +5 -5
app/code/community/ChoiceAI/Personalisation/Block/Base/Script.php
CHANGED
@@ -6,25 +6,31 @@
|
|
6 |
* @copyright Copyright (c) MineWhat
|
7 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
*/
|
9 |
-
class ChoiceAI_Personalisation_Block_Base_Script extends Mage_Core_Block_Template
|
|
|
10 |
|
11 |
-
protected function _construct()
|
|
|
12 |
parent::_construct();
|
13 |
$this->setTemplate('choiceai/personalisation/base/script.phtml');
|
14 |
}
|
15 |
|
16 |
-
protected function _toHtml()
|
|
|
17 |
if (!$this->helper('choiceai_personalisation')->isModuleOutputEnabled()) {
|
18 |
return '';
|
19 |
}
|
|
|
20 |
return parent::_toHtml();
|
21 |
}
|
22 |
|
23 |
-
public function getUser()
|
|
|
24 |
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
25 |
$user = Mage::getSingleton('customer/session')->getCustomer();
|
26 |
return $user;
|
27 |
}
|
|
|
28 |
return null;
|
29 |
}
|
30 |
|
6 |
* @copyright Copyright (c) MineWhat
|
7 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
*/
|
9 |
+
class ChoiceAI_Personalisation_Block_Base_Script extends Mage_Core_Block_Template
|
10 |
+
{
|
11 |
|
12 |
+
protected function _construct()
|
13 |
+
{
|
14 |
parent::_construct();
|
15 |
$this->setTemplate('choiceai/personalisation/base/script.phtml');
|
16 |
}
|
17 |
|
18 |
+
protected function _toHtml()
|
19 |
+
{
|
20 |
if (!$this->helper('choiceai_personalisation')->isModuleOutputEnabled()) {
|
21 |
return '';
|
22 |
}
|
23 |
+
|
24 |
return parent::_toHtml();
|
25 |
}
|
26 |
|
27 |
+
public function getUser()
|
28 |
+
{
|
29 |
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
30 |
$user = Mage::getSingleton('customer/session')->getCustomer();
|
31 |
return $user;
|
32 |
}
|
33 |
+
|
34 |
return null;
|
35 |
}
|
36 |
|
app/code/community/ChoiceAI/Personalisation/Block/Event/Analytics/Listpage.php
CHANGED
@@ -12,14 +12,17 @@
|
|
12 |
* @copyright Copyright (c) MineWhat
|
13 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
14 |
*/
|
15 |
-
class ChoiceAI_Personalisation_Block_Event_Analytics_Listpage extends Mage_Core_Block_Template
|
|
|
16 |
|
17 |
-
protected function _construct()
|
|
|
18 |
parent::_construct();
|
19 |
$this->setTemplate('choiceai/personalisation/analytics/listpage.phtml');
|
20 |
}
|
21 |
|
22 |
-
public function engineStatus()
|
|
|
23 |
return Mage::helper('choiceai_search')->isActiveEngine();
|
24 |
}
|
25 |
|
12 |
* @copyright Copyright (c) MineWhat
|
13 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
14 |
*/
|
15 |
+
class ChoiceAI_Personalisation_Block_Event_Analytics_Listpage extends Mage_Core_Block_Template
|
16 |
+
{
|
17 |
|
18 |
+
protected function _construct()
|
19 |
+
{
|
20 |
parent::_construct();
|
21 |
$this->setTemplate('choiceai/personalisation/analytics/listpage.phtml');
|
22 |
}
|
23 |
|
24 |
+
public function engineStatus()
|
25 |
+
{
|
26 |
return Mage::helper('choiceai_search')->isActiveEngine();
|
27 |
}
|
28 |
|
app/code/community/ChoiceAI/Personalisation/Block/Event/Analytics/Search.php
CHANGED
@@ -12,14 +12,17 @@
|
|
12 |
* @copyright Copyright (c) MineWhat
|
13 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
14 |
*/
|
15 |
-
class ChoiceAI_Personalisation_Block_Event_Analytics_Search extends Mage_Core_Block_Template
|
|
|
16 |
|
17 |
-
protected function _construct()
|
|
|
18 |
parent::_construct();
|
19 |
$this->setTemplate('choiceai/personalisation/analytics/search.phtml');
|
20 |
}
|
21 |
|
22 |
-
public function engineStatus()
|
|
|
23 |
return Mage::helper('choiceai_search')->isActiveEngine();
|
24 |
}
|
25 |
|
12 |
* @copyright Copyright (c) MineWhat
|
13 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
14 |
*/
|
15 |
+
class ChoiceAI_Personalisation_Block_Event_Analytics_Search extends Mage_Core_Block_Template
|
16 |
+
{
|
17 |
|
18 |
+
protected function _construct()
|
19 |
+
{
|
20 |
parent::_construct();
|
21 |
$this->setTemplate('choiceai/personalisation/analytics/search.phtml');
|
22 |
}
|
23 |
|
24 |
+
public function engineStatus()
|
25 |
+
{
|
26 |
return Mage::helper('choiceai_search')->isActiveEngine();
|
27 |
}
|
28 |
|
app/code/community/ChoiceAI/Personalisation/Block/Event/Catalog/Product/View.php
CHANGED
@@ -1,39 +1,45 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Personalisation
|
6 |
-
* @copyright Copyright (c) MineWhat
|
7 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
-
*/
|
9 |
-
class ChoiceAI_Personalisation_Block_Event_Catalog_Product_View extends Mage_Core_Block_Template
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @category ChoiceAI
|
5 |
+
* @package ChoiceAI_Personalisation
|
6 |
+
* @copyright Copyright (c) MineWhat
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*/
|
9 |
+
class ChoiceAI_Personalisation_Block_Event_Catalog_Product_View extends Mage_Core_Block_Template
|
10 |
+
{
|
11 |
+
|
12 |
+
protected function _construct()
|
13 |
+
{
|
14 |
+
parent::_construct();
|
15 |
+
$this->setTemplate('choiceai/personalisation/event/catalog/product/view.phtml');
|
16 |
+
}
|
17 |
+
|
18 |
+
public function getCurrentProduct()
|
19 |
+
{
|
20 |
+
return Mage::registry('current_product');
|
21 |
+
}
|
22 |
+
|
23 |
+
public function getAssociatedProducts($_product)
|
24 |
+
{
|
25 |
+
|
26 |
+
if ($_product->getTypeId() == "configurable") {
|
27 |
+
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
|
28 |
+
return $conf->getUsedProductCollection()->addAttributeToSelect(array('id', 'sku', 'price'))
|
29 |
+
->addFilterByRequiredOptions();
|
30 |
+
} else {
|
31 |
+
return array();
|
32 |
+
}
|
33 |
+
|
34 |
+
}
|
35 |
+
|
36 |
+
protected function _toHtml()
|
37 |
+
{
|
38 |
+
if (!$this->helper('choiceai_personalisation')->isModuleOutputEnabled()) {
|
39 |
+
return '';
|
40 |
+
}
|
41 |
+
|
42 |
+
return parent::_toHtml();
|
43 |
+
}
|
44 |
+
|
45 |
+
}
|
app/code/community/ChoiceAI/Personalisation/Block/Event/Checkout/Cart/Index.php
CHANGED
@@ -1,32 +1,37 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Personalisation
|
6 |
-
* @copyright Copyright (c) MineWhat
|
7 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
-
*/
|
9 |
-
class ChoiceAI_Personalisation_Block_Event_Checkout_Cart_Index extends Mage_Core_Block_Template
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
}
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @category ChoiceAI
|
5 |
+
* @package ChoiceAI_Personalisation
|
6 |
+
* @copyright Copyright (c) MineWhat
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*/
|
9 |
+
class ChoiceAI_Personalisation_Block_Event_Checkout_Cart_Index extends Mage_Core_Block_Template
|
10 |
+
{
|
11 |
+
|
12 |
+
protected function _construct()
|
13 |
+
{
|
14 |
+
parent::_construct();
|
15 |
+
$this->setTemplate('choiceai/personalisation/event/checkout/cart/index.phtml');
|
16 |
+
}
|
17 |
+
|
18 |
+
public function getProductToShoppingCart()
|
19 |
+
{
|
20 |
+
if (($product = Mage::getModel('core/session')->getProductToShoppingCart())) {
|
21 |
+
Mage::getModel('core/session')->unsProductToShoppingCart();
|
22 |
+
return $product;
|
23 |
+
}
|
24 |
+
|
25 |
+
return null;
|
26 |
+
}
|
27 |
+
|
28 |
+
protected function _toHtml()
|
29 |
+
{
|
30 |
+
if (!$this->helper('choiceai_personalisation')->isModuleOutputEnabled()) {
|
31 |
+
return '';
|
32 |
+
}
|
33 |
+
|
34 |
+
return parent::_toHtml();
|
35 |
+
}
|
36 |
+
|
37 |
+
}
|
app/code/community/ChoiceAI/Personalisation/Block/Event/Checkout/Onepage/Success.php
CHANGED
@@ -1,118 +1,119 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* @category ChoiceAI
|
5 |
-
* @package ChoiceAI_Personalisation
|
6 |
-
* @copyright Copyright (c) MineWhat
|
7 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
-
*/
|
9 |
-
class ChoiceAI_Personalisation_Block_Event_Checkout_Onepage_Success extends Mage_Core_Block_Template
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
$
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
$
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
$orderInfo['items'][$item->getItemId()] = array(
|
35 |
-
'id' => $item->getProductId(),
|
36 |
-
'parentId' => '',
|
37 |
-
'sku' => $item->getSku(),
|
38 |
-
'qty' => $item->getQtyOrdered(),
|
39 |
-
'price' => $item->getPrice(),
|
40 |
-
'bundle' => array()
|
41 |
-
);
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
'
|
49 |
-
'
|
50 |
-
|
51 |
-
|
52 |
-
);
|
53 |
-
|
54 |
-
$
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
'
|
65 |
-
'
|
66 |
-
'
|
67 |
-
'
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
$
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
return $this->getRequest()->getRequestedRouteName();
|
112 |
-
}
|
113 |
-
|
114 |
-
protected function _getActionName()
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @category ChoiceAI
|
5 |
+
* @package ChoiceAI_Personalisation
|
6 |
+
* @copyright Copyright (c) MineWhat
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*/
|
9 |
+
class ChoiceAI_Personalisation_Block_Event_Checkout_Onepage_Success extends Mage_Core_Block_Template
|
10 |
+
{
|
11 |
+
|
12 |
+
protected function _construct()
|
13 |
+
{
|
14 |
+
parent::_construct();
|
15 |
+
$this->setTemplate('choiceai/personalisation/event/checkout/onepage/success.phtml');
|
16 |
+
}
|
17 |
+
|
18 |
+
public function getOrderInfo()
|
19 |
+
{
|
20 |
+
try {
|
21 |
+
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
|
22 |
+
|
23 |
+
$order = Mage::getSingleton('sales/order');
|
24 |
+
$order->load($lastOrderId);
|
25 |
+
|
26 |
+
|
27 |
+
if ($order && $order->getId()) {
|
28 |
+
$orderInfo['items'] = array();
|
29 |
+
|
30 |
+
$orderedItems = $order->getAllItems();
|
31 |
+
|
32 |
+
foreach ($orderedItems as $item) {
|
33 |
+
if ($item->getProductType() == "bundle") {
|
34 |
+
$orderInfo['items'][$item->getItemId()] = array(
|
35 |
+
'id' => $item->getProductId(),
|
36 |
+
'parentId' => '',
|
37 |
+
'sku' => $item->getSku(),
|
38 |
+
'qty' => $item->getQtyOrdered(),
|
39 |
+
'price' => $item->getPrice(),
|
40 |
+
'bundle' => array()
|
41 |
+
);
|
42 |
+
} else if ($item->getProductType() != "configurable") {
|
43 |
+
if ($orderInfo['items'][$item->getParentItemId()] != null) {
|
44 |
+
$bundleItems = $orderInfo['items'][$item->getParentItemId()]['bundle'];
|
45 |
+
$bundleItem = array(
|
46 |
+
'pid' => $item->getProductId(),
|
47 |
+
'sku' => $item->getSku(),
|
48 |
+
'qty' => $item->getQtyOrdered(),
|
49 |
+
'price' => $item->getPrice()
|
50 |
+
);
|
51 |
+
$bundleItems[] = $bundleItem;
|
52 |
+
$orderInfo['items'][$item->getParentItemId()]['bundle'] = $bundleItems;
|
53 |
+
} else {
|
54 |
+
$parentId = '';
|
55 |
+
$parentIds = Mage::getModel('catalog/product_type_configurable')->
|
56 |
+
getParentIdsByChild($item->getProductId());
|
57 |
+
if ($parentIds != null && !empty($parentIds)) {
|
58 |
+
$parentId = $parentIds[0];
|
59 |
+
}
|
60 |
+
|
61 |
+
$orderInfo['items'][] = array(
|
62 |
+
'id' => $item->getProductId(),
|
63 |
+
'parentId' => $parentId,
|
64 |
+
'sku' => $item->getSku(),
|
65 |
+
'qty' => $item->getQtyOrdered(),
|
66 |
+
'price' => $item->getPrice(),
|
67 |
+
'bundle' => array()
|
68 |
+
);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
$orderInfo['orderId'] = $order->getIncrementId();
|
74 |
+
$orderInfo['email'] = $order->getCustomerEmail();
|
75 |
+
$orderInfo['createdAt'] = $order->getCreatedAt();
|
76 |
+
|
77 |
+
$currency = $order->getOrderCurrency();
|
78 |
+
if (is_object($currency)) {
|
79 |
+
$orderInfo['currency'] = $currency->getCurrencyCode();
|
80 |
+
}
|
81 |
+
|
82 |
+
$paymentMethod = $order->getPayment()->getMethodInstance()->getTitle();
|
83 |
+
$orderInfo['paymentMethod'] = $paymentMethod;
|
84 |
+
|
85 |
+
return $orderInfo;
|
86 |
+
}
|
87 |
+
} catch (Exception $e) {
|
88 |
+
return null;
|
89 |
+
}
|
90 |
+
|
91 |
+
return null;
|
92 |
+
}
|
93 |
+
|
94 |
+
protected function _toHtml()
|
95 |
+
{
|
96 |
+
if (!$this->helper('choiceai_personalisation')->isModuleOutputEnabled() || !$this->isOrderConfirmation()) {
|
97 |
+
return '';
|
98 |
+
}
|
99 |
+
|
100 |
+
return parent::_toHtml();
|
101 |
+
}
|
102 |
+
|
103 |
+
protected function isOrderConfirmation()
|
104 |
+
{
|
105 |
+
return strpos($this->_getRouteName(), 'checkout') !== false
|
106 |
+
&& $this->_getActionName() == 'success';
|
107 |
+
}
|
108 |
+
|
109 |
+
protected function _getRouteName()
|
110 |
+
{
|
111 |
+
return $this->getRequest()->getRequestedRouteName();
|
112 |
+
}
|
113 |
+
|
114 |
+
protected function _getActionName()
|
115 |
+
{
|
116 |
+
return $this->getRequest()->getRequestedActionName();
|
117 |
+
}
|
118 |
+
|
119 |
+
}
|
app/code/community/ChoiceAI/Personalisation/Block/Searchpage/Addparam.php
CHANGED
@@ -6,14 +6,17 @@
|
|
6 |
* @copyright Copyright (c) MineWhat
|
7 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
*/
|
9 |
-
class ChoiceAI_Personalisation_Block_Searchpage_Addparam extends Mage_Core_Block_Template
|
|
|
10 |
|
11 |
-
protected function _construct()
|
|
|
12 |
parent::_construct();
|
13 |
$this->setTemplate('choiceai/personalisation/base/addparam.phtml');
|
14 |
}
|
15 |
|
16 |
-
public function engineStatus()
|
|
|
17 |
return Mage::helper('choiceai_search')->isActiveEngine();
|
18 |
}
|
19 |
|
6 |
* @copyright Copyright (c) MineWhat
|
7 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
*/
|
9 |
+
class ChoiceAI_Personalisation_Block_Searchpage_Addparam extends Mage_Core_Block_Template
|
10 |
+
{
|
11 |
|
12 |
+
protected function _construct()
|
13 |
+
{
|
14 |
parent::_construct();
|
15 |
$this->setTemplate('choiceai/personalisation/base/addparam.phtml');
|
16 |
}
|
17 |
|
18 |
+
public function engineStatus()
|
19 |
+
{
|
20 |
return Mage::helper('choiceai_search')->isActiveEngine();
|
21 |
}
|
22 |
|
app/code/community/ChoiceAI/Personalisation/Helper/Data.php
CHANGED
@@ -6,12 +6,14 @@
|
|
6 |
* @copyright Copyright (c) MineWhat
|
7 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
*/
|
9 |
-
class ChoiceAI_Personalisation_Helper_Data extends Mage_Core_Helper_Data
|
|
|
10 |
|
11 |
const CONFIG_ACTIVE = 'choiceai_personalisation/settings/active';
|
12 |
const CONFIG_API_KEY = 'choiceai_personalisation/settings/api_key';
|
13 |
|
14 |
-
public function isModuleEnabled($moduleName = null)
|
|
|
15 |
if (Mage::getStoreConfig(self::CONFIG_ACTIVE) == '0') {
|
16 |
return false;
|
17 |
}
|
@@ -19,20 +21,31 @@ class ChoiceAI_Personalisation_Helper_Data extends Mage_Core_Helper_Data {
|
|
19 |
return parent::isModuleEnabled($moduleName = null);
|
20 |
}
|
21 |
|
22 |
-
public function getBaseScript($store = null)
|
|
|
23 |
|
24 |
-
$
|
25 |
|
26 |
try {
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
} catch (Exception $e) {
|
32 |
-
$
|
33 |
}
|
34 |
|
35 |
-
return $
|
36 |
|
37 |
}
|
38 |
|
6 |
* @copyright Copyright (c) MineWhat
|
7 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
*/
|
9 |
+
class ChoiceAI_Personalisation_Helper_Data extends Mage_Core_Helper_Data
|
10 |
+
{
|
11 |
|
12 |
const CONFIG_ACTIVE = 'choiceai_personalisation/settings/active';
|
13 |
const CONFIG_API_KEY = 'choiceai_personalisation/settings/api_key';
|
14 |
|
15 |
+
public function isModuleEnabled($moduleName = null)
|
16 |
+
{
|
17 |
if (Mage::getStoreConfig(self::CONFIG_ACTIVE) == '0') {
|
18 |
return false;
|
19 |
}
|
21 |
return parent::isModuleEnabled($moduleName = null);
|
22 |
}
|
23 |
|
24 |
+
public function getBaseScript($store = null)
|
25 |
+
{
|
26 |
|
27 |
+
// $baseScript = "";
|
28 |
|
29 |
try {
|
30 |
+
$baseScript = "\n<!-- ChoiceAI Script begins -->\n<script type='text/javascript'>!function(){function t(){
|
31 |
+
if(!window.CAIBASE){var t=document.createElement('script'),n='beaconhttp.choice.ai';
|
32 |
+
t.type='text/javascript',t.async=!0,
|
33 |
+
'https:'==location.protocol&&(n='d3caf2da6t944y.cloudfront.net'),t.src='//'+n+'/site/ethno/ORG_HANDLE/choice.js';
|
34 |
+
var e=document.getElementsByTagName('script')[0];e.parentNode.insertBefore(t,e)}}
|
35 |
+
window.CAIBASE&&window.CAIBASE.reinit&&window.CAIBASE.reinit(),!window.CAIBASE && t()}();</script>
|
36 |
+
\n<!-- ChoiceAI Script ends -->\n";
|
37 |
+
$baseScript = str_replace(
|
38 |
+
"ORG_HANDLE", explode(
|
39 |
+
"_", Mage::getStoreConfig(
|
40 |
+
self::CONFIG_API_KEY, $store
|
41 |
+
)
|
42 |
+
)[0], $baseScript
|
43 |
+
);
|
44 |
} catch (Exception $e) {
|
45 |
+
$baseScript = "";
|
46 |
}
|
47 |
|
48 |
+
return $baseScript;
|
49 |
|
50 |
}
|
51 |
|
app/code/community/ChoiceAI/Personalisation/Model/Observer.php
CHANGED
@@ -1,124 +1,123 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class ChoiceAI_Personalisation_Model_Observer
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
68 |
|
69 |
-
} catch (Exception $e) {
|
70 |
-
$error_message = $e->getMessage();
|
71 |
}
|
72 |
|
73 |
-
|
|
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
if($product->getTypeId() == 'bundle') {
|
88 |
-
|
89 |
-
$id = $product->getId();
|
90 |
-
$optionCollection = $product->getTypeInstance()->getOptionsCollection();
|
91 |
-
$selectionCollection = $product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
|
92 |
-
$options = $optionCollection->appendSelections($selectionCollection);
|
93 |
-
foreach( $options as $option )
|
94 |
-
{
|
95 |
-
$_selections = $option->getSelections();
|
96 |
-
foreach( $_selections as $selection )
|
97 |
-
{
|
98 |
-
$bundleItem = array();
|
99 |
-
$bundleItem['pid'] = $selection->getId();
|
100 |
-
$bundleItem['sku'] = $selection->getSku();
|
101 |
-
$bundleItem['price'] = $selection->getPrice();
|
102 |
-
$bundle[] = $bundleItem;
|
103 |
}
|
104 |
-
}
|
105 |
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
-
$parentId = '';
|
109 |
-
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($id);
|
110 |
-
if($parentIds != null && count($parentIds) > 0) {
|
111 |
-
$parentId = $parentIds[0];
|
112 |
}
|
113 |
-
Mage::getModel('core/session')->setProductToShoppingCart(
|
114 |
-
array(
|
115 |
-
'id' => $id,
|
116 |
-
'sku' => $product->getSku(),
|
117 |
-
'parentId' => $parentId,
|
118 |
-
'qty' => $product->getQty(),
|
119 |
-
'bundle' => $bundle
|
120 |
-
)
|
121 |
-
);
|
122 |
-
|
123 |
-
}
|
124 |
}
|
1 |
<?php
|
2 |
|
3 |
+
class ChoiceAI_Personalisation_Model_Observer
|
4 |
+
{
|
5 |
+
|
6 |
+
const CONFIG_ACTIVE = 'choiceai_personalisation/settings/active';
|
7 |
+
const CONFIG_API_KEY = 'choiceai_personalisation/settings/api_key';
|
8 |
+
|
9 |
+
public function onSaveSettings($observer)
|
10 |
+
{
|
11 |
+
|
12 |
+
$enabled = Mage::getStoreConfig(self::CONFIG_ACTIVE);
|
13 |
+
$apiKey = Mage::getStoreConfig(self::CONFIG_API_KEY);
|
14 |
+
$errorMessage = "";
|
15 |
+
|
16 |
+
try {
|
17 |
+
$roles = Mage::getModel('api/roles')->getCollection()->addFieldToFilter('role_name', 'ChoiceAI');
|
18 |
+
|
19 |
+
if ($roles && !empty($roles)) {
|
20 |
+
$apiRole = $roles->getFirstItem();
|
21 |
+
} else {
|
22 |
+
$apiRole = Mage::getModel('api/roles')
|
23 |
+
->setName('ChoiceAI')
|
24 |
+
->setPid("ChoiceAI")
|
25 |
+
->setRoleType('G')
|
26 |
+
->save();
|
27 |
+
}
|
28 |
+
|
29 |
+
Mage::getModel('api/rules')
|
30 |
+
->setRoleId($apiRole->getId())
|
31 |
+
->setResources(array('all'))
|
32 |
+
->saveRel();
|
33 |
+
|
34 |
+
$users = Mage::getModel('api/user')->getCollection()->addFieldToFilter(
|
35 |
+
'email',
|
36 |
+
'magento@choice.ai'
|
37 |
+
);
|
38 |
+
if ($users && !empty($users)) {
|
39 |
+
$apiUser = $users->getFirstItem();
|
40 |
+
} else {
|
41 |
+
$apiUser = Mage::getModel('api/user');
|
42 |
+
$apiUser->setData(
|
43 |
+
array(
|
44 |
+
'username' => 'choiceai',
|
45 |
+
'firstname' => 'ChoiceAI',
|
46 |
+
'lastname' => 'Personalisation',
|
47 |
+
'email' => 'magento@choice.ai',
|
48 |
+
'api_key' => $apiKey,
|
49 |
+
'api_key_confirmation' => $apiKey,
|
50 |
+
'is_active' => 1,
|
51 |
+
'user_roles' => '',
|
52 |
+
'assigned_user_role' => '',
|
53 |
+
'role_name' => '',
|
54 |
+
'roles' => array($apiRole->getId())
|
55 |
+
)
|
56 |
+
);
|
57 |
+
|
58 |
+
$apiUser->save()->load($apiUser->getId());
|
59 |
+
}
|
60 |
+
|
61 |
+
$apiUser->setRoleIds(array($apiRole->getId()))
|
62 |
+
->setRoleUserId($apiUser->getUserId())
|
63 |
+
->saveRelations();
|
64 |
+
} catch (Exception $e) {
|
65 |
+
$errorMessage = $e->getMessage();
|
66 |
+
}
|
67 |
|
68 |
+
file_get_contents(
|
69 |
+
"https://app.choice.ai/stats/magentoinstall?enabled=" . $enabled . "&api_key="
|
70 |
+
. $apiKey . "&error=" . $errorMessage
|
71 |
+
);
|
72 |
|
|
|
|
|
73 |
}
|
74 |
|
75 |
+
public function logCartAdd($observer)
|
76 |
+
{
|
77 |
|
78 |
+
if (!$observer->getQuoteItem()->getProduct()->getId()) {
|
79 |
+
return;
|
80 |
+
}
|
81 |
|
82 |
+
$product = $observer->getProduct();
|
83 |
+
$id = $observer->getQuoteItem()->getProduct()->getId();
|
84 |
+
$bundle = array();
|
85 |
+
|
86 |
+
if ($product->getTypeId() == 'bundle') {
|
87 |
+
$id = $product->getId();
|
88 |
+
$optionCollection = $product->getTypeInstance()->getOptionsCollection();
|
89 |
+
$selectionCollection = $product->getTypeInstance()->getSelectionsCollection(
|
90 |
+
$product->getTypeInstance()
|
91 |
+
->getOptionsIds()
|
92 |
+
);
|
93 |
+
$options = $optionCollection->appendSelections($selectionCollection);
|
94 |
+
foreach ($options as $option) {
|
95 |
+
$_selections = $option->getSelections();
|
96 |
+
foreach ($_selections as $selection) {
|
97 |
+
$bundleItem = array();
|
98 |
+
$bundleItem['pid'] = $selection->getId();
|
99 |
+
$bundleItem['sku'] = $selection->getSku();
|
100 |
+
$bundleItem['price'] = $selection->getPrice();
|
101 |
+
$bundle[] = $bundleItem;
|
102 |
+
}
|
103 |
+
}
|
104 |
+
}
|
105 |
|
106 |
+
$parentId = '';
|
107 |
+
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($id);
|
108 |
+
if ($parentIds != null && !empty($parentIds)) {
|
109 |
+
$parentId = $parentIds[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
}
|
|
|
111 |
|
112 |
+
Mage::getModel('core/session')->setProductToShoppingCart(
|
113 |
+
array(
|
114 |
+
'id' => $id,
|
115 |
+
'sku' => $product->getSku(),
|
116 |
+
'parentId' => $parentId,
|
117 |
+
'qty' => $product->getQty(),
|
118 |
+
'bundle' => $bundle
|
119 |
+
)
|
120 |
+
);
|
121 |
|
|
|
|
|
|
|
|
|
122 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
}
|
app/code/community/ChoiceAI/Personalisation/controllers/ApiController.php
CHANGED
@@ -7,21 +7,28 @@
|
|
7 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
*/
|
9 |
|
10 |
-
class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_Action
|
|
|
11 |
|
12 |
const CONFIG_API_KEY = 'choiceai_personalisation/settings/api_key';
|
13 |
const CONFIG_KEY = 'choiceai_personalisation/settings/config';
|
14 |
-
const API_VERSION =
|
15 |
|
16 |
-
public function _authorise()
|
|
|
17 |
|
18 |
-
$
|
19 |
|
20 |
// Check for api access
|
21 |
-
if(!$
|
22 |
// Api access disabled
|
23 |
$this->getResponse()
|
24 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
25 |
->setHttpResponseCode(403)
|
26 |
->setHeader('Content-type', 'application/json', true);
|
27 |
return false;
|
@@ -38,16 +45,26 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
38 |
Mage::log('Unable to extract authorization header from request', null, 'choiceai.log');
|
39 |
// Internal server error
|
40 |
$this->getResponse()
|
41 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
42 |
->setHttpResponseCode(500)
|
43 |
->setHeader('Content-type', 'application/json', true);
|
44 |
return false;
|
45 |
}
|
46 |
|
47 |
-
if(trim($authHeader) !== trim($
|
48 |
// Api access denied
|
49 |
$this->getResponse()
|
50 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
51 |
->setHttpResponseCode(401)
|
52 |
->setHeader('Content-type', 'application/json', true);
|
53 |
return false;
|
@@ -57,30 +74,134 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
57 |
|
58 |
}
|
59 |
|
60 |
-
public function
|
|
|
61 |
try {
|
62 |
-
if(!$this->_authorise()) {
|
63 |
return $this;
|
64 |
}
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
$responseObj = array();
|
67 |
|
68 |
-
if ($
|
69 |
-
$
|
70 |
$responseObj["status"] = "ok";
|
71 |
-
$responseObj["config"] = json_decode($
|
72 |
-
} else if ($
|
73 |
-
$
|
74 |
-
if($
|
75 |
$input = file_get_contents('php://input');
|
76 |
$input = utf8_encode($input);
|
77 |
-
$
|
78 |
}
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
82 |
}
|
83 |
-
|
|
|
84 |
Mage::app()->getStore()->resetConfig();
|
85 |
$responseObj["status"] = "ok";
|
86 |
} else {
|
@@ -88,24 +209,79 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
88 |
$responseObj['message'] = 'Invalid request';
|
89 |
}
|
90 |
|
91 |
-
if(isset($
|
92 |
-
$storeUrl = $
|
93 |
-
} else{
|
94 |
$storeUrl = Mage::getBaseUrl();
|
95 |
}
|
|
|
96 |
$responseObj['store_url'] = $storeUrl;
|
97 |
-
$responseObj['
|
98 |
$responseObj['api_version'] = self::API_VERSION;
|
99 |
-
$responseObj['plugin_version'] = (string)Mage::getConfig()
|
|
|
100 |
$responseObj['magento_version'] = Mage::getVersion();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
$this->getResponse()
|
102 |
->setBody(json_encode($responseObj))
|
103 |
->setHttpResponseCode(200)
|
104 |
->setHeader('Content-type', 'application/json', true);
|
105 |
-
|
106 |
-
} catch(Exception $e) {
|
107 |
$this->getResponse()
|
108 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
109 |
->setHttpResponseCode(500)
|
110 |
->setHeader('Content-type', 'application/json', true);
|
111 |
}
|
@@ -113,15 +289,16 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
113 |
return $this;
|
114 |
}
|
115 |
|
116 |
-
public function ordersAction()
|
|
|
117 |
try {
|
118 |
-
if(!$this->_authorise()) {
|
119 |
return $this;
|
120 |
}
|
121 |
|
122 |
$sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
|
123 |
|
124 |
-
if(isset($sections[3])) {
|
125 |
// Looking for a specific order
|
126 |
$orderId = $sections[3];
|
127 |
|
@@ -129,9 +306,10 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
129 |
|
130 |
$extras = $this->getRequest()->getParam('extras');
|
131 |
$debug = $this->getRequest()->getParam('mwdebug', 'false') === 'true';
|
132 |
-
if($extras &&
|
133 |
$extras = explode(',', $extras);
|
134 |
-
|
|
|
135 |
$extras[$i] = trim($extras[$i]);
|
136 |
}
|
137 |
}
|
@@ -140,13 +318,13 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
140 |
|
141 |
$orderItems = $order->getItemsCollection()->load();
|
142 |
|
143 |
-
foreach($orderItems as $key => $orderItem) {
|
144 |
$items[] = array(
|
145 |
-
'name'
|
146 |
-
'pid'
|
147 |
-
'sku'
|
148 |
-
'qty'
|
149 |
-
'price' =>
|
150 |
);
|
151 |
}
|
152 |
|
@@ -157,10 +335,10 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
157 |
);
|
158 |
|
159 |
$attributes = $order->debug();
|
160 |
-
if($debug) {
|
161 |
$responseObj['extras'] = $attributes;
|
162 |
} else {
|
163 |
-
foreach($extras as $key) {
|
164 |
$responseObj['extras'][$key] = $attributes[$key];
|
165 |
}
|
166 |
}
|
@@ -173,7 +351,8 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
173 |
} else {
|
174 |
// Looking for a list of orders
|
175 |
$currentTime = time();
|
176 |
-
$fromDate = $this->getRequest()
|
|
|
177 |
$toDate = $this->getRequest()->getParam('toDate', date('Y-m-d', $currentTime));
|
178 |
|
179 |
$orders = array();
|
@@ -184,26 +363,35 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
184 |
->addAttributeToSelect('created_at')
|
185 |
->addAttributeToSelect('increment_id')
|
186 |
->addAttributeToSelect('status')
|
187 |
-
->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate))
|
188 |
-
;
|
189 |
|
190 |
foreach ($ordersCollection as $order) {
|
191 |
$orders[] = array(
|
192 |
-
'order_id'
|
193 |
-
'status'
|
194 |
-
'email'
|
195 |
-
'created_at'
|
196 |
);
|
197 |
}
|
198 |
|
199 |
$this->getResponse()
|
200 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
201 |
->setHttpResponseCode(200)
|
202 |
->setHeader('Content-type', 'application/json', true);
|
203 |
}
|
204 |
-
} catch(Exception $e) {
|
205 |
$this->getResponse()
|
206 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
207 |
->setHttpResponseCode(500)
|
208 |
->setHeader('Content-type', 'application/json', true);
|
209 |
}
|
@@ -211,44 +399,43 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
211 |
return $this;
|
212 |
}
|
213 |
|
214 |
-
public function productattributesAction()
|
|
|
215 |
try {
|
216 |
-
if(!$this->_authorise()) {
|
217 |
return $this;
|
218 |
}
|
219 |
|
220 |
$sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
|
221 |
|
222 |
-
if(!isset($sections[3])) {
|
223 |
// product id
|
224 |
-
|
225 |
}
|
226 |
|
227 |
$productId = $sections[3];
|
228 |
|
229 |
$product = Mage::getModel('catalog/product')->load($productId);
|
230 |
|
231 |
-
$
|
232 |
|
233 |
-
$
|
234 |
-
$
|
235 |
-
$
|
236 |
-
$
|
237 |
-
$
|
238 |
-
$
|
239 |
-
$
|
240 |
-
$
|
241 |
|
242 |
$variants = array();
|
243 |
$options = array();
|
244 |
|
245 |
if ($product->getTypeId() == "configurable") {
|
246 |
-
|
247 |
$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
|
248 |
$attributeTypes = array();
|
249 |
|
250 |
foreach ($productAttributeOptions as $productAttribute) {
|
251 |
-
|
252 |
$attributes = array();
|
253 |
foreach ($productAttribute['values'] as $attribute) {
|
254 |
$attributes[] = array(
|
@@ -267,12 +454,10 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
267 |
);
|
268 |
|
269 |
$attributeTypes[] = $attributeType;
|
270 |
-
|
271 |
}
|
272 |
|
273 |
$associatedProducts = $product->getTypeInstance()->getUsedProducts();
|
274 |
foreach ($associatedProducts as $associatedProduct) {
|
275 |
-
|
276 |
$variant = array();
|
277 |
$variant["is_available"] = $associatedProduct->isAvailable();
|
278 |
$variant["id"] = $associatedProduct->getId();
|
@@ -291,21 +476,130 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
291 |
}
|
292 |
|
293 |
$this->getResponse()
|
294 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
295 |
->setHttpResponseCode(200)
|
296 |
->setHeader('Content-type', 'application/json', true);
|
297 |
-
} catch(Exception $e) {
|
298 |
$this->getResponse()
|
299 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
->setHttpResponseCode(500)
|
301 |
->setHeader('Content-type', 'application/json', true);
|
302 |
}
|
|
|
303 |
return $this;
|
|
|
304 |
}
|
305 |
|
306 |
-
public function productsAction()
|
|
|
307 |
try {
|
308 |
-
if(!$this->_authorise()) {
|
309 |
return $this;
|
310 |
}
|
311 |
|
@@ -317,6 +611,9 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
317 |
'sku',
|
318 |
'image',
|
319 |
'manufacturer',
|
|
|
|
|
|
|
320 |
'price',
|
321 |
'final_price',
|
322 |
'special_price',
|
@@ -324,65 +621,117 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
324 |
);
|
325 |
|
326 |
$extras = $this->getRequest()->getParam('extras');
|
|
|
|
|
|
|
|
|
|
|
327 |
$debug = $this->getRequest()->getParam('mwdebug', 'false') === 'true';
|
328 |
|
329 |
-
if($
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
$extras = explode(',', $extras);
|
331 |
-
|
|
|
332 |
$extras[$i] = trim($extras[$i]);
|
333 |
$attributes[] = $extras[$i];
|
334 |
}
|
335 |
}
|
336 |
|
337 |
-
|
|
|
338 |
// Looking for a specific product
|
339 |
$productId = $sections[3];
|
|
|
|
|
340 |
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
throw new Exception("Failed to fetch the product");
|
348 |
}
|
|
|
349 |
|
350 |
-
|
351 |
// Looking for a list of products
|
352 |
$limit = $this->getRequest()->getParam('limit', 100);
|
353 |
$offset = $this->getRequest()->getParam('offset', 1);
|
354 |
|
355 |
$productsCollection = Mage::getModel('catalog/product')->getCollection();
|
356 |
|
|
|
357 |
// Get only enabled products
|
358 |
-
|
359 |
-
->
|
360 |
-
|
361 |
-
|
362 |
-
|
|
|
363 |
|
364 |
-
|
365 |
-
$
|
366 |
-
if($product !== null) {
|
367 |
-
$products[] = $product;
|
368 |
-
}else{
|
369 |
-
throw new Exception("Failed to fetch the product");
|
370 |
-
}
|
371 |
}
|
372 |
|
373 |
-
|
|
|
|
|
|
|
374 |
|
375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
|
377 |
$this->getResponse()
|
378 |
-
->setBody(json_encode(array('products' => $products, '
|
379 |
->setHttpResponseCode(200)
|
380 |
->setHeader('Content-type', 'application/json', true);
|
381 |
-
|
382 |
-
|
383 |
-
} catch(Exception $e) {
|
384 |
$this->getResponse()
|
385 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
386 |
->setHttpResponseCode(500)
|
387 |
->setHeader('Content-type', 'application/json', true);
|
388 |
}
|
@@ -391,9 +740,10 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
391 |
}
|
392 |
|
393 |
|
394 |
-
public function categoriesAction()
|
|
|
395 |
try {
|
396 |
-
if(!$this->_authorise()) {
|
397 |
return $this;
|
398 |
}
|
399 |
|
@@ -406,6 +756,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
406 |
'path',
|
407 |
'is_anchor',
|
408 |
'is_active',
|
|
|
409 |
'created_at',
|
410 |
'updated_at'
|
411 |
);
|
@@ -417,25 +768,30 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
417 |
$active = $this->getRequest()->getParam('active', 'false') === 'true';
|
418 |
$isAnchor = $this->getRequest()->getParam('is_anchor', 'false') === 'true';
|
419 |
|
420 |
-
if($level &&
|
421 |
-
$level =
|
422 |
} else {
|
423 |
$level = null;
|
424 |
}
|
425 |
|
426 |
-
if(isset($sections[3])) {
|
427 |
// Looking for a specific category
|
428 |
$categoryId = $sections[3];
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
if($category !== null && $category->id != null && is_array($category)) {
|
434 |
$categories[] = $category;
|
435 |
-
} else{
|
436 |
-
|
437 |
-
}
|
438 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
439 |
} else {
|
440 |
// Looking for a list of categories
|
441 |
$limit = $this->getRequest()->getParam('limit', 100);
|
@@ -443,51 +799,54 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
443 |
|
444 |
$categoriesCollection = Mage::getModel('catalog/category')->getCollection();
|
445 |
|
446 |
-
if($level != null) {
|
447 |
$categoriesCollection
|
448 |
->addAttributeToFilter('level', $level) //we can specify the level of categories to be fetched
|
449 |
;
|
450 |
}
|
451 |
|
452 |
-
if($active != null) {
|
453 |
$categoriesCollection
|
454 |
->addAttributeToFilter('is_active', 1) //if you want only active categories
|
455 |
;
|
456 |
}
|
457 |
|
458 |
-
if($isAnchor != null) {
|
459 |
$categoriesCollection
|
460 |
-
->addAttributeToFilter('is_anchor', 1) //
|
461 |
;
|
462 |
}
|
463 |
|
464 |
$categoriesCollection
|
465 |
->addAttributeToSelect($attributes)
|
466 |
-
->getSelect()->limit($limit, $offset) //
|
467 |
;
|
468 |
|
469 |
-
foreach($categoriesCollection as $category) {
|
470 |
$category = $this->getFormattedCategory($category);
|
471 |
-
if($category !== null && is_array($category)) {
|
472 |
$categories[] = $category;
|
473 |
}
|
474 |
}
|
475 |
-
|
476 |
}
|
477 |
|
478 |
$this->getResponse()
|
479 |
->setBody(json_encode(array('categories' => $categories, 'version' => self::API_VERSION)))
|
480 |
->setHttpResponseCode(200)
|
481 |
->setHeader('Content-type', 'application/json', true);
|
482 |
-
|
483 |
-
|
484 |
-
if($e->getMessage() != null)
|
485 |
$message = $e->getMessage();
|
486 |
else
|
487 |
$message = 'Internal server error';
|
488 |
|
489 |
$this->getResponse()
|
490 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
491 |
->setHttpResponseCode(500)
|
492 |
->setHeader('Content-type', 'application/json', true);
|
493 |
}
|
@@ -496,9 +855,10 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
496 |
}
|
497 |
|
498 |
|
499 |
-
public function facetattributesAction()
|
|
|
500 |
try {
|
501 |
-
if(!$this->_authorise()) {
|
502 |
return $this;
|
503 |
}
|
504 |
|
@@ -509,9 +869,9 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
509 |
|
510 |
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
|
511 |
|
512 |
-
if($isFilterable && is_numeric($isFilterable)){
|
513 |
-
$collection->addFieldToFilter('is_filterable', (int)
|
514 |
-
} else{
|
515 |
// Give only is filterable with results
|
516 |
$collection->addFieldToFilter('is_filterable', 1);
|
517 |
}
|
@@ -532,20 +892,20 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
532 |
// "is_used_for_price_rules",
|
533 |
// "used_in_product_listing"
|
534 |
// );
|
535 |
-
//
|
536 |
// $collection->addFieldToSelect($fieldsToSelect);
|
537 |
|
538 |
$collection->setOrder('position', 'ASC');
|
539 |
-
$collection->setPageSize((int)
|
540 |
-
$collection->setCurPage((int)
|
541 |
$collection->load();
|
542 |
|
543 |
-
if($limit * ($page-1) < $collection->getSize()) {
|
544 |
$allAttrs = array();
|
545 |
|
546 |
foreach ($collection as $attr) {
|
547 |
$newAttr = array();
|
548 |
-
if($fields=="all") {
|
549 |
$newAttr['attribute_id'] = $attr->getAttributeId();
|
550 |
$newAttr['is_filterable'] = $attr->getIsFilterable();
|
551 |
$newAttr['attribute_code'] = $attr->getAttributeCode();
|
@@ -560,7 +920,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
560 |
$newAttr['is_used_for_promo_rules'] = $attr->getIsUsedForPromoRules();
|
561 |
$newAttr['is_used_for_price_rules'] = $attr->getIsUsedForPriceRules();
|
562 |
$newAttr['used_in_product_listing'] = $attr->getUsedInProductListing();
|
563 |
-
} else{
|
564 |
$newAttr['attribute_id'] = $attr->getAttributeId();
|
565 |
$newAttr['is_filterable'] = $attr->getIsFilterable();
|
566 |
$newAttr['attribute_code'] = $attr->getAttributeCode();
|
@@ -575,7 +935,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
575 |
|
576 |
$allAttrs[] = $newAttr;
|
577 |
}
|
578 |
-
} else{
|
579 |
$allAttrs = array();
|
580 |
}
|
581 |
|
@@ -583,9 +943,14 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
583 |
->setBody(json_encode(array('attributes' => $allAttrs, 'version' => self::API_VERSION)))
|
584 |
->setHttpResponseCode(200)
|
585 |
->setHeader('Content-type', 'application/json', true);
|
586 |
-
} catch(Exception $e) {
|
587 |
$this->getResponse()
|
588 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
589 |
->setHttpResponseCode(500)
|
590 |
->setHeader('Content-type', 'application/json', true);
|
591 |
}
|
@@ -594,16 +959,17 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
594 |
}
|
595 |
|
596 |
|
597 |
-
public function modifyfacetattributeAction()
|
|
|
598 |
try {
|
599 |
-
if(!$this->_authorise()) {
|
600 |
return $this;
|
601 |
}
|
602 |
|
603 |
$facetData = $this->getRequest()->getParam('newData', false);
|
604 |
$newFacetData = json_decode($facetData);
|
605 |
|
606 |
-
if(!$newFacetData){
|
607 |
if ($facetData == "") {
|
608 |
$input = file_get_contents('php://input');
|
609 |
$input = utf8_encode($input);
|
@@ -611,8 +977,8 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
611 |
}
|
612 |
}
|
613 |
|
614 |
-
if(!$newFacetData && !$newFacetData->attribute_id)
|
615 |
-
|
616 |
|
617 |
// updates the facet
|
618 |
$resourceModel = Mage::getResourceModel('catalog/product_attribute_collection');
|
@@ -624,25 +990,31 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
624 |
foreach ($newFacetData as $key => $value) {
|
625 |
$attributeObj->setData($key, $value);
|
626 |
}
|
|
|
627 |
$updateStatus = $attributeObj->save();
|
628 |
|
629 |
-
if(!$updateStatus)
|
630 |
-
|
631 |
else
|
632 |
Mage::app()->getCache()->save(null, "sysFacets", array("facets"));
|
633 |
|
634 |
$this->getResponse()
|
635 |
-
->setBody(json_encode(array("status"=>"ok", 'version' => self::API_VERSION)))
|
636 |
->setHttpResponseCode(200)
|
637 |
->setHeader('Content-type', 'application/json', true);
|
638 |
-
} catch(Exception $e) {
|
639 |
-
if($e->getMessage())
|
640 |
$errorMsg = $e->getMessage();
|
641 |
else
|
642 |
$errorMsg = "Internal server error";
|
643 |
|
644 |
$this->getResponse()
|
645 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
646 |
->setHttpResponseCode(500)
|
647 |
->setHeader('Content-type', 'application/json', true);
|
648 |
}
|
@@ -651,7 +1023,8 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
651 |
}
|
652 |
|
653 |
// Formats the attribute for save
|
654 |
-
|
|
|
655 |
/** @var $helperCatalog Mage_Catalog_Helper_Data */
|
656 |
$helperCatalog = Mage::helper('catalog');
|
657 |
|
@@ -666,15 +1039,19 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
666 |
if (!isset($data['is_configurable'])) {
|
667 |
$data['is_configurable'] = 0;
|
668 |
}
|
|
|
669 |
if (!isset($data['is_filterable'])) {
|
670 |
$data['is_filterable'] = 1;
|
671 |
}
|
|
|
672 |
if (!isset($data['is_filterable_in_search'])) {
|
673 |
$data['is_filterable_in_search'] = 1;
|
674 |
}
|
|
|
675 |
if (!isset($data['apply_to'])) {
|
676 |
$data['apply_to'] = array();
|
677 |
}
|
|
|
678 |
// set frontend labels array with store_id as keys
|
679 |
if (isset($data['frontend_label']) && is_array($data['frontend_label'])) {
|
680 |
$labels = array();
|
@@ -683,13 +1060,16 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
683 |
$labelText = $helperCatalog->stripTags($label['label']);
|
684 |
$labels[$storeId] = $labelText;
|
685 |
}
|
|
|
686 |
$data['frontend_label'] = $labels;
|
687 |
}
|
|
|
688 |
// set additional fields
|
689 |
if (isset($data['additional_fields']) && is_array($data['additional_fields'])) {
|
690 |
$data = array_merge($data, $data['additional_fields']);
|
691 |
unset($data['additional_fields']);
|
692 |
}
|
|
|
693 |
//default value
|
694 |
if (!empty($data['default_value'])) {
|
695 |
$data['default_value'] = $helperCatalog->stripTags($data['default_value']);
|
@@ -699,31 +1079,33 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
699 |
}
|
700 |
|
701 |
|
702 |
-
public function addfacetattributeAction()
|
|
|
703 |
try {
|
704 |
-
if(!$this->_authorise()) {
|
705 |
return $this;
|
706 |
}
|
707 |
|
708 |
$facetData = $this->getRequest()->getParam('newData', false);
|
709 |
$newFacetData = json_decode($facetData);
|
710 |
|
711 |
-
if(!$newFacetData){
|
712 |
if ($facetData == "") {
|
713 |
$input = file_get_contents('php://input');
|
714 |
$input = utf8_encode($input);
|
715 |
$newFacetData = json_decode($input)->newData;
|
716 |
}
|
717 |
}
|
|
|
718 |
$newFacetData = (array)$newFacetData;
|
719 |
|
720 |
if (!$newFacetData || empty($newFacetData['attribute_code']) || !isset($newFacetData['frontend_label'])) {
|
721 |
-
|
722 |
}
|
723 |
|
724 |
//validate attribute_code
|
725 |
if (!preg_match('/^[a-z][a-z_0-9]{0,254}$/', $newFacetData['attribute_code'])) {
|
726 |
-
|
727 |
}
|
728 |
|
729 |
/** @var $model Mage_Catalog_Model_Resource_Eav_Attribute */
|
@@ -734,7 +1116,7 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
734 |
|
735 |
$newFacetData['source_model'] = $helper->getAttributeSourceModelByInputType('multiselect');
|
736 |
$newFacetData['backend_model'] = $helper->getAttributeBackendModelByInputType('multiselect');
|
737 |
-
if (
|
738 |
$newFacetData['backend_type'] = $model->getBackendTypeByInput('multiselect');
|
739 |
}
|
740 |
|
@@ -752,17 +1134,22 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
752 |
Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG));
|
753 |
|
754 |
$this->getResponse()
|
755 |
-
->setBody(json_encode(array("status"=>"ok", 'version' => self::API_VERSION)))
|
756 |
->setHttpResponseCode(200)
|
757 |
->setHeader('Content-type', 'application/json', true);
|
758 |
-
} catch(Exception $e) {
|
759 |
-
if($e->getMessage())
|
760 |
$errorMsg = $e->getMessage();
|
761 |
else
|
762 |
$errorMsg = "Internal server error";
|
763 |
|
764 |
$this->getResponse()
|
765 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
766 |
->setHttpResponseCode(500)
|
767 |
->setHeader('Content-type', 'application/json', true);
|
768 |
}
|
@@ -771,11 +1158,11 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
771 |
}
|
772 |
|
773 |
|
774 |
-
public function usersAction()
|
|
|
775 |
|
776 |
try {
|
777 |
-
|
778 |
-
if(!$this->_authorise()) {
|
779 |
return $this;
|
780 |
}
|
781 |
|
@@ -795,29 +1182,25 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
795 |
|
796 |
$usersCollection = Mage::getModel('customer/customer')->getCollection();
|
797 |
|
798 |
-
if($email != null &&
|
799 |
-
|
800 |
$usersCollection
|
801 |
->addAttributeToFilter('email', $email);
|
802 |
-
|
803 |
} else {
|
804 |
-
|
805 |
-
$
|
806 |
-
$created_at_max = $this->getRequest()->getParam('created_at_max');
|
807 |
|
808 |
$usersCollection->addAttributeToSelect($attributes);
|
809 |
|
810 |
-
if($
|
811 |
-
$usersCollection->addAttributeToFilter('created_at', array('from' => $
|
812 |
}
|
813 |
|
814 |
-
if($
|
815 |
-
$usersCollection->addAttributeToFilter('created_at', array('to' => $
|
816 |
}
|
817 |
|
818 |
$usersCollection->getSelect()
|
819 |
->limit($limit, $offset);
|
820 |
-
|
821 |
}
|
822 |
|
823 |
$users = array();
|
@@ -838,10 +1221,14 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
838 |
->setBody(json_encode(array('users' => $users, 'version' => self::API_VERSION)))
|
839 |
->setHttpResponseCode(200)
|
840 |
->setHeader('Content-type', 'application/json', true);
|
841 |
-
|
842 |
-
} catch(Exception $e) {
|
843 |
$this->getResponse()
|
844 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
845 |
->setHttpResponseCode(500)
|
846 |
->setHeader('Content-type', 'application/json', true);
|
847 |
}
|
@@ -850,168 +1237,485 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
850 |
|
851 |
}
|
852 |
|
|
|
|
|
|
|
|
|
|
|
|
|
853 |
|
854 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
855 |
|
856 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
857 |
|
858 |
-
|
859 |
-
|
|
|
|
|
|
|
|
|
|
|
860 |
}
|
861 |
|
862 |
-
$productId
|
863 |
-
|
|
|
|
|
864 |
|
|
|
865 |
|
866 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
867 |
|
868 |
-
$
|
869 |
-
->
|
870 |
-
|
871 |
-
->setHeader('Content-type', 'application/json', true);
|
872 |
|
873 |
-
|
|
|
|
|
|
|
874 |
|
875 |
-
|
876 |
-
|
877 |
-
$
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
|
|
|
|
|
|
|
|
884 |
}
|
885 |
-
$productId = $product->getId();
|
886 |
}
|
|
|
887 |
|
888 |
-
|
889 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
890 |
|
891 |
-
|
|
|
892 |
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
|
|
|
|
|
|
|
|
|
|
897 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
898 |
}
|
899 |
|
900 |
-
} catch(Exception $e) {
|
901 |
$this->getResponse()
|
902 |
-
->setBody(json_encode(array('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
903 |
->setHttpResponseCode(500)
|
904 |
->setHeader('Content-type', 'application/json', true);
|
905 |
}
|
906 |
|
907 |
return $this;
|
|
|
|
|
|
|
|
|
|
|
908 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
909 |
}
|
910 |
|
|
|
|
|
911 |
|
912 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
913 |
|
914 |
$formattedProduct = null;
|
915 |
|
916 |
try {
|
917 |
$formattedProduct = array(
|
918 |
-
'id'
|
919 |
-
'sku'
|
920 |
-
'name'
|
921 |
-
'cat'
|
922 |
-
'manufacturer'
|
923 |
-
'
|
924 |
-
'
|
925 |
-
'
|
926 |
-
'
|
927 |
-
'
|
928 |
-
'
|
929 |
-
'
|
930 |
-
'
|
931 |
-
'
|
932 |
-
'
|
|
|
|
|
|
|
|
|
|
|
933 |
);
|
934 |
-
if(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
935 |
$product = Mage::getModel('catalog/product')->load($product->getId());
|
936 |
$formattedProduct['manufacturer'] = $product->getAttributeText('manufacturer');
|
937 |
}
|
938 |
|
939 |
-
if($formattedProduct['type'] == "configurable") {
|
940 |
-
|
941 |
-
|
942 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
943 |
}
|
944 |
|
945 |
-
|
946 |
-
|
947 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
948 |
|
949 |
-
if($debug) {
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
954 |
|
955 |
-
|
956 |
-
$formattedProduct['extras'][$key] = $product->getAttributeText($key);
|
957 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
958 |
} else {
|
959 |
-
foreach($extras as $key) {
|
960 |
// Sanity check, or else crashes without proper error handling
|
961 |
$existenceCheck = $product->getResource()->getAttribute($key);
|
962 |
|
963 |
-
if($existenceCheck)
|
964 |
$formattedProduct['extras'][$key] = $product->getAttributeText($key);
|
965 |
}
|
966 |
}
|
967 |
|
968 |
$categories = $product->getCategoryCollection()
|
969 |
->addAttributeToSelect('id')
|
970 |
-
->addAttributeToSelect('name')
|
971 |
-
->addAttributeToSelect('path')
|
972 |
-
->addAttributeToSelect('level');
|
973 |
-
foreach($categories as $category) {
|
974 |
-
$formattedCategory = array();
|
975 |
-
$formattedCategory['id'] = $category->getId();
|
976 |
-
$formattedCategory['name'] = $category->getName();
|
977 |
-
$formattedCategory['level'] = $category->getLevel();
|
978 |
-
$formattedCategory['path'] = $category->getPath();
|
979 |
-
$formattedProduct['cat'][$formattedCategory['id']] = $formattedCategory;
|
|
|
980 |
}
|
981 |
|
982 |
return $formattedProduct;
|
983 |
-
} catch(Exception $e) {
|
984 |
return NULL;
|
985 |
}
|
986 |
}
|
987 |
|
988 |
-
|
|
|
989 |
|
990 |
$formattedCategory = null;
|
991 |
|
992 |
try {
|
993 |
$formattedCategory = array(
|
994 |
-
'id'
|
995 |
-
'name'
|
996 |
-
'image'
|
997 |
-
'url'
|
998 |
-
'level'
|
999 |
-
'path'
|
1000 |
-
'
|
1001 |
-
'
|
1002 |
-
'
|
1003 |
-
'
|
|
|
|
|
1004 |
);
|
1005 |
-
|
1006 |
-
}
|
1007 |
|
1008 |
return $formattedCategory;
|
1009 |
}
|
1010 |
|
1011 |
-
public function sortbyAction()
|
|
|
1012 |
|
1013 |
try {
|
1014 |
-
if(!$this->_authorise()) {
|
1015 |
return $this;
|
1016 |
}
|
1017 |
|
@@ -1036,22 +1740,31 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
1036 |
|
1037 |
foreach ($attributesData as $key => $attributeData) {
|
1038 |
$sortByOptions[] = array(
|
1039 |
-
"_id"=> $key,
|
1040 |
-
"name"=> $attributeData,
|
1041 |
-
"default"=> $key
|
1042 |
-
"order"=> $i
|
1043 |
);
|
1044 |
$i++;
|
1045 |
}
|
1046 |
|
1047 |
$this->getResponse()
|
1048 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
1049 |
->setHttpResponseCode(200)
|
1050 |
->setHeader('Content-type', 'application/json', true);
|
1051 |
-
|
1052 |
-
} catch(Exception $e) {
|
1053 |
$this->getResponse()
|
1054 |
-
->setBody(
|
|
|
|
|
|
|
|
|
|
|
1055 |
->setHttpResponseCode(500)
|
1056 |
->setHeader('Content-type', 'application/json', true);
|
1057 |
}
|
@@ -1059,15 +1772,16 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
1059 |
return $this;
|
1060 |
}
|
1061 |
|
1062 |
-
public function choicepageAction()
|
1063 |
-
|
1064 |
-
|
|
|
1065 |
return $this;
|
1066 |
}
|
1067 |
|
1068 |
$responseObj = array();
|
1069 |
-
|
1070 |
-
if ($
|
1071 |
// Create Choice page
|
1072 |
// Expects title, url_path and content
|
1073 |
|
@@ -1077,12 +1791,13 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
1077 |
$input = utf8_encode($input);
|
1078 |
$pageData = json_encode(json_decode($input)->data);
|
1079 |
}
|
|
|
1080 |
$pageData = json_decode($pageData);
|
1081 |
$urlPath = $pageData->url_path;
|
1082 |
|
1083 |
-
if(!$urlPath){
|
1084 |
// What can this poor guy do without the path?
|
1085 |
-
|
1086 |
}
|
1087 |
|
1088 |
// Ensure no other existing page contains the same URL path or say "identifier"
|
@@ -1093,18 +1808,20 @@ class ChoiceAI_Personalisation_ApiController extends Mage_Core_Controller_Front_
|
|
1093 |
// $existingPages = Mage::getModel('cms/page')->load($collection->getFirstItem()->getId());
|
1094 |
|
1095 |
// There can be multiple pages with same url path, but different store scope. Let's disable all
|
1096 |
-
foreach ($collection as $existingPage){
|
1097 |
// Page already exists && is_active
|
1098 |
-
if($existingPage->getId()) {
|
1099 |
// Delete all other pages having same URL
|
1100 |
// and then continue adding our new page
|
1101 |
-
// $this->updateChoiceUrl(false, $existingPage->getId(), array("is_active" => 0,
|
|
|
1102 |
$existingPage->delete();
|
1103 |
}
|
1104 |
}
|
1105 |
|
1106 |
// Setting default content if not provided
|
1107 |
-
$pageContent = (!isset($pageData->content)) ?
|
|
|
1108 |
|
1109 |
// Setting default Title if not available
|
1110 |
$pageTitle = (!isset($pageData->title)) ? "Choice.AI" : $pageData->title;
|
@@ -1126,7 +1843,7 @@ class ChoiceAI_Personalisation_ApiCo |