Version Notes
* Bug fixes
Download this release
Release Info
Developer | Duc Ngo |
Extension | Jmango360_Japi |
Version | 2.8.1 |
Comparing to | |
See all releases |
Version 2.8.1
- app/code/community/Jmango360/Japi/Block/Adminhtml/Order.php +17 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Order/Grid.php +141 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Chart/Customers.php +297 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Chart/Orders.php +296 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Chart/Sales.php +292 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Customers.php +34 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Customers/Chart.php +24 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Customers/Grid.php +64 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Filter/Form.php +12 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Filter/Form/Orders.php +12 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Orders.php +34 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Orders/Chart.php +24 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Orders/Grid.php +47 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Sales.php +34 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Sales/Chart.php +24 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Sales/Grid.php +24 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/System/Config/Form/Log.php +135 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/System/Config/Form/User.php +18 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/System/Config/Form/Version.php +17 -0
- app/code/community/Jmango360/Japi/Block/Adminhtml/Widget/Form/Renderer/Element/Chart.php +21 -0
- app/code/community/Jmango360/Japi/Block/Catalog/Layer/Filter/Attribute.php +10 -0
- app/code/community/Jmango360/Japi/Block/Catalog/Layer/Filter/Category.php +10 -0
- app/code/community/Jmango360/Japi/Block/Catalog/Layer/Filter/Decimal.php +10 -0
- app/code/community/Jmango360/Japi/Block/Catalog/Layer/Filter/Price.php +10 -0
- app/code/community/Jmango360/Japi/Block/Catalog/Layer/View.php +26 -0
- app/code/community/Jmango360/Japi/Block/Catalog/Product/List.php +18 -0
- app/code/community/Jmango360/Japi/Block/Catalogsearch/Layer.php +35 -0
- app/code/community/Jmango360/Japi/Block/Catalogsearch/Layer/Filter/Attribute.php +13 -0
- app/code/community/Jmango360/Japi/Block/Checkout/Cart/Totals.php +33 -0
- app/code/community/Jmango360/Japi/Block/Checkout/Onepage/Addjs.php +19 -0
- app/code/community/Jmango360/Japi/Block/Checkout/Onepage/Address.php +62 -0
- app/code/community/Jmango360/Japi/Block/Checkout/Onepage/Billing.php +26 -0
- app/code/community/Jmango360/Japi/Block/Checkout/Onepage/Shipping.php +16 -0
- app/code/community/Jmango360/Japi/Block/Form.php +83 -0
- app/code/community/Jmango360/Japi/Block/GiftMessage/Message/Inline.php +20 -0
- app/code/community/Jmango360/Japi/Controller/Abstract.php +34 -0
- app/code/community/Jmango360/Japi/Exception.php +30 -0
- app/code/community/Jmango360/Japi/Helper/Adminhtml/Report/Order.php +49 -0
- app/code/community/Jmango360/Japi/Helper/Data.php +944 -0
- app/code/community/Jmango360/Japi/Helper/Debug.php +21 -0
- app/code/community/Jmango360/Japi/Helper/GiftMessage/Message.php +27 -0
- app/code/community/Jmango360/Japi/Helper/Product.php +1511 -0
- app/code/community/Jmango360/Japi/Helper/Product/Bundle.php +191 -0
- app/code/community/Jmango360/Japi/Helper/Product/Configurable.php +298 -0
- app/code/community/Jmango360/Japi/Helper/Product/Downloadable.php +77 -0
- app/code/community/Jmango360/Japi/Helper/Product/Grouped.php +82 -0
- app/code/community/Jmango360/Japi/Helper/Product/Media.php +157 -0
- app/code/community/Jmango360/Japi/Helper/Product/Options.php +108 -0
- app/code/community/Jmango360/Japi/Helper/Product/TierPrice.php +92 -0
- app/code/community/Jmango360/Japi/Helper/Tax.php +132 -0
- app/code/community/Jmango360/Japi/Model/Catalog/Layer/Filter/Attribute.php +17 -0
- app/code/community/Jmango360/Japi/Model/Catalog/Layer/Filter/Decimal.php +17 -0
- app/code/community/Jmango360/Japi/Model/Catalog/Layer/Filter/Price.php +17 -0
- app/code/community/Jmango360/Japi/Model/Catalogsearch/Layer/Filter/Attribute.php +17 -0
- app/code/community/Jmango360/Japi/Model/Core/Session.php +137 -0
- app/code/community/Jmango360/Japi/Model/Dispatcher.php +16 -0
- app/code/community/Jmango360/Japi/Model/Magpleasure/Tierprices/Price.php +16 -0
- app/code/community/Jmango360/Japi/Model/Observer.php +440 -0
- app/code/community/Jmango360/Japi/Model/Renderer.php +4 -0
- app/code/community/Jmango360/Japi/Model/Renderer/Json.php +9 -0
- app/code/community/Jmango360/Japi/Model/Request.php +82 -0
- app/code/community/Jmango360/Japi/Model/Resource/Catalog/Layer/Filter/Attribute.php +6 -0
- app/code/community/Jmango360/Japi/Model/Resource/Catalog/Layer/Filter/Decimal.php +6 -0
- app/code/community/Jmango360/Japi/Model/Resource/Catalog/Layer/Filter/Price.php +6 -0
- app/code/community/Jmango360/Japi/Model/Resource/Report/Order/Collection.php +146 -0
- app/code/community/Jmango360/Japi/Model/Resource/Sales/Report/Order.php +232 -0
- app/code/community/Jmango360/Japi/Model/Resource/Sales/Report/Order/Collection/Aggregated.php +60 -0
- app/code/community/Jmango360/Japi/Model/Resource/Sales/Report/Order/Collection/Live.php +273 -0
- app/code/community/Jmango360/Japi/Model/Resource/Setup.php +4 -0
- app/code/community/Jmango360/Japi/Model/Response.php +31 -0
- app/code/community/Jmango360/Japi/Model/Rest/Cart.php +459 -0
- app/code/community/Jmango360/Japi/Model/Rest/Cart/Coupon.php +63 -0
- app/code/community/Jmango360/Japi/Model/Rest/Cart/Update.php +342 -0
- app/code/community/Jmango360/Japi/Model/Rest/Catalog.php +183 -0
- app/code/community/Jmango360/Japi/Model/Rest/Catalog/Category/Assignedproducts.php +221 -0
- app/code/community/Jmango360/Japi/Model/Rest/Catalog/Category/Tree.php +200 -0
- app/code/community/Jmango360/Japi/Model/Rest/Catalog/Search/Products.php +239 -0
- app/code/community/Jmango360/Japi/Model/Rest/Catalog/Search/Terms.php +49 -0
- app/code/community/Jmango360/Japi/Model/Rest/Checkout.php +392 -0
- app/code/community/Jmango360/Japi/Model/Rest/Checkout/Methods.php +638 -0
- app/code/community/Jmango360/Japi/Model/Rest/Checkout/Onepage.php +787 -0
- app/code/community/Jmango360/Japi/Model/Rest/Checkout/Redirect.php +26 -0
- app/code/community/Jmango360/Japi/Model/Rest/Checkout/Submit.php +290 -0
- app/code/community/Jmango360/Japi/Model/Rest/Cms.php +54 -0
- app/code/community/Jmango360/Japi/Model/Rest/Cms/Page.php +56 -0
- app/code/community/Jmango360/Japi/Model/Rest/Customer.php +354 -0
- app/code/community/Jmango360/Japi/Model/Rest/Customer/Address.php +118 -0
- app/code/community/Jmango360/Japi/Model/Rest/Customer/Edit.php +107 -0
- app/code/community/Jmango360/Japi/Model/Rest/Customer/Group.php +128 -0
- app/code/community/Jmango360/Japi/Model/Rest/Customer/List.php +56 -0
- app/code/community/Jmango360/Japi/Model/Rest/Customer/Login.php +91 -0
- app/code/community/Jmango360/Japi/Model/Rest/Customer/Order.php +176 -0
- app/code/community/Jmango360/Japi/Model/Rest/Customer/Order/List.php +436 -0
- app/code/community/Jmango360/Japi/Model/Rest/Customer/Password.php +59 -0
- app/code/community/Jmango360/Japi/Model/Rest/Customer/Register.php +211 -0
- app/code/community/Jmango360/Japi/Model/Rest/Mage.php +819 -0
- app/code/community/Jmango360/Japi/Model/Rest/Product.php +151 -0
- app/code/community/Jmango360/Japi/Model/Rest/Product/List.php +53 -0
- app/code/community/Jmango360/Japi/Model/Rest/Product/Purchased.php +70 -0
- app/code/community/Jmango360/Japi/Model/Rest/Product/Search.php +153 -0
- app/code/community/Jmango360/Japi/Model/Rest/Product/Viewed.php +45 -0
- app/code/community/Jmango360/Japi/Model/Rest/Wishlist.php +662 -0
- app/code/community/Jmango360/Japi/Model/Server.php +441 -0
- app/code/community/Jmango360/Japi/Model/System/Config/Backend/Payment.php +28 -0
- app/code/community/Jmango360/Japi/Model/System/Config/Backend/Shipping.php +28 -0
- app/code/community/Jmango360/Japi/Model/System/Config/Source/Address/Attributes.php +35 -0
- app/code/community/Jmango360/Japi/Model/System/Config/Source/Address/Validatetype.php +33 -0
- app/code/community/Jmango360/Japi/Model/System/Config/Source/Attributes.php +24 -0
- app/code/community/Jmango360/Japi/Model/System/Config/Source/Catalogimage.php +37 -0
- app/code/community/Jmango360/Japi/Model/System/Config/Source/Customer/Attributes.php +35 -0
- app/code/community/Jmango360/Japi/Model/System/Config/Source/Defaultimage.php +37 -0
- app/code/community/Jmango360/Japi/Model/System/Config/Source/Payment.php +19 -0
- app/code/community/Jmango360/Japi/Model/System/Config/Source/Shipping.php +27 -0
- app/code/community/Jmango360/Japi/controllers/Adminhtml/Japi/LogController.php +42 -0
- app/code/community/Jmango360/Japi/controllers/Adminhtml/Japi/OrderController.php +45 -0
- app/code/community/Jmango360/Japi/controllers/Adminhtml/Japi/ReportController.php +178 -0
- app/code/community/Jmango360/Japi/controllers/CheckoutController.php +465 -0
- app/code/community/Jmango360/Japi/controllers/CustomerController.php +467 -0
- app/code/community/Jmango360/Japi/controllers/ImageController.php +115 -0
- app/code/community/Jmango360/Japi/controllers/Rest/CartController.php +39 -0
- app/code/community/Jmango360/Japi/controllers/Rest/CatalogController.php +73 -0
- app/code/community/Jmango360/Japi/controllers/Rest/CheckoutController.php +53 -0
- app/code/community/Jmango360/Japi/controllers/Rest/CmsController.php +12 -0
- app/code/community/Jmango360/Japi/controllers/Rest/CustomerController.php +102 -0
- app/code/community/Jmango360/Japi/controllers/Rest/MageController.php +112 -0
- app/code/community/Jmango360/Japi/controllers/Rest/ProductController.php +46 -0
- app/code/community/Jmango360/Japi/controllers/Rest/WishlistController.php +53 -0
- app/code/community/Jmango360/Japi/controllers/TestController.php +234 -0
- app/code/community/Jmango360/Japi/data/japi_setup/data-install-2.0.0.php +7 -0
- app/code/community/Jmango360/Japi/etc/adminhtml.xml +97 -0
- app/code/community/Jmango360/Japi/etc/config.xml +301 -0
- app/code/community/Jmango360/Japi/etc/system.xml +517 -0
- app/code/community/Jmango360/Japi/sql/japi_setup/install-1.0.0.php +1 -0
- app/code/community/Jmango360/Japi/sql/japi_setup/upgrade-2.0.1.2-2.0.2.php +123 -0
- app/code/community/Jmango360/Japi/sql/japi_setup/upgrade-2.1.6-2.2.0.php +22 -0
- app/code/community/Jmango360/Japi/sql/japi_setup/upgrade-2.2.0-2.2.1.php +23 -0
- app/design/adminhtml/default/default/layout/jmango360_japi.xml +68 -0
- app/design/adminhtml/default/default/template/japi/report/chart.phtml +11 -0
- app/design/adminhtml/default/default/template/japi/report/grid/container.phtml +84 -0
- app/design/adminhtml/default/default/template/japi/widget/form/renderer/element/chart.phtml +11 -0
- app/design/frontend/base/default/layout/jmango360_japi.xml +196 -0
- app/design/frontend/base/default/template/japi/TIG/PostNL/address_validation/checkout/onepage/billing.phtml +208 -0
- app/design/frontend/base/default/template/japi/TIG/PostNL/address_validation/checkout/onepage/shipping.phtml +176 -0
- app/design/frontend/base/default/template/japi/TIG/PostNL/address_validation/customer/address/edit.phtml +165 -0
- app/design/frontend/base/default/template/japi/TIG/PostNL/address_validation/customer/address/postcode_check.phtml +160 -0
- app/design/frontend/base/default/template/japi/checkout/onepage.phtml +77 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/address.phtml +48 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/agreements.phtml +78 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/billing.phtml +324 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/coupon.phtml +70 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/js.phtml +6 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/payment.phtml +60 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/payment/info.phtml +29 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/review.phtml +29 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/review/button.phtml +30 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/review/info.phtml +57 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/review/item.phtml +159 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/review/totals.phtml +47 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/shipping.phtml +259 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/shipping_method.phtml +46 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/shipping_method/additional.phtml +29 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/shipping_method/available.phtml +112 -0
- app/design/frontend/base/default/template/japi/checkout/onepage/style.phtml +114 -0
- app/design/frontend/base/default/template/japi/customer/address/edit.phtml +242 -0
- app/design/frontend/base/default/template/japi/customer/form/edit.phtml +135 -0
- app/design/frontend/base/default/template/japi/customer/form/register.phtml +270 -0
- app/design/frontend/base/default/template/japi/form.phtml +48 -0
- app/design/frontend/base/default/template/japi/giftmessage/inline.phtml +334 -0
- app/design/frontend/base/default/template/japi/page/html/head.phtml +45 -0
- app/design/frontend/base/default/template/japi/page/rwd.phtml +19 -0
- app/etc/modules/Jmango360_Japi.xml +12 -0
- app/locale/ar_SA/Jmango360_Japi.csv +233 -0
- app/locale/en_US/Jmango360_Japi.csv +220 -0
app/code/community/Jmango360/Japi/Block/Adminhtml/Order.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2016 JMango360
|
4 |
+
*/
|
5 |
+
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Order extends Mage_Adminhtml_Block_Widget_Grid_Container
|
7 |
+
{
|
8 |
+
public function __construct()
|
9 |
+
{
|
10 |
+
parent::__construct();
|
11 |
+
|
12 |
+
$this->_blockGroup = 'japi';
|
13 |
+
$this->_controller = 'adminhtml_order';
|
14 |
+
$this->_headerText = Mage::helper('japi')->__('Order List');
|
15 |
+
$this->_removeButton('add');
|
16 |
+
}
|
17 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Order/Grid.php
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2016 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
7 |
+
{
|
8 |
+
public function __construct()
|
9 |
+
{
|
10 |
+
parent::__construct();
|
11 |
+
$this->setId('japi_order_grid');
|
12 |
+
$this->setUseAjax(true);
|
13 |
+
$this->setDefaultSort('created_at');
|
14 |
+
$this->setDefaultDir('DESC');
|
15 |
+
$this->setSaveParametersInSession(true);
|
16 |
+
}
|
17 |
+
|
18 |
+
protected function _prepareCollection()
|
19 |
+
{
|
20 |
+
$collection = Mage::getResourceModel('sales/order_collection')
|
21 |
+
->addFieldToFilter('japi', array('eq' => 1))
|
22 |
+
->join(
|
23 |
+
array('b' => 'sales/order_address'),
|
24 |
+
'main_table.entity_id = b.parent_id AND b.address_type = \'billing\'',
|
25 |
+
array(
|
26 |
+
'billing_country_id' => 'b.country_id'
|
27 |
+
)
|
28 |
+
)
|
29 |
+
->join(
|
30 |
+
array('s' => 'sales/order_address'),
|
31 |
+
'main_table.entity_id = s.parent_id AND s.address_type = \'shipping\'',
|
32 |
+
array(
|
33 |
+
'shipping_country_id' => 's.country_id'
|
34 |
+
)
|
35 |
+
)
|
36 |
+
;
|
37 |
+
|
38 |
+
$this->setCollection($collection);
|
39 |
+
return parent::_prepareCollection();
|
40 |
+
//return $this;
|
41 |
+
}
|
42 |
+
|
43 |
+
protected function _prepareColumns()
|
44 |
+
{
|
45 |
+
$helper = Mage::helper('japi');
|
46 |
+
$currency = (string)Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
|
47 |
+
|
48 |
+
$this->addColumn('real_order_id', array(
|
49 |
+
'header' => Mage::helper('sales')->__('Order #'),
|
50 |
+
'width' => '80px',
|
51 |
+
'type' => 'text',
|
52 |
+
'index' => 'increment_id',
|
53 |
+
));
|
54 |
+
|
55 |
+
$this->addColumn('created_at', array(
|
56 |
+
'header' => $helper->__('Order Date'),
|
57 |
+
'type' => 'datetime',
|
58 |
+
'index' => 'created_at'
|
59 |
+
));
|
60 |
+
|
61 |
+
$this->addColumn('billing_country', array(
|
62 |
+
'header' => $helper->__('Billing Country'),
|
63 |
+
'index' => 'billing_country_id',
|
64 |
+
'type' => 'country',
|
65 |
+
'renderer' => 'adminhtml/widget_grid_column_renderer_country',
|
66 |
+
'filter_index' => 'b.country_id'
|
67 |
+
));
|
68 |
+
|
69 |
+
$this->addColumn('shipping_country', array(
|
70 |
+
'header' => $helper->__('Shipping Country'),
|
71 |
+
'index' => 'shipping_country_id',
|
72 |
+
'type' => 'country',
|
73 |
+
'renderer' => 'adminhtml/widget_grid_column_renderer_country',
|
74 |
+
'filter_index' => 's.country_id'
|
75 |
+
));
|
76 |
+
|
77 |
+
$this->addColumn('total_item_count', array(
|
78 |
+
'header' => $helper->__('Qty. Ordered'),
|
79 |
+
'type' => 'number',
|
80 |
+
'index' => 'total_item_count'
|
81 |
+
));
|
82 |
+
|
83 |
+
$this->addColumn('subtotal', array(
|
84 |
+
'header' => $helper->__('Subtotal'),
|
85 |
+
'index' => 'subtotal',
|
86 |
+
'type' => 'currency',
|
87 |
+
'currency_code' => $currency
|
88 |
+
));
|
89 |
+
|
90 |
+
$this->addColumn('grand_total', array(
|
91 |
+
'header' => $helper->__('Total'),
|
92 |
+
'index' => 'grand_total',
|
93 |
+
'type' => 'currency',
|
94 |
+
'currency_code' => $currency
|
95 |
+
));
|
96 |
+
|
97 |
+
$this->addColumn('total_invoiced', array(
|
98 |
+
'header' => $helper->__('Invoiced'),
|
99 |
+
'index' => 'total_invoiced',
|
100 |
+
'type' => 'currency',
|
101 |
+
'currency_code' => $currency
|
102 |
+
));
|
103 |
+
|
104 |
+
$this->addColumn('order_status', array(
|
105 |
+
'header' => $helper->__('Status'),
|
106 |
+
'index' => 'status',
|
107 |
+
'type' => 'options',
|
108 |
+
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
|
109 |
+
));
|
110 |
+
|
111 |
+
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
|
112 |
+
$this->addColumn('action',
|
113 |
+
array(
|
114 |
+
'header' => Mage::helper('sales')->__('Action'),
|
115 |
+
'width' => '50px',
|
116 |
+
'type' => 'action',
|
117 |
+
'getter' => 'getId',
|
118 |
+
'actions' => array(
|
119 |
+
array(
|
120 |
+
'caption' => Mage::helper('japi')->__('View'),
|
121 |
+
'url' => array('base' => '*/sales_order/view'),
|
122 |
+
'field' => 'order_id',
|
123 |
+
'data-column' => 'action',
|
124 |
+
'target' => '_blank'
|
125 |
+
)
|
126 |
+
),
|
127 |
+
'filter' => false,
|
128 |
+
'sortable' => false,
|
129 |
+
'index' => 'stores',
|
130 |
+
'is_system' => true,
|
131 |
+
));
|
132 |
+
}
|
133 |
+
|
134 |
+
return parent::_prepareColumns();
|
135 |
+
}
|
136 |
+
|
137 |
+
public function getGridUrl()
|
138 |
+
{
|
139 |
+
return $this->getUrl('*/*/grid', array('_current' => true));
|
140 |
+
}
|
141 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Chart/Customers.php
ADDED
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Chart_Customers extends Mage_Adminhtml_Block_Dashboard_Graph
|
7 |
+
{
|
8 |
+
public function __construct()
|
9 |
+
{
|
10 |
+
parent::__construct();
|
11 |
+
$this->setTemplate('japi/report/chart.phtml');
|
12 |
+
}
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Prepare chart data
|
16 |
+
*
|
17 |
+
* @return void
|
18 |
+
*/
|
19 |
+
protected function _prepareData()
|
20 |
+
{
|
21 |
+
$this->setDataHelperName('japi/adminhtml_report_order');
|
22 |
+
$this->getDataHelper()->setParams($this->getFilterData()->getData());
|
23 |
+
$this->getDataHelper()->setParam('live', true);
|
24 |
+
|
25 |
+
$this->setDataRows('customers_count');
|
26 |
+
$this->_axisMaps = array(
|
27 |
+
'x' => 'range',
|
28 |
+
'y' => 'customers_count'
|
29 |
+
);
|
30 |
+
|
31 |
+
parent::_prepareData();
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Get chart url
|
36 |
+
*
|
37 |
+
* @param bool $directUrl
|
38 |
+
* @return string
|
39 |
+
*/
|
40 |
+
public function getChartUrl($directUrl = true)
|
41 |
+
{
|
42 |
+
$params = array(
|
43 |
+
'cht' => 'lc',
|
44 |
+
'chf' => 'bg,s,fafafa|c,lg,90,ffffff,0.1,ededed,0',
|
45 |
+
'chm' => 'B,f4d4b2,0,0,0',
|
46 |
+
'chco' => 'db4814'
|
47 |
+
);
|
48 |
+
|
49 |
+
$this->_allSeries = $this->getRowsData($this->_dataRows);
|
50 |
+
|
51 |
+
foreach ($this->_axisMaps as $axis => $attr) {
|
52 |
+
$this->setAxisLabels($axis, $this->getRowsData($attr, true));
|
53 |
+
}
|
54 |
+
|
55 |
+
$dateStart = strtotime($this->getDataHelper()->getParam('from'));
|
56 |
+
$dateEnd = strtotime($this->getDataHelper()->getParam('to'));
|
57 |
+
|
58 |
+
$dates = array();
|
59 |
+
$datas = array();
|
60 |
+
|
61 |
+
while ($dateStart <= $dateEnd) {
|
62 |
+
$d = '';
|
63 |
+
|
64 |
+
switch ($this->getDataHelper()->getParam('period_type')) {
|
65 |
+
case 'day':
|
66 |
+
$d = date('Y-m-d', $dateStart);
|
67 |
+
$dateStart = strtotime('+1 day', $dateStart);
|
68 |
+
break;
|
69 |
+
case 'month':
|
70 |
+
if (date('j', $dateStart) != 1) {
|
71 |
+
$dateStart = strtotime(date('Y-m-1', $dateStart));
|
72 |
+
}
|
73 |
+
$d = date('Y-m', $dateStart);
|
74 |
+
$dateStart = strtotime('+1 month', $dateStart);
|
75 |
+
break;
|
76 |
+
case 'year':
|
77 |
+
if (date('n', $dateStart) != 1 || date('j', $dateStart) != 1) {
|
78 |
+
$dateStart = strtotime(date('Y-1-1', $dateStart));
|
79 |
+
}
|
80 |
+
$d = date('Y', $dateStart);
|
81 |
+
$dateStart = strtotime('+1 year', $dateStart);
|
82 |
+
break;
|
83 |
+
}
|
84 |
+
|
85 |
+
foreach ($this->getAllSeries() as $index => $serie) {
|
86 |
+
if (in_array($d, $this->_axisLabels['x'])) {
|
87 |
+
$datas[$index][] = (float)array_shift($this->_allSeries[$index]);
|
88 |
+
} else {
|
89 |
+
$datas[$index][] = 0;
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
$dates[] = $d;
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* setting skip step
|
98 |
+
*/
|
99 |
+
if (count($dates) > 8 && count($dates) < 15) {
|
100 |
+
$c = 1;
|
101 |
+
} else if (count($dates) >= 15) {
|
102 |
+
$c = 2;
|
103 |
+
} else {
|
104 |
+
$c = 0;
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* skipping some x labels for good reading
|
109 |
+
*/
|
110 |
+
$i = 0;
|
111 |
+
foreach ($dates as $k => $d) {
|
112 |
+
if ($i == $c) {
|
113 |
+
$dates[$k] = $d;
|
114 |
+
$i = 0;
|
115 |
+
} else {
|
116 |
+
$dates[$k] = '';
|
117 |
+
$i++;
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
$this->_axisLabels['x'] = $dates;
|
122 |
+
$this->_allSeries = $datas;
|
123 |
+
|
124 |
+
//Google encoding values
|
125 |
+
if ($this->_encoding == "s") {
|
126 |
+
// simple encoding
|
127 |
+
$params['chd'] = "s:";
|
128 |
+
$dataDelimiter = "";
|
129 |
+
$dataSetdelimiter = ",";
|
130 |
+
$dataMissing = "_";
|
131 |
+
} else {
|
132 |
+
// extended encoding
|
133 |
+
$params['chd'] = "e:";
|
134 |
+
$dataDelimiter = "";
|
135 |
+
$dataSetdelimiter = ",";
|
136 |
+
$dataMissing = "__";
|
137 |
+
}
|
138 |
+
|
139 |
+
// process each string in the array, and find the max length
|
140 |
+
$localmaxvalue = array();
|
141 |
+
$localminvalue = array();
|
142 |
+
foreach ($this->getAllSeries() as $index => $serie) {
|
143 |
+
$localmaxlength[$index] = sizeof($serie);
|
144 |
+
$localmaxvalue[$index] = max($serie);
|
145 |
+
$localminvalue[$index] = min($serie);
|
146 |
+
}
|
147 |
+
|
148 |
+
if (is_numeric($this->_max)) {
|
149 |
+
$maxvalue = $this->_max;
|
150 |
+
} else {
|
151 |
+
$maxvalue = max($localmaxvalue);
|
152 |
+
}
|
153 |
+
|
154 |
+
if (is_numeric($this->_min)) {
|
155 |
+
$minvalue = $this->_min;
|
156 |
+
} else {
|
157 |
+
$minvalue = min($localminvalue);
|
158 |
+
}
|
159 |
+
|
160 |
+
// default values
|
161 |
+
$yrange = 0;
|
162 |
+
$yLabels = array();
|
163 |
+
$yorigin = 0;
|
164 |
+
|
165 |
+
if ($minvalue >= 0 && $maxvalue >= 0) {
|
166 |
+
$miny = 0;
|
167 |
+
if ($maxvalue > 10) {
|
168 |
+
$p = pow(10, $this->_getPow($maxvalue));
|
169 |
+
$maxy = (ceil($maxvalue / $p)) * $p;
|
170 |
+
$yLabels = range($miny, $maxy, $p);
|
171 |
+
} else {
|
172 |
+
$maxy = ceil($maxvalue + 1);
|
173 |
+
$yLabels = range($miny, $maxy, 1);
|
174 |
+
}
|
175 |
+
$yrange = $maxy;
|
176 |
+
$yorigin = 0;
|
177 |
+
}
|
178 |
+
|
179 |
+
$chartdata = array();
|
180 |
+
|
181 |
+
foreach ($this->getAllSeries() as $index => $serie) {
|
182 |
+
$thisdataarray = $serie;
|
183 |
+
if ($this->_encoding == "s") {
|
184 |
+
// SIMPLE ENCODING
|
185 |
+
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
|
186 |
+
$currentvalue = $thisdataarray[$j];
|
187 |
+
if (is_numeric($currentvalue)) {
|
188 |
+
$ylocation = round((strlen($this->_simpleEncoding) - 1) * ($yorigin + $currentvalue) / $yrange);
|
189 |
+
array_push($chartdata, substr($this->_simpleEncoding, $ylocation, 1) . $dataDelimiter);
|
190 |
+
} else {
|
191 |
+
array_push($chartdata, $dataMissing . $dataDelimiter);
|
192 |
+
}
|
193 |
+
}
|
194 |
+
// END SIMPLE ENCODING
|
195 |
+
} else {
|
196 |
+
// EXTENDED ENCODING
|
197 |
+
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
|
198 |
+
$currentvalue = $thisdataarray[$j];
|
199 |
+
if (is_numeric($currentvalue)) {
|
200 |
+
if ($yrange) {
|
201 |
+
$ylocation = (4095 * ($yorigin + $currentvalue) / $yrange);
|
202 |
+
} else {
|
203 |
+
$ylocation = 0;
|
204 |
+
}
|
205 |
+
$firstchar = floor($ylocation / 64);
|
206 |
+
$secondchar = $ylocation % 64;
|
207 |
+
$mappedchar = substr($this->_extendedEncoding, $firstchar, 1)
|
208 |
+
. substr($this->_extendedEncoding, $secondchar, 1);
|
209 |
+
array_push($chartdata, $mappedchar . $dataDelimiter);
|
210 |
+
} else {
|
211 |
+
array_push($chartdata, $dataMissing . $dataDelimiter);
|
212 |
+
}
|
213 |
+
}
|
214 |
+
// ============= END EXTENDED ENCODING =============
|
215 |
+
}
|
216 |
+
array_push($chartdata, $dataSetdelimiter);
|
217 |
+
}
|
218 |
+
|
219 |
+
$buffer = implode('', $chartdata);
|
220 |
+
$buffer = rtrim($buffer, $dataSetdelimiter);
|
221 |
+
$buffer = rtrim($buffer, $dataDelimiter);
|
222 |
+
$buffer = str_replace(($dataDelimiter . $dataSetdelimiter), $dataSetdelimiter, $buffer);
|
223 |
+
|
224 |
+
$params['chd'] .= $buffer;
|
225 |
+
|
226 |
+
$valueBuffer = array();
|
227 |
+
|
228 |
+
if (sizeof($this->_axisLabels) > 0) {
|
229 |
+
$params['chxt'] = implode(',', array_keys($this->_axisLabels));
|
230 |
+
$indexid = 0;
|
231 |
+
foreach ($this->_axisLabels as $idx => $labels) {
|
232 |
+
if ($idx == 'x') {
|
233 |
+
/**
|
234 |
+
* Format date
|
235 |
+
*/
|
236 |
+
foreach ($this->_axisLabels[$idx] as $_index => $_label) {
|
237 |
+
if ($_label != '') {
|
238 |
+
switch ($this->getDataHelper()->getParam('period_type')) {
|
239 |
+
case 'day':
|
240 |
+
$this->_axisLabels[$idx][$_index] = date('d/m/Y', strtotime($_label));
|
241 |
+
break;
|
242 |
+
case 'month':
|
243 |
+
$this->_axisLabels[$idx][$_index] = date('m/Y', strtotime($_label));
|
244 |
+
break;
|
245 |
+
case 'year':
|
246 |
+
$this->_axisLabels[$idx][$_index] = $_label;
|
247 |
+
break;
|
248 |
+
}
|
249 |
+
} else {
|
250 |
+
$this->_axisLabels[$idx][$_index] = '';
|
251 |
+
}
|
252 |
+
}
|
253 |
+
|
254 |
+
$tmpstring = implode('|', $this->_axisLabels[$idx]);
|
255 |
+
|
256 |
+
$valueBuffer[] = $indexid . ":|" . $tmpstring;
|
257 |
+
if (sizeof($this->_axisLabels[$idx]) > 1) {
|
258 |
+
$deltaX = 100 / (sizeof($this->_axisLabels[$idx]) - 1);
|
259 |
+
} else {
|
260 |
+
$deltaX = 100;
|
261 |
+
}
|
262 |
+
} else if ($idx == 'y') {
|
263 |
+
$valueBuffer[] = $indexid . ":|" . implode('|', $yLabels);
|
264 |
+
if (sizeof($yLabels) - 1) {
|
265 |
+
$deltaY = 100 / (sizeof($yLabels) - 1);
|
266 |
+
} else {
|
267 |
+
$deltaY = 100;
|
268 |
+
}
|
269 |
+
}
|
270 |
+
$indexid++;
|
271 |
+
}
|
272 |
+
|
273 |
+
$params['chxl'] = implode('|', $valueBuffer);
|
274 |
+
};
|
275 |
+
|
276 |
+
// chart size
|
277 |
+
$params['chs'] = $this->getWidth() . 'x' . $this->getHeight();
|
278 |
+
|
279 |
+
if (isset($deltaX) && isset($deltaY)) {
|
280 |
+
$params['chg'] = $deltaX . ',' . $deltaY . ',1,0';
|
281 |
+
}
|
282 |
+
|
283 |
+
// return the encoded data
|
284 |
+
if ($directUrl) {
|
285 |
+
$p = array();
|
286 |
+
foreach ($params as $name => $value) {
|
287 |
+
$p[] = $name . '=' . urlencode($value);
|
288 |
+
}
|
289 |
+
return self::API_URL . '?' . implode('&', $p);
|
290 |
+
} else {
|
291 |
+
$gaData = urlencode(base64_encode(json_encode($params)));
|
292 |
+
$gaHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
|
293 |
+
$params = array('ga' => $gaData, 'h' => $gaHash);
|
294 |
+
return $this->getUrl('adminhtml/japi_report/tunnel', array('_query' => $params));
|
295 |
+
}
|
296 |
+
}
|
297 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Chart/Orders.php
ADDED
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Chart_Orders extends Mage_Adminhtml_Block_Dashboard_Graph
|
7 |
+
{
|
8 |
+
public function __construct()
|
9 |
+
{
|
10 |
+
parent::__construct();
|
11 |
+
$this->setTemplate('japi/report/chart.phtml');
|
12 |
+
}
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Prepare chart data
|
16 |
+
*
|
17 |
+
* @return void
|
18 |
+
*/
|
19 |
+
protected function _prepareData()
|
20 |
+
{
|
21 |
+
$this->setDataHelperName('japi/adminhtml_report_order');
|
22 |
+
$this->getDataHelper()->setParams($this->getFilterData()->getData());
|
23 |
+
|
24 |
+
$this->setDataRows('quantity');
|
25 |
+
$this->_axisMaps = array(
|
26 |
+
'x' => 'range',
|
27 |
+
'y' => 'quantity'
|
28 |
+
);
|
29 |
+
|
30 |
+
parent::_prepareData();
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Get chart url
|
35 |
+
*
|
36 |
+
* @param bool $directUrl
|
37 |
+
* @return string
|
38 |
+
*/
|
39 |
+
public function getChartUrl($directUrl = true)
|
40 |
+
{
|
41 |
+
$params = array(
|
42 |
+
'cht' => 'lc',
|
43 |
+
'chf' => 'bg,s,fafafa|c,lg,90,ffffff,0.1,ededed,0',
|
44 |
+
'chm' => 'B,f4d4b2,0,0,0',
|
45 |
+
'chco' => 'db4814'
|
46 |
+
);
|
47 |
+
|
48 |
+
$this->_allSeries = $this->getRowsData($this->_dataRows);
|
49 |
+
|
50 |
+
foreach ($this->_axisMaps as $axis => $attr) {
|
51 |
+
$this->setAxisLabels($axis, $this->getRowsData($attr, true));
|
52 |
+
}
|
53 |
+
|
54 |
+
$dateStart = strtotime($this->getDataHelper()->getParam('from'));
|
55 |
+
$dateEnd = strtotime($this->getDataHelper()->getParam('to'));
|
56 |
+
|
57 |
+
$dates = array();
|
58 |
+
$datas = array();
|
59 |
+
|
60 |
+
while ($dateStart <= $dateEnd) {
|
61 |
+
$d = '';
|
62 |
+
|
63 |
+
switch ($this->getDataHelper()->getParam('period_type')) {
|
64 |
+
case 'day':
|
65 |
+
$d = date('Y-m-d', $dateStart);
|
66 |
+
$dateStart = strtotime('+1 day', $dateStart);
|
67 |
+
break;
|
68 |
+
case 'month':
|
69 |
+
if (date('j', $dateStart) != 1) {
|
70 |
+
$dateStart = strtotime(date('Y-m-1', $dateStart));
|
71 |
+
}
|
72 |
+
$d = date('Y-m', $dateStart);
|
73 |
+
$dateStart = strtotime('+1 month', $dateStart);
|
74 |
+
break;
|
75 |
+
case 'year':
|
76 |
+
if (date('n', $dateStart) != 1 || date('j', $dateStart) != 1) {
|
77 |
+
$dateStart = strtotime(date('Y-1-1', $dateStart));
|
78 |
+
}
|
79 |
+
$d = date('Y', $dateStart);
|
80 |
+
$dateStart = strtotime('+1 year', $dateStart);
|
81 |
+
break;
|
82 |
+
}
|
83 |
+
|
84 |
+
foreach ($this->getAllSeries() as $index => $serie) {
|
85 |
+
if (in_array($d, $this->_axisLabels['x'])) {
|
86 |
+
$datas[$index][] = (float)array_shift($this->_allSeries[$index]);
|
87 |
+
} else {
|
88 |
+
$datas[$index][] = 0;
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
$dates[] = $d;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* setting skip step
|
97 |
+
*/
|
98 |
+
if (count($dates) > 8 && count($dates) < 15) {
|
99 |
+
$c = 1;
|
100 |
+
} else if (count($dates) >= 15) {
|
101 |
+
$c = 2;
|
102 |
+
} else {
|
103 |
+
$c = 0;
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* skipping some x labels for good reading
|
108 |
+
*/
|
109 |
+
$i = 0;
|
110 |
+
foreach ($dates as $k => $d) {
|
111 |
+
if ($i == $c) {
|
112 |
+
$dates[$k] = $d;
|
113 |
+
$i = 0;
|
114 |
+
} else {
|
115 |
+
$dates[$k] = '';
|
116 |
+
$i++;
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
$this->_axisLabels['x'] = $dates;
|
121 |
+
$this->_allSeries = $datas;
|
122 |
+
|
123 |
+
//Google encoding values
|
124 |
+
if ($this->_encoding == "s") {
|
125 |
+
// simple encoding
|
126 |
+
$params['chd'] = "s:";
|
127 |
+
$dataDelimiter = "";
|
128 |
+
$dataSetdelimiter = ",";
|
129 |
+
$dataMissing = "_";
|
130 |
+
} else {
|
131 |
+
// extended encoding
|
132 |
+
$params['chd'] = "e:";
|
133 |
+
$dataDelimiter = "";
|
134 |
+
$dataSetdelimiter = ",";
|
135 |
+
$dataMissing = "__";
|
136 |
+
}
|
137 |
+
|
138 |
+
// process each string in the array, and find the max length
|
139 |
+
$localmaxvalue = array();
|
140 |
+
$localminvalue = array();
|
141 |
+
foreach ($this->getAllSeries() as $index => $serie) {
|
142 |
+
$localmaxlength[$index] = sizeof($serie);
|
143 |
+
$localmaxvalue[$index] = max($serie);
|
144 |
+
$localminvalue[$index] = min($serie);
|
145 |
+
}
|
146 |
+
|
147 |
+
if (is_numeric($this->_max)) {
|
148 |
+
$maxvalue = $this->_max;
|
149 |
+
} else {
|
150 |
+
$maxvalue = max($localmaxvalue);
|
151 |
+
}
|
152 |
+
|
153 |
+
if (is_numeric($this->_min)) {
|
154 |
+
$minvalue = $this->_min;
|
155 |
+
} else {
|
156 |
+
$minvalue = min($localminvalue);
|
157 |
+
}
|
158 |
+
|
159 |
+
// default values
|
160 |
+
$yrange = 0;
|
161 |
+
$yLabels = array();
|
162 |
+
$yorigin = 0;
|
163 |
+
|
164 |
+
if ($minvalue >= 0 && $maxvalue >= 0) {
|
165 |
+
$miny = 0;
|
166 |
+
if ($maxvalue > 10) {
|
167 |
+
$p = pow(10, $this->_getPow($maxvalue));
|
168 |
+
$maxy = (ceil($maxvalue / $p)) * $p;
|
169 |
+
$yLabels = range($miny, $maxy, $p);
|
170 |
+
} else {
|
171 |
+
$maxy = ceil($maxvalue + 1);
|
172 |
+
$yLabels = range($miny, $maxy, 1);
|
173 |
+
}
|
174 |
+
$yrange = $maxy;
|
175 |
+
$yorigin = 0;
|
176 |
+
}
|
177 |
+
|
178 |
+
$chartdata = array();
|
179 |
+
|
180 |
+
foreach ($this->getAllSeries() as $index => $serie) {
|
181 |
+
$thisdataarray = $serie;
|
182 |
+
if ($this->_encoding == "s") {
|
183 |
+
// SIMPLE ENCODING
|
184 |
+
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
|
185 |
+
$currentvalue = $thisdataarray[$j];
|
186 |
+
if (is_numeric($currentvalue)) {
|
187 |
+
$ylocation = round((strlen($this->_simpleEncoding) - 1) * ($yorigin + $currentvalue) / $yrange);
|
188 |
+
array_push($chartdata, substr($this->_simpleEncoding, $ylocation, 1) . $dataDelimiter);
|
189 |
+
} else {
|
190 |
+
array_push($chartdata, $dataMissing . $dataDelimiter);
|
191 |
+
}
|
192 |
+
}
|
193 |
+
// END SIMPLE ENCODING
|
194 |
+
} else {
|
195 |
+
// EXTENDED ENCODING
|
196 |
+
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
|
197 |
+
$currentvalue = $thisdataarray[$j];
|
198 |
+
if (is_numeric($currentvalue)) {
|
199 |
+
if ($yrange) {
|
200 |
+
$ylocation = (4095 * ($yorigin + $currentvalue) / $yrange);
|
201 |
+
} else {
|
202 |
+
$ylocation = 0;
|
203 |
+
}
|
204 |
+
$firstchar = floor($ylocation / 64);
|
205 |
+
$secondchar = $ylocation % 64;
|
206 |
+
$mappedchar = substr($this->_extendedEncoding, $firstchar, 1)
|
207 |
+
. substr($this->_extendedEncoding, $secondchar, 1);
|
208 |
+
array_push($chartdata, $mappedchar . $dataDelimiter);
|
209 |
+
} else {
|
210 |
+
array_push($chartdata, $dataMissing . $dataDelimiter);
|
211 |
+
}
|
212 |
+
}
|
213 |
+
// ============= END EXTENDED ENCODING =============
|
214 |
+
}
|
215 |
+
array_push($chartdata, $dataSetdelimiter);
|
216 |
+
}
|
217 |
+
|
218 |
+
$buffer = implode('', $chartdata);
|
219 |
+
$buffer = rtrim($buffer, $dataSetdelimiter);
|
220 |
+
$buffer = rtrim($buffer, $dataDelimiter);
|
221 |
+
$buffer = str_replace(($dataDelimiter . $dataSetdelimiter), $dataSetdelimiter, $buffer);
|
222 |
+
|
223 |
+
$params['chd'] .= $buffer;
|
224 |
+
|
225 |
+
$valueBuffer = array();
|
226 |
+
|
227 |
+
if (sizeof($this->_axisLabels) > 0) {
|
228 |
+
$params['chxt'] = implode(',', array_keys($this->_axisLabels));
|
229 |
+
$indexid = 0;
|
230 |
+
foreach ($this->_axisLabels as $idx => $labels) {
|
231 |
+
if ($idx == 'x') {
|
232 |
+
/**
|
233 |
+
* Format date
|
234 |
+
*/
|
235 |
+
foreach ($this->_axisLabels[$idx] as $_index => $_label) {
|
236 |
+
if ($_label != '') {
|
237 |
+
switch ($this->getDataHelper()->getParam('period_type')) {
|
238 |
+
case 'day':
|
239 |
+
$this->_axisLabels[$idx][$_index] = date('d/m/Y', strtotime($_label));
|
240 |
+
break;
|
241 |
+
case 'month':
|
242 |
+
$this->_axisLabels[$idx][$_index] = date('m/Y', strtotime($_label));
|
243 |
+
break;
|
244 |
+
case 'year':
|
245 |
+
$this->_axisLabels[$idx][$_index] = $_label;
|
246 |
+
break;
|
247 |
+
}
|
248 |
+
} else {
|
249 |
+
$this->_axisLabels[$idx][$_index] = '';
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
$tmpstring = implode('|', $this->_axisLabels[$idx]);
|
254 |
+
|
255 |
+
$valueBuffer[] = $indexid . ":|" . $tmpstring;
|
256 |
+
if (sizeof($this->_axisLabels[$idx]) > 1) {
|
257 |
+
$deltaX = 100 / (sizeof($this->_axisLabels[$idx]) - 1);
|
258 |
+
} else {
|
259 |
+
$deltaX = 100;
|
260 |
+
}
|
261 |
+
} else if ($idx == 'y') {
|
262 |
+
$valueBuffer[] = $indexid . ":|" . implode('|', $yLabels);
|
263 |
+
if (sizeof($yLabels) - 1) {
|
264 |
+
$deltaY = 100 / (sizeof($yLabels) - 1);
|
265 |
+
} else {
|
266 |
+
$deltaY = 100;
|
267 |
+
}
|
268 |
+
}
|
269 |
+
$indexid++;
|
270 |
+
}
|
271 |
+
|
272 |
+
$params['chxl'] = implode('|', $valueBuffer);
|
273 |
+
};
|
274 |
+
|
275 |
+
// chart size
|
276 |
+
$params['chs'] = $this->getWidth() . 'x' . $this->getHeight();
|
277 |
+
|
278 |
+
if (isset($deltaX) && isset($deltaY)) {
|
279 |
+
$params['chg'] = $deltaX . ',' . $deltaY . ',1,0';
|
280 |
+
}
|
281 |
+
|
282 |
+
// return the encoded data
|
283 |
+
if ($directUrl) {
|
284 |
+
$p = array();
|
285 |
+
foreach ($params as $name => $value) {
|
286 |
+
$p[] = $name . '=' . urlencode($value);
|
287 |
+
}
|
288 |
+
return self::API_URL . '?' . implode('&', $p);
|
289 |
+
} else {
|
290 |
+
$gaData = urlencode(base64_encode(json_encode($params)));
|
291 |
+
$gaHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
|
292 |
+
$params = array('ga' => $gaData, 'h' => $gaHash);
|
293 |
+
return $this->getUrl('adminhtml/japi_report/tunnel', array('_query' => $params));
|
294 |
+
}
|
295 |
+
}
|
296 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Chart/Sales.php
ADDED
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2015 JMango360
|
4 |
+
*/
|
5 |
+
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Chart_Sales extends Mage_Adminhtml_Block_Dashboard_Graph{
|
7 |
+
public function __construct(){
|
8 |
+
parent::__construct();
|
9 |
+
$this->setTemplate('japi/report/chart.phtml');
|
10 |
+
}
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Prepare chart data
|
14 |
+
*
|
15 |
+
* @return void
|
16 |
+
*/
|
17 |
+
protected function _prepareData(){
|
18 |
+
$this->setDataHelperName('japi/adminhtml_report_order');
|
19 |
+
$this->getDataHelper()->setParams($this->getFilterData()->getData());
|
20 |
+
|
21 |
+
$this->setDataRows('amount');
|
22 |
+
$this->_axisMaps = array(
|
23 |
+
'x' => 'range',
|
24 |
+
'y' => 'amount'
|
25 |
+
);
|
26 |
+
|
27 |
+
parent::_prepareData();
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Get chart url
|
32 |
+
*
|
33 |
+
* @param bool $directUrl
|
34 |
+
* @return string
|
35 |
+
*/
|
36 |
+
public function getChartUrl($directUrl = true){
|
37 |
+
$params = array(
|
38 |
+
'cht' => 'lc',
|
39 |
+
'chf' => 'bg,s,fafafa|c,lg,90,ffffff,0.1,ededed,0',
|
40 |
+
'chm' => 'B,f4d4b2,0,0,0',
|
41 |
+
'chco' => 'db4814'
|
42 |
+
);
|
43 |
+
|
44 |
+
$this->_allSeries = $this->getRowsData($this->_dataRows);
|
45 |
+
|
46 |
+
foreach ($this->_axisMaps as $axis => $attr){
|
47 |
+
$this->setAxisLabels($axis, $this->getRowsData($attr, true));
|
48 |
+
}
|
49 |
+
|
50 |
+
$dateStart = strtotime($this->getDataHelper()->getParam('from'));
|
51 |
+
$dateEnd = strtotime($this->getDataHelper()->getParam('to'));
|
52 |
+
|
53 |
+
$dates = array();
|
54 |
+
$datas = array();
|
55 |
+
|
56 |
+
while ($dateStart <= $dateEnd){
|
57 |
+
$d = '';
|
58 |
+
|
59 |
+
switch ($this->getDataHelper()->getParam('period_type')) {
|
60 |
+
case 'day':
|
61 |
+
$d = date('Y-m-d', $dateStart);
|
62 |
+
$dateStart = strtotime('+1 day', $dateStart);
|
63 |
+
break;
|
64 |
+
case 'month':
|
65 |
+
if (date('j', $dateStart) != 1){
|
66 |
+
$dateStart = strtotime(date('Y-m-1', $dateStart));
|
67 |
+
}
|
68 |
+
$d = date('Y-m', $dateStart);
|
69 |
+
$dateStart = strtotime('+1 month', $dateStart);
|
70 |
+
break;
|
71 |
+
case 'year':
|
72 |
+
if (date('n', $dateStart) != 1 || date('j', $dateStart) != 1){
|
73 |
+
$dateStart = strtotime(date('Y-1-1', $dateStart));
|
74 |
+
}
|
75 |
+
$d = date('Y', $dateStart);
|
76 |
+
$dateStart = strtotime('+1 year', $dateStart);
|
77 |
+
break;
|
78 |
+
}
|
79 |
+
|
80 |
+
foreach ($this->getAllSeries() as $index => $serie) {
|
81 |
+
if (in_array($d, $this->_axisLabels['x'])) {
|
82 |
+
$datas[$index][] = (float)array_shift($this->_allSeries[$index]);
|
83 |
+
} else {
|
84 |
+
$datas[$index][] = 0;
|
85 |
+
}
|
86 |
+
}
|
87 |
+
|
88 |
+
$dates[] = $d;
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* setting skip step
|
93 |
+
*/
|
94 |
+
if (count($dates) > 8 && count($dates) < 15) {
|
95 |
+
$c = 1;
|
96 |
+
} else if (count($dates) >= 15){
|
97 |
+
$c = 2;
|
98 |
+
} else {
|
99 |
+
$c = 0;
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* skipping some x labels for good reading
|
104 |
+
*/
|
105 |
+
$i=0;
|
106 |
+
foreach ($dates as $k => $d) {
|
107 |
+
if ($i == $c) {
|
108 |
+
$dates[$k] = $d;
|
109 |
+
$i = 0;
|
110 |
+
} else {
|
111 |
+
$dates[$k] = '';
|
112 |
+
$i++;
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
$this->_axisLabels['x'] = $dates;
|
117 |
+
$this->_allSeries = $datas;
|
118 |
+
|
119 |
+
//Google encoding values
|
120 |
+
if ($this->_encoding == "s") {
|
121 |
+
// simple encoding
|
122 |
+
$params['chd'] = "s:";
|
123 |
+
$dataDelimiter = "";
|
124 |
+
$dataSetdelimiter = ",";
|
125 |
+
$dataMissing = "_";
|
126 |
+
} else {
|
127 |
+
// extended encoding
|
128 |
+
$params['chd'] = "e:";
|
129 |
+
$dataDelimiter = "";
|
130 |
+
$dataSetdelimiter = ",";
|
131 |
+
$dataMissing = "__";
|
132 |
+
}
|
133 |
+
|
134 |
+
// process each string in the array, and find the max length
|
135 |
+
$localmaxvalue = array();
|
136 |
+
$localminvalue = array();
|
137 |
+
foreach ($this->getAllSeries() as $index => $serie) {
|
138 |
+
$localmaxlength[$index] = sizeof($serie);
|
139 |
+
$localmaxvalue[$index] = max($serie);
|
140 |
+
$localminvalue[$index] = min($serie);
|
141 |
+
}
|
142 |
+
|
143 |
+
if (is_numeric($this->_max)) {
|
144 |
+
$maxvalue = $this->_max;
|
145 |
+
} else {
|
146 |
+
$maxvalue = max($localmaxvalue);
|
147 |
+
}
|
148 |
+
|
149 |
+
if (is_numeric($this->_min)) {
|
150 |
+
$minvalue = $this->_min;
|
151 |
+
} else {
|
152 |
+
$minvalue = min($localminvalue);
|
153 |
+
}
|
154 |
+
|
155 |
+
// default values
|
156 |
+
$yrange = 0;
|
157 |
+
$yLabels = array();
|
158 |
+
$yorigin = 0;
|
159 |
+
|
160 |
+
if ($minvalue >= 0 && $maxvalue >= 0) {
|
161 |
+
$miny = 0;
|
162 |
+
if ($maxvalue > 10) {
|
163 |
+
$p = pow(10, $this->_getPow($maxvalue));
|
164 |
+
$maxy = (ceil($maxvalue/$p))*$p;
|
165 |
+
$yLabels = range($miny, $maxy, $p);
|
166 |
+
} else {
|
167 |
+
$maxy = ceil($maxvalue+1);
|
168 |
+
$yLabels = range($miny, $maxy, 1);
|
169 |
+
}
|
170 |
+
$yrange = $maxy;
|
171 |
+
$yorigin = 0;
|
172 |
+
}
|
173 |
+
|
174 |
+
$chartdata = array();
|
175 |
+
|
176 |
+
foreach ($this->getAllSeries() as $index => $serie) {
|
177 |
+
$thisdataarray = $serie;
|
178 |
+
if ($this->_encoding == "s") {
|
179 |
+
// SIMPLE ENCODING
|
180 |
+
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
|
181 |
+
$currentvalue = $thisdataarray[$j];
|
182 |
+
if (is_numeric($currentvalue)) {
|
183 |
+
$ylocation = round((strlen($this->_simpleEncoding)-1) * ($yorigin + $currentvalue) / $yrange);
|
184 |
+
array_push($chartdata, substr($this->_simpleEncoding, $ylocation, 1) . $dataDelimiter);
|
185 |
+
} else {
|
186 |
+
array_push($chartdata, $dataMissing . $dataDelimiter);
|
187 |
+
}
|
188 |
+
}
|
189 |
+
// END SIMPLE ENCODING
|
190 |
+
} else {
|
191 |
+
// EXTENDED ENCODING
|
192 |
+
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
|
193 |
+
$currentvalue = $thisdataarray[$j];
|
194 |
+
if (is_numeric($currentvalue)) {
|
195 |
+
if ($yrange) {
|
196 |
+
$ylocation = (4095 * ($yorigin + $currentvalue) / $yrange);
|
197 |
+
} else {
|
198 |
+
$ylocation = 0;
|
199 |
+
}
|
200 |
+
$firstchar = floor($ylocation / 64);
|
201 |
+
$secondchar = $ylocation % 64;
|
202 |
+
$mappedchar = substr($this->_extendedEncoding, $firstchar, 1)
|
203 |
+
. substr($this->_extendedEncoding, $secondchar, 1);
|
204 |
+
array_push($chartdata, $mappedchar . $dataDelimiter);
|
205 |
+
} else {
|
206 |
+
array_push($chartdata, $dataMissing . $dataDelimiter);
|
207 |
+
}
|
208 |
+
}
|
209 |
+
// ============= END EXTENDED ENCODING =============
|
210 |
+
}
|
211 |
+
array_push($chartdata, $dataSetdelimiter);
|
212 |
+
}
|
213 |
+
|
214 |
+
$buffer = implode('', $chartdata);
|
215 |
+
$buffer = rtrim($buffer, $dataSetdelimiter);
|
216 |
+
$buffer = rtrim($buffer, $dataDelimiter);
|
217 |
+
$buffer = str_replace(($dataDelimiter . $dataSetdelimiter), $dataSetdelimiter, $buffer);
|
218 |
+
|
219 |
+
$params['chd'] .= $buffer;
|
220 |
+
|
221 |
+
$valueBuffer = array();
|
222 |
+
|
223 |
+
if (sizeof($this->_axisLabels) > 0) {
|
224 |
+
$params['chxt'] = implode(',', array_keys($this->_axisLabels));
|
225 |
+
$indexid = 0;
|
226 |
+
foreach ($this->_axisLabels as $idx => $labels){
|
227 |
+
if ($idx == 'x') {
|
228 |
+
/**
|
229 |
+
* Format date
|
230 |
+
*/
|
231 |
+
foreach ($this->_axisLabels[$idx] as $_index => $_label) {
|
232 |
+
if ($_label != '') {
|
233 |
+
switch ($this->getDataHelper()->getParam('period_type')) {
|
234 |
+
case 'day':
|
235 |
+
$this->_axisLabels[$idx][$_index] = date('d/m/Y', strtotime($_label));
|
236 |
+
break;
|
237 |
+
case 'month':
|
238 |
+
$this->_axisLabels[$idx][$_index] = date('m/Y', strtotime($_label));
|
239 |
+
break;
|
240 |
+
case 'year':
|
241 |
+
$this->_axisLabels[$idx][$_index] = $_label;
|
242 |
+
break;
|
243 |
+
}
|
244 |
+
} else {
|
245 |
+
$this->_axisLabels[$idx][$_index] = '';
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
$tmpstring = implode('|', $this->_axisLabels[$idx]);
|
250 |
+
|
251 |
+
$valueBuffer[] = $indexid . ":|" . $tmpstring;
|
252 |
+
if (sizeof($this->_axisLabels[$idx]) > 1) {
|
253 |
+
$deltaX = 100/(sizeof($this->_axisLabels[$idx])-1);
|
254 |
+
} else {
|
255 |
+
$deltaX = 100;
|
256 |
+
}
|
257 |
+
} else if ($idx == 'y') {
|
258 |
+
$valueBuffer[] = $indexid . ":|" . implode('|', $yLabels);
|
259 |
+
if (sizeof($yLabels)-1) {
|
260 |
+
$deltaY = 100/(sizeof($yLabels)-1);
|
261 |
+
} else {
|
262 |
+
$deltaY = 100;
|
263 |
+
}
|
264 |
+
}
|
265 |
+
$indexid++;
|
266 |
+
}
|
267 |
+
|
268 |
+
$params['chxl'] = implode('|', $valueBuffer);
|
269 |
+
};
|
270 |
+
|
271 |
+
// chart size
|
272 |
+
$params['chs'] = $this->getWidth().'x'.$this->getHeight();
|
273 |
+
|
274 |
+
if (isset($deltaX) && isset($deltaY)) {
|
275 |
+
$params['chg'] = $deltaX . ',' . $deltaY . ',1,0';
|
276 |
+
}
|
277 |
+
|
278 |
+
// return the encoded data
|
279 |
+
if ($directUrl) {
|
280 |
+
$p = array();
|
281 |
+
foreach ($params as $name => $value) {
|
282 |
+
$p[] = $name . '=' .urlencode($value);
|
283 |
+
}
|
284 |
+
return self::API_URL . '?' . implode('&', $p);
|
285 |
+
} else {
|
286 |
+
$gaData = urlencode(base64_encode(json_encode($params)));
|
287 |
+
$gaHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
|
288 |
+
$params = array('ga' => $gaData, 'h' => $gaHash);
|
289 |
+
return $this->getUrl('adminhtml/japi_report/tunnel', array('_query' => $params));
|
290 |
+
}
|
291 |
+
}
|
292 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Customers.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Customers extends Mage_Adminhtml_Block_Widget_Grid_Container
|
7 |
+
{
|
8 |
+
public function __construct()
|
9 |
+
{
|
10 |
+
$this->_blockGroup = 'japi';
|
11 |
+
$this->_controller = 'adminhtml_report_customers';
|
12 |
+
$this->_headerText = Mage::helper('reports')->__('Total Customers from JMango360 Report');
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
|
16 |
+
$this->setTemplate('report/grid/container.phtml');
|
17 |
+
$this->_removeButton('add');
|
18 |
+
$this->addButton('filter_form_submit', array(
|
19 |
+
'label' => Mage::helper('reports')->__('Show Report'),
|
20 |
+
'onclick' => 'filterFormSubmit()'
|
21 |
+
));
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getFilterUrl()
|
25 |
+
{
|
26 |
+
$this->getRequest()->setParam('filter', null);
|
27 |
+
return $this->getUrl('*/*/customers', array('_current' => true));
|
28 |
+
}
|
29 |
+
|
30 |
+
public function getHeaderCssClass()
|
31 |
+
{
|
32 |
+
return '';
|
33 |
+
}
|
34 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Customers/Chart.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Customers_Chart extends Mage_Adminhtml_Block_Widget_Form
|
7 |
+
{
|
8 |
+
protected function _prepareForm()
|
9 |
+
{
|
10 |
+
$form = new Varien_Data_Form();
|
11 |
+
$fieldset = $form->addFieldset('chart_fieldset', array(
|
12 |
+
'legend' => $this->__('Chart')
|
13 |
+
));
|
14 |
+
$fieldset->addField('chart', 'text', array(
|
15 |
+
'filter_data' => $this->getFilterData(),
|
16 |
+
'graph_name' => 'japi/adminhtml_report_chart_customers'
|
17 |
+
));
|
18 |
+
$form->getElement('chart')->setRenderer(
|
19 |
+
$this->getLayout()->createBlock('japi/adminhtml_widget_form_renderer_element_chart')
|
20 |
+
);
|
21 |
+
$this->setForm($form);
|
22 |
+
return parent::_prepareForm();
|
23 |
+
}
|
24 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Customers/Grid.php
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Customers_Grid
|
7 |
+
extends Mage_Adminhtml_Block_Report_Sales_Sales_Grid
|
8 |
+
{
|
9 |
+
|
10 |
+
public function getResourceCollectionName()
|
11 |
+
{
|
12 |
+
return 'japi/sales_report_order_collection_live';
|
13 |
+
}
|
14 |
+
|
15 |
+
protected function _prepareColumns()
|
16 |
+
{
|
17 |
+
$this->addColumn('period', array(
|
18 |
+
'header' => Mage::helper('sales')->__('Period'),
|
19 |
+
'index' => 'period',
|
20 |
+
'width' => 100,
|
21 |
+
'sortable' => false,
|
22 |
+
'period_type' => $this->getPeriodType(),
|
23 |
+
'renderer' => 'adminhtml/report_sales_grid_column_renderer_date',
|
24 |
+
'totals_label' => Mage::helper('sales')->__('Total'),
|
25 |
+
'html_decorators' => array('nobr')
|
26 |
+
));
|
27 |
+
|
28 |
+
$this->addColumn('customers_count', array(
|
29 |
+
'header' => Mage::helper('sales')->__('Customers'),
|
30 |
+
'index' => 'customers_count',
|
31 |
+
'type' => 'number',
|
32 |
+
'total' => 'sum',
|
33 |
+
'sortable' => false
|
34 |
+
));
|
35 |
+
|
36 |
+
$this->addColumn('orders_count', array(
|
37 |
+
'header' => Mage::helper('sales')->__('Orders'),
|
38 |
+
'index' => 'orders_count',
|
39 |
+
'type' => 'number',
|
40 |
+
'total' => 'sum',
|
41 |
+
'sortable' => false
|
42 |
+
));
|
43 |
+
|
44 |
+
$this->addExportType('*/*/exportSalesCsv', Mage::helper('adminhtml')->__('CSV'));
|
45 |
+
$this->addExportType('*/*/exportSalesExcel', Mage::helper('adminhtml')->__('Excel XML'));
|
46 |
+
|
47 |
+
return call_user_func(array(get_parent_class(get_parent_class($this)), '_prepareColumns'));
|
48 |
+
}
|
49 |
+
|
50 |
+
protected function _getAggregatedColumns()
|
51 |
+
{
|
52 |
+
if (is_null($this->_aggregatedColumns)) {
|
53 |
+
foreach ($this->getColumns() as $column) {
|
54 |
+
if (!is_array($this->_aggregatedColumns)) {
|
55 |
+
$this->_aggregatedColumns = array();
|
56 |
+
}
|
57 |
+
if ($column->hasTotal()) {
|
58 |
+
$this->_aggregatedColumns[$column->getId()] = "{$column->getTotal()}(r.{$column->getIndex()})";
|
59 |
+
}
|
60 |
+
}
|
61 |
+
}
|
62 |
+
return $this->_aggregatedColumns;
|
63 |
+
}
|
64 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Filter/Form.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Filter_Form extends Mage_Sales_Block_Adminhtml_Report_Filter_Form_Order
|
4 |
+
{
|
5 |
+
protected function _prepareForm()
|
6 |
+
{
|
7 |
+
parent::_prepareForm();
|
8 |
+
$this->getForm()->getElement('base_fieldset')->removeField('report_type');
|
9 |
+
|
10 |
+
return $this;
|
11 |
+
}
|
12 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Filter/Form/Orders.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Filter_Form_Orders extends Jmango360_Japi_Block_Adminhtml_Report_Filter_Form
|
4 |
+
{
|
5 |
+
protected function _prepareForm()
|
6 |
+
{
|
7 |
+
parent::_prepareForm();
|
8 |
+
$this->getForm()->getElement('base_fieldset')->removeField('show_actual_columns');
|
9 |
+
|
10 |
+
return $this;
|
11 |
+
}
|
12 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Orders.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Orders extends Mage_Adminhtml_Block_Widget_Grid_Container
|
7 |
+
{
|
8 |
+
public function __construct()
|
9 |
+
{
|
10 |
+
$this->_blockGroup = 'japi';
|
11 |
+
$this->_controller = 'adminhtml_report_orders';
|
12 |
+
$this->_headerText = Mage::helper('japi')->__('Total Ordered from JMango360 Report');
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
|
16 |
+
$this->setTemplate('report/grid/container.phtml');
|
17 |
+
$this->_removeButton('add');
|
18 |
+
$this->addButton('filter_form_submit', array(
|
19 |
+
'label' => Mage::helper('reports')->__('Show Report'),
|
20 |
+
'onclick' => 'filterFormSubmit()'
|
21 |
+
));
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getFilterUrl()
|
25 |
+
{
|
26 |
+
$this->getRequest()->setParam('filter', null);
|
27 |
+
return $this->getUrl('*/*/orders', array('_current' => true));
|
28 |
+
}
|
29 |
+
|
30 |
+
public function getHeaderCssClass()
|
31 |
+
{
|
32 |
+
return '';
|
33 |
+
}
|
34 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Orders/Chart.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Orders_Chart extends Mage_Adminhtml_Block_Widget_Form
|
7 |
+
{
|
8 |
+
protected function _prepareForm()
|
9 |
+
{
|
10 |
+
$form = new Varien_Data_Form();
|
11 |
+
$fieldset = $form->addFieldset('chart_fieldset', array(
|
12 |
+
'legend' => $this->__('Chart')
|
13 |
+
));
|
14 |
+
$fieldset->addField('chart', 'text', array(
|
15 |
+
'filter_data' => $this->getFilterData(),
|
16 |
+
'graph_name' => 'japi/adminhtml_report_chart_orders'
|
17 |
+
));
|
18 |
+
$form->getElement('chart')->setRenderer(
|
19 |
+
$this->getLayout()->createBlock('japi/adminhtml_widget_form_renderer_element_chart')
|
20 |
+
);
|
21 |
+
$this->setForm($form);
|
22 |
+
return parent::_prepareForm();
|
23 |
+
}
|
24 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Orders/Grid.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Orders_Grid extends Mage_Adminhtml_Block_Report_Sales_Sales_Grid
|
7 |
+
{
|
8 |
+
public function getResourceCollectionName()
|
9 |
+
{
|
10 |
+
return 'japi/sales_report_order_collection_aggregated';
|
11 |
+
}
|
12 |
+
|
13 |
+
protected function _prepareColumns()
|
14 |
+
{
|
15 |
+
$this->addColumn('period', array(
|
16 |
+
'header' => Mage::helper('sales')->__('Period'),
|
17 |
+
'index' => 'period',
|
18 |
+
'width' => 100,
|
19 |
+
'sortable' => false,
|
20 |
+
'period_type' => $this->getPeriodType(),
|
21 |
+
'renderer' => 'adminhtml/report_sales_grid_column_renderer_date',
|
22 |
+
'totals_label' => Mage::helper('sales')->__('Total'),
|
23 |
+
'html_decorators' => array('nobr'),
|
24 |
+
));
|
25 |
+
|
26 |
+
$this->addColumn('orders_count', array(
|
27 |
+
'header' => Mage::helper('sales')->__('Orders'),
|
28 |
+
'index' => 'orders_count',
|
29 |
+
'type' => 'number',
|
30 |
+
'total' => 'sum',
|
31 |
+
'sortable' => false
|
32 |
+
));
|
33 |
+
|
34 |
+
$this->addColumn('total_qty_ordered', array(
|
35 |
+
'header' => Mage::helper('sales')->__('Sales Items'),
|
36 |
+
'index' => 'total_qty_ordered',
|
37 |
+
'type' => 'number',
|
38 |
+
'total' => 'sum',
|
39 |
+
'sortable' => false
|
40 |
+
));
|
41 |
+
|
42 |
+
$this->addExportType('*/*/exportSalesCsv', Mage::helper('adminhtml')->__('CSV'));
|
43 |
+
$this->addExportType('*/*/exportSalesExcel', Mage::helper('adminhtml')->__('Excel XML'));
|
44 |
+
|
45 |
+
return call_user_func(array(get_parent_class(get_parent_class($this)), '_prepareColumns'));
|
46 |
+
}
|
47 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Sales.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Sales extends Mage_Adminhtml_Block_Widget_Grid_Container
|
7 |
+
{
|
8 |
+
public function __construct()
|
9 |
+
{
|
10 |
+
$this->_blockGroup = 'japi';
|
11 |
+
$this->_controller = 'adminhtml_report_sales';
|
12 |
+
$this->_headerText = Mage::helper('reports')->__('Total Sales from JMango360 Report');
|
13 |
+
|
14 |
+
parent::__construct();
|
15 |
+
|
16 |
+
$this->setTemplate('report/grid/container.phtml');
|
17 |
+
$this->_removeButton('add');
|
18 |
+
$this->addButton('filter_form_submit', array(
|
19 |
+
'label' => Mage::helper('reports')->__('Show Report'),
|
20 |
+
'onclick' => 'filterFormSubmit()'
|
21 |
+
));
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getFilterUrl()
|
25 |
+
{
|
26 |
+
$this->getRequest()->setParam('filter', null);
|
27 |
+
return $this->getUrl('*/*/sales', array('_current' => true));
|
28 |
+
}
|
29 |
+
|
30 |
+
public function getHeaderCssClass()
|
31 |
+
{
|
32 |
+
return '';
|
33 |
+
}
|
34 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Sales/Chart.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Sales_Chart extends Mage_Adminhtml_Block_Widget_Form
|
7 |
+
{
|
8 |
+
protected function _prepareForm()
|
9 |
+
{
|
10 |
+
$form = new Varien_Data_Form();
|
11 |
+
$fieldset = $form->addFieldset('chart_fieldset', array(
|
12 |
+
'legend' => $this->__('Chart')
|
13 |
+
));
|
14 |
+
$fieldset->addField('chart', 'text', array(
|
15 |
+
'filter_data' => $this->getFilterData(),
|
16 |
+
'graph_name' => 'japi/adminhtml_report_chart_sales'
|
17 |
+
));
|
18 |
+
$form->getElement('chart')->setRenderer(
|
19 |
+
$this->getLayout()->createBlock('japi/adminhtml_widget_form_renderer_element_chart')
|
20 |
+
);
|
21 |
+
$this->setForm($form);
|
22 |
+
return parent::_prepareForm();
|
23 |
+
}
|
24 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Report/Sales/Grid.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Report_Sales_Grid
|
7 |
+
extends Mage_Adminhtml_Block_Report_Sales_Sales_Grid
|
8 |
+
{
|
9 |
+
|
10 |
+
public function getResourceCollectionName()
|
11 |
+
{
|
12 |
+
return 'japi/sales_report_order_collection_aggregated';
|
13 |
+
}
|
14 |
+
|
15 |
+
protected function _prepareColumns()
|
16 |
+
{
|
17 |
+
parent::_prepareColumns();
|
18 |
+
$this->removeColumn('orders_count');
|
19 |
+
$this->removeColumn('total_qty_ordered');
|
20 |
+
$this->removeColumn('total_qty_invoiced');
|
21 |
+
|
22 |
+
return $this;
|
23 |
+
}
|
24 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/System/Config/Form/Log.php
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_System_Config_Form_Log extends Mage_Adminhtml_Block_System_Config_Form_Field
|
7 |
+
{
|
8 |
+
protected $_element;
|
9 |
+
|
10 |
+
protected function _construct()
|
11 |
+
{
|
12 |
+
parent::_construct();
|
13 |
+
$this->setTemplate('japi/system/config/form/log.phtml');
|
14 |
+
}
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Return element html
|
18 |
+
*
|
19 |
+
* @param Varien_Data_Form_Element_Abstract $element
|
20 |
+
* @return string
|
21 |
+
*/
|
22 |
+
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
23 |
+
{
|
24 |
+
$this->_element = $element;
|
25 |
+
return $this->_toHtml();
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Render block HTML
|
30 |
+
*
|
31 |
+
* @return string
|
32 |
+
*/
|
33 |
+
protected function _toHtml()
|
34 |
+
{
|
35 |
+
$html = $this->getLogSelectHtml();
|
36 |
+
$html .= $this->getDownloadButtonHtml();
|
37 |
+
return $html;
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* @return string
|
42 |
+
*/
|
43 |
+
protected function getLogSelectHtml()
|
44 |
+
{
|
45 |
+
$html = '<select id="' . $this->_element->getHtmlId() . '" onchange="japiChangeLog(this)">';
|
46 |
+
$logDir = Mage::getBaseDir('var') . DS . 'log';
|
47 |
+
foreach (scandir($logDir) as $fileName) {
|
48 |
+
if ($fileName == '.' || $fileName == '..') continue;
|
49 |
+
$fileSize = $this->_getLogSize($logDir . DS . $fileName);
|
50 |
+
$html .= '<option value="' . $fileName . '">' . sprintf('%s (%s)', $fileName, $fileSize) . '</option>';
|
51 |
+
}
|
52 |
+
$html .= '</select>';
|
53 |
+
return $html;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Generate button html
|
58 |
+
*
|
59 |
+
* @return string
|
60 |
+
*/
|
61 |
+
protected function getDownloadButtonHtml()
|
62 |
+
{
|
63 |
+
$html = $this->getLayout()->createBlock('adminhtml/widget_button', '', array(
|
64 |
+
'type' => 'button',
|
65 |
+
'style' => 'margin-top:3px',
|
66 |
+
'label' => $this->helper('japi')->__('Download'),
|
67 |
+
'onclick' => sprintf('japiSubmitUrl(\'%s\')', $this->getUrl('adminhtml/japi_log/download'))
|
68 |
+
))->toHtml();
|
69 |
+
|
70 |
+
$html .= $this->getLayout()->createBlock('adminhtml/widget_button', '', array(
|
71 |
+
'id' => $this->_element->getHtmlId() . '_clear',
|
72 |
+
'type' => 'button',
|
73 |
+
'style' => 'margin-top:3px;margin-left:3px;',
|
74 |
+
'label' => $this->helper('japi')->__('Clear'),
|
75 |
+
'disabled' => true,
|
76 |
+
'class' => 'disable',
|
77 |
+
'onclick' => sprintf('japiSubmitUrl(\'%s\')', $this->getUrl('adminhtml/japi_log/clear'))
|
78 |
+
))->toHtml();
|
79 |
+
|
80 |
+
$script = '<script type="text/javascript">
|
81 |
+
function japiSubmitUrl(url){
|
82 |
+
var file = $("' . $this->_element->getHtmlId() . '").value;
|
83 |
+
url += "?file=" + file;
|
84 |
+
setLocation(url);
|
85 |
+
}
|
86 |
+
function japiChangeLog(el){
|
87 |
+
if (el.value == "japi.log" || el.value == "japi_cron.log"){
|
88 |
+
enableElement($("' . $this->_element->getHtmlId() . '_clear' . '"));
|
89 |
+
}else{
|
90 |
+
disableElement($("' . $this->_element->getHtmlId() . '_clear' . '"));
|
91 |
+
}
|
92 |
+
}
|
93 |
+
</script>';
|
94 |
+
return $html . $script;
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Get SOAP log file size
|
99 |
+
*
|
100 |
+
* @param string $logFile
|
101 |
+
* @return string
|
102 |
+
*/
|
103 |
+
protected function _getLogSize($logFile = null)
|
104 |
+
{
|
105 |
+
if (!$logFile) {
|
106 |
+
return '';
|
107 |
+
}
|
108 |
+
|
109 |
+
if (!file_exists($logFile)) {
|
110 |
+
return '';
|
111 |
+
}
|
112 |
+
|
113 |
+
try {
|
114 |
+
$logSize = filesize($logFile);
|
115 |
+
if ($logSize == 0) return '0B';
|
116 |
+
return $this->_humanFilesize($logSize);
|
117 |
+
} catch (Exception $e) {
|
118 |
+
return '';
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* @param int $bytes
|
124 |
+
* @param int $decimals
|
125 |
+
* @return string
|
126 |
+
* @author Jeffrey Sambells
|
127 |
+
* @url http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
|
128 |
+
*/
|
129 |
+
protected function _humanFilesize($bytes = 0, $decimals = 2)
|
130 |
+
{
|
131 |
+
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
132 |
+
$factor = floor((strlen($bytes) - 1) / 3);
|
133 |
+
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
|
134 |
+
}
|
135 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/System/Config/Form/User.php
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_System_Config_Form_User extends Mage_Adminhtml_Block_System_Config_Form_Field
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Return element html
|
10 |
+
*
|
11 |
+
* @param Varien_Data_Form_Element_Abstract $element
|
12 |
+
* @return string
|
13 |
+
*/
|
14 |
+
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
15 |
+
{
|
16 |
+
return Mage::getStoreConfig('japi/jmango_rest_api/apiuser');
|
17 |
+
}
|
18 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/System/Config/Form/Version.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Adminhtml_System_Config_Form_Version extends Mage_Adminhtml_Block_System_Config_Form_Field
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* @param Varien_Data_Form_Element_Abstract $element
|
7 |
+
* @return string
|
8 |
+
*/
|
9 |
+
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
10 |
+
{
|
11 |
+
$class = get_class($this);
|
12 |
+
$parts = explode('_', $class);
|
13 |
+
$module = ucfirst($parts[0]) . '_' . ucfirst($parts[1]);
|
14 |
+
|
15 |
+
return (string)Mage::getConfig()->getNode('modules')->$module->version;
|
16 |
+
}
|
17 |
+
}
|
app/code/community/Jmango360/Japi/Block/Adminhtml/Widget/Form/Renderer/Element/Chart.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Adminhtml_Widget_Form_Renderer_Element_Chart
|
7 |
+
extends Mage_Adminhtml_Block_Widget_Form_Renderer_Element
|
8 |
+
{
|
9 |
+
protected function _construct()
|
10 |
+
{
|
11 |
+
parent::_construct();
|
12 |
+
$this->setTemplate('japi/widget/form/renderer/element/chart.phtml');
|
13 |
+
}
|
14 |
+
|
15 |
+
public function getGraphHtml()
|
16 |
+
{
|
17 |
+
return $this->getLayout()->createBlock($this->getElement()->getGraphName(), '', array(
|
18 |
+
'filter_data' => $this->getElement()->getFilterData()
|
19 |
+
))->toHtml();
|
20 |
+
}
|
21 |
+
}
|
app/code/community/Jmango360/Japi/Block/Catalog/Layer/Filter/Attribute.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Catalog_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Attribute
|
4 |
+
{
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
parent::__construct();
|
8 |
+
$this->_filterModelName = 'Jmango360_Japi_Model_Catalog_Layer_Filter_Attribute';
|
9 |
+
}
|
10 |
+
}
|
app/code/community/Jmango360/Japi/Block/Catalog/Layer/Filter/Category.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Catalog_Layer_Filter_Category extends Mage_Catalog_Block_Layer_Filter_Category
|
4 |
+
{
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
parent::__construct();
|
8 |
+
$this->_filterModelName = 'Mage_Catalog_Model_Layer_Filter_Category';
|
9 |
+
}
|
10 |
+
}
|
app/code/community/Jmango360/Japi/Block/Catalog/Layer/Filter/Decimal.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Catalog_Layer_Filter_Decimal extends Mage_Catalog_Block_Layer_Filter_Decimal
|
4 |
+
{
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
parent::__construct();
|
8 |
+
$this->_filterModelName = 'Jmango360_Japi_Model_Catalog_Layer_Filter_Decimal';
|
9 |
+
}
|
10 |
+
}
|
app/code/community/Jmango360/Japi/Block/Catalog/Layer/Filter/Price.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Catalog_Layer_Filter_Price extends Mage_Catalog_Block_Layer_Filter_Price
|
4 |
+
{
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
parent::__construct();
|
8 |
+
$this->_filterModelName = 'Jmango360_Japi_Model_Catalog_Layer_Filter_Price';
|
9 |
+
}
|
10 |
+
}
|
app/code/community/Jmango360/Japi/Block/Catalog/Layer/View.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Catalog_Layer_View extends Mage_Catalog_Block_Layer_View
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Initialize blocks names
|
7 |
+
*/
|
8 |
+
protected function _initBlocks()
|
9 |
+
{
|
10 |
+
$this->_stateBlockName = 'catalog/layer_state';
|
11 |
+
$this->_categoryBlockName = 'catalog/layer_filter_category';
|
12 |
+
$this->_attributeFilterBlockName = 'Jmango360_Japi_Block_Catalog_Layer_Filter_Attribute';
|
13 |
+
$this->_priceFilterBlockName = 'Jmango360_Japi_Block_Catalog_Layer_Filter_Price';
|
14 |
+
$this->_decimalFilterBlockName = 'Jmango360_Japi_Block_Catalog_Layer_Filter_Decimal';
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Get layer object
|
19 |
+
*
|
20 |
+
* @return Mage_Catalog_Model_Layer
|
21 |
+
*/
|
22 |
+
public function getLayer()
|
23 |
+
{
|
24 |
+
return Mage::getSingleton('Mage_Catalog_Model_Layer');
|
25 |
+
}
|
26 |
+
}
|
app/code/community/Jmango360/Japi/Block/Catalog/Product/List.php
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Catalog_Product_List extends Mage_Catalog_Block_Product_List
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Get catalog layer model
|
7 |
+
*
|
8 |
+
* @return Mage_Catalog_Model_Layer
|
9 |
+
*/
|
10 |
+
public function getLayer()
|
11 |
+
{
|
12 |
+
$layer = Mage::registry('current_layer');
|
13 |
+
if ($layer) {
|
14 |
+
return $layer;
|
15 |
+
}
|
16 |
+
return Mage::getSingleton('Mage_Catalog_Model_Layer');
|
17 |
+
}
|
18 |
+
}
|
app/code/community/Jmango360/Japi/Block/Catalogsearch/Layer.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Catalogsearch_Layer extends Mage_CatalogSearch_Block_Layer
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Initialize blocks names
|
7 |
+
*/
|
8 |
+
protected function _initBlocks()
|
9 |
+
{
|
10 |
+
parent::_initBlocks();
|
11 |
+
$this->_stateBlockName = 'Mage_Catalog_Block_Layer_State';
|
12 |
+
$this->_categoryBlockName = 'Jmango360_Japi_Block_Catalog_Layer_Filter_Category';
|
13 |
+
$this->_attributeFilterBlockName = 'Jmango360_Japi_Block_Catalogsearch_Layer_Filter_Attribute';
|
14 |
+
$this->_priceFilterBlockName = 'Jmango360_Japi_Block_Catalog_Layer_Filter_Price';
|
15 |
+
$this->_decimalFilterBlockName = 'Jmango360_Japi_Block_Catalog_Layer_Filter_Decimal';
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Get layer object
|
20 |
+
*
|
21 |
+
* @return Mage_CatalogSearch_Model_Layer
|
22 |
+
*/
|
23 |
+
public function getLayer()
|
24 |
+
{
|
25 |
+
$layer = Mage::getSingleton('catalogsearch/layer');
|
26 |
+
switch (get_class($layer)) {
|
27 |
+
case 'Mage_CatalogSearch_Model_Layer':
|
28 |
+
case 'Mirasvit_SearchIndex_Model_Catalogsearch_Layer':
|
29 |
+
return $layer;
|
30 |
+
break;
|
31 |
+
default:
|
32 |
+
return Mage::getSingleton('Mage_CatalogSearch_Model_Layer');
|
33 |
+
}
|
34 |
+
}
|
35 |
+
}
|
app/code/community/Jmango360/Japi/Block/Catalogsearch/Layer/Filter/Attribute.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_Catalogsearch_Layer_Filter_Attribute extends Mage_CatalogSearch_Block_Layer_Filter_Attribute
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Set filter model name
|
7 |
+
*/
|
8 |
+
public function __construct()
|
9 |
+
{
|
10 |
+
parent::__construct();
|
11 |
+
$this->_filterModelName = 'Jmango360_Japi_Model_Catalogsearch_Layer_Filter_Attribute';
|
12 |
+
}
|
13 |
+
}
|
app/code/community/Jmango360/Japi/Block/Checkout/Cart/Totals.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2015 JMango360
|
4 |
+
*/
|
5 |
+
class Jmango360_Japi_Block_Checkout_Cart_Totals extends Mage_Checkout_Block_Cart_Totals
|
6 |
+
{
|
7 |
+
/**
|
8 |
+
* Render total line
|
9 |
+
*/
|
10 |
+
public function renderTotal($total, $area = null, $colspan = 1)
|
11 |
+
{
|
12 |
+
$code = $total->getCode();
|
13 |
+
if ($total->getAs()) {
|
14 |
+
$code = $total->getAs();
|
15 |
+
}
|
16 |
+
$block = $this->_getTotalRenderer($code);
|
17 |
+
|
18 |
+
$baseDir = 'japi/rwd/onepage/review/totals/';
|
19 |
+
switch ($code) {
|
20 |
+
case 'subtotal':
|
21 |
+
case 'shipping':
|
22 |
+
case 'tax':
|
23 |
+
case 'grand_total':
|
24 |
+
$block->setTemplate($baseDir . $code . '.phtml');
|
25 |
+
break;
|
26 |
+
}
|
27 |
+
|
28 |
+
return $block->setTotal($total)
|
29 |
+
->setColspan($colspan)
|
30 |
+
->setRenderingArea(is_null($area) ? -1 : $area)
|
31 |
+
->toHtml();
|
32 |
+
}
|
33 |
+
}
|
app/code/community/Jmango360/Japi/Block/Checkout/Onepage/Addjs.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2016 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Checkout_Onepage_Addjs extends Mage_Page_Block_Html_Head
|
7 |
+
{
|
8 |
+
protected function _construct()
|
9 |
+
{
|
10 |
+
parent::_construct();
|
11 |
+
$this->setTemplate('japi/checkout/onepage/js.phtml');
|
12 |
+
}
|
13 |
+
|
14 |
+
public function getCustomCss()
|
15 |
+
{
|
16 |
+
$css = Mage::getStoreConfig('japi/jmango_rest_checkout_settings/custom_css');
|
17 |
+
if ($css) return $css;
|
18 |
+
}
|
19 |
+
}
|
app/code/community/Jmango360/Japi/Block/Checkout/Onepage/Address.php
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2016 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Checkout_Onepage_Address extends Mage_Core_Block_Template
|
7 |
+
{
|
8 |
+
protected $_address;
|
9 |
+
protected $_prefix;
|
10 |
+
|
11 |
+
protected function _construct()
|
12 |
+
{
|
13 |
+
parent::_construct();
|
14 |
+
$this->setTemplate('japi/checkout/onepage/address.phtml');
|
15 |
+
}
|
16 |
+
|
17 |
+
public function getFields()
|
18 |
+
{
|
19 |
+
/* @var $model Jmango360_Japi_Model_Rest_Mage */
|
20 |
+
$model = Mage::getModel('japi/rest_mage');
|
21 |
+
$fields = $model->getAddressAttributes();
|
22 |
+
|
23 |
+
return $fields;
|
24 |
+
}
|
25 |
+
|
26 |
+
public function getAddress()
|
27 |
+
{
|
28 |
+
return $this->_address;
|
29 |
+
}
|
30 |
+
|
31 |
+
public function setAddress($address)
|
32 |
+
{
|
33 |
+
$this->_address = $address;
|
34 |
+
return $this;
|
35 |
+
}
|
36 |
+
|
37 |
+
public function getFieldPrefix()
|
38 |
+
{
|
39 |
+
return $this->_prefix;
|
40 |
+
}
|
41 |
+
|
42 |
+
public function setFieldPrefix($prefix)
|
43 |
+
{
|
44 |
+
$this->_prefix = $prefix;
|
45 |
+
return $this;
|
46 |
+
}
|
47 |
+
|
48 |
+
public function getFieldName($field)
|
49 |
+
{
|
50 |
+
return sprintf('%s[%s]', $this->_prefix, $field);
|
51 |
+
}
|
52 |
+
|
53 |
+
public function getFieldId($field)
|
54 |
+
{
|
55 |
+
return sprintf('%s:%s', $this->_prefix, $field);
|
56 |
+
}
|
57 |
+
|
58 |
+
public function getFieldValue($field)
|
59 |
+
{
|
60 |
+
return $this->getAddress()->getData($field);
|
61 |
+
}
|
62 |
+
}
|
app/code/community/Jmango360/Japi/Block/Checkout/Onepage/Billing.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2016 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Checkout_Onepage_Billing extends Mage_Checkout_Block_Onepage_Billing
|
7 |
+
{
|
8 |
+
public function getAddress()
|
9 |
+
{
|
10 |
+
if (is_null($this->_address)) {
|
11 |
+
$this->_address = $this->getQuote()->getBillingAddress();
|
12 |
+
|
13 |
+
if ($this->isCustomerLoggedIn()) {
|
14 |
+
$this->_address = $this->getQuote()->getBillingAddress();
|
15 |
+
if (!$this->_address->getFirstname()) {
|
16 |
+
$this->_address->setFirstname($this->getQuote()->getCustomer()->getFirstname());
|
17 |
+
}
|
18 |
+
if (!$this->_address->getLastname()) {
|
19 |
+
$this->_address->setLastname($this->getQuote()->getCustomer()->getLastname());
|
20 |
+
}
|
21 |
+
}
|
22 |
+
}
|
23 |
+
|
24 |
+
return $this->_address;
|
25 |
+
}
|
26 |
+
}
|
app/code/community/Jmango360/Japi/Block/Checkout/Onepage/Shipping.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2016 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Checkout_Onepage_Shipping extends Mage_Checkout_Block_Onepage_Shipping
|
7 |
+
{
|
8 |
+
public function getAddress()
|
9 |
+
{
|
10 |
+
if (is_null($this->_address)) {
|
11 |
+
$this->_address = $this->getQuote()->getShippingAddress();
|
12 |
+
}
|
13 |
+
|
14 |
+
return $this->_address;
|
15 |
+
}
|
16 |
+
}
|
app/code/community/Jmango360/Japi/Block/Form.php
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2016 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Block_Form extends Mage_Core_Block_Template
|
7 |
+
{
|
8 |
+
protected $_fields;
|
9 |
+
protected $_prefix;
|
10 |
+
protected $_form;
|
11 |
+
|
12 |
+
protected function _construct()
|
13 |
+
{
|
14 |
+
parent::_construct();
|
15 |
+
$this->setTemplate('japi/form.phtml');
|
16 |
+
}
|
17 |
+
|
18 |
+
public function setForm($form)
|
19 |
+
{
|
20 |
+
$this->_form = $form;
|
21 |
+
return $this;
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getForm()
|
25 |
+
{
|
26 |
+
return $this->_form;
|
27 |
+
}
|
28 |
+
|
29 |
+
public function getFields()
|
30 |
+
{
|
31 |
+
if ($this->_fields) return $this->_fields;
|
32 |
+
switch ($this->_form) {
|
33 |
+
case 'billing':
|
34 |
+
$fields = array_merge(
|
35 |
+
Mage::helper('japi')->getCustomerAddressFormFields(),
|
36 |
+
Mage::helper('japi')->getCheckoutAddressFormFields()
|
37 |
+
);
|
38 |
+
$keys = array();
|
39 |
+
foreach ($fields as $i => $field) {
|
40 |
+
if (!in_array($field['key'], $keys)) {
|
41 |
+
$keys[] = $field['key'];
|
42 |
+
} else {
|
43 |
+
unset($fields[$i]);
|
44 |
+
}
|
45 |
+
}
|
46 |
+
return $fields;
|
47 |
+
break;
|
48 |
+
}
|
49 |
+
return array();
|
50 |
+
}
|
51 |
+
|
52 |
+
public function setFields($fields)
|
53 |
+
{
|
54 |
+
$this->_fields = $fields;
|
55 |
+
return $this;
|
56 |
+
}
|
57 |
+
|
58 |
+
public function getPrefix()
|
59 |
+
{
|
60 |
+
return $this->_prefix;
|
61 |
+
}
|
62 |
+
|
63 |
+
public function setPrefix($prefix)
|
64 |
+
{
|
65 |
+
$this->_prefix = $prefix;
|
66 |
+
return $this;
|
67 |
+
}
|
68 |
+
|
69 |
+
public function getFieldName($field)
|
70 |
+
{
|
71 |
+
return $this->_prefix ? sprintf('%s[%s]', $this->_prefix, $field) : $field;
|
72 |
+
}
|
73 |
+
|
74 |
+
public function getFieldId($field)
|
75 |
+
{
|
76 |
+
return $this->_prefix ? sprintf('%s:%s', $this->_prefix, $field) : $field;
|
77 |
+
}
|
78 |
+
|
79 |
+
public function getFieldValue($field)
|
80 |
+
{
|
81 |
+
|
82 |
+
}
|
83 |
+
}
|
app/code/community/Jmango360/Japi/Block/GiftMessage/Message/Inline.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Block_GiftMessage_Message_Inline extends Mage_GiftMessage_Block_Message_Inline
|
4 |
+
{
|
5 |
+
protected function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
$this->setTemplate('japi/giftmessage/inline.phtml');
|
9 |
+
}
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Retrieve additional url
|
13 |
+
*
|
14 |
+
* @return bool
|
15 |
+
*/
|
16 |
+
public function getAdditionalUrl()
|
17 |
+
{
|
18 |
+
return $this->getUrl('japi/checkout/getAdditional', array('_secure' => true));
|
19 |
+
}
|
20 |
+
}
|
app/code/community/Jmango360/Japi/Controller/Abstract.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Controller_Abstract extends Mage_Core_Controller_Front_Action
|
4 |
+
{
|
5 |
+
/* @var Jmango360_Japi_Model_Server */
|
6 |
+
protected $_server = null;
|
7 |
+
|
8 |
+
public function _construct()
|
9 |
+
{
|
10 |
+
if (!Mage::getStoreConfigFlag('japi/jmango_rest_developer_settings/enable')) {
|
11 |
+
// suppress notice, warning
|
12 |
+
error_reporting(E_ERROR | E_PARSE);
|
13 |
+
}
|
14 |
+
|
15 |
+
$this->_server = Mage::getSingleton('japi/server');
|
16 |
+
$this->_server->setControllerInstance($this);
|
17 |
+
|
18 |
+
/* @var $helper Jmango360_Japi_Helper_Data */
|
19 |
+
$helper = Mage::helper('japi');
|
20 |
+
//Set Theme follow by Design config of Magento
|
21 |
+
$helper->setTheme(
|
22 |
+
Mage::getSingleton('core/design_package')->getTheme('frontend'),
|
23 |
+
Mage::getSingleton('core/design_package')->getPackageName()
|
24 |
+
);
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @return Jmango360_Japi_Model_Server
|
29 |
+
*/
|
30 |
+
public function getServer()
|
31 |
+
{
|
32 |
+
return $this->_server;
|
33 |
+
}
|
34 |
+
}
|
app/code/community/Jmango360/Japi/Exception.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Jmango360_Japi_Exception extends Exception
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Exception constructor
|
6 |
+
*
|
7 |
+
* @param string $message
|
8 |
+
* @param int $code
|
9 |
+
*/
|
10 |
+
public function __construct($message, $code)
|
11 |
+
{
|
12 |
+
if ($code <= 100 || $code >= 599) {
|
13 |
+
throw new Exception(sprintf(Mage::helper('japi')->__("Invalid Exception code '%d'", $code)));
|
14 |
+
}
|
15 |
+
|
16 |
+
if (is_String($message)) {
|
17 |
+
$message = Mage::helper('japi')->__($message);
|
18 |
+
}
|
19 |
+
parent::__construct($message, $code);
|
20 |
+
|
21 |
+
|
22 |
+
/*
|
23 |
+
* @TODO The request and response object saved in the core/session on exiting the script returns a fatal error;
|
24 |
+
* -- should find a better way; maybe creating a rest owned session
|
25 |
+
*/
|
26 |
+
$server = Mage::getSingleton('japi/server');
|
27 |
+
$server->unsRequest();
|
28 |
+
$server->unsResponse();
|
29 |
+
}
|
30 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Adminhtml/Report/Order.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Helper_Adminhtml_Report_Order extends Mage_Adminhtml_Helper_Dashboard_Abstract
|
7 |
+
{
|
8 |
+
protected function _initCollection()
|
9 |
+
{
|
10 |
+
$dateStart = $this->getParam('from');
|
11 |
+
$dateEnd = $this->getParam('to');
|
12 |
+
$range = $this->getParam('period_type');
|
13 |
+
if (is_null($this->getParam('store_ids'))) {
|
14 |
+
$this->setParam('store_ids', 0);
|
15 |
+
}
|
16 |
+
|
17 |
+
if ($dateStart && $dateEnd) {
|
18 |
+
$this->_collection = Mage::getResourceSingleton('japi/report_order_collection')
|
19 |
+
->prepareSummary($range, $dateStart, $dateEnd, $this->getParam('live'));
|
20 |
+
|
21 |
+
if ($this->getParam('store_ids')) {
|
22 |
+
$this->_collection
|
23 |
+
->addFieldToFilter('store_id', array('in' => explode(',', $this->getParam('store_ids'))));
|
24 |
+
} else {
|
25 |
+
if (!$this->getParam('live')) {
|
26 |
+
$this->_collection
|
27 |
+
->addFieldToFilter('store_id', array('eq' => 0));
|
28 |
+
}
|
29 |
+
}
|
30 |
+
|
31 |
+
if (count($this->getParam('order_statuses'))) {
|
32 |
+
$this->_collection
|
33 |
+
->addFieldToFilter(
|
34 |
+
$this->getParam('live') ? 'status' : 'order_status',
|
35 |
+
array('in' => $this->getParam('order_statuses'))
|
36 |
+
);
|
37 |
+
}
|
38 |
+
|
39 |
+
$this->_collection->load();
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
public function getItems()
|
44 |
+
{
|
45 |
+
return is_array($this->getCollection())
|
46 |
+
? $this->getCollection()
|
47 |
+
: (is_null($this->getCollection()) ? array() : $this->getCollection()->getItems());
|
48 |
+
}
|
49 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Data.php
ADDED
@@ -0,0 +1,944 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_Data extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
const USESHOPDESIGNSETTINGSPATH = 'japi/jmango_rest_design_settings/use_shopdesign_setting';
|
6 |
+
const DEFAULTRESTPACKAGEPATH = 'japi/jmango_rest_design_settings/mobile_package_name';
|
7 |
+
const DEFAULTRESTTHEMEPATH = 'japi/jmango_rest_design_settings/mobile_theme_name';
|
8 |
+
const DEFAULTRESTPACKAGE = 'default';
|
9 |
+
const DEFAULTRESTTHEME = 'default';
|
10 |
+
|
11 |
+
protected $DEFAULT_CUSTOMER_ATTRIBUTES = array(
|
12 |
+
'prefix', 'firstname', 'middlename', 'lastname', 'suffix', 'email', 'dob', 'taxvat', 'gender'
|
13 |
+
);
|
14 |
+
protected $DEFAULT_CUSTOMER_ADDRESS_ATTRIBUTES = array(
|
15 |
+
'prefix', 'firstname', 'middlename', 'lastname', 'suffix', 'company', 'street', 'city', 'country_id',
|
16 |
+
'region', 'region_id', 'postcode', 'telephone', 'fax', 'vat_id'
|
17 |
+
);
|
18 |
+
|
19 |
+
/**
|
20 |
+
* @param $form Mage_Eav_Model_Form
|
21 |
+
* @param $excluded array
|
22 |
+
* @return array
|
23 |
+
*/
|
24 |
+
protected function _getFormAttributes($form, $excluded = array())
|
25 |
+
{
|
26 |
+
if (!$form) return array();
|
27 |
+
|
28 |
+
/* @var $eavConfig Mage_Eav_Model_Config */
|
29 |
+
$eavConfig = Mage::getSingleton('eav/config');
|
30 |
+
|
31 |
+
$attributes = array();
|
32 |
+
foreach ($form->getAttributes() as $attribute) {
|
33 |
+
$attributeCode = $attribute->getAttributeCode();
|
34 |
+
if (in_array($attributeCode, $excluded)) continue;
|
35 |
+
$entityType = $attribute->getEntityType();
|
36 |
+
$data = array(
|
37 |
+
'key' => $attributeCode,
|
38 |
+
'label' => $eavConfig->getAttribute($entityType->getEntityTypeCode(), $attributeCode)->getStoreLabel(),
|
39 |
+
'display_type' => $attribute->getFrontendInput(),
|
40 |
+
'required' => (bool)$attribute->getIsRequired()
|
41 |
+
);
|
42 |
+
try {
|
43 |
+
foreach ($attribute->getSource()->getAllOptions() as $option) {
|
44 |
+
$data['options'][$option['value']] = $this->__($option['label']);
|
45 |
+
}
|
46 |
+
} catch (Exception $e) {
|
47 |
+
}
|
48 |
+
$attributes[] = $data;
|
49 |
+
}
|
50 |
+
|
51 |
+
return $attributes;
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Get additional fields on signup form
|
56 |
+
*/
|
57 |
+
public function getSignupFormFields()
|
58 |
+
{
|
59 |
+
/* @var $customerForm Mage_Customer_Model_Form */
|
60 |
+
$customerForm = Mage::getModel('customer/form');
|
61 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
62 |
+
$customer = Mage::getModel('customer/customer');
|
63 |
+
$customerForm->setFormCode('customer_account_create');
|
64 |
+
$customerForm->setEntity($customer);
|
65 |
+
|
66 |
+
return $this->_getFormAttributes($customerForm, $this->DEFAULT_CUSTOMER_ATTRIBUTES);
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Get additional fields on signup address form
|
71 |
+
*/
|
72 |
+
public function getSignupAddressFormFields()
|
73 |
+
{
|
74 |
+
/* @var $address Mage_Customer_Model_Address */
|
75 |
+
$address = Mage::getModel('customer/address');
|
76 |
+
/* @var $addressForm Mage_Customer_Model_Form */
|
77 |
+
$addressForm = Mage::getModel('customer/form');
|
78 |
+
$addressForm->setFormCode('customer_register_address')
|
79 |
+
->setEntity($address);
|
80 |
+
|
81 |
+
return $this->_getFormAttributes($addressForm, $this->DEFAULT_CUSTOMER_ADDRESS_ATTRIBUTES);
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Get additional fields on customer address form
|
86 |
+
*/
|
87 |
+
public function getCustomerAddressFormFields()
|
88 |
+
{
|
89 |
+
/* @var $address Mage_Customer_Model_Address */
|
90 |
+
$address = Mage::getModel('customer/address');
|
91 |
+
/* @var $addressForm Mage_Customer_Model_Form */
|
92 |
+
$addressForm = Mage::getModel('customer/form');
|
93 |
+
$addressForm->setFormCode('customer_address_edit')
|
94 |
+
->setEntity($address);
|
95 |
+
|
96 |
+
return $this->_getFormAttributes($addressForm, $this->DEFAULT_CUSTOMER_ADDRESS_ATTRIBUTES);
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Get additional fields on checkout address form
|
101 |
+
*/
|
102 |
+
public function getCheckoutAddressFormFields()
|
103 |
+
{
|
104 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
105 |
+
$customer = Mage::getModel('customer/customer');
|
106 |
+
/* @var $addressForm Mage_Customer_Model_Form */
|
107 |
+
$addressForm = Mage::getModel('customer/form');
|
108 |
+
$addressForm->setFormCode('checkout_register')
|
109 |
+
->setEntity($customer);
|
110 |
+
|
111 |
+
return $this->_getFormAttributes($addressForm, array_merge(
|
112 |
+
$this->DEFAULT_CUSTOMER_ADDRESS_ATTRIBUTES,
|
113 |
+
$this->DEFAULT_CUSTOMER_ATTRIBUTES
|
114 |
+
));
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Get extension version
|
119 |
+
*/
|
120 |
+
public function getExtensionVersion($module)
|
121 |
+
{
|
122 |
+
try {
|
123 |
+
if (!$module) return null;
|
124 |
+
return (string)Mage::getConfig()->getNode()->modules->$module->version;
|
125 |
+
} catch (Exception $e) {
|
126 |
+
return null;
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Check if column "japi" exist in table "sales_flat_order"
|
132 |
+
*/
|
133 |
+
public function hasJapiOrderData()
|
134 |
+
{
|
135 |
+
/* @var $resource Mage_Core_Model_Resource */
|
136 |
+
$resource = Mage::getSingleton('core/resource');
|
137 |
+
$connection = $resource->getConnection('core_read');
|
138 |
+
return $connection->tableColumnExists($resource->getTableName('sales/order'), 'japi');
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Check if customer entity has "japi" attribute
|
143 |
+
*/
|
144 |
+
public function hasJapiCustomerData()
|
145 |
+
{
|
146 |
+
/* @var $setup Mage_Eav_Model_Entity_Setup */
|
147 |
+
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
148 |
+
return $setup->getAttribute('customer', 'japi');
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* @param Mage_Sales_Model_Quote $quote
|
153 |
+
* @return array
|
154 |
+
*/
|
155 |
+
public function getTotals($quote = null)
|
156 |
+
{
|
157 |
+
/* @var $quote Mage_Sales_Model_Quote */
|
158 |
+
$quote = $quote ?: Mage::getSingleton('checkout/session')->getQuote();
|
159 |
+
$totals = $quote->getTotals();
|
160 |
+
/* @var $taxConfig Mage_Tax_Model_Config */
|
161 |
+
$taxConfig = Mage::getSingleton('tax/config');
|
162 |
+
/* @var $taxHelper Mage_Tax_Helper_Data */
|
163 |
+
$taxHelper = Mage::helper('tax');
|
164 |
+
|
165 |
+
$rows = array();
|
166 |
+
foreach ($totals as $total) {
|
167 |
+
/* @var $total Mage_Sales_Model_Quote_Address_Total_Abstract */
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Fix for MPLUGIN-665
|
171 |
+
* Not add total to return data if title or value is null
|
172 |
+
*/
|
173 |
+
if ($total->getTitle() === null || $total->getValue() === null) {
|
174 |
+
continue;
|
175 |
+
}
|
176 |
+
|
177 |
+
switch ($total->getCode()) {
|
178 |
+
case 'shipping':
|
179 |
+
if ($taxConfig->displayCartShippingBoth()) {
|
180 |
+
$rows[] = array(
|
181 |
+
'title' => $taxHelper->__('Shipping Excl. Tax (%s)', $total->getAddress()->getShippingDescription()),
|
182 |
+
'code' => $total->getCode(),
|
183 |
+
'value' => $total->getAddress()->getShippingAmount()
|
184 |
+
);
|
185 |
+
$rows[] = array(
|
186 |
+
'title' => $taxHelper->__('Shipping Incl. Tax (%s)', $total->getAddress()->getShippingDescription()),
|
187 |
+
'code' => $total->getCode() . '_incl',
|
188 |
+
'value' => $total->getAddress()->getShippingInclTax()
|
189 |
+
);
|
190 |
+
} elseif ($taxConfig->displayCartShippingInclTax()) {
|
191 |
+
$rows[] = array(
|
192 |
+
'title' => $total->getTitle(),
|
193 |
+
'code' => $total->getCode(),
|
194 |
+
'value' => $total->getAddress()->getShippingInclTax()
|
195 |
+
);
|
196 |
+
} else {
|
197 |
+
$rows[] = array(
|
198 |
+
'title' => $total->getTitle(),
|
199 |
+
'code' => $total->getCode(),
|
200 |
+
'value' => $total->getAddress()->getShippingAmount()
|
201 |
+
);
|
202 |
+
}
|
203 |
+
break;
|
204 |
+
case 'subtotal':
|
205 |
+
if ($taxConfig->displayCartSubtotalBoth()) {
|
206 |
+
$rows[] = array(
|
207 |
+
'title' => $taxHelper->__('Subtotal (Excl. Tax)'),
|
208 |
+
'code' => $total->getCode(),
|
209 |
+
'value' => $total->getValueExclTax()
|
210 |
+
);
|
211 |
+
$rows[] = array(
|
212 |
+
'title' => $taxHelper->__('Subtotal (Incl. Tax)'),
|
213 |
+
'code' => $total->getCode() . '_incl',
|
214 |
+
'value' => $total->getValueInclTax()
|
215 |
+
);
|
216 |
+
} else {
|
217 |
+
$rows[] = array(
|
218 |
+
'title' => $total->getTitle(),
|
219 |
+
'code' => $total->getCode(),
|
220 |
+
'value' => $total->getValue()
|
221 |
+
);
|
222 |
+
}
|
223 |
+
break;
|
224 |
+
case 'tax':
|
225 |
+
if ($taxConfig->displayFullSummary() && $total->getValue()) {
|
226 |
+
foreach ($total->getFullInfo() as $info) {
|
227 |
+
if (isset($info['hidden']) && $info['hidden']) continue;
|
228 |
+
$rates = isset($info['rates']) ? $info['rates'] : array();
|
229 |
+
foreach ($rates as $rate) {
|
230 |
+
$rows[] = array(
|
231 |
+
'title' => $taxHelper->escapeHtml(isset($rate['title']) ? $rate['title'] : '') .
|
232 |
+
(!empty($rate['percent']) ? ' (' . $rate['percent'] . '%)' : ''),
|
233 |
+
'code' => $total->getCode(),
|
234 |
+
'value' => isset($info['amount']) ? $info['amount'] : ''
|
235 |
+
);
|
236 |
+
}
|
237 |
+
}
|
238 |
+
}
|
239 |
+
$rows[] = array(
|
240 |
+
'title' => $total->getTitle(),
|
241 |
+
'code' => $total->getCode(),
|
242 |
+
'value' => $total->getValue()
|
243 |
+
);
|
244 |
+
break;
|
245 |
+
case 'grand_total':
|
246 |
+
if ($total->getAddress()->getGrandTotal() && $taxConfig->displayCartTaxWithGrandTotal()) {
|
247 |
+
$rows[] = array(
|
248 |
+
'title' => Mage::helper('tax')->__('Grand Total Excl. Tax'),
|
249 |
+
'code' => $total->getCode(),
|
250 |
+
'value' => max($total->getAddress()->getGrandTotal() - $total->getAddress()->getTaxAmount(), 0)
|
251 |
+
);
|
252 |
+
$rows[] = array(
|
253 |
+
'title' => Mage::helper('tax')->__('Grand Total Incl. Tax'),
|
254 |
+
'code' => $total->getCode() . '_incl',
|
255 |
+
'value' => $total->getValue()
|
256 |
+
);
|
257 |
+
} else {
|
258 |
+
$rows[] = array(
|
259 |
+
'title' => $total->getTitle(),
|
260 |
+
'code' => $total->getCode(),
|
261 |
+
'value' => $total->getValue()
|
262 |
+
);
|
263 |
+
}
|
264 |
+
break;
|
265 |
+
case 'cashondelivery':
|
266 |
+
if ($taxHelper->isModuleEnabled('Phoenix_CashOnDelivery')) {
|
267 |
+
if (Mage::getStoreConfig('tax/display/cod_fee') == Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH ||
|
268 |
+
Mage::getStoreConfig('tax/display/phoenix_cashondelivery_fee') == Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH
|
269 |
+
) {
|
270 |
+
$rows[] = array(
|
271 |
+
'title' => $total->getTitle(),
|
272 |
+
'code' => $total->getCode(),
|
273 |
+
'value' => $total->getAddress()->getCodFee()
|
274 |
+
);
|
275 |
+
$rows[] = array(
|
276 |
+
'title' => $total->getTitle(),
|
277 |
+
'code' => $total->getCode() . '_incl',
|
278 |
+
'value' => $total->getAddress()->getCodFee() + $total->getAddress()->getCodTaxAmount()
|
279 |
+
);
|
280 |
+
} elseif (Mage::getStoreConfig('tax/display/cod_fee') == Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX ||
|
281 |
+
Mage::getStoreConfig('tax/display/phoenix_cashondelivery_fee') == Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX
|
282 |
+
) {
|
283 |
+
$rows[] = array(
|
284 |
+
'title' => $total->getTitle(),
|
285 |
+
'code' => $total->getCode() . '_incl',
|
286 |
+
'value' => $total->getAddress()->getCodFee() + $total->getAddress()->getCodTaxAmount()
|
287 |
+
);
|
288 |
+
} else {
|
289 |
+
$rows[] = array(
|
290 |
+
'title' => $total->getTitle(),
|
291 |
+
'code' => $total->getCode(),
|
292 |
+
'value' => $total->getAddress()->getCodFee()
|
293 |
+
);
|
294 |
+
}
|
295 |
+
} else {
|
296 |
+
$rows[] = array(
|
297 |
+
'title' => $total->getTitle(),
|
298 |
+
'code' => $total->getCode(),
|
299 |
+
'value' => $total->getValue()
|
300 |
+
);
|
301 |
+
}
|
302 |
+
break;
|
303 |
+
case 'rewardpoints_label':
|
304 |
+
if (!$taxHelper->isModuleEnabled('Magestore_RewardPoints')) {
|
305 |
+
continue;
|
306 |
+
} else {
|
307 |
+
$rows[] = array(
|
308 |
+
'title' => $total->getTitle(),
|
309 |
+
'code' => $total->getCode(),
|
310 |
+
'value' => $total->getValue()
|
311 |
+
);
|
312 |
+
}
|
313 |
+
break;
|
314 |
+
default:
|
315 |
+
$rows[] = array(
|
316 |
+
'title' => $total->getTitle(),
|
317 |
+
'code' => $total->getCode(),
|
318 |
+
'value' => $total->getValue()
|
319 |
+
);
|
320 |
+
}
|
321 |
+
}
|
322 |
+
|
323 |
+
return $rows;
|
324 |
+
}
|
325 |
+
|
326 |
+
public function isNeedCatalogProductLoadAfterEvent()
|
327 |
+
{
|
328 |
+
return true;
|
329 |
+
}
|
330 |
+
|
331 |
+
public function isNeedByPassSessionValidation()
|
332 |
+
{
|
333 |
+
return Mage::getStoreConfigFlag('web/session/use_remote_addr')
|
334 |
+
|| Mage::getStoreConfigFlag('web/session/use_http_via')
|
335 |
+
|| Mage::getStoreConfigFlag('web/session/use_http_x_forwarded_for')
|
336 |
+
|| Mage::getStoreConfigFlag('web/session/use_http_user_agent');
|
337 |
+
}
|
338 |
+
|
339 |
+
public function isNeedByPassMIMT()
|
340 |
+
{
|
341 |
+
return version_compare(Mage::getVersion(), '1.9.1.0', '>=')
|
342 |
+
&& Mage::app()->getFrontController()->getRequest()->isSecure();
|
343 |
+
}
|
344 |
+
|
345 |
+
public function isUseSidFrontend()
|
346 |
+
{
|
347 |
+
return Mage::getStoreConfigFlag('web/session/use_frontend_sid');
|
348 |
+
}
|
349 |
+
|
350 |
+
public function addJapiKey($url)
|
351 |
+
{
|
352 |
+
if (!$url) return '';
|
353 |
+
if (!$this->isNeedByPassMIMT() && !$this->isNeedByPassSessionValidation() && $this->isUseSidFrontend()) {
|
354 |
+
return $url;
|
355 |
+
}
|
356 |
+
|
357 |
+
$sessionId = Mage::getSingleton('core/session')->getSessionId();
|
358 |
+
$apiKey = Mage::getStoreConfig('japi/jmango_rest_api/apikey');
|
359 |
+
if (!$apiKey) return $url;
|
360 |
+
|
361 |
+
$key = md5($sessionId . $apiKey);
|
362 |
+
if (strpos($url, '?') !== false) {
|
363 |
+
return $url .= '&jkey=' . $key;
|
364 |
+
} else {
|
365 |
+
return $url .= '?jkey=' . $key;
|
366 |
+
}
|
367 |
+
}
|
368 |
+
|
369 |
+
public function getJapiKey()
|
370 |
+
{
|
371 |
+
$sessionId = Mage::getSingleton('core/session')->getSessionId();
|
372 |
+
$apiKey = Mage::getStoreConfig('japi/jmango_rest_api/apikey');
|
373 |
+
if (!$apiKey) return null;
|
374 |
+
|
375 |
+
return md5($sessionId . $apiKey);
|
376 |
+
}
|
377 |
+
|
378 |
+
public function checkJapiKey()
|
379 |
+
{
|
380 |
+
if (!$this->isNeedByPassMIMT() && !$this->isNeedByPassSessionValidation()) {
|
381 |
+
return true;
|
382 |
+
}
|
383 |
+
|
384 |
+
$key = Mage::app()->getRequest()->getParam('jkey');
|
385 |
+
if (!$key) return false;
|
386 |
+
|
387 |
+
$sessionId = Mage::app()->getRequest()->getParam('SID');
|
388 |
+
$apiKey = Mage::getStoreConfig('japi/jmango_rest_api/apikey');
|
389 |
+
if (!$apiKey) return false;
|
390 |
+
|
391 |
+
return md5($sessionId . $apiKey) === $key;
|
392 |
+
}
|
393 |
+
|
394 |
+
public function getCountryById($countryId)
|
395 |
+
{
|
396 |
+
$countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray();
|
397 |
+
foreach ($countries as $country) {
|
398 |
+
if ($country['value'] == $countryId) {
|
399 |
+
return $country['label'];
|
400 |
+
}
|
401 |
+
}
|
402 |
+
|
403 |
+
return '';
|
404 |
+
}
|
405 |
+
|
406 |
+
public function getRegionById($countryId, $regionId)
|
407 |
+
{
|
408 |
+
$regions = Mage::getResourceModel('directory/region_collection')->addCountryFilter($countryId)->toOptionArray();
|
409 |
+
|
410 |
+
foreach ($regions as $region) {
|
411 |
+
if ($region['value'] == $regionId) {
|
412 |
+
return $region['label'];
|
413 |
+
}
|
414 |
+
}
|
415 |
+
|
416 |
+
return '';
|
417 |
+
}
|
418 |
+
|
419 |
+
public function getRequest()
|
420 |
+
{
|
421 |
+
return $this->getServer()->getRequest();
|
422 |
+
}
|
423 |
+
|
424 |
+
public function getResponse()
|
425 |
+
{
|
426 |
+
return $this->getServer()->getResponse();
|
427 |
+
}
|
428 |
+
|
429 |
+
/**
|
430 |
+
* @return Jmango360_Japi_Model_Server
|
431 |
+
*/
|
432 |
+
public function getServer()
|
433 |
+
{
|
434 |
+
return Mage::getSingleton('japi/server');
|
435 |
+
}
|
436 |
+
|
437 |
+
public function getUseShopDesignSettingsPath()
|
438 |
+
{
|
439 |
+
return Mage::getStoreConfigFlag(self::USESHOPDESIGNSETTINGSPATH);
|
440 |
+
}
|
441 |
+
|
442 |
+
public function getDefaultRestTheme()
|
443 |
+
{
|
444 |
+
$theme = Mage::getStoreConfig(self::DEFAULTRESTTHEMEPATH);
|
445 |
+
if (empty($theme)) {
|
446 |
+
$theme = self::DEFAULTRESTTHEME;
|
447 |
+
}
|
448 |
+
|
449 |
+
return $theme;
|
450 |
+
}
|
451 |
+
|
452 |
+
public function getDefaultRestPackage()
|
453 |
+
{
|
454 |
+
$package = Mage::getStoreConfig(self::DEFAULTRESTPACKAGEPATH);
|
455 |
+
if (empty($package)) {
|
456 |
+
$package = self::DEFAULTRESTPACKAGE;
|
457 |
+
}
|
458 |
+
|
459 |
+
return $package;
|
460 |
+
}
|
461 |
+
|
462 |
+
/*
|
463 |
+
* The "base" package is the Magento base code. This is never updated by custom plugins.
|
464 |
+
* -- To be sure never use plugin code you could use "base" as a package name in the REST requests.
|
465 |
+
* The "default" package is where plugins standard add there code.
|
466 |
+
* -- custom and other plugin code can be added in any other package
|
467 |
+
* The theme(name) is set as name for: 'layout', 'template', 'skin', 'locale'
|
468 |
+
* -- so if you chose another theme name it could influence language as well
|
469 |
+
* Maybe an idea to add a locale setting special for laguage too or maybe create another method to do so
|
470 |
+
* -- however, there could already be a better method to do so
|
471 |
+
*
|
472 |
+
*/
|
473 |
+
public function setTheme($themeName = null, $packageName = null)
|
474 |
+
{
|
475 |
+
if (empty($themeName)) {
|
476 |
+
$themeName = $this->getDefaultRestTheme();
|
477 |
+
}
|
478 |
+
|
479 |
+
if (empty($packageName)) {
|
480 |
+
$packageName = $this->getDefaultRestPackage();
|
481 |
+
}
|
482 |
+
|
483 |
+
Mage::getDesign()->setArea('frontend')
|
484 |
+
->setPackageName($packageName)
|
485 |
+
->setTheme($themeName);
|
486 |
+
|
487 |
+
return $this;
|
488 |
+
}
|
489 |
+
|
490 |
+
/**
|
491 |
+
* @param null $layoutName
|
492 |
+
* @return Mage_Core_Model_Layout|null
|
493 |
+
* @throws Mage_Core_Exception
|
494 |
+
*/
|
495 |
+
public function loadLayout($layoutName = null)
|
496 |
+
{
|
497 |
+
if (!$layoutName) return null;
|
498 |
+
|
499 |
+
/* @var $layout Mage_Core_Model_Layout */
|
500 |
+
$layout = Mage::app()->getLayout();
|
501 |
+
$update = $layout->getUpdate();
|
502 |
+
$update->load($layoutName);
|
503 |
+
$layout->generateXml();
|
504 |
+
$layout->generateBlocks();
|
505 |
+
|
506 |
+
return $layout;
|
507 |
+
}
|
508 |
+
|
509 |
+
public function getBlock($blockname, $alias = null, $attributes = array())
|
510 |
+
{
|
511 |
+
foreach (Mage::app()->getLayout()->getAllBlocks() as $name => $block) {
|
512 |
+
if ($block->getType() == $blockname) {
|
513 |
+
if (!is_null($alias)) {
|
514 |
+
if ($block->getBlockAlias() == $alias) {
|
515 |
+
return $block;
|
516 |
+
}
|
517 |
+
} else {
|
518 |
+
return $block;
|
519 |
+
}
|
520 |
+
}
|
521 |
+
}
|
522 |
+
|
523 |
+
return Mage::app()->getLayout()->createBlock($blockname, $alias, $attributes);
|
524 |
+
}
|
525 |
+
|
526 |
+
public function stripTokenFromUrl($url)
|
527 |
+
{
|
528 |
+
if (!is_String($url) || !stristr($url, 'token') || !stristr($url, '?')) {
|
529 |
+
return $url;
|
530 |
+
}
|
531 |
+
$split = (array)explode('?', $url);
|
532 |
+
$parts = (array)explode('&', $split[1]);
|
533 |
+
foreach ($parts as $key => $part) {
|
534 |
+
if (stristr($part, 'token=')) {
|
535 |
+
unset($parts[$key]);
|
536 |
+
}
|
537 |
+
}
|
538 |
+
$split[1] = implode('&', $parts);
|
539 |
+
$url = implode('?', $split);
|
540 |
+
|
541 |
+
return $url;
|
542 |
+
}
|
543 |
+
|
544 |
+
public function getCheckoutUrl()
|
545 |
+
{
|
546 |
+
/**
|
547 |
+
* MPLUGIN-1126: by pass check user's IP adress to auto redirect when website installed "Experius_Geoipredirect"
|
548 |
+
*/
|
549 |
+
if ($this->isModuleEnabled('Experius_Geoipredirect')) {
|
550 |
+
Mage::getSingleton('core/session')->setData('ipcheck_redirected', Mage::app()->getStore()->getId());
|
551 |
+
}
|
552 |
+
|
553 |
+
if (Mage::getStoreConfigFlag('japi/jmango_rest_checkout_settings/onepage')) {
|
554 |
+
$checkoutUrl = Mage::getUrl('japi/checkout/onepage', array('_secure' => true));
|
555 |
+
} else {
|
556 |
+
$checkoutUrl = Mage::getStoreConfig('japi/jmango_rest_checkout_settings/checkout_url');
|
557 |
+
}
|
558 |
+
|
559 |
+
if ($checkoutUrl) {
|
560 |
+
if (strpos($checkoutUrl, 'http') === 0) {
|
561 |
+
return $checkoutUrl;
|
562 |
+
} else {
|
563 |
+
return Mage::getUrl($checkoutUrl);
|
564 |
+
}
|
565 |
+
}
|
566 |
+
|
567 |
+
$_cacheUrlKey = 'japi_checkout_url' . Mage::app()->getStore()->getStoreId();
|
568 |
+
$cache = Mage::app()->getCache();
|
569 |
+
$checkoutUrl = $cache->load($_cacheUrlKey);
|
570 |
+
if ($checkoutUrl) {
|
571 |
+
return $checkoutUrl;
|
572 |
+
}
|
573 |
+
|
574 |
+
/* @var $layout Mage_Core_Model_Layout */
|
575 |
+
$layout = Mage::getSingleton('core/layout');
|
576 |
+
$update = $layout->getUpdate();
|
577 |
+
$update->load('checkout_cart_index');
|
578 |
+
$layout->generateXml();
|
579 |
+
$layout->generateBlocks();
|
580 |
+
foreach ($layout->getAllBlocks() as $name => $block) {
|
581 |
+
if ($name == 'checkout.cart.methods') {
|
582 |
+
$html = $block->toHtml();
|
583 |
+
$value = $this->parseCheckoutUrl($html);
|
584 |
+
$cache->save($value, $_cacheUrlKey, array(Mage_Core_Model_Config::CACHE_TAG), null);
|
585 |
+
return $value;
|
586 |
+
break;
|
587 |
+
}
|
588 |
+
}
|
589 |
+
|
590 |
+
return '';
|
591 |
+
}
|
592 |
+
|
593 |
+
public function parseCheckoutUrl($html)
|
594 |
+
{
|
595 |
+
if (!$html) return '';
|
596 |
+
|
597 |
+
$doc = new DOMDocument();
|
598 |
+
$doc->loadHTML($html);
|
599 |
+
$xpath = new DOMXPath($doc);
|
600 |
+
$checkoutUrl = '';
|
601 |
+
|
602 |
+
$elements = $xpath->query('//button[contains(@class,"btn-checkout")]');
|
603 |
+
foreach ($elements as $element) {
|
604 |
+
foreach ($element->attributes as $attribute) {
|
605 |
+
if ($attribute->name == 'onclick') {
|
606 |
+
$checkoutUrl = $this->_parseCheckoutUrl($attribute->value);
|
607 |
+
}
|
608 |
+
}
|
609 |
+
}
|
610 |
+
|
611 |
+
if (0) {
|
612 |
+
$params = array(
|
613 |
+
'SID' => Mage::getSingleton('core/session')->getSessionId(),
|
614 |
+
'jkey' => $this->getJapiKey()
|
615 |
+
);
|
616 |
+
if (strpos($checkoutUrl, '?') !== false) {
|
617 |
+
$checkoutUrl .= '&' . http_build_query($params);
|
618 |
+
} else {
|
619 |
+
$checkoutUrl .= '?' . http_build_query($params);
|
620 |
+
}
|
621 |
+
}
|
622 |
+
|
623 |
+
return $checkoutUrl;
|
624 |
+
}
|
625 |
+
|
626 |
+
protected function _parseCheckoutUrl($text)
|
627 |
+
{
|
628 |
+
if (!$text) return '';
|
629 |
+
|
630 |
+
if (strpos($text, 'http') === 0) {
|
631 |
+
return $text;
|
632 |
+
}
|
633 |
+
if (strpos($text, 'window') === 0) {
|
634 |
+
$chars = array('\'', ';', 'window.location=');
|
635 |
+
$replace = array('', '', '');
|
636 |
+
return str_replace($chars, $replace, $text);
|
637 |
+
}
|
638 |
+
|
639 |
+
return '';
|
640 |
+
}
|
641 |
+
|
642 |
+
public function parseTotalsHtml($html)
|
643 |
+
{
|
644 |
+
if (!$html) return array();
|
645 |
+
|
646 |
+
$doc = new DOMDocument();
|
647 |
+
$doc->loadHTML($html);
|
648 |
+
$xpath = new DOMXPath($doc);
|
649 |
+
|
650 |
+
$output = array();
|
651 |
+
$rows = $xpath->query('//tr');
|
652 |
+
foreach ($rows as $row) {
|
653 |
+
$columns = $xpath->query('descendant::td', $row);
|
654 |
+
$row = array();
|
655 |
+
foreach ($columns as $index => $column) {
|
656 |
+
if ($index == 0) {
|
657 |
+
$row['title'] = trim($column->nodeValue);
|
658 |
+
} elseif ($index == 1) {
|
659 |
+
$row['value'] = trim($column->nodeValue);
|
660 |
+
}
|
661 |
+
}
|
662 |
+
$output[] = $row;
|
663 |
+
}
|
664 |
+
|
665 |
+
return $output;
|
666 |
+
}
|
667 |
+
|
668 |
+
public function parseHtmlForm($html)
|
669 |
+
{
|
670 |
+
$doc = new DOMDocument();
|
671 |
+
$doc->loadHTML($html);
|
672 |
+
$position = 1;
|
673 |
+
|
674 |
+
$xpath = new DOMXPath($doc);
|
675 |
+
$result = $xpath->query('//select');
|
676 |
+
$selects = array();
|
677 |
+
foreach ($result as $element) {
|
678 |
+
$current = array('element' => $element);
|
679 |
+
foreach ($element->attributes as $attribute) {
|
680 |
+
$current[$attribute->name] = $attribute->value;
|
681 |
+
}
|
682 |
+
if (!empty($current['id']) && $current['id']) {
|
683 |
+
$id = $current['id'];
|
684 |
+
$labels = $xpath->query("//label[@for='{$id}']");
|
685 |
+
if ($labels->length) {
|
686 |
+
foreach ($labels as $label) {
|
687 |
+
$current['label'] = (string)$label->nodeValue;
|
688 |
+
}
|
689 |
+
} else {
|
690 |
+
$labels = $xpath->query('ancestor::label', $element);
|
691 |
+
foreach ($labels as $label) {
|
692 |
+
$current['label'] = $this->stripHtml($label);
|
693 |
+
}
|
694 |
+
}
|
695 |
+
$position = stripos($html, "id=\"{$id}\"");
|
696 |
+
if ($position === false) {
|
697 |
+
$position = stripos($html, "id='{$id}'");
|
698 |
+
}
|
699 |
+
} else {
|
700 |
+
$labels = $xpath->query('ancestor::label', $element);
|
701 |
+
foreach ($labels as $label) {
|
702 |
+
$current['label'] = $this->stripHtml($label);
|
703 |
+
}
|
704 |
+
}
|
705 |
+
++$position;
|
706 |
+
$current['position'] = $position;
|
707 |
+
$selects[] = $current;
|
708 |
+
}
|
709 |
+
foreach ($selects as $key => $attributes) {
|
710 |
+
$result = $xpath->query("descendant::option", $attributes['element']);
|
711 |
+
$hasZero = false;
|
712 |
+
foreach ($result as $optionIndex => $element) {
|
713 |
+
$currentValue = null;
|
714 |
+
foreach ($element->attributes as $attribute) {
|
715 |
+
$attributeName = (string)$attribute->name;
|
716 |
+
if ('value' == $attributeName) {
|
717 |
+
$currentValue = (string)$attribute->value;
|
718 |
+
$currentLabel = trim((string)$element->nodeValue);
|
719 |
+
if ($optionIndex == 0 && $currentValue == '0') {
|
720 |
+
$hasZero = true;
|
721 |
+
}
|
722 |
+
$selects[$key]['options'][$currentValue] = $currentLabel;
|
723 |
+
} elseif ('selected' == $attributeName) {
|
724 |
+
$selects[$key]['selected'] = $currentValue;
|
725 |
+
}
|
726 |
+
}
|
727 |
+
}
|
728 |
+
if ($hasZero) {
|
729 |
+
$selects[$key]['options'] = array_reverse($selects[$key]['options'], true);
|
730 |
+
}
|
731 |
+
}
|
732 |
+
$selectOptions = $selects;
|
733 |
+
|
734 |
+
$result = $xpath->query('//input');
|
735 |
+
$inputs = array();
|
736 |
+
foreach ($result as $element) {
|
737 |
+
$current = array('element' => $element);
|
738 |
+
foreach ($element->attributes as $attribute) {
|
739 |
+
$current[$attribute->name] = $attribute->value;
|
740 |
+
}
|
741 |
+
if (empty($current['type'])) {
|
742 |
+
$current['type'] = 'text';
|
743 |
+
}
|
744 |
+
if (!empty($current['id']) && $current['id']) {
|
745 |
+
$id = $current['id'];
|
746 |
+
$labels = $xpath->query("//label[@for='{$id}']");
|
747 |
+
if ($labels->length) {
|
748 |
+
foreach ($labels as $label) {
|
749 |
+
$current['label'] = trim((string)$label->nodeValue);
|
750 |
+
}
|
751 |
+
if (!$current['label']) {
|
752 |
+
foreach ($labels as $label) {
|
753 |
+
$images = $xpath->query("descendant::img", $label);
|
754 |
+
foreach ($images as $image) {
|
755 |
+
foreach ($image->attributes as $attribute) {
|
756 |
+
if ($attribute->name == 'title') {
|
757 |
+
$current['label'] = $attribute->value;
|
758 |
+
}
|
759 |
+
}
|
760 |
+
}
|
761 |
+
}
|
762 |
+
}
|
763 |
+
} else {
|
764 |
+
$labels = $xpath->query('ancestor::label', $element);
|
765 |
+
foreach ($labels as $label) {
|
766 |
+
$current['label'] = $this->stripHtml($label);
|
767 |
+
}
|
768 |
+
}
|
769 |
+
$position = stripos($html, "id=\"{$id}\"");
|
770 |
+
if ($position === false) {
|
771 |
+
$position = stripos($html, "id='{$id}'");
|
772 |
+
}
|
773 |
+
} else {
|
774 |
+
$labels = $xpath->query('ancestor::label', $element);
|
775 |
+
foreach ($labels as $label) {
|
776 |
+
$current['label'] = $this->stripHtml($label);
|
777 |
+
}
|
778 |
+
}
|
779 |
+
++$position;
|
780 |
+
$current['position'] = $position;
|
781 |
+
$inputs[] = $current;
|
782 |
+
}
|
783 |
+
|
784 |
+
$inputOptions = $inputs;
|
785 |
+
|
786 |
+
$form = array();
|
787 |
+
foreach ($inputOptions as $input) {
|
788 |
+
$position = $input['position'];
|
789 |
+
unset($input['position']);
|
790 |
+
$input['element'] = 'input';
|
791 |
+
$form[$position] = $input;
|
792 |
+
}
|
793 |
+
foreach ($selectOptions as $select) {
|
794 |
+
$position = $select['position'];
|
795 |
+
unset($select['position']);
|
796 |
+
$select['element'] = 'select';
|
797 |
+
$form[$position] = $select;
|
798 |
+
}
|
799 |
+
|
800 |
+
ksort($form);
|
801 |
+
$form = array_values($form);
|
802 |
+
|
803 |
+
return $form;
|
804 |
+
}
|
805 |
+
|
806 |
+
protected function stripHtml(DOMNode $node)
|
807 |
+
{
|
808 |
+
$html = $this->DOMInnerHTML($node);
|
809 |
+
$html = preg_replace('#<(select)(?:[^>]+)?>.*?</\1>#s', '', $html);
|
810 |
+
|
811 |
+
return trim(strip_tags(str_replace(' ', ' ', $html)), " \t\n\r\0\x0B-");
|
812 |
+
}
|
813 |
+
|
814 |
+
protected function DOMInnerHTML(DOMNode $element)
|
815 |
+
{
|
816 |
+
$innerHTML = "";
|
817 |
+
$children = $element->childNodes;
|
818 |
+
|
819 |
+
foreach ($children as $child) {
|
820 |
+
$innerHTML .= $element->ownerDocument->saveHTML($child);
|
821 |
+
}
|
822 |
+
|
823 |
+
return $innerHTML;
|
824 |
+
}
|
825 |
+
|
826 |
+
/**
|
827 |
+
* Check Plugin update available
|
828 |
+
* @return mixed
|
829 |
+
*/
|
830 |
+
public function getUpdateAvailable()
|
831 |
+
{
|
832 |
+
$_installedVersion = $this->getPluginVersion();
|
833 |
+
|
834 |
+
try {
|
835 |
+
$_connectVersion = $this->getPluginVersionFromConnectHtml();
|
836 |
+
} catch (Exception $e) {
|
837 |
+
return false;
|
838 |
+
}
|
839 |
+
|
840 |
+
if (!$_connectVersion) {
|
841 |
+
return false;
|
842 |
+
}
|
843 |
+
|
844 |
+
$_installedVersion2 = $this->_getMajorVersion($_installedVersion);
|
845 |
+
$_connectVersion2 = $this->_getMajorVersion($_connectVersion);
|
846 |
+
|
847 |
+
$data['needUpdate'] = version_compare($_installedVersion2, $_connectVersion2, '<');
|
848 |
+
$data['currentVer'] = $_installedVersion;
|
849 |
+
$data['connectVer'] = $_connectVersion;
|
850 |
+
|
851 |
+
return $data;
|
852 |
+
}
|
853 |
+
|
854 |
+
/**
|
855 |
+
* Only notice user if new major version released
|
856 |
+
*
|
857 |
+
* @param string $version
|
858 |
+
* @return string
|
859 |
+
*/
|
860 |
+
protected function _getMajorVersion($version)
|
861 |
+
{
|
862 |
+
if (!$version) return '';
|
863 |
+
|
864 |
+
$oldParts = explode('.', $version);
|
865 |
+
$newParts = array();
|
866 |
+
$level = 2;
|
867 |
+
for ($i = 0; $i < $level; $i++) {
|
868 |
+
if ($i >= $level) break;
|
869 |
+
$newParts[] = isset($oldParts[$i]) ? $oldParts[$i] : 0;
|
870 |
+
}
|
871 |
+
|
872 |
+
return implode('.', $newParts);
|
873 |
+
}
|
874 |
+
|
875 |
+
/**
|
876 |
+
* Get current Plugin version installed
|
877 |
+
* @return string
|
878 |
+
*/
|
879 |
+
public function getPluginVersion()
|
880 |
+
{
|
881 |
+
$class = get_class($this);
|
882 |
+
$parts = explode('_', $class);
|
883 |
+
$module = ucfirst($parts[0]) . '_' . ucfirst($parts[1]);
|
884 |
+
|
885 |
+
$_version = (string)Mage::getConfig()->getNode('modules')->$module->version;
|
886 |
+
|
887 |
+
return $_version;
|
888 |
+
}
|
889 |
+
|
890 |
+
/**
|
891 |
+
* Get Lastest Plugin version in Magento Connect page
|
892 |
+
* @return bool|string
|
893 |
+
*/
|
894 |
+
public function getPluginVersionFromConnectHtml()
|
895 |
+
{
|
896 |
+
// suppress error reporting
|
897 |
+
$currentErrorReportLevel = error_reporting(0);
|
898 |
+
|
899 |
+
$ctx = stream_context_create(array('http' => array('timeout' => 3)));
|
900 |
+
$url = 'https://www.magentocommerce.com/magento-connect/jmango360-rest-plugin.html';
|
901 |
+
$data = file_get_contents($url, false, $ctx);
|
902 |
+
|
903 |
+
$dom = new DOMDocument();
|
904 |
+
$dom->loadHTML($data);
|
905 |
+
|
906 |
+
$xpath = new DOMXPath($dom);
|
907 |
+
$nodesUl = $xpath->query('//ul[contains(@class,"extension-version-meta")]');
|
908 |
+
if ($nodesUl->length <= 0) {
|
909 |
+
return false;
|
910 |
+
}
|
911 |
+
|
912 |
+
$nodesItem = $xpath->query('//li[contains(@class,"item")]', $nodesUl->item(0));
|
913 |
+
if ($nodesItem->length <= 0) {
|
914 |
+
return false;
|
915 |
+
}
|
916 |
+
|
917 |
+
$_pluginInfo = $nodesItem->item(0)->nodeValue;
|
918 |
+
if ($_pluginInfo == '') {
|
919 |
+
return false;
|
920 |
+
}
|
921 |
+
|
922 |
+
$_pluginInfoArr = explode(':', $_pluginInfo);
|
923 |
+
if (count($_pluginInfoArr) < 2) {
|
924 |
+
return false;
|
925 |
+
}
|
926 |
+
|
927 |
+
$_pluginVersion = trim($_pluginInfoArr[1]);
|
928 |
+
|
929 |
+
// rollback error reporting
|
930 |
+
error_reporting($currentErrorReportLevel);
|
931 |
+
|
932 |
+
return $_pluginVersion;
|
933 |
+
}
|
934 |
+
|
935 |
+
public function getLastCheckUpdate()
|
936 |
+
{
|
937 |
+
return Mage::app()->loadCache('admin_japi_lastcheck_update');
|
938 |
+
}
|
939 |
+
|
940 |
+
public function setLastCheckUpdate()
|
941 |
+
{
|
942 |
+
Mage::app()->saveCache(time(), 'admin_japi_lastcheck_update', array(Mage_Core_Model_Config::CACHE_TAG));
|
943 |
+
}
|
944 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Debug.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_debug extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
public function getLogFile($logFile = 'japi.log', $include_path = false)
|
6 |
+
{
|
7 |
+
if (file_exists($logFile)) { // should not a absolute path
|
8 |
+
return '';
|
9 |
+
}
|
10 |
+
|
11 |
+
if (strpos($logFile, '/') === 0 || strpos($logFile, '..') === 0) { // should not a relative path
|
12 |
+
return '';
|
13 |
+
}
|
14 |
+
|
15 |
+
if ($include_path) {
|
16 |
+
return Mage::getBaseDir('var') . DS . 'log' . DS . $logFile;
|
17 |
+
} else {
|
18 |
+
return $logFile;
|
19 |
+
}
|
20 |
+
}
|
21 |
+
}
|
app/code/community/Jmango360/Japi/Helper/GiftMessage/Message.php
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_GiftMessage_Message extends Mage_GiftMessage_Helper_Message
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Retrive inline giftmessage edit form for specified entity
|
7 |
+
*
|
8 |
+
* @param string $type
|
9 |
+
* @param Varien_Object $entity
|
10 |
+
* @param boolean $dontDisplayContainer
|
11 |
+
* @return string
|
12 |
+
*/
|
13 |
+
public function getInline($type, Varien_Object $entity, $dontDisplayContainer = false)
|
14 |
+
{
|
15 |
+
if (!in_array($type, array('onepage_checkout', 'multishipping_adress'))
|
16 |
+
&& !$this->isMessagesAvailable($type, $entity)
|
17 |
+
) {
|
18 |
+
return '';
|
19 |
+
}
|
20 |
+
|
21 |
+
return Mage::getSingleton('core/layout')->createBlock('japi/giftMessage_message_inline')
|
22 |
+
->setId('giftmessage_form_' . $this->_nextId++)
|
23 |
+
->setDontDisplayContainer($dontDisplayContainer)
|
24 |
+
->setEntity($entity)
|
25 |
+
->setType($type)->toHtml();
|
26 |
+
}
|
27 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Product.php
ADDED
@@ -0,0 +1,1511 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_Product extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
const CONFIGURABLE_SCP_TYPE = 'configurable_scp';
|
6 |
+
|
7 |
+
protected $_defaultImagesPaths = array(
|
8 |
+
'image' => array(
|
9 |
+
'width' => 'japi/jmango_rest_gallery_settings/image_width',
|
10 |
+
'height' => 'japi/jmango_rest_gallery_settings/image_height',
|
11 |
+
),
|
12 |
+
'small_image' => array(
|
13 |
+
'width' => 'japi/jmango_rest_gallery_settings/small_image_width',
|
14 |
+
'height' => 'japi/jmango_rest_gallery_settings/small_image_height',
|
15 |
+
),
|
16 |
+
'thumbnail' => array(
|
17 |
+
'width' => 'japi/jmango_rest_gallery_settings/thumbnail_width',
|
18 |
+
'height' => 'japi/jmango_rest_gallery_settings/thumbnail_height',
|
19 |
+
)
|
20 |
+
);
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Default ignored attribute codes
|
24 |
+
*
|
25 |
+
* @var array
|
26 |
+
*/
|
27 |
+
protected $_ignoredAttributeCodes = array(
|
28 |
+
'entity_id',
|
29 |
+
'attribute_set_id',
|
30 |
+
'entity_type_id',
|
31 |
+
'tier_price',
|
32 |
+
'minimal_price',
|
33 |
+
'additional_information'
|
34 |
+
);
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Default ignored attribute types
|
38 |
+
*
|
39 |
+
* @var array
|
40 |
+
*/
|
41 |
+
protected $_ignoredAttributeTypes = array(
|
42 |
+
'gallery',
|
43 |
+
'media_image'
|
44 |
+
);
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Selectable product attributes
|
48 |
+
*
|
49 |
+
* @var array
|
50 |
+
*/
|
51 |
+
protected $_selectedAttributes = array(
|
52 |
+
'sku',
|
53 |
+
'name',
|
54 |
+
'description',
|
55 |
+
'short_description',
|
56 |
+
'visibility',
|
57 |
+
'price',
|
58 |
+
'special_price',
|
59 |
+
'special_from_date',
|
60 |
+
'special_to_date',
|
61 |
+
'image',
|
62 |
+
'media_gallery'
|
63 |
+
);
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Compacted product attributes
|
67 |
+
*
|
68 |
+
* @var array
|
69 |
+
*/
|
70 |
+
protected $_compactedAttributes = array(
|
71 |
+
'sku',
|
72 |
+
'name',
|
73 |
+
'description',
|
74 |
+
'short_description',
|
75 |
+
'visibility',
|
76 |
+
'price',
|
77 |
+
'image'
|
78 |
+
);
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Product Attributes used in product view
|
82 |
+
*
|
83 |
+
* @var array
|
84 |
+
*/
|
85 |
+
protected $_usedInProductView;
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Check if site use modules like OrganicInternet_SimpleConfigurableProducts
|
89 |
+
*/
|
90 |
+
public function isSCPActive()
|
91 |
+
{
|
92 |
+
return $this->isModuleEnabled('OrganicInternet_SimpleConfigurableProducts')
|
93 |
+
|| $this->isModuleEnabled('Amasty_Conf')
|
94 |
+
|| ($this->isModuleEnabled('Ayasoftware_SimpleProductPricing') && Mage::getStoreConfigFlag('spp/setting/enableModule'))
|
95 |
+
|| $this->isModuleEnabled('Itonomy_SimpleConfigurable');
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* @param $collection Mage_Catalog_Model_Resource_Product_Collection
|
100 |
+
* @return $this
|
101 |
+
*/
|
102 |
+
public function addPageSettings($collection)
|
103 |
+
{
|
104 |
+
/* @var $request Jmango360_Japi_Model_Request */
|
105 |
+
$request = Mage::helper('japi')->getRequest();
|
106 |
+
|
107 |
+
$pageSize = $request->getParam('limit', false);
|
108 |
+
if ($pageSize) {
|
109 |
+
$collection->setPageSize($pageSize);
|
110 |
+
}
|
111 |
+
|
112 |
+
$pageNumber = $request->getParam('p', false);
|
113 |
+
if ($pageNumber) {
|
114 |
+
$collection->setCurPage($pageNumber);
|
115 |
+
}
|
116 |
+
|
117 |
+
$field = $request->getParam('order', false);
|
118 |
+
if ($field) {
|
119 |
+
$direction = $request->getParam('dir', Varien_Data_Collection::SORT_ORDER_DESC);
|
120 |
+
$collection->setOrder($field, $direction);
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Fix for MPLUGIN-661
|
124 |
+
* Remove OREDER BY 'on_top' added by module 'RicardoMartins_OutofstockLast'
|
125 |
+
*/
|
126 |
+
if ($this->isModuleEnabled('RicardoMartins_OutofstockLast')) {
|
127 |
+
$orderPaths = $collection->getSelect()->getPart(Zend_Db_Select::ORDER);
|
128 |
+
foreach ($orderPaths as $key => $orderPath) {
|
129 |
+
if ($orderPath[0] == 'on_top') {
|
130 |
+
unset($orderPaths[$key]);
|
131 |
+
break;
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
$collection->getSelect()->reset(Zend_Db_Select::ORDER);
|
136 |
+
foreach ($orderPaths as $orderPath) {
|
137 |
+
$collection->getSelect()->order($orderPath[0] . ' ' . $orderPath[1]);
|
138 |
+
}
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* MPLUGIN-767
|
143 |
+
*/
|
144 |
+
$fromPart = $collection->getSelect()->getPart(Zend_Db_Select::FROM);
|
145 |
+
if (!isset($fromPart['price_index'])) {
|
146 |
+
$this->_addPriceData($collection);
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
return $this;
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* @param $collection Mage_Catalog_Model_Resource_Product_Collection
|
155 |
+
* @param $isSearch bool
|
156 |
+
* @return array
|
157 |
+
*/
|
158 |
+
public function getToolbarInfo($collection, $isSearch = false)
|
159 |
+
{
|
160 |
+
$data = array();
|
161 |
+
|
162 |
+
/* @var $request Jmango360_Japi_Model_Request */
|
163 |
+
$request = Mage::helper('japi')->getRequest();
|
164 |
+
|
165 |
+
/* @var $toolBarBlock Mage_Catalog_Block_Product_List_Toolbar */
|
166 |
+
$toolBarBlock = Mage::helper('japi')->getBlock('catalog/product_list_toolbar');
|
167 |
+
|
168 |
+
if ($limit = $request->getParam('limit')) {
|
169 |
+
$toolBarBlock->addPagerLimit('list', $limit);
|
170 |
+
$toolBarBlock->addPagerLimit('grid', $limit);
|
171 |
+
}
|
172 |
+
|
173 |
+
/* @var $category Mage_Catalog_Model_Category */
|
174 |
+
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
|
175 |
+
if ($category && $category->getId()) {
|
176 |
+
$availableOrders = $category->getAvailableSortByOptions();
|
177 |
+
if (!$availableOrders) {
|
178 |
+
$availableOrders = $toolBarBlock->getAvailableOrders();
|
179 |
+
}
|
180 |
+
if ($availableOrders) {
|
181 |
+
if ($isSearch) {
|
182 |
+
unset($availableOrders['position']);
|
183 |
+
$availableOrders = array_merge(array(
|
184 |
+
'relevance' => $this->__('Relevance')
|
185 |
+
), $availableOrders);
|
186 |
+
$defaultOrder = 'relevance';
|
187 |
+
$toolBarBlock->setDefaultDirection('desc');
|
188 |
+
} else {
|
189 |
+
$defaultOrder = $category->getDefaultSortBy();
|
190 |
+
}
|
191 |
+
$toolBarBlock->setAvailableOrders($availableOrders);
|
192 |
+
if (isset($availableOrders[$defaultOrder])) {
|
193 |
+
$toolBarBlock->setDefaultOrder($defaultOrder);
|
194 |
+
}
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
$toolBarBlock->setCollection($collection);
|
199 |
+
|
200 |
+
/**
|
201 |
+
* MPLUGIN-565
|
202 |
+
* MPLUGIN-1039
|
203 |
+
* Set products list order for API's return data to same the Web view when sort many products same data
|
204 |
+
*/
|
205 |
+
$storeId = Mage::app()->getStore()->getId();
|
206 |
+
$session = Mage::getSingleton('core/session');
|
207 |
+
$_isUseFlatOnWeb = $session->getData('use_flat_product_' . $storeId);
|
208 |
+
|
209 |
+
$field = $request->getParam('order', false);
|
210 |
+
$direction = $request->getParam('dir', Varien_Data_Collection::SORT_ORDER_DESC);
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Fix list order when sort by position and enable Product Flat data
|
214 |
+
* Always add sort by 'entity_id' for website http://www.gopro-mania.nl
|
215 |
+
*/
|
216 |
+
if ($field == 'position' && ($_isUseFlatOnWeb || $this->isModuleEnabled('Samiflabs_Shopby'))) {
|
217 |
+
$collection->getSelect()->order('cat_index_position ' . strtoupper($direction));
|
218 |
+
$collection->setOrder('entity_id', 'asc');
|
219 |
+
}
|
220 |
+
|
221 |
+
if (version_compare(Mage::getVersion(), '1.9.0.0', '>=')) {
|
222 |
+
$_ignoreOrder = array('position', 'entity_id');
|
223 |
+
} else {
|
224 |
+
$_ignoreOrder = array('position', 'entity_id', 'relevance');
|
225 |
+
}
|
226 |
+
if (!in_array($field, $_ignoreOrder)) {
|
227 |
+
if ($request->getParam('category_id')) {
|
228 |
+
$collection->setOrder('position', 'asc');
|
229 |
+
}
|
230 |
+
if ($_isUseFlatOnWeb) {
|
231 |
+
$collection->setOrder('entity_id', 'asc');
|
232 |
+
} elseif ($this->isModuleEnabled('Samiflabs_Shopby')) {
|
233 |
+
//Always add sort by 'entity_id' for website http://www.gopro-mania.nl
|
234 |
+
$collection->setOrder('entity_id', 'asc');
|
235 |
+
}
|
236 |
+
}
|
237 |
+
|
238 |
+
Mage::dispatchEvent('catalog_block_product_list_collection', array(
|
239 |
+
'collection' => $collection
|
240 |
+
));
|
241 |
+
$collection->load();
|
242 |
+
|
243 |
+
$data['current_page_num'] = $toolBarBlock->getCurrentPage();
|
244 |
+
$data['last_page_num'] = $toolBarBlock->getLastPageNum();
|
245 |
+
|
246 |
+
$data['current_limit'] = $toolBarBlock->getLimit();
|
247 |
+
$data['available_limit'] = $toolBarBlock->getAvailableLimit();
|
248 |
+
|
249 |
+
$data['current_order'] = $toolBarBlock->getCurrentOrder();
|
250 |
+
$data['current_direction'] = $toolBarBlock->getCurrentDirection();
|
251 |
+
$data['available_orders'] = $toolBarBlock->getAvailableOrders();
|
252 |
+
|
253 |
+
return $data;
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Convert a product to collection and return to api json
|
258 |
+
*
|
259 |
+
* @param int $product
|
260 |
+
* @return null|Mage_Catalog_Model_Resource_Product_Collection
|
261 |
+
* @throws Jmango360_Japi_Exception
|
262 |
+
*/
|
263 |
+
public function convertProductIdToApiResponse($product)
|
264 |
+
{
|
265 |
+
if (!is_numeric($product)) {
|
266 |
+
return null;
|
267 |
+
}
|
268 |
+
|
269 |
+
$collection = Mage::getResourceModel('catalog/product_collection')
|
270 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
271 |
+
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
|
272 |
+
->addMinimalPrice()
|
273 |
+
->addFinalPrice()
|
274 |
+
->addTaxPercents()
|
275 |
+
->addIdFilter($product);
|
276 |
+
|
277 |
+
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
|
278 |
+
//Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
|
279 |
+
|
280 |
+
$result = $this->convertProductCollectionToApiResponse($collection);
|
281 |
+
return count($result) ? array_pop($result) : null;
|
282 |
+
}
|
283 |
+
|
284 |
+
/**
|
285 |
+
* Convert a product to collection and return to api json
|
286 |
+
*
|
287 |
+
* @param int $product
|
288 |
+
* @return null|array
|
289 |
+
* @throws Jmango360_Japi_Exception
|
290 |
+
*/
|
291 |
+
public function convertProductIdToApiResponseV2($product)
|
292 |
+
{
|
293 |
+
if (!is_numeric($product)) {
|
294 |
+
return null;
|
295 |
+
}
|
296 |
+
|
297 |
+
$collection = Mage::getResourceModel('catalog/product_collection')
|
298 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
299 |
+
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
|
300 |
+
->addMinimalPrice()
|
301 |
+
->addFinalPrice()
|
302 |
+
->addTaxPercents()
|
303 |
+
->addIdFilter($product);
|
304 |
+
|
305 |
+
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
|
306 |
+
//Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
|
307 |
+
|
308 |
+
$result = $this->convertProductCollectionToApiResponseV2($collection, true);
|
309 |
+
return count($result) ? array_pop($result) : null;
|
310 |
+
}
|
311 |
+
|
312 |
+
/**
|
313 |
+
* Convert some products to collection and return to api json
|
314 |
+
*
|
315 |
+
* @param array $products
|
316 |
+
* @return null|Mage_Catalog_Model_Resource_Product_Collection
|
317 |
+
*/
|
318 |
+
public function convertProductIdsToApiResponse($products)
|
319 |
+
{
|
320 |
+
if (!count($products)) {
|
321 |
+
return array();
|
322 |
+
}
|
323 |
+
|
324 |
+
$collection = Mage::getResourceModel('catalog/product_collection')
|
325 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
326 |
+
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
|
327 |
+
->addMinimalPrice()
|
328 |
+
->addFinalPrice()
|
329 |
+
->addTaxPercents()
|
330 |
+
->addIdFilter($products);
|
331 |
+
|
332 |
+
return $this->convertProductCollectionToApiResponse($collection);
|
333 |
+
}
|
334 |
+
|
335 |
+
/**
|
336 |
+
* Default the product collection only return the flat product table depending on flags the stock
|
337 |
+
* -- In the API we need all information about the product in one call so we dont have to call on the API more than ones
|
338 |
+
* -- this code was originally added by the Duc and Team in Vietnam; just changed a view bits to make it fit foor the REST API
|
339 |
+
*
|
340 |
+
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
|
341 |
+
* @return array
|
342 |
+
*/
|
343 |
+
public function convertProductCollectionToApiResponse(Mage_Catalog_Model_Resource_Product_Collection $collection)
|
344 |
+
{
|
345 |
+
$collection->setFlag('require_stock_items', true);
|
346 |
+
$collection->applyFrontendPriceLimitations();
|
347 |
+
$collection->addAttributeToSelect($this->_selectedAttributes);
|
348 |
+
$collection->addAttributeToSelect($this->getAttributesUsedInProductView());
|
349 |
+
$collection->addTierPriceData();
|
350 |
+
$collection->addOptionsToResult();
|
351 |
+
|
352 |
+
/* @var $helper Jmango360_Japi_Helper_Product_Media */
|
353 |
+
$helper = Mage::helper('japi/product_media');
|
354 |
+
$helper->addMediaGalleryAttributeToCollection($collection);
|
355 |
+
|
356 |
+
$result = array();
|
357 |
+
foreach ($collection as $product) {
|
358 |
+
$result[] = $this->convertProductToApiResponse($product);
|
359 |
+
}
|
360 |
+
|
361 |
+
return $result;
|
362 |
+
}
|
363 |
+
|
364 |
+
/**
|
365 |
+
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
|
366 |
+
* @param bool $details
|
367 |
+
* @return array
|
368 |
+
*/
|
369 |
+
public function convertProductCollectionToApiResponseV2(Mage_Catalog_Model_Resource_Product_Collection $collection, $details = false)
|
370 |
+
{
|
371 |
+
$collection->applyFrontendPriceLimitations();
|
372 |
+
|
373 |
+
if ($details) {
|
374 |
+
$attributeDetails = Mage::getStoreConfig('japi/jmango_rest_catalog_settings/attribute_on_details');
|
375 |
+
if ($attributeDetails) {
|
376 |
+
$collection->addAttributeToSelect($attributeDetails);
|
377 |
+
}
|
378 |
+
|
379 |
+
$collection->addAttributeToSelect($this->_selectedAttributes);
|
380 |
+
$collection->addAttributeToSelect($this->getAttributesUsedInProductView());
|
381 |
+
$collection->addTierPriceData();
|
382 |
+
$collection->addOptionsToResult();
|
383 |
+
} else {
|
384 |
+
$collection->addAttributeToSelect($this->_compactedAttributes);
|
385 |
+
|
386 |
+
$attributeListing = Mage::getStoreConfig('japi/jmango_rest_catalog_settings/attribute_on_listing');
|
387 |
+
if ($attributeListing) {
|
388 |
+
$collection->addAttributeToSelect($attributeListing);
|
389 |
+
}
|
390 |
+
}
|
391 |
+
|
392 |
+
$result = array();
|
393 |
+
foreach ($collection as $product) {
|
394 |
+
if ($details) {
|
395 |
+
$result[] = $this->convertProductToApiResponseV2($product, true);
|
396 |
+
} else {
|
397 |
+
$result[] = $this->convertProductToApiResponseV2($product, false);
|
398 |
+
}
|
399 |
+
}
|
400 |
+
|
401 |
+
return $result;
|
402 |
+
}
|
403 |
+
|
404 |
+
/**
|
405 |
+
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
|
406 |
+
* @return array
|
407 |
+
*/
|
408 |
+
public function convertSuggestProductCollectionToApiResponse(Mage_Catalog_Model_Resource_Product_Collection $collection)
|
409 |
+
{
|
410 |
+
$result = array();
|
411 |
+
|
412 |
+
$collection->addAttributeToSelect($this->_compactedAttributes);
|
413 |
+
foreach ($collection as $product) {
|
414 |
+
$result[] = $this->convertProductToApiResponseV3($product);
|
415 |
+
}
|
416 |
+
|
417 |
+
return $result;
|
418 |
+
}
|
419 |
+
|
420 |
+
/**
|
421 |
+
* Prepare product info for suggest api response
|
422 |
+
*
|
423 |
+
* @param Mage_Catalog_Model_Product $product
|
424 |
+
* @return array
|
425 |
+
*/
|
426 |
+
public function convertProductToApiResponseV3(Mage_Catalog_Model_Product $product)
|
427 |
+
{
|
428 |
+
$result = array(
|
429 |
+
'product_id' => (int)$product->getId(),
|
430 |
+
'type' => $product->getTypeId(),
|
431 |
+
'name' => $product->getName(),
|
432 |
+
'image' => $this->_getProductImage($product)
|
433 |
+
);
|
434 |
+
|
435 |
+
return $result;
|
436 |
+
}
|
437 |
+
|
438 |
+
/**
|
439 |
+
* Get product for image
|
440 |
+
*
|
441 |
+
* @param $product Mage_Catalog_Model_Product
|
442 |
+
* @return string
|
443 |
+
*/
|
444 |
+
protected function _getProductImage(Mage_Catalog_Model_Product $product)
|
445 |
+
{
|
446 |
+
/* @var $helper Mage_Catalog_Helper_Image */
|
447 |
+
$helper = Mage::helper('catalog/image');
|
448 |
+
$size = $this->_getImageSizes();
|
449 |
+
$imageListing = Mage::getStoreConfig('japi/jmango_rest_gallery_settings/image_default_listing');
|
450 |
+
if (!$imageListing) $imageListing = 'small_image';
|
451 |
+
$imageWidth = !empty($size[$imageListing]['width']) ? $size[$imageListing]['width'] : 400;
|
452 |
+
$imageHeight = !empty($size[$imageListing]['height']) ? $size[$imageListing]['height'] : 400;
|
453 |
+
$imageFallback = false;
|
454 |
+
$image = '';
|
455 |
+
|
456 |
+
if ($this->isModuleEnabled('Softwareimc_Razuna')) {
|
457 |
+
/* @var $razunaImageModel Softwareimc_Razuna_Model_Images */
|
458 |
+
$razunaImageModel = Mage::getModel('razuna/images');
|
459 |
+
$_razunaMainImages = $razunaImageModel->getImagesBySku($product, 'Main');
|
460 |
+
if (count($_razunaMainImages) > 0) {
|
461 |
+
$image = $_razunaMainImages[0]['url'];
|
462 |
+
} else {
|
463 |
+
$_razunaThumbImages = $razunaImageModel->getImagesBySku($product, 'Thumbnail');
|
464 |
+
if (count($_razunaThumbImages) > 0) {
|
465 |
+
$image = $_razunaMainImages[0]['thumb_url'];
|
466 |
+
} else {
|
467 |
+
$imageFallback = true;
|
468 |
+
}
|
469 |
+
}
|
470 |
+
} else {
|
471 |
+
$imageFallback = true;
|
472 |
+
}
|
473 |
+
|
474 |
+
if ($imageFallback) {
|
475 |
+
$image = (string)$helper->init($product, $imageListing)->resize($imageWidth, $imageHeight);
|
476 |
+
}
|
477 |
+
|
478 |
+
return $image;
|
479 |
+
}
|
480 |
+
|
481 |
+
/**
|
482 |
+
* Prepares Product info for api response
|
483 |
+
*
|
484 |
+
* @param Mage_Catalog_Model_Product $product
|
485 |
+
* @param bool $details
|
486 |
+
* @return array
|
487 |
+
*/
|
488 |
+
public function convertProductToApiResponseV2(Mage_Catalog_Model_Product $product, $details = false)
|
489 |
+
{
|
490 |
+
Mage::dispatchEvent('catalog_product_type_configurable_price', array('product' => $product));
|
491 |
+
Mage::dispatchEvent('catalog_product_load_after', array('product' => $product, 'data_object' => $product));
|
492 |
+
|
493 |
+
//MPLUGIN-847
|
494 |
+
if ($product->getTypeId() == 'bundle') {
|
495 |
+
$product->unsetData('final_price');
|
496 |
+
}
|
497 |
+
|
498 |
+
$_basePrice = $this->_getSCPBasePrice($product);
|
499 |
+
|
500 |
+
$result = array(
|
501 |
+
'product_id' => (int)$product->getId(),
|
502 |
+
'name' => $product->getName(),
|
503 |
+
'sku' => $product->getSku(),
|
504 |
+
'type' => $product->getTypeId(),
|
505 |
+
'type_id' => $product->getTypeId(),
|
506 |
+
'stock' => $this->_getStockLevel($product),
|
507 |
+
'is_in_stock' => $product->getStockItem() ? (int)$product->getStockItem()->getIsInStock() : null,
|
508 |
+
'is_saleable' => (int)$product->isSalable(),
|
509 |
+
'price' => $this->calculatePriceIncludeTax($product, $_basePrice),
|
510 |
+
'final_price' => $this->calculatePriceIncludeTax($product, $product->getFinalPrice()),
|
511 |
+
'min_price' => $this->calculatePriceIncludeTax($product, $product->getMinPrice()),
|
512 |
+
'max_price' => $this->calculatePriceIncludeTax($product, $product->getMaxPrice()),
|
513 |
+
'minimal_price' => $this->calculatePriceIncludeTax($product, $product->getMinimalPrice()),
|
514 |
+
'image' => $this->_getProductImage($product)
|
515 |
+
);
|
516 |
+
|
517 |
+
if ($details) {
|
518 |
+
$product->load($product->getId());
|
519 |
+
$this->_addTierPriceInfo($product, $result);
|
520 |
+
$this->_addGalleryInfo($product, $result);
|
521 |
+
$this->_addCustomOptions($product, $result);
|
522 |
+
$this->_addConfigurableAttributes($product, $result, true);
|
523 |
+
$this->_addGroupedItems($product, $result, true);
|
524 |
+
$this->_addBundleInfo($product, $result);
|
525 |
+
} else {
|
526 |
+
if ($product->getTypeId() == 'bundle') {
|
527 |
+
$result['bundle_attributes'] = Mage::helper('japi/product_bundle')->getBundleAttributes($product);
|
528 |
+
}
|
529 |
+
}
|
530 |
+
|
531 |
+
/* @var $productHelper Mage_Catalog_Helper_Output */
|
532 |
+
$productHelper = Mage::helper('catalog/output');
|
533 |
+
|
534 |
+
$attributes = $product->getTypeInstance(false)->getEditableAttributes($product);
|
535 |
+
$attributeListing = Mage::getStoreConfig('japi/jmango_rest_catalog_settings/attribute_on_listing');
|
536 |
+
$attributeDetails = Mage::getStoreConfig('japi/jmango_rest_catalog_settings/attribute_on_details');
|
537 |
+
$hideNullValue = Mage::getStoreConfigFlag('japi/jmango_rest_catalog_settings/hide_null_value');
|
538 |
+
|
539 |
+
foreach ($attributes as $attribute) {
|
540 |
+
/* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
|
541 |
+
if (!$this->_isAllowedAttribute($attribute)) continue;
|
542 |
+
|
543 |
+
if (!$attribute->hasData('is_visible_on_front')) {
|
544 |
+
$attribute->load($attribute->getId());
|
545 |
+
}
|
546 |
+
|
547 |
+
$attributeCode = $attribute->getAttributeCode();
|
548 |
+
|
549 |
+
if (in_array($attributeCode, array('short_description', 'description'))) {
|
550 |
+
if ($attribute->getData('is_wysiwyg_enabled') == 1) {
|
551 |
+
$html = '<style>';
|
552 |
+
$html .= 'pre,code,blockquote{white-space:normal!important;}';
|
553 |
+
$html .= 'table{width:100%!important;}';
|
554 |
+
$html .= '</style>';
|
555 |
+
$html .= $productHelper->productAttribute(
|
556 |
+
$product, $product->getData($attributeCode), $attributeCode
|
557 |
+
);
|
558 |
+
$result[$attributeCode] = $html;
|
559 |
+
} else {
|
560 |
+
$result[$attributeCode] = $product->getData($attributeCode);
|
561 |
+
}
|
562 |
+
}
|
563 |
+
|
564 |
+
if ($attribute->getFrontendInput() == 'multiselect') {
|
565 |
+
$options = $attribute->getFrontend()->getOption($product->getData($attributeCode));
|
566 |
+
if (is_array($options)) {
|
567 |
+
$value = implode("\n", $options);
|
568 |
+
}
|
569 |
+
} else {
|
570 |
+
$value = $attribute->getFrontend()->getValue($product);
|
571 |
+
}
|
572 |
+
|
573 |
+
if ($attribute->getIsVisibleOnFront() || in_array($attributeCode, array($attributeListing, $attributeDetails))) {
|
574 |
+
if (!$product->hasData($attributeCode)) {
|
575 |
+
if ($hideNullValue) continue;
|
576 |
+
$value = Mage::helper('catalog')->__('N/A');
|
577 |
+
} elseif ((string)$value == '') {
|
578 |
+
$value = Mage::helper('catalog')->__('No');
|
579 |
+
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
|
580 |
+
$value = Mage::app()->getStore()->convertPrice($value, true);
|
581 |
+
}
|
582 |
+
}
|
583 |
+
|
584 |
+
if ($details) {
|
585 |
+
if ($attributeCode == $attributeDetails) {
|
586 |
+
$result['detail_display'] = array(
|
587 |
+
'label' => $attribute->getStoreLabel(),
|
588 |
+
'value' => $value,
|
589 |
+
'code' => $attributeCode
|
590 |
+
);
|
591 |
+
}
|
592 |
+
if ($attribute->getIsVisibleOnFront()) {
|
593 |
+
if (is_string($value) && strlen($value)) {
|
594 |
+
$result['additional_information'][] = array(
|
595 |
+
'label' => $attribute->getStoreLabel(),
|
596 |
+
'value' => $value,
|
597 |
+
'code' => $attributeCode
|
598 |
+
);
|
599 |
+
}
|
600 |
+
}
|
601 |
+
} elseif ($attributeCode == $attributeListing) {
|
602 |
+
$result['list_display'] = array(
|
603 |
+
'label' => $attribute->getStoreLabel(),
|
604 |
+
'value' => $value,
|
605 |
+
'code' => $attributeCode
|
606 |
+
);
|
607 |
+
}
|
608 |
+
}
|
609 |
+
|
610 |
+
/* @var $customerSession Mage_Customer_Model_Session */
|
611 |
+
$customerSession = Mage::getSingleton('customer/session');
|
612 |
+
if (Mage::getStoreConfigFlag('japi/jmango_app_login_settings/require_login')) {
|
613 |
+
if ($customerSession->isLoggedIn()) {
|
614 |
+
$result['show_price_label'] = true;
|
615 |
+
} else {
|
616 |
+
$result['show_price_label'] = false;
|
617 |
+
}
|
618 |
+
} else {
|
619 |
+
$result['show_price_label'] = true;
|
620 |
+
}
|
621 |
+
|
622 |
+
if ($result['type'] != $result['type_id']) $result['type'] = $result['type_id'];
|
623 |
+
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $this->isSCPActive()) {
|
624 |
+
$result['type'] = self::CONFIGURABLE_SCP_TYPE;
|
625 |
+
$result['type_id'] = self::CONFIGURABLE_SCP_TYPE;
|
626 |
+
}
|
627 |
+
|
628 |
+
return $result;
|
629 |
+
}
|
630 |
+
|
631 |
+
/**
|
632 |
+
* Prepares Product info for api response
|
633 |
+
*
|
634 |
+
* @param Mage_Catalog_Model_Product $product
|
635 |
+
* @return array
|
636 |
+
*/
|
637 |
+
public function convertProductToApiResponse(Mage_Catalog_Model_Product $product)
|
638 |
+
{
|
639 |
+
Mage::dispatchEvent('catalog_product_type_configurable_price', array('product' => $product));
|
640 |
+
Mage::dispatchEvent('catalog_product_load_after', array('product' => $product, 'data_object' => $product));
|
641 |
+
|
642 |
+
//MPLUGIN-847
|
643 |
+
if ($product->getTypeId() == 'bundle') {
|
644 |
+
$product->unsetData('final_price');
|
645 |
+
}
|
646 |
+
|
647 |
+
$result = array(
|
648 |
+
'product_id' => $product->getId(),
|
649 |
+
'sku' => $product->getSku(),
|
650 |
+
'set' => $product->getAttributeSetId(),
|
651 |
+
'type' => $product->getTypeId(),
|
652 |
+
'type_id' => $product->getTypeId(),
|
653 |
+
'categories' => $product->getCategoryIds(),
|
654 |
+
'websites' => $product->getWebsiteIds(),
|
655 |
+
'position' => $product->getCatIndexPosition(),
|
656 |
+
'final_price' => $this->calculatePriceIncludeTax($product, $product->getFinalPrice()),
|
657 |
+
'stock' => $this->_getStockLevel($product),
|
658 |
+
'is_in_stock' => $product->getStockItem() ? (int)$product->getStockItem()->getIsInStock() : null,
|
659 |
+
'is_saleable' => (int)$product->isSalable(),
|
660 |
+
'min_price' => $this->calculatePriceIncludeTax($product, $product->getMinPrice()),
|
661 |
+
'max_price' => $this->calculatePriceIncludeTax($product, $product->getMaxPrice()),
|
662 |
+
'minimal_price' => $this->calculatePriceIncludeTax($product, $product->getMinimalPrice()),
|
663 |
+
'additional_information' => array(),
|
664 |
+
'catalog_display' => array()
|
665 |
+
);
|
666 |
+
|
667 |
+
/*DEPRICATED*/
|
668 |
+
$this->_addMediaInfo($product, $result);
|
669 |
+
/*REPLACES addMediaInfo*/
|
670 |
+
$this->_addMediaUrls($product, $result);
|
671 |
+
|
672 |
+
$this->_addCustomOptions($product, $result);
|
673 |
+
$this->_addConfigurableAttributes($product, $result);
|
674 |
+
$this->_addGroupedItems($product, $result);
|
675 |
+
$this->_addBundleInfo($product, $result);
|
676 |
+
$this->_addDownloadableInfo($product, $result);
|
677 |
+
$this->_addTierPriceInfo($product, $result);
|
678 |
+
|
679 |
+
// MPLUGIN-153
|
680 |
+
//$basePriceWithTax = $this->calculatePriceIncludeTax($product, $product->getPrice());
|
681 |
+
//$product->setPrice($basePriceWithTax);
|
682 |
+
|
683 |
+
/* @var $productHelper Mage_Catalog_Helper_Output */
|
684 |
+
$productHelper = Mage::helper('catalog/output');
|
685 |
+
|
686 |
+
$attributes = $product->getTypeInstance(false)->getEditableAttributes($product);
|
687 |
+
$attributeListing = Mage::getStoreConfig('japi/jmango_rest_catalog_settings/attribute_on_listing');
|
688 |
+
$attributeDetails = Mage::getStoreConfig('japi/jmango_rest_catalog_settings/attribute_on_details');
|
689 |
+
$hideNullValue = Mage::getStoreConfigFlag('japi/jmango_rest_catalog_settings/hide_null_value');
|
690 |
+
|
691 |
+
foreach ($attributes as $attribute) {
|
692 |
+
/* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
|
693 |
+
if (!$this->_isAllowedAttribute($attribute)) continue;
|
694 |
+
|
695 |
+
//MPLUGIN-975
|
696 |
+
if (!$attribute->hasData('is_wysiwyg_enabled') || !$attribute->hasData('is_visible_on_front')) {
|
697 |
+
$attribute->load($attribute->getId());
|
698 |
+
}
|
699 |
+
|
700 |
+
$attributeCode = $attribute->getAttributeCode();
|
701 |
+
|
702 |
+
if ($attribute->getData('is_wysiwyg_enabled') == 1) {
|
703 |
+
/**
|
704 |
+
* MPLUGIN-1031: Validate data of attribute
|
705 |
+
* Return empty data if value of attribute null or contains only html tags
|
706 |
+
*/
|
707 |
+
$attrContent = $productHelper->productAttribute(
|
708 |
+
$product, $product->getData($attributeCode), $attributeCode
|
709 |
+
);
|
710 |
+
if (!$attrContent || $attrContent == '' || trim(strip_tags($attrContent)) == '') {
|
711 |
+
$result[$attributeCode] = '';
|
712 |
+
} else {
|
713 |
+
$html = '<style>';
|
714 |
+
$html .= 'pre,code,blockquote{white-space:normal!important;}';
|
715 |
+
$html .= 'table{width:100%!important;}';
|
716 |
+
$html .= '</style>';
|
717 |
+
$html .= $attrContent;
|
718 |
+
$result[$attributeCode] = $html;
|
719 |
+
}
|
720 |
+
} else {
|
721 |
+
$result[$attributeCode] = $product->getData($attributeCode);
|
722 |
+
}
|
723 |
+
|
724 |
+
$value = '';
|
725 |
+
|
726 |
+
if ($attribute->getIsVisibleOnFront() || $attributeListing == $attributeCode || $attributeDetails == $attributeCode) {
|
727 |
+
if ($attribute->getFrontendInput() == 'multiselect') {
|
728 |
+
$options = $attribute->getFrontend()->getOption($product->getData($attributeCode));
|
729 |
+
if (is_array($options)) {
|
730 |
+
$value = implode("\n", $options);
|
731 |
+
}
|
732 |
+
} else {
|
733 |
+
$value = $attribute->getFrontend()->getValue($product);
|
734 |
+
}
|
735 |
+
if (!$product->hasData($attributeCode)) {
|
736 |
+
if ($hideNullValue) continue;
|
737 |
+
$value = Mage::helper('catalog')->__('N/A');
|
738 |
+
} elseif ((string)$value == '') {
|
739 |
+
$value = Mage::helper('catalog')->__('No');
|
740 |
+
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
|
741 |
+
$value = Mage::app()->getStore()->convertPrice($value, true);
|
742 |
+
}
|
743 |
+
}
|
744 |
+
|
745 |
+
if ($attribute->getIsVisibleOnFront()) {
|
746 |
+
if (is_string($value) && strlen($value)) {
|
747 |
+
$result['additional_information'][] = array(
|
748 |
+
'label' => $attribute->getStoreLabel(),
|
749 |
+
'value' => $value,
|
750 |
+
'code' => $attributeCode
|
751 |
+
);
|
752 |
+
}
|
753 |
+
}
|
754 |
+
|
755 |
+
if ($attributeListing == $attributeCode) {
|
756 |
+
if (is_string($value) && strlen($value)) {
|
757 |
+
$result['catalog_display']['list'] = array(
|
758 |
+
'label' => $attribute->getStoreLabel(),
|
759 |
+
'value' => $value,
|
760 |
+
'code' => $attributeCode
|
761 |
+
);
|
762 |
+
}
|
763 |
+
}
|
764 |
+
|
765 |
+
if ($attributeDetails == $attributeCode) {
|
766 |
+
if (is_string($value) && strlen($value)) {
|
767 |
+
$result['catalog_display']['details'] = array(
|
768 |
+
'label' => $attribute->getStoreLabel(),
|
769 |
+
'value' => $value,
|
770 |
+
'code' => $attributeCode
|
771 |
+
);
|
772 |
+
}
|
773 |
+
}
|
774 |
+
}
|
775 |
+
|
776 |
+
if (empty($result['catalog_display'])) {
|
777 |
+
$result['catalog_display'] = new stdClass();
|
778 |
+
}
|
779 |
+
|
780 |
+
if ($result['type'] != $result['type_id']) $result['type'] = $result['type_id'];
|
781 |
+
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $this->isSCPActive()) {
|
782 |
+
$result['type'] = self::CONFIGURABLE_SCP_TYPE;
|
783 |
+
$result['type_id'] = self::CONFIGURABLE_SCP_TYPE;
|
784 |
+
}
|
785 |
+
|
786 |
+
$result['price'] = $this->calculatePriceIncludeTax($product, $this->_getSCPBasePrice($product));
|
787 |
+
|
788 |
+
return $result;
|
789 |
+
}
|
790 |
+
|
791 |
+
/**
|
792 |
+
* @param $product Mage_Catalog_Model_Product
|
793 |
+
* @param $result
|
794 |
+
*/
|
795 |
+
protected function _addMediaUrls($product, &$result)
|
796 |
+
{
|
797 |
+
$imageNames = array_keys($this->_defaultImagesPaths);
|
798 |
+
$size = $this->_getImageSizes();
|
799 |
+
/* @var $helper Mage_Catalog_Helper_Image */
|
800 |
+
$helper = Mage::helper('catalog/image');
|
801 |
+
$images = array();
|
802 |
+
/**
|
803 |
+
* MPLUGIN-761
|
804 |
+
* Support for websites using 'Softwareimc_Razuna' extension
|
805 |
+
*/
|
806 |
+
if ($this->isModuleEnabled('Softwareimc_Razuna')) {
|
807 |
+
/* @var $razunaImageModel Softwareimc_Razuna_Model_Images */
|
808 |
+
$razunaImageModel = Mage::getModel('razuna/images');
|
809 |
+
$_razunaMainImages = $razunaImageModel->getImagesBySku($product, 'Main');
|
810 |
+
if (count($_razunaMainImages) > 0) {
|
811 |
+
$images['thumbnail']['url'] = $_razunaMainImages[0]['url'];
|
812 |
+
} else {
|
813 |
+
$_razunaThumbImages = $razunaImageModel->getImagesBySku($product, 'Thumbnail');
|
814 |
+
if (count($_razunaThumbImages) > 0) {
|
815 |
+
$images['thumbnail']['url'] = $_razunaMainImages[0]['thumb_url'];
|
816 |
+
} else {
|
817 |
+
$_imageListingDefault = Mage::getStoreConfig('japi/jmango_rest_gallery_settings/image_default_listing');
|
818 |
+
$images['thumbnail']['url'] = (string)$helper->init($product, $_imageListingDefault)->resize($size['thumbnail']['width'], $size['thumbnail']['height']);
|
819 |
+
}
|
820 |
+
}
|
821 |
+
$images['thumbnail']['label'] = $product->getName();
|
822 |
+
} else {
|
823 |
+
$_imageListingDefault = Mage::getStoreConfig('japi/jmango_rest_gallery_settings/image_default_listing');
|
824 |
+
|
825 |
+
foreach ($imageNames as $imageName) {
|
826 |
+
if ($imageName == 'thumbnail' && $_imageListingDefault != 'thumbnail') { // Replaces thumbnail url by config
|
827 |
+
$images[$imageName]['url'] = (string)$helper->init($product, $_imageListingDefault)->resize($size[$imageName]['width'], $size[$imageName]['height']);
|
828 |
+
} else {
|
829 |
+
$images[$imageName]['url'] = (string)$helper->init($product, $imageName)->resize($size[$imageName]['width'], $size[$imageName]['height']);
|
830 |
+
}
|
831 |
+
$images[$imageName]['label'] = (string)$product->getData($imageName . '_label') ? $product->getData($imageName . '_label') : $product->getName();
|
832 |
+
}
|
833 |
+
}
|
834 |
+
|
835 |
+
//MPLUGIN-1133 - get Ignore image - will not add to gallery data
|
836 |
+
$_ignoreName = $this->_getImageFileName($images['thumbnail']['url']);
|
837 |
+
|
838 |
+
/**
|
839 |
+
* Fix for issues MPLUGIN-727, MPLUGIN-764
|
840 |
+
* Load media gallery form 'media_gallery' data instead of load media gallery images object
|
841 |
+
* Update for MPLUGIN-761 - Support for websites using 'Softwareimc_Razuna' extension
|
842 |
+
*/
|
843 |
+
if (!$this->isModuleEnabled('Softwareimc_Razuna')) { // not installed 'Softwareimc_Razuna'
|
844 |
+
$images['gallery'] = $this->_getGalleryUrlsData($product, $_ignoreName);
|
845 |
+
} else {// installed 'Softwareimc_Razuna'
|
846 |
+
/* @var $razunaImageModel Softwareimc_Razuna_Model_Images */
|
847 |
+
$razunaImageModel = Mage::getModel('razuna/images');
|
848 |
+
$_razunaThumbImages = $razunaImageModel->getImagesBySku($product, 'Thumbnail');
|
849 |
+
if (count($_razunaThumbImages) > 0) {
|
850 |
+
$index = 0;
|
851 |
+
foreach ($_razunaThumbImages as $_thumb) {
|
852 |
+
$images['gallery'][$index]['url'] = $_thumb['thumb_url'];
|
853 |
+
$images['gallery'][$index]['label'] = $product->getName();
|
854 |
+
$index++;
|
855 |
+
}
|
856 |
+
} else {
|
857 |
+
$images['gallery'] = $this->_getGalleryUrlsData($product, $_ignoreName);
|
858 |
+
}
|
859 |
+
}
|
860 |
+
|
861 |
+
$result['media_urls'] = $images;
|
862 |
+
}
|
863 |
+
|
864 |
+
protected function _getGalleryUrlsData(Mage_Catalog_Model_Product $product, $ignoreName)
|
865 |
+
{
|
866 |
+
/* @var $helper Mage_Catalog_Helper_Image */
|
867 |
+
$helper = Mage::helper('catalog/image');
|
868 |
+
$size = $this->_getImageSizes();
|
869 |
+
$images = array();
|
870 |
+
|
871 |
+
$gallery = $product->getData('media_gallery');
|
872 |
+
if (version_compare(Mage::getVersion(), '1.9.0', '<')) {
|
873 |
+
$gallery = $gallery['images'];
|
874 |
+
} else {
|
875 |
+
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
|
876 |
+
$gallery = !empty($gallery['configurable_images']) ? $gallery['configurable_images'] : $gallery['images'];
|
877 |
+
} else {
|
878 |
+
$gallery = $gallery['images'];
|
879 |
+
}
|
880 |
+
}
|
881 |
+
|
882 |
+
if (count($gallery)) {
|
883 |
+
$index = 0;
|
884 |
+
foreach ($gallery as $image) {
|
885 |
+
if ($image['disabled_default']) continue;
|
886 |
+
|
887 |
+
//MPLUGIN-1133 - not add image used on listing to gallery
|
888 |
+
$_imageFileName = $this->_getImageFileName($image['file']);
|
889 |
+
if ($_imageFileName == $ignoreName) continue;
|
890 |
+
|
891 |
+
$images[$index]['url'] = (string)$helper->init($product, 'thumbnail', $image['file'])->resize($size['thumbnail']['width'], $size['thumbnail']['height']);
|
892 |
+
$images[$index]['label'] = $image['label'] ? $image['label'] : $product->getName();
|
893 |
+
$index++;
|
894 |
+
}
|
895 |
+
}
|
896 |
+
return $images;
|
897 |
+
}
|
898 |
+
|
899 |
+
public function getImageSizes()
|
900 |
+
{
|
901 |
+
return $this->_getImageSizes();
|
902 |
+
}
|
903 |
+
|
904 |
+
protected function _getImageSizes()
|
905 |
+
{
|
906 |
+
/* @var $request Jmango360_Japi_Model_Request */
|
907 |
+
$request = Mage::helper('japi')->getRequest();
|
908 |
+
|
909 |
+
$imageNames = array_keys($this->_defaultImagesPaths);
|
910 |
+
$imageSizesParams = $request->getParam('image_sizes', array());
|
911 |
+
|
912 |
+
/**
|
913 |
+
* MPLUGIN-1134 - Updated: Only get images size from store config, not check data in session
|
914 |
+
*/
|
915 |
+
$sizes = array();
|
916 |
+
foreach ($imageNames as $imageName) {
|
917 |
+
if (!empty($imageSizesParams[$imageName]['width'])) {
|
918 |
+
$sizes[$imageName]['width'] = $imageSizesParams[$imageName]['width'];
|
919 |
+
if (empty($imageSizesParams[$imageName]['height'])) {
|
920 |
+
$imageSizesParams[$imageName]['height'] = $imageSizesParams[$imageName]['width'];
|
921 |
+
}
|
922 |
+
} elseif (Mage::getStoreConfig($this->_defaultImagesPaths[$imageName]['width'])) {
|
923 |
+
$sizes[$imageName]['width'] = Mage::getStoreConfig($this->_defaultImagesPaths[$imageName]['width']);
|
924 |
+
} else {
|
925 |
+
$sizes[$imageName]['width'] = null;
|
926 |
+
}
|
927 |
+
|
928 |
+
if (!empty($imageSizesParams[$imageName]['height'])) {
|
929 |
+
$sizes[$imageName]['height'] = $imageSizesParams[$imageName]['height'];
|
930 |
+
} elseif (Mage::getStoreConfig($this->_defaultImagesPaths[$imageName]['height'])) {
|
931 |
+
$sizes[$imageName]['height'] = Mage::getStoreConfig($this->_defaultImagesPaths[$imageName]['height']);
|
932 |
+
} else {
|
933 |
+
$sizes[$imageName]['height'] = null;
|
934 |
+
}
|
935 |
+
}
|
936 |
+
|
937 |
+
return $sizes;
|
938 |
+
}
|
939 |
+
|
940 |
+
/**
|
941 |
+
* This function will return product final price with/without tax
|
942 |
+
* that based on Tax settings in Sale -> Tax & System -> Sale -> Tax
|
943 |
+
*
|
944 |
+
* @param Mage_Catalog_Model_Product $_product
|
945 |
+
* @param float $productFinalPrice
|
946 |
+
* @return float
|
947 |
+
*/
|
948 |
+
|
949 |
+
public function calculatePriceIncludeTax(Mage_Catalog_Model_Product $_product, $productFinalPrice)
|
950 |
+
{
|
951 |
+
if (version_compare(Mage::getVersion(), '1.8.1.0', '<')) {
|
952 |
+
/* @var $taxHelper Jmango360_Japi_Helper_Tax */
|
953 |
+
$taxHelper = Mage::helper('japi/tax');
|
954 |
+
} else {
|
955 |
+
/* @var $taxHelper Mage_Tax_Helper_Data */
|
956 |
+
$taxHelper = Mage::helper('tax');
|
957 |
+
}
|
958 |
+
|
959 |
+
/**
|
960 |
+
* MPLUGIN-980: get Cutomer tax class when customer logged-in or not
|
961 |
+
*/
|
962 |
+
if (Mage::getSingleton('customer/session')->isLoggedin()) {
|
963 |
+
$customerTaxClass = Mage::getSingleton('tax/calculation')->getRateRequest()->getCustomerClassId();
|
964 |
+
} else {
|
965 |
+
$customerTaxClass = Mage::getModel('customer/group')->getTaxClassId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
|
966 |
+
}
|
967 |
+
|
968 |
+
/**
|
969 |
+
* Get product price display type
|
970 |
+
* 1 - Excluding tax
|
971 |
+
* 2 - Including tax
|
972 |
+
* 3 - Both
|
973 |
+
*/
|
974 |
+
|
975 |
+
/* @var Mage_Tax_Model_Config */
|
976 |
+
$productPriceDisplayType = $taxHelper->getPriceDisplayType(Mage::app()->getStore()->getId());
|
977 |
+
|
978 |
+
if ($productPriceDisplayType == 1) {
|
979 |
+
// Exclude tax
|
980 |
+
$productFinalPrice = $taxHelper->getPrice($_product, $productFinalPrice, false, null, null, $customerTaxClass, null, null, false);
|
981 |
+
} else {
|
982 |
+
// Including tax or both
|
983 |
+
$productFinalPrice = $taxHelper->getPrice($_product, $productFinalPrice, true, null, null, $customerTaxClass, null, null, false);
|
984 |
+
}
|
985 |
+
|
986 |
+
return $productFinalPrice;
|
987 |
+
}
|
988 |
+
|
989 |
+
/**
|
990 |
+
* Return the stock level if user manage stock otherwise return -1
|
991 |
+
* @param Mage_Catalog_Model_Product $_product
|
992 |
+
* @return int stock level
|
993 |
+
*/
|
994 |
+
protected function _getStockLevel(Mage_Catalog_Model_Product $_product)
|
995 |
+
{
|
996 |
+
$manageStock = $_product->getStockItem() ? $_product->getStockItem()->getManageStock() : null;
|
997 |
+
|
998 |
+
$stockQuantity = -1;
|
999 |
+
if ($manageStock == 1) {
|
1000 |
+
$stockQuantity = $_product->getStockItem()->getQty();
|
1001 |
+
}
|
1002 |
+
|
1003 |
+
return (float)$stockQuantity;
|
1004 |
+
}
|
1005 |
+
|
1006 |
+
/**
|
1007 |
+
* DEPRICATED
|
1008 |
+
* @param Mage_Catalog_Model_Product $product
|
1009 |
+
* @param $result
|
1010 |
+
*/
|
1011 |
+
protected function _addMediaInfo(Mage_Catalog_Model_Product $product, &$result)
|
1012 |
+
{
|
1013 |
+
/* @var $helper Jmango360_Japi_Helper_Product_Media */
|
1014 |
+
/*DEPRICATED*/
|
1015 |
+
$helper = Mage::helper('japi/product_media');
|
1016 |
+
$result['media_info'] = $helper->getMediaInfo($product);
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
protected function _addGalleryInfo(Mage_Catalog_Model_Product $product, &$result)
|
1020 |
+
{
|
1021 |
+
if ($this->isModuleEnabled('Softwareimc_Razuna')) {
|
1022 |
+
/* @var $razunaImageModel Softwareimc_Razuna_Model_Images */
|
1023 |
+
$razunaImageModel = Mage::getModel('razuna/images');
|
1024 |
+
$_razunaThumbImages = $razunaImageModel->getImagesBySku($product, 'Thumbnail');
|
1025 |
+
if (count($_razunaThumbImages) > 0) {
|
1026 |
+
$index = 0;
|
1027 |
+
foreach ($_razunaThumbImages as $_thumb) {
|
1028 |
+
$images['gallery'][$index]['url'] = $_thumb['thumb_url'];
|
1029 |
+
$images['gallery'][$index]['label'] = $product->getName();
|
1030 |
+
$index++;
|
1031 |
+
}
|
1032 |
+
return;
|
1033 |
+
}
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
/* @var $helper Mage_Catalog_Helper_Image */
|
1037 |
+
$helper = Mage::helper('catalog/image');
|
1038 |
+
$size = $this->_getImageSizes();
|
1039 |
+
$images = array();
|
1040 |
+
|
1041 |
+
$gallery = $product->getMediaGalleryImages();
|
1042 |
+
if (version_compare(Mage::getVersion(), '1.9.0', '<')) {
|
1043 |
+
if (is_array($gallery) && isset($gallery['images'])) {
|
1044 |
+
$gallery = $gallery['images'];
|
1045 |
+
}
|
1046 |
+
} else {
|
1047 |
+
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
|
1048 |
+
if (is_array($gallery) && isset($gallery['configurable_images'])) {
|
1049 |
+
$gallery = count($gallery['configurable_images']) ? $gallery['configurable_images'] : $gallery['images'];
|
1050 |
+
} else {
|
1051 |
+
if (is_array($gallery) && isset($gallery['images'])) {
|
1052 |
+
$gallery = $gallery['images'];
|
1053 |
+
}
|
1054 |
+
}
|
1055 |
+
} else {
|
1056 |
+
if (is_array($gallery) && isset($gallery['images'])) {
|
1057 |
+
$gallery = $gallery['images'];
|
1058 |
+
}
|
1059 |
+
}
|
1060 |
+
}
|
1061 |
+
$_ignoreName = $this->_getImageFileName($result['image']);
|
1062 |
+
if (count($gallery)) {
|
1063 |
+
foreach ($gallery as $image) {
|
1064 |
+
/* @var $image Varien_Object */
|
1065 |
+
if ($image->getDisabledDefault()) continue;
|
1066 |
+
|
1067 |
+
//MPLUGIN-1133 - not add image used on listing to gallery
|
1068 |
+
$_imageName = $this->_getImageFileName($image->getFile());
|
1069 |
+
if ($_imageName == $_ignoreName) continue;
|
1070 |
+
|
1071 |
+
$images[] = array(
|
1072 |
+
'url' => (string)$helper->init($product, 'thumbnail', $image->getFile())
|
1073 |
+
->resize($size['thumbnail']['width'], $size['thumbnail']['height']),
|
1074 |
+
'label' => $image->getLabel() ? $image->getLabel() : $product->getName()
|
1075 |
+
);
|
1076 |
+
}
|
1077 |
+
}
|
1078 |
+
|
1079 |
+
$result['gallery'] = $images;
|
1080 |
+
}
|
1081 |
+
|
1082 |
+
/**
|
1083 |
+
* @param Mage_Catalog_Model_Product $product
|
1084 |
+
* @param $result
|
1085 |
+
*/
|
1086 |
+
protected function _addCustomOptions(Mage_Catalog_Model_Product $product, &$result)
|
1087 |
+
{
|
1088 |
+
/* @var $helper Jmango360_Japi_Helper_Product_Options */
|
1089 |
+
$helper = Mage::helper('japi/product_options');
|
1090 |
+
$result['options'] = $helper->getOptionList($product);
|
1091 |
+
}
|
1092 |
+
|
1093 |
+
/**
|
1094 |
+
* @param Mage_Catalog_Model_Product $product
|
1095 |
+
* @param $result
|
1096 |
+
* @param $includePrice
|
1097 |
+
*/
|
1098 |
+
protected function _addConfigurableAttributes(Mage_Catalog_Model_Product $product, &$result, $includePrice = false)
|
1099 |
+
{
|
1100 |
+
if ($product->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
|
1101 |
+
return;
|
1102 |
+
}
|
1103 |
+
|
1104 |
+
/* @var $helper Jmango360_Japi_Helper_Product_Configurable */
|
1105 |
+
$helper = Mage::helper('japi/product_configurable');
|
1106 |
+
$result['configurable_attributes'] = $helper->getConfigurableAttributes($product, $includePrice);
|
1107 |
+
}
|
1108 |
+
|
1109 |
+
/**
|
1110 |
+
* @param Mage_Catalog_Model_Product $product
|
1111 |
+
* @param $includePrice bool
|
1112 |
+
* @param $result
|
1113 |
+
*/
|
1114 |
+
protected function _addGroupedItems(Mage_Catalog_Model_Product $product, &$result, $includePrice = false)
|
1115 |
+
{
|
1116 |
+
if ($product->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
|
1117 |
+
return;
|
1118 |
+
}
|
1119 |
+
/* @var $helper Jmango360_Japi_Helper_Product_Grouped */
|
1120 |
+
$helper = Mage::helper('japi/product_grouped');
|
1121 |
+
$result['grouped_items'] = $helper->getGroupedItems($product, $includePrice);
|
1122 |
+
}
|
1123 |
+
|
1124 |
+
/**
|
1125 |
+
* @param Mage_Catalog_Model_Product $product
|
1126 |
+
* @param $result
|
1127 |
+
*/
|
1128 |
+
protected function _addBundleInfo(Mage_Catalog_Model_Product $product, &$result)
|
1129 |
+
{
|
1130 |
+
if ($product->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
|
1131 |
+
return;
|
1132 |
+
}
|
1133 |
+
/* @var $helper Jmango360_Japi_Helper_Product_Bundle */
|
1134 |
+
$helper = Mage::helper('japi/product_bundle');
|
1135 |
+
$result['bundle_attributes'] = $helper->getBundleAttributes($product);
|
1136 |
+
$result['bundle_items'] = $helper->getBundleItems($product);
|
1137 |
+
}
|
1138 |
+
|
1139 |
+
/**
|
1140 |
+
* @param Mage_Catalog_Model_Product $product
|
1141 |
+
* @param $result
|
1142 |
+
*/
|
1143 |
+
protected function _addDownloadableInfo(Mage_Catalog_Model_Product $product, &$result)
|
1144 |
+
{
|
1145 |
+
if ($product->getTypeId() !== Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
|
1146 |
+
return;
|
1147 |
+
}
|
1148 |
+
/* @var $helper Jmango360_Japi_Helper_Product_Downloadable */
|
1149 |
+
$helper = Mage::helper('japi/product_downloadable');
|
1150 |
+
$result['downloadable_info'] = $helper->getDownloadableLinks($product);
|
1151 |
+
}
|
1152 |
+
|
1153 |
+
/**
|
1154 |
+
* @param Mage_Catalog_Model_Product $product
|
1155 |
+
* @param $result
|
1156 |
+
*/
|
1157 |
+
protected function _addTierPriceInfo(Mage_Catalog_Model_Product $product, &$result)
|
1158 |
+
{
|
1159 |
+
/* @var $helper Jmango360_Japi_Helper_Product_TierPrice */
|
1160 |
+
$helper = Mage::helper('japi/product_tierPrice');
|
1161 |
+
$result['tier_price'] = $helper->getTierPriceInfo($product);
|
1162 |
+
}
|
1163 |
+
|
1164 |
+
/**
|
1165 |
+
* Check is attribute allowed
|
1166 |
+
*
|
1167 |
+
* @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
|
1168 |
+
* @param array $attributes
|
1169 |
+
* @return bool
|
1170 |
+
*/
|
1171 |
+
protected function _isAllowedAttribute($attribute, $attributes = null)
|
1172 |
+
{
|
1173 |
+
return !in_array($attribute->getFrontendInput(), $this->_ignoredAttributeTypes)
|
1174 |
+
&& !in_array($attribute->getAttributeCode(), $this->_ignoredAttributeCodes);
|
1175 |
+
}
|
1176 |
+
|
1177 |
+
/**
|
1178 |
+
* Returns max possible amount of products according to memory limit settings
|
1179 |
+
* Copied from Mage_ImportExport_Model_Export_Entity_Product::export()
|
1180 |
+
*
|
1181 |
+
* @return int
|
1182 |
+
*/
|
1183 |
+
public function getProductLimit()
|
1184 |
+
{
|
1185 |
+
|
1186 |
+
$memoryLimit = trim(ini_get('memory_limit'));
|
1187 |
+
$lastMemoryLimitLetter = strtolower($memoryLimit[strlen($memoryLimit) - 1]);
|
1188 |
+
switch ($lastMemoryLimitLetter) {
|
1189 |
+
case 'g':
|
1190 |
+
$memoryLimit *= 1024;
|
1191 |
+
break;
|
1192 |
+
case 'm':
|
1193 |
+
$memoryLimit *= 1024;
|
1194 |
+
break;
|
1195 |
+
case 'k':
|
1196 |
+
$memoryLimit *= 1024;
|
1197 |
+
break;
|
1198 |
+
default:
|
1199 |
+
// minimum memory required by Magento
|
1200 |
+
$memoryLimit = 250000000;
|
1201 |
+
}
|
1202 |
+
|
1203 |
+
// Tested one product to have up to such size
|
1204 |
+
$memoryPerProduct = 100000;
|
1205 |
+
// Decrease memory limit to have supply
|
1206 |
+
$memoryUsagePercent = 0.8;
|
1207 |
+
// Minimum Products limit
|
1208 |
+
$minProductsLimit = 500;
|
1209 |
+
|
1210 |
+
$productLimit = intval(($memoryLimit * $memoryUsagePercent - memory_get_usage(true)) / $memoryPerProduct);
|
1211 |
+
if ($productLimit < $minProductsLimit) {
|
1212 |
+
$productLimit = $minProductsLimit;
|
1213 |
+
}
|
1214 |
+
|
1215 |
+
return $productLimit;
|
1216 |
+
}
|
1217 |
+
|
1218 |
+
/**
|
1219 |
+
*
|
1220 |
+
* Get product
|
1221 |
+
*
|
1222 |
+
* @param $productId
|
1223 |
+
* @param int $storeId
|
1224 |
+
* @return mixed
|
1225 |
+
*/
|
1226 |
+
public function getProduct($productId, $storeId = null)
|
1227 |
+
{
|
1228 |
+
$product = Mage::getModel('catalog/product');
|
1229 |
+
if ($storeId !== null) {
|
1230 |
+
$product->setStoreId($storeId);
|
1231 |
+
}
|
1232 |
+
|
1233 |
+
if (is_string($productId)) {
|
1234 |
+
$idBySku = $product->getIdBySku($productId);
|
1235 |
+
if ($idBySku) {
|
1236 |
+
$product->load($idBySku);
|
1237 |
+
}
|
1238 |
+
} else {
|
1239 |
+
$product->load($productId);
|
1240 |
+
}
|
1241 |
+
return $product;
|
1242 |
+
}
|
1243 |
+
|
1244 |
+
/**
|
1245 |
+
* Retrieve Attributes used in product listing
|
1246 |
+
*
|
1247 |
+
* @return array
|
1248 |
+
*/
|
1249 |
+
public function getAttributesUsedInProductView()
|
1250 |
+
{
|
1251 |
+
if (is_null($this->_usedInProductView)) {
|
1252 |
+
$this->_usedInProductView = array();
|
1253 |
+
$attributesData = $this->_getAttributesUsedInProductView();
|
1254 |
+
foreach ($attributesData as $attributeData) {
|
1255 |
+
$this->_usedInProductView[] = $attributeData['attribute_code'];
|
1256 |
+
}
|
1257 |
+
}
|
1258 |
+
|
1259 |
+
$attributeListing = Mage::getStoreConfig('japi/jmango_rest_catalog_settings/attribute_on_listing');
|
1260 |
+
if (!in_array($attributeListing, $this->_usedInProductView)) $this->_usedInProductView[] = $attributeListing;
|
1261 |
+
$attributeDetails = Mage::getStoreConfig('japi/jmango_rest_catalog_settings/attribute_on_details');
|
1262 |
+
if (!in_array($attributeDetails, $this->_usedInProductView)) $this->_usedInProductView[] = $attributeDetails;
|
1263 |
+
|
1264 |
+
return $this->_usedInProductView;
|
1265 |
+
}
|
1266 |
+
|
1267 |
+
/**
|
1268 |
+
* Retrieve Product Attributes Used in Catalog Product listing
|
1269 |
+
*
|
1270 |
+
* @return array
|
1271 |
+
*/
|
1272 |
+
protected function _getAttributesUsedInProductView()
|
1273 |
+
{
|
1274 |
+
/* @var $resource Mage_Core_Model_Resource */
|
1275 |
+
$resource = Mage::getSingleton('core/resource');
|
1276 |
+
$adapter = $resource->getConnection('core_read');
|
1277 |
+
$entityTypeId = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getId();
|
1278 |
+
$storeId = Mage::app()->getStore()->getId();
|
1279 |
+
$storeLabelExpr = $adapter->getCheckSql('al.value IS NOT NULL', 'al.value', 'main_table.frontend_label');
|
1280 |
+
|
1281 |
+
$select = $adapter->select()
|
1282 |
+
->from(array('main_table' => $resource->getTableName('eav/attribute')))
|
1283 |
+
->join(
|
1284 |
+
array('additional_table' => $resource->getTableName('catalog/eav_attribute')),
|
1285 |
+
'main_table.attribute_id = additional_table.attribute_id'
|
1286 |
+
)
|
1287 |
+
->joinLeft(
|
1288 |
+
array('al' => $resource->getTableName('eav/attribute_label')),
|
1289 |
+
'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int)$storeId,
|
1290 |
+
array('store_label' => $storeLabelExpr)
|
1291 |
+
)
|
1292 |
+
->where('main_table.entity_type_id = ?', (int)$entityTypeId)
|
1293 |
+
->where('additional_table.is_visible_on_front = ?', 1);
|
1294 |
+
|
1295 |
+
return $adapter->fetchAll($select);
|
1296 |
+
}
|
1297 |
+
|
1298 |
+
/**
|
1299 |
+
* Add Price data to products collection if not exist
|
1300 |
+
*
|
1301 |
+
* @param $collection
|
1302 |
+
* @param bool $joinLeft
|
1303 |
+
* @return $this
|
1304 |
+
* @throws Mage_Core_Exception
|
1305 |
+
*/
|
1306 |
+
protected function _addPriceData($collection, $joinLeft = false)
|
1307 |
+
{
|
1308 |
+
$resource = Mage::getSingleton('core/resource');
|
1309 |
+
$customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
|
1310 |
+
$websiteId = Mage::app()->getWebsite()->getId();
|
1311 |
+
|
1312 |
+
$select = $collection->getSelect();
|
1313 |
+
$connection = $collection->getConnection();
|
1314 |
+
|
1315 |
+
$joinCond = join(' AND ', array(
|
1316 |
+
'price_index.entity_id = e.entity_id',
|
1317 |
+
$connection->quoteInto('price_index.website_id = ?', $websiteId),
|
1318 |
+
$connection->quoteInto('price_index.customer_group_id = ?', $customerGroupId)
|
1319 |
+
));
|
1320 |
+
|
1321 |
+
$least = $connection->getLeastSql(array('price_index.min_price', 'price_index.tier_price'));
|
1322 |
+
$minimalExpr = $connection->getCheckSql('price_index.tier_price IS NOT NULL',
|
1323 |
+
$least, 'price_index.min_price');
|
1324 |
+
$colls = array('price', 'tax_class_id', 'final_price',
|
1325 |
+
'minimal_price' => $minimalExpr, 'min_price', 'max_price', 'tier_price');
|
1326 |
+
$tableName = array('price_index' => $resource->getTableName('catalog/product_index_price'));
|
1327 |
+
if ($joinLeft) {
|
1328 |
+
$select->joinLeft($tableName, $joinCond, $colls);
|
1329 |
+
} else {
|
1330 |
+
$select->join($tableName, $joinCond, $colls);
|
1331 |
+
}
|
1332 |
+
|
1333 |
+
//Clean duplicated fields
|
1334 |
+
$helper = Mage::getResourceHelper('core');
|
1335 |
+
$helper->prepareColumnsList($select);
|
1336 |
+
|
1337 |
+
return $this;
|
1338 |
+
}
|
1339 |
+
|
1340 |
+
/**
|
1341 |
+
* Get buy request data
|
1342 |
+
*
|
1343 |
+
* @param $item Mage_Sales_Model_Quote_Item
|
1344 |
+
* @param $product array
|
1345 |
+
* @return null|array
|
1346 |
+
*/
|
1347 |
+
public function getCartProductBuyRequest($item, $product)
|
1348 |
+
{
|
1349 |
+
if (!$item || !$product) return null;
|
1350 |
+
|
1351 |
+
$optionCollection = Mage::getModel('sales/quote_item_option')->getCollection()->addItemFilter($item);
|
1352 |
+
$item->setOptions($optionCollection->getOptionsByItem($item));
|
1353 |
+
$buyRequest = $item->getBuyRequest();
|
1354 |
+
if ($buyRequest) {
|
1355 |
+
$buyRequestData = array();
|
1356 |
+
|
1357 |
+
switch ($product['type_id']) {
|
1358 |
+
case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE:
|
1359 |
+
case self::CONFIGURABLE_SCP_TYPE:
|
1360 |
+
$buyRequestData['super_attribute'] = $buyRequest->getData('super_attribute');
|
1361 |
+
$buyRequestData['qty'] = $buyRequest->getData('qty');
|
1362 |
+
break;
|
1363 |
+
case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE:
|
1364 |
+
$options = $buyRequest->getData('bundle_option');
|
1365 |
+
if (is_array($options) && !empty($options)) {
|
1366 |
+
foreach ($options as $key => $value) {
|
1367 |
+
if (empty($value)) {
|
1368 |
+
unset($options[$key]);
|
1369 |
+
} elseif (!is_array($value)) {
|
1370 |
+
$options[$key] = array($value);
|
1371 |
+
}
|
1372 |
+
}
|
1373 |
+
$buyRequestData['bundle_option'] = $options;
|
1374 |
+
} else {
|
1375 |
+
$buyRequestData['bundle_option'] = null;
|
1376 |
+
}
|
1377 |
+
$buyRequestData['bundle_option_qty'] = $this->_getBundleOptionQty($item);
|
1378 |
+
$buyRequestData['qty'] = $buyRequest->getData('qty');
|
1379 |
+
break;
|
1380 |
+
}
|
1381 |
+
|
1382 |
+
$options = $buyRequest->getData('options');
|
1383 |
+
if (is_array($options) && !empty($options)) {
|
1384 |
+
foreach ($options as $key => $value) {
|
1385 |
+
if (empty($value)) {
|
1386 |
+
unset($options[$key]);
|
1387 |
+
} elseif (!is_array($value)) {
|
1388 |
+
$options[$key] = array($value);
|
1389 |
+
} elseif (isset($value['hour']) || isset($value['day']) || isset($value['type'])) {
|
1390 |
+
unset($options[$key]);
|
1391 |
+
}
|
1392 |
+
}
|
1393 |
+
$buyRequestData['options'] = empty($options) ? null : $options;
|
1394 |
+
} else {
|
1395 |
+
$buyRequestData['options'] = null;
|
1396 |
+
}
|
1397 |
+
|
1398 |
+
$buyRequestData['qty'] = $buyRequest->getData('qty');
|
1399 |
+
|
1400 |
+
return !empty($buyRequestData) ? $buyRequestData : null;
|
1401 |
+
} else {
|
1402 |
+
return null;
|
1403 |
+
}
|
1404 |
+
}
|
1405 |
+
|
1406 |
+
/**
|
1407 |
+
* Get bundle options selections qty
|
1408 |
+
*
|
1409 |
+
* @param $item Mage_Sales_Model_Quote_Item
|
1410 |
+
* @return array
|
1411 |
+
*/
|
1412 |
+
protected function _getBundleOptionQty($item)
|
1413 |
+
{
|
1414 |
+
$options = array();
|
1415 |
+
$product = $item->getProduct();
|
1416 |
+
$typeInstance = $product->getTypeInstance(true);
|
1417 |
+
$optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
|
1418 |
+
$bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : array();
|
1419 |
+
if ($bundleOptionsIds) {
|
1420 |
+
$optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);
|
1421 |
+
$selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');
|
1422 |
+
$bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue());
|
1423 |
+
if (!empty($bundleSelectionIds)) {
|
1424 |
+
$selectionsCollection = $typeInstance->getSelectionsByIds(
|
1425 |
+
unserialize($selectionsQuoteItemOption->getValue()),
|
1426 |
+
$product
|
1427 |
+
);
|
1428 |
+
$bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
|
1429 |
+
foreach ($bundleOptions as $bundleOption) {
|
1430 |
+
if ($bundleOption->getSelections()) {
|
1431 |
+
$bundleSelections = $bundleOption->getSelections();
|
1432 |
+
foreach ($bundleSelections as $bundleSelection) {
|
1433 |
+
$options[$bundleOption->getOptionId()][] = sprintf("%d:%d",
|
1434 |
+
$bundleSelection->getSelectionId(),
|
1435 |
+
$this->_getSelectionQty($product, $bundleSelection->getSelectionId()) * 1
|
1436 |
+
);
|
1437 |
+
}
|
1438 |
+
}
|
1439 |
+
}
|
1440 |
+
}
|
1441 |
+
}
|
1442 |
+
|
1443 |
+
return empty($options) ? null : $options;
|
1444 |
+
}
|
1445 |
+
|
1446 |
+
/**
|
1447 |
+
* Get selection quantity
|
1448 |
+
*
|
1449 |
+
* @param Mage_Catalog_Model_Product $product
|
1450 |
+
* @param int $selectionId
|
1451 |
+
*
|
1452 |
+
* @return decimal
|
1453 |
+
*/
|
1454 |
+
protected function _getSelectionQty($product, $selectionId)
|
1455 |
+
{
|
1456 |
+
$selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
|
1457 |
+
if ($selectionQty) {
|
1458 |
+
return $selectionQty->getValue();
|
1459 |
+
}
|
1460 |
+
return 0;
|
1461 |
+
}
|
1462 |
+
|
1463 |
+
/**
|
1464 |
+
* Get SCP Base price
|
1465 |
+
*
|
1466 |
+
* @param Mage_Catalog_Model_Product $product
|
1467 |
+
* @return float
|
1468 |
+
*/
|
1469 |
+
protected function _getSCPBasePrice($product)
|
1470 |
+
{
|
1471 |
+
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE &&
|
1472 |
+
$this->isModuleEnabled('OrganicInternet_SimpleConfigurableProducts')
|
1473 |
+
) {
|
1474 |
+
$action = $this->_getRequest()->getActionName();
|
1475 |
+
if ($action == 'search' || $action == 'searchProducts') {
|
1476 |
+
$_price = $product->getData('price');
|
1477 |
+
try {
|
1478 |
+
$_priceBlock = new OrganicInternet_SimpleConfigurableProducts_Catalog_Model_Product_Type_Configurable_Price;
|
1479 |
+
$childProduct = $_priceBlock->getChildProductWithLowestPrice($product, "finalPrice");
|
1480 |
+
if (!$childProduct) {
|
1481 |
+
$childProduct = $_priceBlock->getChildProductWithLowestPrice($product, "finalPrice", false);
|
1482 |
+
}
|
1483 |
+
$_childBaseprice = $childProduct->getPrice();
|
1484 |
+
|
1485 |
+
if ($_price > $_childBaseprice) {
|
1486 |
+
return $_price;
|
1487 |
+
} else {
|
1488 |
+
return $_childBaseprice;
|
1489 |
+
}
|
1490 |
+
} catch (Exception $e) {
|
1491 |
+
return $_price;
|
1492 |
+
}
|
1493 |
+
} else {
|
1494 |
+
return $product->getPrice();
|
1495 |
+
}
|
1496 |
+
} else {
|
1497 |
+
return $product->getPrice();
|
1498 |
+
}
|
1499 |
+
}
|
1500 |
+
|
1501 |
+
/**
|
1502 |
+
* Get image file name from Url
|
1503 |
+
*
|
1504 |
+
* @param $url
|
1505 |
+
* @return string
|
1506 |
+
*/
|
1507 |
+
protected function _getImageFileName($url)
|
1508 |
+
{
|
1509 |
+
return basename($url);
|
1510 |
+
}
|
1511 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Product/Bundle.php
ADDED
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_Product_Bundle extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
const PRICE_VIEW_PRICE_RANGE = 0;
|
6 |
+
|
7 |
+
const PRICE_VIEW_AS_LOW_AS = 1;
|
8 |
+
|
9 |
+
const SELECTION_PRICE_TYPE_FIXED = 0;
|
10 |
+
|
11 |
+
const SELECTION_PRICE_TYPE_PERCENT = 1;
|
12 |
+
|
13 |
+
/* @var Mage_Catalog_Model_Product */
|
14 |
+
protected $_product = null;
|
15 |
+
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Returns bundle attributes as array
|
19 |
+
*
|
20 |
+
* @param Mage_Catalog_Model_Product $currentProduct
|
21 |
+
* @return array
|
22 |
+
*/
|
23 |
+
public function getBundleAttributes(Mage_Catalog_Model_Product $currentProduct)
|
24 |
+
{
|
25 |
+
$priceType = '';
|
26 |
+
if ($currentProduct->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
|
27 |
+
$priceType = 'fixed';
|
28 |
+
} else if ($currentProduct->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
|
29 |
+
$priceType = 'dynamic';
|
30 |
+
}
|
31 |
+
$priceView = '';
|
32 |
+
if ($currentProduct->getPriceView() == self::PRICE_VIEW_AS_LOW_AS) {
|
33 |
+
$priceView = 'as_low_as';
|
34 |
+
} else if ($currentProduct->getPriceView() == self::PRICE_VIEW_PRICE_RANGE) {
|
35 |
+
$priceView = 'price_range';
|
36 |
+
}
|
37 |
+
$attributes = array(
|
38 |
+
'price_type' => $priceType,
|
39 |
+
'price_view' => $priceView
|
40 |
+
);
|
41 |
+
|
42 |
+
return $attributes;
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Returns bundle options as array
|
47 |
+
*
|
48 |
+
* @param Mage_Catalog_Model_Product $product
|
49 |
+
* @return array
|
50 |
+
*/
|
51 |
+
public function getBundleItems(Mage_Catalog_Model_Product $product)
|
52 |
+
{
|
53 |
+
$this->_product = $product;
|
54 |
+
/* @var $typeInstance Mage_Bundle_Model_Product_Type */
|
55 |
+
$typeInstance = $product->getTypeInstance(true);
|
56 |
+
$typeInstance->setStoreFilter($product->getStoreId(), $product);
|
57 |
+
|
58 |
+
$optionCollection = $typeInstance->getOptionsCollection($product);
|
59 |
+
|
60 |
+
$selectionCollection = $typeInstance->getSelectionsCollection(
|
61 |
+
$typeInstance->getOptionsIds($product),
|
62 |
+
$product
|
63 |
+
);
|
64 |
+
|
65 |
+
$options = $optionCollection->appendSelections(
|
66 |
+
$selectionCollection,
|
67 |
+
false,
|
68 |
+
true//$this->getSkipSaleableCheck()
|
69 |
+
);
|
70 |
+
|
71 |
+
$result = array();
|
72 |
+
foreach ($options as $option) {
|
73 |
+
$result[] = $this->_convertOptionToArray($option);
|
74 |
+
}
|
75 |
+
|
76 |
+
return $result;
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Used for compatibility wih old versions, magento 1.6 doesn't have Mage_Catalog_Helper_Product::getSkipSaleableCheck()
|
81 |
+
*
|
82 |
+
* @return bool
|
83 |
+
*/
|
84 |
+
public function getSkipSaleableCheck()
|
85 |
+
{
|
86 |
+
/* @var $helper Mage_Catalog_Helper_Product */
|
87 |
+
$helper = Mage::helper('catalog/product');
|
88 |
+
if (method_exists($helper, 'getSkipSaleableCheck')) {
|
89 |
+
return $helper->getSkipSaleableCheck();
|
90 |
+
}
|
91 |
+
return false;
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Converts option to api response format
|
97 |
+
*
|
98 |
+
* @param $option
|
99 |
+
* @return array
|
100 |
+
*/
|
101 |
+
protected function _convertOptionToArray($option)
|
102 |
+
{
|
103 |
+
$result = array();
|
104 |
+
if (!is_object($option)) {
|
105 |
+
return result;
|
106 |
+
}
|
107 |
+
|
108 |
+
$result['option_id'] = (int)$option->getOptionId();
|
109 |
+
$result['required'] = (int)$option->getRequired();
|
110 |
+
$result['position'] = (int)$option->getPosition();
|
111 |
+
$result['type'] = $option->getType();
|
112 |
+
$result['default_title'] = $option->getDefaultTitle();
|
113 |
+
$result['title'] = $option->getTitle();
|
114 |
+
$result['selections'] = array();
|
115 |
+
|
116 |
+
if (is_array($option->getSelections())) {
|
117 |
+
foreach ($option->getSelections() as $index => $selection) {
|
118 |
+
$tmp = $this->_convertSelectionToArray($selection);
|
119 |
+
$tmp['position'] = $index;
|
120 |
+
$result['selections'][] = $tmp;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
return $result;
|
125 |
+
}
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Converts selection to api response format
|
129 |
+
*
|
130 |
+
* @param $selection
|
131 |
+
* @return array
|
132 |
+
*/
|
133 |
+
protected function _convertSelectionToArray($selection)
|
134 |
+
{
|
135 |
+
$result = array();
|
136 |
+
|
137 |
+
$result['product_id'] = (int)$selection->getProductId();
|
138 |
+
$result['selection_id'] = (int)$selection->getSelectionId();
|
139 |
+
$result['sku'] = $selection->getSku();
|
140 |
+
$result['position'] = (int)$selection->getPosition();
|
141 |
+
$result['is_default'] = (int)$selection->getIsDefault();
|
142 |
+
$result['name'] = $selection->getName();
|
143 |
+
$result['is_saleable'] = (int)$selection->isSaleable();
|
144 |
+
$result['qty'] = $selection->getSelectionQty();
|
145 |
+
$result['stock'] = $selection->getStockItem() ? $selection->getStockItem()->getQty() : null;
|
146 |
+
$result['is_in_stock'] = $selection->getStockItem() ? (int)$selection->getStockItem()->getIsInStock() : null;
|
147 |
+
switch ($selection->getOption()->getType()) {
|
148 |
+
case 'select':
|
149 |
+
case 'radio':
|
150 |
+
$result['can_change_qty'] = (int)$selection->getData('selection_can_change_qty');
|
151 |
+
break;
|
152 |
+
default:
|
153 |
+
$result['can_change_qty'] = 0;
|
154 |
+
}
|
155 |
+
if ($selection->getSelectionPriceType() == self::SELECTION_PRICE_TYPE_FIXED) {
|
156 |
+
$result['price_type'] = 'fixed';
|
157 |
+
} else if ($selection->getSelectionPriceType() == self::SELECTION_PRICE_TYPE_PERCENT) {
|
158 |
+
$result['price_type'] = 'percent';
|
159 |
+
}
|
160 |
+
$result['price'] = $this->_getSelectionPrice($selection);
|
161 |
+
|
162 |
+
return $result;
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Return selection price
|
167 |
+
*
|
168 |
+
* @param Mage_Catalog_Model_Product $selection
|
169 |
+
* @return string
|
170 |
+
*/
|
171 |
+
protected function _getSelectionPrice($selection)
|
172 |
+
{
|
173 |
+
$price = $this->_product->getPriceModel()->getSelectionPreFinalPrice($this->_product, $selection, 1);
|
174 |
+
|
175 |
+
if ($this->_product->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
|
176 |
+
$product = $selection;
|
177 |
+
} else {
|
178 |
+
$product = $this->_product;
|
179 |
+
}
|
180 |
+
|
181 |
+
/* @var $taxHelper Jmango360_Japi_Helper_Product */
|
182 |
+
$taxHelper = Mage::helper('japi/product');
|
183 |
+
$priceTax = $taxHelper->calculatePriceIncludeTax($product, $price);
|
184 |
+
|
185 |
+
/* @var $storeHelper Mage_Core_Helper_Data */
|
186 |
+
//$storeHelper = Mage::helper('core');
|
187 |
+
//$priceStore = $storeHelper->currencyByStore($priceTax, null, false);
|
188 |
+
|
189 |
+
return $priceTax;
|
190 |
+
}
|
191 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Product/Configurable.php
ADDED
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_Product_Configurable extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Get allowed attributes
|
7 |
+
*
|
8 |
+
* @param Mage_Catalog_Model_Product $product
|
9 |
+
* @return array
|
10 |
+
*/
|
11 |
+
public function getAllowAttributes(Mage_Catalog_Model_Product $product)
|
12 |
+
{
|
13 |
+
return $product->getTypeInstance(true)->getConfigurableAttributes($product);
|
14 |
+
}
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Check if allowed attributes have options
|
18 |
+
*
|
19 |
+
* @param Mage_Catalog_Model_Product $product
|
20 |
+
* @return bool
|
21 |
+
*/
|
22 |
+
public function hasOptions(Mage_Catalog_Model_Product $product)
|
23 |
+
{
|
24 |
+
$attributes = $this->getAllowAttributes($product);
|
25 |
+
if (count($attributes)) {
|
26 |
+
foreach ($attributes as $attribute) {
|
27 |
+
/** @var Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute */
|
28 |
+
if ($attribute->getData('prices')) {
|
29 |
+
return true;
|
30 |
+
}
|
31 |
+
}
|
32 |
+
}
|
33 |
+
return false;
|
34 |
+
}
|
35 |
+
|
36 |
+
protected $allowProducts = null;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Get Allowed Products
|
40 |
+
*
|
41 |
+
* @param Mage_Catalog_Model_Product $product
|
42 |
+
* @return array
|
43 |
+
*/
|
44 |
+
public function getAllowProducts(Mage_Catalog_Model_Product $product)
|
45 |
+
{
|
46 |
+
$products = array();
|
47 |
+
$skipSaleableCheck = true;//$this->getSkipSaleableCheck();
|
48 |
+
$allProducts = $product->getTypeInstance(true)
|
49 |
+
->getUsedProducts(null, $product);
|
50 |
+
|
51 |
+
foreach ($allProducts as $product) {
|
52 |
+
/* @var $product Mage_Catalog_Model_Product */
|
53 |
+
if ($product->isSaleable() || $skipSaleableCheck) {
|
54 |
+
$products[] = $product;
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
return $products;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Used for compatibility wih old versions, magento 1.6 doesn't have Mage_Catalog_Helper_Product::getSkipSaleableCheck()
|
63 |
+
*
|
64 |
+
* @return bool
|
65 |
+
*/
|
66 |
+
public function getSkipSaleableCheck()
|
67 |
+
{
|
68 |
+
/* @var $helper Mage_Catalog_Helper_Product */
|
69 |
+
$helper = Mage::helper('catalog/product');
|
70 |
+
if (method_exists($helper, 'getSkipSaleableCheck')) {
|
71 |
+
return $helper->getSkipSaleableCheck();
|
72 |
+
}
|
73 |
+
return false;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* retrieve current store
|
78 |
+
*
|
79 |
+
* @return Mage_Core_Model_Store
|
80 |
+
*/
|
81 |
+
public function getCurrentStore()
|
82 |
+
{
|
83 |
+
return Mage::app()->getStore();
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Composes configuration for js
|
88 |
+
*
|
89 |
+
* @param Mage_Catalog_Model_Product $currentProduct
|
90 |
+
* @param $includePrice bool
|
91 |
+
* @return array
|
92 |
+
*/
|
93 |
+
public function getConfigurableAttributes(Mage_Catalog_Model_Product $currentProduct, $includePrice = false)
|
94 |
+
{
|
95 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
96 |
+
$helper = Mage::helper('japi/product');
|
97 |
+
|
98 |
+
$isNeedPrice = false;
|
99 |
+
if ($helper->isSCPActive()) {
|
100 |
+
$isNeedPrice = true;
|
101 |
+
}
|
102 |
+
|
103 |
+
$attributes = array();
|
104 |
+
$options = array();
|
105 |
+
|
106 |
+
foreach ($this->getAllowProducts($currentProduct) as $product) {
|
107 |
+
/* @var $product Mage_Catalog_Model_Product */
|
108 |
+
$productId = $product->getId();
|
109 |
+
|
110 |
+
if ($isNeedPrice) {
|
111 |
+
$product->load($product->getId(), 'final_price');
|
112 |
+
}
|
113 |
+
|
114 |
+
foreach ($this->getAllowAttributes($currentProduct) as $attribute) {
|
115 |
+
$productAttribute = $attribute->getProductAttribute();
|
116 |
+
if (!$productAttribute) continue;
|
117 |
+
$productAttributeId = $productAttribute->getId();
|
118 |
+
$attributeValue = $product->getData($productAttribute->getAttributeCode());
|
119 |
+
|
120 |
+
if (!isset($options[$productAttributeId])) {
|
121 |
+
$options[$productAttributeId] = array();
|
122 |
+
}
|
123 |
+
|
124 |
+
if (!isset($options[$productAttributeId][$attributeValue])) {
|
125 |
+
$options[$productAttributeId][$attributeValue] = array();
|
126 |
+
}
|
127 |
+
|
128 |
+
$temp = array(
|
129 |
+
'id' => $productId,
|
130 |
+
'sku' => $product->getSku(),
|
131 |
+
'stock' => $product->getStockItem() ? $product->getStockItem()->getQty() : null,
|
132 |
+
'is_in_stock' => $product->getStockItem() ? (int)$product->getStockItem()->getIsInStock() : null,
|
133 |
+
'is_saleable' => (int)$product->isSaleable()
|
134 |
+
);
|
135 |
+
|
136 |
+
if ($isNeedPrice && $includePrice) {
|
137 |
+
$temp['final_price'] = $helper->calculatePriceIncludeTax($product, $product->getFinalPrice());
|
138 |
+
}
|
139 |
+
|
140 |
+
$options[$productAttributeId][$attributeValue][] = $temp;
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
foreach ($this->getAllowAttributes($currentProduct) as $attribute) {
|
145 |
+
$productAttribute = $attribute->getProductAttribute();
|
146 |
+
if (!$productAttribute) continue;
|
147 |
+
$attributeId = $productAttribute->getId();
|
148 |
+
$info = array(
|
149 |
+
'id' => $productAttribute->getId(),
|
150 |
+
'code' => $productAttribute->getAttributeCode(),
|
151 |
+
'label' => $attribute->getLabel(),
|
152 |
+
'options' => array()
|
153 |
+
);
|
154 |
+
|
155 |
+
$optionPrices = array();
|
156 |
+
$prices = $attribute->getPrices();
|
157 |
+
|
158 |
+
if (is_array($prices)) {
|
159 |
+
foreach ($prices as $value) {
|
160 |
+
if (!$this->_validateAttributeValue($attributeId, $value, $options)) {
|
161 |
+
continue;
|
162 |
+
}
|
163 |
+
$currentProduct->setConfigurablePrice(
|
164 |
+
$this->_preparePrice($currentProduct, $value['pricing_value'], $value['is_percent'])
|
165 |
+
);
|
166 |
+
$currentProduct->setParentId(true);
|
167 |
+
Mage::dispatchEvent(
|
168 |
+
'catalog_product_type_configurable_price',
|
169 |
+
array('product' => $currentProduct)
|
170 |
+
);
|
171 |
+
$configurablePrice = $currentProduct->getConfigurablePrice();
|
172 |
+
|
173 |
+
if (isset($options[$attributeId][$value['value_index']])) {
|
174 |
+
$productsIndex = $options[$attributeId][$value['value_index']];
|
175 |
+
} else {
|
176 |
+
$productsIndex = array();
|
177 |
+
}
|
178 |
+
|
179 |
+
$info['options'][] = array(
|
180 |
+
'id' => $value['value_index'],
|
181 |
+
'label' => $value['label'],
|
182 |
+
'price' => $configurablePrice,
|
183 |
+
'oldPrice' => $this->_prepareOldPrice($currentProduct, $value['pricing_value'], $value['is_percent']),
|
184 |
+
'products' => $productsIndex,
|
185 |
+
);
|
186 |
+
$optionPrices[] = $configurablePrice;
|
187 |
+
}
|
188 |
+
}
|
189 |
+
if ($this->_validateAttributeInfo($info)) {
|
190 |
+
$attributes[] = $info;
|
191 |
+
}
|
192 |
+
}
|
193 |
+
return $attributes;
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Validating of super product option value
|
198 |
+
*
|
199 |
+
* @param array $attributeId
|
200 |
+
* @param array $value
|
201 |
+
* @param array $options
|
202 |
+
* @return boolean
|
203 |
+
*/
|
204 |
+
protected function _validateAttributeValue($attributeId, &$value, &$options)
|
205 |
+
{
|
206 |
+
if (isset($options[$attributeId][$value['value_index']])) {
|
207 |
+
return true;
|
208 |
+
}
|
209 |
+
|
210 |
+
return false;
|
211 |
+
}
|
212 |
+
|
213 |
+
/**
|
214 |
+
* Validation of super product option
|
215 |
+
*
|
216 |
+
* @param array $info
|
217 |
+
* @return boolean
|
218 |
+
*/
|
219 |
+
protected function _validateAttributeInfo(&$info)
|
220 |
+
{
|
221 |
+
if (count($info['options']) > 0) {
|
222 |
+
return true;
|
223 |
+
}
|
224 |
+
return false;
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Calculation real price
|
229 |
+
*
|
230 |
+
* @param Mage_Catalog_Model_Product $product
|
231 |
+
* @param float $price
|
232 |
+
* @param bool $isPercent
|
233 |
+
* @return mixed
|
234 |
+
*/
|
235 |
+
protected function _preparePrice(Mage_Catalog_Model_Product $product, $price, $isPercent = false)
|
236 |
+
{
|
237 |
+
if ($isPercent && !empty($price)) {
|
238 |
+
$price = $product->getFinalPrice() * $price / 100;
|
239 |
+
}
|
240 |
+
|
241 |
+
/* @var $taxHelper Japi_Product_Helper */
|
242 |
+
$configurableItemPriceWithTax = Mage::helper('japi/product')->calculatePriceIncludeTax($product, $price);
|
243 |
+
|
244 |
+
return $this->_registerJsPrice($this->_convertPrice($configurableItemPriceWithTax, true));
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* Calculation price before special price
|
249 |
+
*
|
250 |
+
* @param Mage_Catalog_Model_Product $product
|
251 |
+
* @param float $price
|
252 |
+
* @param bool $isPercent
|
253 |
+
* @return mixed
|
254 |
+
*/
|
255 |
+
protected function _prepareOldPrice(Mage_Catalog_Model_Product $product, $price, $isPercent = false)
|
256 |
+
{
|
257 |
+
if ($isPercent && !empty($price)) {
|
258 |
+
$price = $product->getPrice() * $price / 100;
|
259 |
+
}
|
260 |
+
|
261 |
+
/* @var $taxHelper Japi_Product_Helper */
|
262 |
+
$configurableItemPriceWithTax = Mage::helper('japi/product')->calculatePriceIncludeTax($product, $price);
|
263 |
+
|
264 |
+
return $this->_registerJsPrice($this->_convertPrice($configurableItemPriceWithTax, true));
|
265 |
+
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Replace ',' on '.' for js
|
269 |
+
*
|
270 |
+
* @param float $price
|
271 |
+
* @return string
|
272 |
+
*/
|
273 |
+
protected function _registerJsPrice($price)
|
274 |
+
{
|
275 |
+
return str_replace(',', '.', $price);
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Convert price from default currency to current currency
|
280 |
+
*
|
281 |
+
* @param float $price
|
282 |
+
* @param boolean $round
|
283 |
+
* @return float
|
284 |
+
*/
|
285 |
+
protected function _convertPrice($price, $round = false)
|
286 |
+
{
|
287 |
+
if (empty($price)) {
|
288 |
+
return 0;
|
289 |
+
}
|
290 |
+
|
291 |
+
$price = $this->getCurrentStore()->convertPrice($price);
|
292 |
+
if ($round) {
|
293 |
+
$price = $this->getCurrentStore()->roundPrice($price);
|
294 |
+
}
|
295 |
+
|
296 |
+
return $price;
|
297 |
+
}
|
298 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Product/Downloadable.php
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_Product_Downloadable extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Retrieve downloadable product links
|
7 |
+
*
|
8 |
+
* @param Mage_Catalog_Model_Product $product
|
9 |
+
* @return array
|
10 |
+
*/
|
11 |
+
public function getDownloadableLinks(Mage_Catalog_Model_Product $product)
|
12 |
+
{
|
13 |
+
$linkArr = array();
|
14 |
+
$links = $product->getTypeInstance(true)->getLinks($product);
|
15 |
+
foreach ($links as $item) {
|
16 |
+
$tmpLinkItem = array(
|
17 |
+
'link_id' => $item->getId(),
|
18 |
+
'title' => $item->getTitle(),
|
19 |
+
'price' => $item->getPrice(),
|
20 |
+
'number_of_downloads' => $item->getNumberOfDownloads(),
|
21 |
+
'is_shareable' => $item->getIsShareable(),
|
22 |
+
'link_url' => $item->getLinkUrl(),
|
23 |
+
'link_type' => $item->getLinkType(),
|
24 |
+
'sample_file' => $item->getSampleFile(),
|
25 |
+
'sample_url' => $item->getSampleUrl(),
|
26 |
+
'sample_type' => $item->getSampleType(),
|
27 |
+
'sort_order' => $item->getSortOrder()
|
28 |
+
);
|
29 |
+
$file = Mage::helper('downloadable/file')->getFilePath(
|
30 |
+
Mage_Downloadable_Model_Link::getBasePath(), $item->getLinkFile()
|
31 |
+
);
|
32 |
+
|
33 |
+
if ($item->getLinkFile() && !is_file($file)) {
|
34 |
+
Mage::helper('core/file_storage_database')->saveFileToFilesystem($file);
|
35 |
+
}
|
36 |
+
|
37 |
+
if ($item->getLinkFile() && is_file($file)) {
|
38 |
+
$name = Mage::helper('downloadable/file')->getFileFromPathFile($item->getLinkFile());
|
39 |
+
$tmpLinkItem['file_save'] = array(
|
40 |
+
array(
|
41 |
+
'file' => $item->getLinkFile(),
|
42 |
+
'name' => $name,
|
43 |
+
'size' => filesize($file),
|
44 |
+
'status' => 'old'
|
45 |
+
));
|
46 |
+
}
|
47 |
+
$sampleFile = Mage::helper('downloadable/file')->getFilePath(
|
48 |
+
Mage_Downloadable_Model_Link::getBaseSamplePath(), $item->getSampleFile()
|
49 |
+
);
|
50 |
+
if ($item->getSampleFile() && is_file($sampleFile)) {
|
51 |
+
$tmpLinkItem['sample_file_save'] = array(
|
52 |
+
array(
|
53 |
+
'file' => $item->getSampleFile(),
|
54 |
+
'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
|
55 |
+
'size' => filesize($sampleFile),
|
56 |
+
'status' => 'old'
|
57 |
+
));
|
58 |
+
}
|
59 |
+
if ($item->getNumberOfDownloads() == '0') {
|
60 |
+
$tmpLinkItem['is_unlimited'] = 1;
|
61 |
+
}
|
62 |
+
if ($product->getStoreId() && $item->getStoreTitle()) {
|
63 |
+
$tmpLinkItem['store_title'] = $item->getStoreTitle();
|
64 |
+
}
|
65 |
+
if ($product->getStoreId() ) {
|
66 |
+
$tmpLinkItem['website_price'] = $item->getWebsitePrice();
|
67 |
+
}
|
68 |
+
$linkArr[] = $tmpLinkItem;
|
69 |
+
}
|
70 |
+
unset($item);
|
71 |
+
unset($tmpLinkItem);
|
72 |
+
unset($links);
|
73 |
+
|
74 |
+
$samples = $product->getTypeInstance(true)->getSamples($product)->getData();
|
75 |
+
return array('links' => $linkArr, 'samples' => $samples);
|
76 |
+
}
|
77 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Product/Grouped.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_Product_Grouped extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Returns items of grouped product according to Api Response format
|
7 |
+
*
|
8 |
+
* @param Mage_Catalog_Model_Product $product
|
9 |
+
* @param $includePrice bool
|
10 |
+
* @return array
|
11 |
+
*/
|
12 |
+
public function getGroupedItems(Mage_Catalog_Model_Product $product, $includePrice = false)
|
13 |
+
{
|
14 |
+
$items = $product->getTypeInstance(true)->getAssociatedProducts($product);
|
15 |
+
|
16 |
+
$result = array();
|
17 |
+
$index = 0;
|
18 |
+
foreach ($items as $item) {
|
19 |
+
$result[] = $this->_convertItemToArray($item, $includePrice, $index++);
|
20 |
+
}
|
21 |
+
return $result;
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Converts item into array according to Api Response format
|
26 |
+
*
|
27 |
+
* @param Mage_Catalog_Model_Product $item
|
28 |
+
* @param $includePrice bool
|
29 |
+
* @param $index int
|
30 |
+
* @return array
|
31 |
+
*/
|
32 |
+
protected function _convertItemToArray(Mage_Catalog_Model_Product $item, $includePrice = false, $index = null)
|
33 |
+
{
|
34 |
+
$result = array();
|
35 |
+
|
36 |
+
$result['product_id'] = $item->getEntityId();
|
37 |
+
$result['sku'] = $item->getSku();
|
38 |
+
$result['name'] = $item->getName();
|
39 |
+
|
40 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
41 |
+
$helper = Mage::helper('japi/product');
|
42 |
+
|
43 |
+
try {
|
44 |
+
$result['showImage'] = Mage::getStoreConfigFlag('japi/jmango_rest_catalog_settings/show_grouped_item_image');
|
45 |
+
if ($result['showImage']) {
|
46 |
+
$imageType = Mage::getStoreConfig('japi/jmango_rest_gallery_settings/image_default_listing');
|
47 |
+
if (!$imageType) $imageType = 'thumbnail';
|
48 |
+
/* @var $imageHelper Mage_Catalog_Helper_Image */
|
49 |
+
$imageHelper = Mage::helper('catalog/image');
|
50 |
+
$size = $helper->getImageSizes();
|
51 |
+
$result['image'] = (string)$imageHelper
|
52 |
+
->init($item, $imageType, $item->getData($imageType))
|
53 |
+
->resize($size[$imageType]['width'], $size[$imageType]['height']);
|
54 |
+
} else {
|
55 |
+
$result['image'] = '';
|
56 |
+
}
|
57 |
+
} catch (Exception $e) {
|
58 |
+
Mage::logException($e);
|
59 |
+
$result['image'] = '';
|
60 |
+
}
|
61 |
+
|
62 |
+
$selectionPriceWithTax = $helper->calculatePriceIncludeTax($item, $item->getFinalPrice());
|
63 |
+
$result['price'] = (string)$selectionPriceWithTax;
|
64 |
+
if ($includePrice) {
|
65 |
+
$result['final_price'] = $selectionPriceWithTax;
|
66 |
+
$result['base_price'] = $helper->calculatePriceIncludeTax($item, $item->getPrice());
|
67 |
+
}
|
68 |
+
|
69 |
+
$result['is_saleable'] = (int)$item->isSaleable();
|
70 |
+
$result['position'] = $index !== null ? $index : (int)$item->getPosition();
|
71 |
+
$result['qty'] = $item->getQty();
|
72 |
+
$result['stock'] = $item->getStockItem() ? $item->getStockItem()->getQty() : null;
|
73 |
+
$result['is_in_stock'] = $item->getStockItem() ? (int)$item->getStockItem()->getIsInStock() : null;
|
74 |
+
|
75 |
+
// Load tier price if present
|
76 |
+
/* @var $tierPriceHelper Jmango360_Japi_Helper_Product_TierPrice */
|
77 |
+
$tierPriceHelper = Mage::helper('japi/product_tierPrice');
|
78 |
+
$result['tier_price'] = $tierPriceHelper->getTierPriceInfo($item);
|
79 |
+
|
80 |
+
return $result;
|
81 |
+
}
|
82 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Product/Media.php
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* DEPRICATED (repaced by method _addMediaUrls in product helper)
|
6 |
+
* -- before removing this helper add media gallery to the product collection
|
7 |
+
* -- in a Magento way
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
class Jmango360_Japi_Helper_Product_Media extends Mage_Core_Helper_Abstract
|
11 |
+
{
|
12 |
+
/**
|
13 |
+
* Default image attribute code set
|
14 |
+
*
|
15 |
+
* @var array
|
16 |
+
*/
|
17 |
+
protected $_imageDefaultAttributeCodes = array('image', 'small_image', 'thumbnail');
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Adds media_gallery to product collection
|
21 |
+
*
|
22 |
+
* @param Mage_Catalog_Model_Resource_Product_Collection $productCollection
|
23 |
+
* @return Mage_Catalog_Model_Resource_Product_Collection
|
24 |
+
*/
|
25 |
+
public function addMediaGalleryAttributeToCollection(Mage_Catalog_Model_Resource_Product_Collection $productCollection)
|
26 |
+
{
|
27 |
+
$mediaGalleryAttributeId = Mage::getSingleton('eav/config')
|
28 |
+
->getAttribute('catalog_product', 'media_gallery')
|
29 |
+
->getAttributeId();
|
30 |
+
|
31 |
+
/* @var $resource Mage_Core_Model_Resource */
|
32 |
+
$resource = Mage::getSingleton('core/resource');
|
33 |
+
$connection = $resource->getConnection('catalog_read');
|
34 |
+
|
35 |
+
$select = $connection->select()->reset();
|
36 |
+
$select->from(
|
37 |
+
array('main' => $resource->getTableName('catalog/product_attribute_media_gallery')),
|
38 |
+
array('entity_id', 'value_id', 'file' => 'value')
|
39 |
+
);
|
40 |
+
$select->joinLeft(
|
41 |
+
array('value' => $resource->getTableName('catalog/product_attribute_media_gallery_value')),
|
42 |
+
'main.value_id=value.value_id AND value.store_id=' . Mage::app()->getStore()->getId(),
|
43 |
+
array('label', 'position', 'disabled')
|
44 |
+
);
|
45 |
+
$select->joinLeft(
|
46 |
+
array('default_value' => $resource->getTableName('catalog/product_attribute_media_gallery_value')),
|
47 |
+
'main.value_id=default_value.value_id AND default_value.store_id=0',
|
48 |
+
array(
|
49 |
+
'label_default' => 'default_value.label',
|
50 |
+
'position_default' => 'default_value.position',
|
51 |
+
'disabled_default' => 'default_value.disabled'
|
52 |
+
)
|
53 |
+
);
|
54 |
+
$select->where('main.attribute_id=?', $mediaGalleryAttributeId);
|
55 |
+
$select->where('main.entity_id IN(?)', $this->_getAllIds($productCollection));
|
56 |
+
$select->order('IF(value.position IS NULL, default_value.position, value.position) ASC');
|
57 |
+
|
58 |
+
$mediaGalleryData = $connection->fetchAll($select);
|
59 |
+
|
60 |
+
$mediaGalleryByProductId = array();
|
61 |
+
foreach ($mediaGalleryData as $galleryImage) {
|
62 |
+
$k = $galleryImage['entity_id'];
|
63 |
+
unset($galleryImage['entity_id']);
|
64 |
+
if (!isset($mediaGalleryByProductId[$k])) {
|
65 |
+
$mediaGalleryByProductId[$k] = array();
|
66 |
+
}
|
67 |
+
$mediaGalleryByProductId[$k][] = $galleryImage;
|
68 |
+
}
|
69 |
+
unset($mediaGalleryData);
|
70 |
+
foreach ($productCollection as $product) {
|
71 |
+
$productId = $product->getEntityId();
|
72 |
+
if (isset($mediaGalleryByProductId[$productId])) {
|
73 |
+
$product->setData('media_gallery', array('images' => $mediaGalleryByProductId[$productId]));
|
74 |
+
}
|
75 |
+
}
|
76 |
+
unset($mediaGalleryByProductId);
|
77 |
+
$productCollection->addAttributeToSelect($this->_imageDefaultAttributeCodes);
|
78 |
+
return $productCollection;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Standard function doesn't suit our requirements because it doesn't have order by category position
|
83 |
+
*
|
84 |
+
* @param $productCollection
|
85 |
+
* @return array
|
86 |
+
*/
|
87 |
+
protected function _getAllIds($productCollection)
|
88 |
+
{
|
89 |
+
$ids = array();
|
90 |
+
foreach ($productCollection as $product) {
|
91 |
+
$ids[] = $product->getId();
|
92 |
+
}
|
93 |
+
|
94 |
+
return $ids;
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Returns media info as array (needed for api)
|
99 |
+
*
|
100 |
+
* @param Mage_Catalog_Model_Product $product
|
101 |
+
* @return array
|
102 |
+
*/
|
103 |
+
public function getMediaInfo(Mage_Catalog_Model_Product $product)
|
104 |
+
{
|
105 |
+
$galleryData = $product->getData('media_gallery');
|
106 |
+
|
107 |
+
if (!isset($galleryData['images']) || !is_array($galleryData['images'])) {
|
108 |
+
return array();
|
109 |
+
}
|
110 |
+
|
111 |
+
$result = array();
|
112 |
+
|
113 |
+
foreach ($galleryData['images'] as &$image) {
|
114 |
+
$result[] = $this->_imageToArray($image, $product);
|
115 |
+
}
|
116 |
+
|
117 |
+
return $result;
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Converts image to api array data
|
122 |
+
*
|
123 |
+
* @param array $image
|
124 |
+
* @param Mage_Catalog_Model_Product $product
|
125 |
+
* @return array
|
126 |
+
*/
|
127 |
+
protected function _imageToArray(&$image, $product)
|
128 |
+
{
|
129 |
+
$attributes = array();
|
130 |
+
|
131 |
+
// Get image attributes
|
132 |
+
foreach ($product->getMediaAttributes() as $attribute) {
|
133 |
+
if ($product->getData($attribute->getAttributeCode()) == $image['file']) {
|
134 |
+
$attributes[] = $attribute->getAttributeCode();
|
135 |
+
}
|
136 |
+
}
|
137 |
+
|
138 |
+
$storeUrl = Mage::getBaseUrl() . 'japi/image/index';
|
139 |
+
|
140 |
+
// specify storeId
|
141 |
+
$storeUrl = $storeUrl . '/store/' . Mage::app()->getStore()->getId();
|
142 |
+
|
143 |
+
// specify productId
|
144 |
+
$storeUrl = $storeUrl . '/id/' . $product->getId();
|
145 |
+
|
146 |
+
$result = array(
|
147 |
+
'file' => $image['file'],
|
148 |
+
'label' => $image['label'] === null ? $image['label_default'] : $image['label'],
|
149 |
+
'position' => $image['position'] === null ? $image['position_default'] : $image['position'],
|
150 |
+
'exclude' => $image['disabled'] === null ? $image['disabled_default'] : $image['disabled'],
|
151 |
+
'url' => $storeUrl . '/?file=' . $image['file'],
|
152 |
+
'types' => $attributes
|
153 |
+
);
|
154 |
+
|
155 |
+
return $result;
|
156 |
+
}
|
157 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Product/Options.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_Product_Options extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
protected $excludeTypes = array('date', 'date_time', 'time');
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Retrieve list of product custom options
|
9 |
+
*
|
10 |
+
* @param Mage_Catalog_Model_Product $product
|
11 |
+
* @return array
|
12 |
+
*/
|
13 |
+
public function getOptionList(Mage_Catalog_Model_Product $product)
|
14 |
+
{
|
15 |
+
$result = array();
|
16 |
+
/** @var $option Mage_Catalog_Model_Product_Option */
|
17 |
+
foreach ($product->getProductOptionsCollection() as $option) {
|
18 |
+
if (in_array($option->getType(), $this->excludeTypes)) continue;
|
19 |
+
$result[] = $this->_getOptionInfo($product, $option);
|
20 |
+
}
|
21 |
+
return $result;
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Get full information about custom option in product
|
26 |
+
*
|
27 |
+
* @param Mage_Catalog_Model_Product_Option $option
|
28 |
+
* @return array
|
29 |
+
*/
|
30 |
+
protected function _getOptionInfo(Mage_Catalog_Model_Product $product, Mage_Catalog_Model_Product_Option $option)
|
31 |
+
{
|
32 |
+
$optionPriceWithTax = $this->_preparePrice($product, $option->getPrice(), $option->getPriceType());
|
33 |
+
|
34 |
+
$result = array(
|
35 |
+
'option_id' => $option->getId(),
|
36 |
+
'title' => $option->getTitle(),
|
37 |
+
'type' => $option->getType(),
|
38 |
+
'is_require' => $option->getIsRequire(),
|
39 |
+
'sort_order' => $option->getSortOrder(),
|
40 |
+
// additional_fields should be two-dimensional array for all option types
|
41 |
+
'additional_fields' => array(
|
42 |
+
array(
|
43 |
+
'price' => $optionPriceWithTax,
|
44 |
+
'price_type' => $option->getPriceType(),
|
45 |
+
'sku' => $option->getSku()
|
46 |
+
)
|
47 |
+
)
|
48 |
+
);
|
49 |
+
|
50 |
+
// MPLUGIN-648: Advanced Product Options compatibility
|
51 |
+
switch ($option->getType()) {
|
52 |
+
case 'swatch':
|
53 |
+
$result['type'] = 'drop_down';
|
54 |
+
break;
|
55 |
+
case 'multiswatch':
|
56 |
+
$result['type'] = 'multiple';
|
57 |
+
break;
|
58 |
+
}
|
59 |
+
|
60 |
+
// Set additional fields to each type group
|
61 |
+
switch ($option->getGroupByType()) {
|
62 |
+
case Mage_Catalog_Model_Product_Option::OPTION_GROUP_TEXT:
|
63 |
+
$result['additional_fields'][0]['max_characters'] = $option->getMaxCharacters();
|
64 |
+
break;
|
65 |
+
case Mage_Catalog_Model_Product_Option::OPTION_GROUP_FILE:
|
66 |
+
$result['additional_fields'][0]['file_extension'] = $option->getFileExtension();
|
67 |
+
$result['additional_fields'][0]['image_size_x'] = $option->getImageSizeX();
|
68 |
+
$result['additional_fields'][0]['image_size_y'] = $option->getImageSizeY();
|
69 |
+
break;
|
70 |
+
case Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT:
|
71 |
+
$result['additional_fields'] = array();
|
72 |
+
foreach ($option->getValues() as $value) {
|
73 |
+
$valuePriceWithTax = $this->_preparePrice($product, $value->getPrice(), $value->getPriceType());
|
74 |
+
$result['additional_fields'][] = array(
|
75 |
+
'value_id' => $value->getId(),
|
76 |
+
'title' => $value->getTitle(),
|
77 |
+
'price' => $valuePriceWithTax,
|
78 |
+
'price_type' => $value->getPriceType(),
|
79 |
+
'sku' => $value->getSku(),
|
80 |
+
'sort_order' => $value->getSortOrder()
|
81 |
+
);
|
82 |
+
}
|
83 |
+
break;
|
84 |
+
}
|
85 |
+
|
86 |
+
return $result;
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Calculation real price
|
91 |
+
*
|
92 |
+
* @param Mage_Catalog_Model_Product $product
|
93 |
+
* @param float $optionPrice
|
94 |
+
* @param string $priceType
|
95 |
+
* @return mixed
|
96 |
+
*/
|
97 |
+
protected function _preparePrice(Mage_Catalog_Model_Product $product, $optionPrice, $priceType)
|
98 |
+
{
|
99 |
+
if (!empty($priceType) && strcasecmp($priceType, 'percent') == 0) {
|
100 |
+
$optionPrice = $product->getFinalPrice() * $optionPrice / 100;
|
101 |
+
}
|
102 |
+
|
103 |
+
/* @var $taxHelper Japi_Product_Helper */
|
104 |
+
$configurableItemPriceWithTax = Mage::helper('japi/product')->calculatePriceIncludeTax($product, $optionPrice);
|
105 |
+
|
106 |
+
return (string)$configurableItemPriceWithTax;
|
107 |
+
}
|
108 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Product/TierPrice.php
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_Product_TierPrice extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Returns price info as array (needed for api)
|
7 |
+
*
|
8 |
+
* @param Mage_Catalog_Model_Product $product
|
9 |
+
* @return array
|
10 |
+
*/
|
11 |
+
public function getTierPriceInfo(Mage_Catalog_Model_Product $product)
|
12 |
+
{
|
13 |
+
if ($this->isModuleEnabled('Magpleasure_Tierprices')) { // Check if extension Amasty 'Magpleasure_Tierprices' is enabled
|
14 |
+
$tierPriceResourceMysql = new Magpleasure_Tierprices_Model_Mysql4_Product_Attribute_Backend_Tierprice;
|
15 |
+
$priceData = $tierPriceResourceMysql->loadPriceData($product->getId());
|
16 |
+
|
17 |
+
/* @var $_customTierpriceHelper Magpleasure_Tierprices_Helper_Data */
|
18 |
+
$_customTierpriceHelper = Mage::helper('tierprices');
|
19 |
+
if ($_customTierpriceHelper->confUseFinalPrice()) {
|
20 |
+
$productPrice = $product->getFinalPrice();
|
21 |
+
} else {
|
22 |
+
$productPrice = $product->getPrice();
|
23 |
+
}
|
24 |
+
} else {
|
25 |
+
$priceData = $product->getTierPrice();
|
26 |
+
$productPrice = $product->getFinalPrice();
|
27 |
+
}
|
28 |
+
|
29 |
+
if (!isset($priceData) || !is_array($priceData)) {
|
30 |
+
return array();
|
31 |
+
}
|
32 |
+
|
33 |
+
$useEcomwiseTierPrice = $this->isModuleEnabled('Ecomwise_Mshop');
|
34 |
+
$result = array();
|
35 |
+
|
36 |
+
foreach ($priceData as $price) {
|
37 |
+
if ($this->isModuleEnabled('Magpleasure_Tierprices')) {
|
38 |
+
$result[] = $this->_priceToArray($product, $price, $productPrice);
|
39 |
+
} else {
|
40 |
+
if ($useEcomwiseTierPrice && isset($price['tier_type']) && $price['tier_type'] == 1 && $price['price'] < 100) {
|
41 |
+
$price['price'] = $productPrice - ($productPrice * $price['price']) / 100;
|
42 |
+
$price['website_price'] = $price['price'];
|
43 |
+
}
|
44 |
+
$result[] = $this->_priceToArray($product, $price, $productPrice);
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
return $result;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Converts tier price to api array data
|
53 |
+
*
|
54 |
+
* @param Mage_Catalog_Model_Product $product
|
55 |
+
* @param array $price
|
56 |
+
* @param float $productPrice
|
57 |
+
* @return array
|
58 |
+
*/
|
59 |
+
protected function _priceToArray(Mage_Catalog_Model_Product $product, $price, $productPrice)
|
60 |
+
{
|
61 |
+
$result = array(
|
62 |
+
'customer_group_id' => $price['cust_group'],
|
63 |
+
'website' => $price['website_id'],
|
64 |
+
'qty' => $price['price_qty'],
|
65 |
+
'price' => $this->_preparePrice($product, $price['price']),
|
66 |
+
'savePercent' => $productPrice ? ceil(100 - ((100 / $productPrice) * $price['price'])) : null
|
67 |
+
);
|
68 |
+
|
69 |
+
return $result;
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Calculation real price
|
74 |
+
*
|
75 |
+
* @param Mage_Catalog_Model_Product $product
|
76 |
+
* @param float $optionPrice
|
77 |
+
* @return mixed
|
78 |
+
*/
|
79 |
+
protected function _preparePrice(Mage_Catalog_Model_Product $product, $optionPrice)
|
80 |
+
{
|
81 |
+
$tierPriceWithTax = $optionPrice;
|
82 |
+
|
83 |
+
// If not Bundle product then calculate tax. Bundle always return percentage
|
84 |
+
if ($product->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
|
85 |
+
$taxHelper = Mage::helper('japi/product');
|
86 |
+
/* @var $taxHelper Jmango360_Japi_Helper_Product */
|
87 |
+
$tierPriceWithTax = $taxHelper->calculatePriceIncludeTax($product, $optionPrice);
|
88 |
+
}
|
89 |
+
|
90 |
+
return (string)$tierPriceWithTax;
|
91 |
+
}
|
92 |
+
}
|
app/code/community/Jmango360/Japi/Helper/Tax.php
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Helper_Tax extends Mage_Tax_Helper_Data
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Get product price with all tax settings processing
|
7 |
+
*
|
8 |
+
* @param Mage_Catalog_Model_Product $product
|
9 |
+
* @param float $price inputed product price
|
10 |
+
* @param bool $includingTax return price include tax flag
|
11 |
+
* @param null|Mage_Customer_Model_Address $shippingAddress
|
12 |
+
* @param null|Mage_Customer_Model_Address $billingAddress
|
13 |
+
* @param null|int $ctc customer tax class
|
14 |
+
* @param mixed $store
|
15 |
+
* @param bool $priceIncludesTax flag what price parameter contain tax
|
16 |
+
* @param bool $roundTax flag if price should be rounded
|
17 |
+
* @return float
|
18 |
+
*/
|
19 |
+
public function getPrice($product,
|
20 |
+
$price,
|
21 |
+
$includingTax = null,
|
22 |
+
$shippingAddress = null,
|
23 |
+
$billingAddress = null,
|
24 |
+
$ctc = null,
|
25 |
+
$store = null,
|
26 |
+
$priceIncludesTax = null,
|
27 |
+
$roundTax = false
|
28 |
+
)
|
29 |
+
{
|
30 |
+
if (!$price) {
|
31 |
+
return $price;
|
32 |
+
}
|
33 |
+
|
34 |
+
$store = Mage::app()->getStore($store);
|
35 |
+
if (!$this->needPriceConversion($store)) {
|
36 |
+
return $store->roundPrice($price);
|
37 |
+
}
|
38 |
+
|
39 |
+
if (is_null($priceIncludesTax)) {
|
40 |
+
$priceIncludesTax = $this->priceIncludesTax($store);
|
41 |
+
}
|
42 |
+
|
43 |
+
$percent = $product->getTaxPercent();
|
44 |
+
$includingPercent = null;
|
45 |
+
|
46 |
+
$taxClassId = $product->getTaxClassId();
|
47 |
+
if (is_null($percent)) {
|
48 |
+
if ($taxClassId) {
|
49 |
+
$request = Mage::getSingleton('tax/calculation')
|
50 |
+
->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
|
51 |
+
$percent = Mage::getSingleton('tax/calculation')
|
52 |
+
->getRate($request->setProductClassId($taxClassId));
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
if ($taxClassId && $priceIncludesTax) {
|
57 |
+
$request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false, $store);
|
58 |
+
$includingPercent = Mage::getSingleton('tax/calculation')
|
59 |
+
->getRate($request->setProductClassId($taxClassId));
|
60 |
+
}
|
61 |
+
|
62 |
+
if ($percent === false || is_null($percent)) {
|
63 |
+
if ($priceIncludesTax && !$includingPercent) {
|
64 |
+
return $price;
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
$product->setTaxPercent($percent);
|
69 |
+
|
70 |
+
if (!is_null($includingTax)) {
|
71 |
+
if ($priceIncludesTax) {
|
72 |
+
if ($includingTax) {
|
73 |
+
/**
|
74 |
+
* Recalculate price include tax in case of different rates
|
75 |
+
*/
|
76 |
+
if ($includingPercent != $percent) {
|
77 |
+
$price = $this->_calculatePrice($price, $includingPercent, false);
|
78 |
+
/**
|
79 |
+
* Using regular rounding. Ex:
|
80 |
+
* price incl tax = 52.76
|
81 |
+
* store tax rate = 19.6%
|
82 |
+
* customer tax rate= 19%
|
83 |
+
*
|
84 |
+
* price excl tax = 52.76 / 1.196 = 44.11371237 ~ 44.11
|
85 |
+
* tax = 44.11371237 * 0.19 = 8.381605351 ~ 8.38
|
86 |
+
* price incl tax = 52.49531773 ~ 52.50 != 52.49
|
87 |
+
*
|
88 |
+
* that why we need round prices excluding tax before applying tax
|
89 |
+
* this calculation is used for showing prices on catalog pages
|
90 |
+
*/
|
91 |
+
if ($percent != 0) {
|
92 |
+
$price = $this->getCalculator()->round($price);
|
93 |
+
$price = $this->_calculatePrice($price, $percent, true);
|
94 |
+
}
|
95 |
+
}
|
96 |
+
} else {
|
97 |
+
$price = $this->_calculatePrice($price, $includingPercent, false);
|
98 |
+
}
|
99 |
+
} else {
|
100 |
+
if ($includingTax) {
|
101 |
+
$price = $this->_calculatePrice($price, $percent, true);
|
102 |
+
}
|
103 |
+
}
|
104 |
+
} else {
|
105 |
+
if ($priceIncludesTax) {
|
106 |
+
switch ($this->getPriceDisplayType($store)) {
|
107 |
+
case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
|
108 |
+
case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
|
109 |
+
$price = $this->_calculatePrice($price, $includingPercent, false);
|
110 |
+
break;
|
111 |
+
|
112 |
+
case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
|
113 |
+
$price = $this->_calculatePrice($price, $includingPercent, false);
|
114 |
+
$price = $this->_calculatePrice($price, $percent, true);
|
115 |
+
break;
|
116 |
+
}
|
117 |
+
} else {
|
118 |
+
switch ($this->getPriceDisplayType($store)) {
|
119 |
+
case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
|
120 |
+
$price = $this->_calculatePrice($price, $percent, true);
|
121 |
+
break;
|
122 |
+
|
123 |
+
case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
|
124 |
+
case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
|
125 |
+
break;
|
126 |
+
}
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
return $roundTax ? $store->roundPrice($price) : $price;
|
131 |
+
}
|
132 |
+
}
|
app/code/community/Jmango360/Japi/Model/Catalog/Layer/Filter/Attribute.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Catalog_Layer_Filter_Attribute extends Mage_Catalog_Model_Layer_Filter_Attribute
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Retrieve resource instance
|
7 |
+
*
|
8 |
+
* @return Jmango360_Japi_Model_Resource_Catalog_Layer_Filter_Attribute
|
9 |
+
*/
|
10 |
+
protected function _getResource()
|
11 |
+
{
|
12 |
+
if (is_null($this->_resource)) {
|
13 |
+
$this->_resource = Mage::getResourceModel('japi/catalog_layer_filter_attribute');
|
14 |
+
}
|
15 |
+
return $this->_resource;
|
16 |
+
}
|
17 |
+
}
|
app/code/community/Jmango360/Japi/Model/Catalog/Layer/Filter/Decimal.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Catalog_Layer_Filter_Decimal extends Mage_Catalog_Model_Layer_Filter_Decimal
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Retrieve resource instance
|
7 |
+
*
|
8 |
+
* @return Jmango360_Japi_Model_Resource_Catalog_Layer_Filter_Decimal
|
9 |
+
*/
|
10 |
+
protected function _getResource()
|
11 |
+
{
|
12 |
+
if (is_null($this->_resource)) {
|
13 |
+
$this->_resource = Mage::getResourceModel('japi/catalog_layer_filter_decimal');
|
14 |
+
}
|
15 |
+
return $this->_resource;
|
16 |
+
}
|
17 |
+
}
|
app/code/community/Jmango360/Japi/Model/Catalog/Layer/Filter/Price.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Catalog_Layer_Filter_Price extends Mage_Catalog_Model_Layer_Filter_Price
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Retrieve resource instance
|
7 |
+
*
|
8 |
+
* @return Jmango360_Japi_Model_Resource_Catalog_Layer_Filter_Price
|
9 |
+
*/
|
10 |
+
protected function _getResource()
|
11 |
+
{
|
12 |
+
if (is_null($this->_resource)) {
|
13 |
+
$this->_resource = Mage::getResourceModel('japi/catalog_layer_filter_price');
|
14 |
+
}
|
15 |
+
return $this->_resource;
|
16 |
+
}
|
17 |
+
}
|
app/code/community/Jmango360/Japi/Model/Catalogsearch/Layer/Filter/Attribute.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Catalogsearch_Layer_Filter_Attribute extends Mage_CatalogSearch_Model_Layer_Filter_Attribute
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Retrieve resource instance
|
7 |
+
*
|
8 |
+
* @return Jmango360_Japi_Model_Resource_Catalog_Layer_Filter_Attribute
|
9 |
+
*/
|
10 |
+
protected function _getResource()
|
11 |
+
{
|
12 |
+
if (is_null($this->_resource)) {
|
13 |
+
$this->_resource = Mage::getResourceModel('japi/catalog_layer_filter_attribute');
|
14 |
+
}
|
15 |
+
return $this->_resource;
|
16 |
+
}
|
17 |
+
}
|
app/code/community/Jmango360/Japi/Model/Core/Session.php
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Core_Session extends Mage_Core_Model_Session
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Configure and start session
|
7 |
+
*
|
8 |
+
* @param string $sessionName
|
9 |
+
* @return Mage_Core_Model_Session_Abstract_Varien
|
10 |
+
*/
|
11 |
+
public function start($sessionName = null)
|
12 |
+
{
|
13 |
+
if (isset($_SESSION) && !$this->getSkipEmptySessionCheck()) {
|
14 |
+
return $this;
|
15 |
+
}
|
16 |
+
|
17 |
+
// getSessionSaveMethod has to return correct version of handler in any case
|
18 |
+
$moduleName = $this->getSessionSaveMethod();
|
19 |
+
switch ($moduleName) {
|
20 |
+
/**
|
21 |
+
* backward compatibility with db argument (option is @deprecated after 1.12.0.2)
|
22 |
+
*/
|
23 |
+
case 'db':
|
24 |
+
$moduleName = 'user';
|
25 |
+
/* @var $sessionResource Mage_Core_Model_Resource_Session */
|
26 |
+
$sessionResource = Mage::getResourceSingleton('core/session');
|
27 |
+
$sessionResource->setSaveHandler();
|
28 |
+
break;
|
29 |
+
case 'user':
|
30 |
+
// getSessionSavePath represents static function for custom session handler setup
|
31 |
+
call_user_func($this->getSessionSavePath());
|
32 |
+
break;
|
33 |
+
case 'files':
|
34 |
+
//don't change path if it's not writable
|
35 |
+
if (!is_writable($this->getSessionSavePath())) {
|
36 |
+
break;
|
37 |
+
}
|
38 |
+
default:
|
39 |
+
session_save_path($this->getSessionSavePath());
|
40 |
+
break;
|
41 |
+
}
|
42 |
+
session_module_name($moduleName);
|
43 |
+
|
44 |
+
$cookie = $this->getCookie();
|
45 |
+
if (Mage::app()->getStore()->isAdmin()) {
|
46 |
+
$sessionMaxLifetime = Mage_Core_Model_Resource_Session::SEESION_MAX_COOKIE_LIFETIME;
|
47 |
+
$adminSessionLifetime = (int)Mage::getStoreConfig('admin/security/session_cookie_lifetime');
|
48 |
+
if ($adminSessionLifetime > $sessionMaxLifetime) {
|
49 |
+
$adminSessionLifetime = $sessionMaxLifetime;
|
50 |
+
}
|
51 |
+
if ($adminSessionLifetime > 60) {
|
52 |
+
$cookie->setLifetime($adminSessionLifetime);
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
// session cookie params
|
57 |
+
$cookieParams = array(
|
58 |
+
'lifetime' => $cookie->getLifetime(),
|
59 |
+
'path' => $cookie->getPath(),
|
60 |
+
'domain' => $cookie->getConfigDomain(),
|
61 |
+
'secure' => $cookie->isSecure(),
|
62 |
+
'httponly' => $cookie->getHttponly()
|
63 |
+
);
|
64 |
+
|
65 |
+
if (!$cookieParams['httponly']) {
|
66 |
+
unset($cookieParams['httponly']);
|
67 |
+
if (!$cookieParams['secure']) {
|
68 |
+
unset($cookieParams['secure']);
|
69 |
+
if (!$cookieParams['domain']) {
|
70 |
+
unset($cookieParams['domain']);
|
71 |
+
}
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
if (isset($cookieParams['domain'])) {
|
76 |
+
$cookieParams['domain'] = $cookie->getDomain();
|
77 |
+
}
|
78 |
+
|
79 |
+
call_user_func_array('session_set_cookie_params', $cookieParams);
|
80 |
+
|
81 |
+
if (!empty($sessionName)) {
|
82 |
+
$this->setSessionName($sessionName);
|
83 |
+
}
|
84 |
+
|
85 |
+
// potential custom logic for session id (ex. switching between hosts)
|
86 |
+
$this->setSessionId();
|
87 |
+
|
88 |
+
Varien_Profiler::start(__METHOD__ . '/start');
|
89 |
+
$sessionCacheLimiter = Mage::getConfig()->getNode('global/session_cache_limiter');
|
90 |
+
if ($sessionCacheLimiter) {
|
91 |
+
session_cache_limiter((string)$sessionCacheLimiter);
|
92 |
+
}
|
93 |
+
|
94 |
+
session_start();
|
95 |
+
|
96 |
+
// REMOVED SECURE CODE PREVENT MITM ATTACK (1.9.1.0+)
|
97 |
+
if (defined('self::SECURE_COOKIE_CHECK_KEY') && isset($_SESSION[self::SECURE_COOKIE_CHECK_KEY])) {
|
98 |
+
unset($_SESSION[self::SECURE_COOKIE_CHECK_KEY]);
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Renew cookie expiration time if session id did not change
|
103 |
+
*/
|
104 |
+
if ($cookie->get(session_name()) == $this->getSessionId()) {
|
105 |
+
$cookie->renew(session_name());
|
106 |
+
}
|
107 |
+
Varien_Profiler::stop(__METHOD__ . '/start');
|
108 |
+
|
109 |
+
// FORCE SESSION DATA TO CURRENT REQUEST TO BYPASS VALIDATOR
|
110 |
+
$this->_fakeSessionData();
|
111 |
+
|
112 |
+
return $this;
|
113 |
+
}
|
114 |
+
|
115 |
+
protected function _fakeSessionData()
|
116 |
+
{
|
117 |
+
if (!is_array($_SESSION)) return;
|
118 |
+
|
119 |
+
foreach ($_SESSION as $namespace => $session) {
|
120 |
+
if (isset($session[self::VALIDATOR_KEY])) {
|
121 |
+
$_SESSION[$namespace][self::VALIDATOR_KEY] = $this->getValidatorData();
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Check whether SID can be used for session initialization
|
128 |
+
* Admin area will always have this feature enabled
|
129 |
+
* Always enabled with 'japi' routers or extist param request 'jkey'
|
130 |
+
*
|
131 |
+
* @return bool
|
132 |
+
*/
|
133 |
+
public function useSid()
|
134 |
+
{
|
135 |
+
return true;
|
136 |
+
}
|
137 |
+
}
|
app/code/community/Jmango360/Japi/Model/Dispatcher.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Dispatcher extends Mage_Api2_Model_Dispatcher
|
4 |
+
{
|
5 |
+
public function dispatch(Mage_Api2_Model_Request $request, Mage_Api2_Model_Response $response)
|
6 |
+
{
|
7 |
+
ob_start();
|
8 |
+
|
9 |
+
$model = $request->getModel();
|
10 |
+
$model->dispatch();
|
11 |
+
|
12 |
+
ob_end_clean();
|
13 |
+
|
14 |
+
return $this;
|
15 |
+
}
|
16 |
+
}
|
app/code/community/Jmango360/Japi/Model/Magpleasure/Tierprices/Price.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Model_Magpleasure_Tierprices_Price extends Magpleasure_Tierprices_Model_Price
|
7 |
+
{
|
8 |
+
protected function _isCheckout()
|
9 |
+
{
|
10 |
+
if (Mage::app()->getRequest()->getModuleName() == 'japi') {
|
11 |
+
return true;
|
12 |
+
} else {
|
13 |
+
return parent::_isCheckout();
|
14 |
+
}
|
15 |
+
}
|
16 |
+
}
|
app/code/community/Jmango360/Japi/Model/Observer.php
ADDED
@@ -0,0 +1,440 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Observer
|
4 |
+
{
|
5 |
+
public function addressBookPostcodeCheck($observe)
|
6 |
+
{
|
7 |
+
if (Mage::app()->getRequest()->getModuleName() != 'japi') return;
|
8 |
+
if (!Mage::helper('core')->isModuleEnabled('TIG_PostNL')) return;
|
9 |
+
if (!class_exists('TIG_PostNL_Model_AddressValidation_Observer_AddressBook')) return;
|
10 |
+
if (!class_exists('TIG_PostNL_Helper_AddressValidation')) return;
|
11 |
+
$blockClass = Mage::getConfig()->getBlockClassName(TIG_PostNL_Model_AddressValidation_Observer_AddressBook::ADDRESS_COMMUNITY_BLOCK_NAME);
|
12 |
+
$block = $observe->getBlock();
|
13 |
+
if (!$block || get_class($block) != $blockClass) return;
|
14 |
+
if (!Mage::helper('postnl/addressValidation')->isPostcodeCheckEnabled(null, TIG_PostNL_Model_AddressValidation_Observer_AddressBook::POSTCODECHECK_ENV)) return;
|
15 |
+
Mage::app()->getStore()->setConfig(TIG_PostNL_Helper_AddressValidation::XPATH_POSTCODE_CHECK_IN_ADDRESSBOOK, 0);
|
16 |
+
$block->setTemplate('japi/TIG/PostNL/address_validation/customer/address/edit.phtml');
|
17 |
+
}
|
18 |
+
|
19 |
+
public function shippingAddressPostcodeCheck($observe)
|
20 |
+
{
|
21 |
+
if (Mage::app()->getRequest()->getModuleName() != 'japi') return;
|
22 |
+
if (!Mage::helper('core')->isModuleEnabled('TIG_PostNL')) return;
|
23 |
+
if (!class_exists('TIG_PostNL_Model_AddressValidation_Observer_Onepage')) return;
|
24 |
+
if (!class_exists('TIG_PostNL_Helper_AddressValidation')) return;
|
25 |
+
$blockClass = Mage::getConfig()->getBlockClassName(TIG_PostNL_Model_AddressValidation_Observer_Onepage::SHIPPING_ADDRESS_BLOCK_NAME);
|
26 |
+
$block = $observe->getBlock();
|
27 |
+
if (!$block || get_class($block) != $blockClass) return;
|
28 |
+
if (!Mage::helper('postnl/addressValidation')->isPostcodeCheckEnabled(null, TIG_PostNL_Model_AddressValidation_Observer_Onepage::POSTCODECHECK_ENV)) return;
|
29 |
+
Mage::app()->getStore()->setConfig(TIG_PostNL_Helper_AddressValidation::XPATH_POSTCODE_CHECK_IN_CHECKOUT, 0);
|
30 |
+
$block->setTemplate('japi/TIG/PostNL/address_validation/checkout/onepage/shipping.phtml');
|
31 |
+
}
|
32 |
+
|
33 |
+
public function billingAddressPostcodeCheck($observe)
|
34 |
+
{
|
35 |
+
if (Mage::app()->getRequest()->getModuleName() != 'japi') return;
|
36 |
+
if (!Mage::helper('core')->isModuleEnabled('TIG_PostNL')) return;
|
37 |
+
if (!class_exists('TIG_PostNL_Model_AddressValidation_Observer_Onepage')) return;
|
38 |
+
if (!class_exists('TIG_PostNL_Helper_AddressValidation')) return;
|
39 |
+
$blockClass = Mage::getConfig()->getBlockClassName(TIG_PostNL_Model_AddressValidation_Observer_Onepage::BILLING_ADDRESS_BLOCK_NAME);
|
40 |
+
$block = $observe->getBlock();
|
41 |
+
if (!$block || get_class($block) != $blockClass) return;
|
42 |
+
if (!Mage::helper('postnl/addressValidation')->isPostcodeCheckEnabled(null, TIG_PostNL_Model_AddressValidation_Observer_Onepage::POSTCODECHECK_ENV)) return;
|
43 |
+
Mage::app()->getStore()->setConfig(TIG_PostNL_Helper_AddressValidation::XPATH_POSTCODE_CHECK_IN_CHECKOUT, 0);
|
44 |
+
$block->setTemplate('japi/TIG/PostNL/address_validation/checkout/onepage/billing.phtml');
|
45 |
+
}
|
46 |
+
|
47 |
+
public function handleErrorCheckout($observe)
|
48 |
+
{
|
49 |
+
/* @var $server Jmango360_Japi_Model_Server */
|
50 |
+
$server = Mage::getSingleton('japi/server');
|
51 |
+
if ($server->getIsRest() && $server->getIsSubmit()) {
|
52 |
+
$server->unsetIsSubmit();
|
53 |
+
|
54 |
+
/* @var $action Mage_Core_Controller_Varien_Action */
|
55 |
+
$action = $observe->getControllerAction();
|
56 |
+
if (!$action) return;
|
57 |
+
|
58 |
+
/* @var $coreSession Mage_Core_Model_Session */
|
59 |
+
$coreSession = Mage::getSingleton('core/session');
|
60 |
+
/* @var $checkoutSession Mage_Checkout_Model_Session */
|
61 |
+
$checkoutSession = Mage::getSingleton('checkout/session');
|
62 |
+
$messages = $coreSession->getMessages(true);
|
63 |
+
foreach ($messages->getItems() as $message) {
|
64 |
+
$checkoutSession->addMessage($message);
|
65 |
+
}
|
66 |
+
|
67 |
+
$request = $action->getRequest();
|
68 |
+
$request->initForward()
|
69 |
+
->setModuleName('japi')
|
70 |
+
->setControllerName('checkout')
|
71 |
+
->setActionName('onepage')
|
72 |
+
->setDispatched(false);
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
public function skipPaypalExpressReview()
|
77 |
+
{
|
78 |
+
/* @var $server Jmango360_Japi_Model_Server */
|
79 |
+
$server = Mage::getSingleton('japi/server');
|
80 |
+
if ($server->getIsRest()) {
|
81 |
+
try {
|
82 |
+
if (defined('Mage_Paypal_Model_Config::XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG')) {
|
83 |
+
Mage::app()->getStore()->setConfig(Mage_Paypal_Model_Config::XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG, 1);
|
84 |
+
}
|
85 |
+
Mage::app()->getStore()->setConfig('checkout/options/enable_agreements', 0);
|
86 |
+
} catch (Exception $e) {
|
87 |
+
Mage::logException($e);
|
88 |
+
}
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
public function setOrderIdToHeader()
|
93 |
+
{
|
94 |
+
/* @var $server Jmango360_Japi_Model_Server */
|
95 |
+
$server = Mage::getSingleton('japi/server');
|
96 |
+
if ($server->getIsRest()) {
|
97 |
+
/* @var $session Mage_Checkout_Model_Session */
|
98 |
+
$session = Mage::getSingleton('checkout/session');
|
99 |
+
$lastRealOrderId = $session->getLastRealOrderId();
|
100 |
+
if ($lastRealOrderId) {
|
101 |
+
Mage::app()->getFrontController()->getResponse()->setHeader('Last-Real-Order-Id', $lastRealOrderId, true);
|
102 |
+
}
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
public function setOrderIdToHead($observe)
|
107 |
+
{
|
108 |
+
/* @var $server Jmango360_Japi_Model_Server */
|
109 |
+
$server = Mage::getSingleton('japi/server');
|
110 |
+
if ($server->getIsRest()) {
|
111 |
+
$request = Mage::app()->getRequest();
|
112 |
+
/* @var $layout Mage_Core_Model_Layout */
|
113 |
+
$layout = $observe->getLayout();
|
114 |
+
if (!$layout) return;
|
115 |
+
$head = $layout->getBlock('head');
|
116 |
+
if (!$head) return;
|
117 |
+
|
118 |
+
/* @var $session Mage_Checkout_Model_Session */
|
119 |
+
$session = Mage::getSingleton('checkout/session');
|
120 |
+
$lastRealOrderId = $session->getLastRealOrderId();
|
121 |
+
if ($lastRealOrderId) {
|
122 |
+
$block = $layout->createBlock('core/text');
|
123 |
+
$block->setText(sprintf('<meta name="%s" content="%s">', 'last-real-order-id', $lastRealOrderId));
|
124 |
+
$head->append($block, 'last-real-order-id');
|
125 |
+
}
|
126 |
+
|
127 |
+
if ($request->getModuleName() == 'japi' && $request->getControllerName() == 'customer' && $request->getActionName() == 'edit') {
|
128 |
+
/* @var $customerSession Mage_Customer_Model_Session */
|
129 |
+
$customerSession = Mage::getSingleton('customer/session');
|
130 |
+
if ($customerSession->getIsSubmit() && !$customerSession->getMessages()->getErrors()) {
|
131 |
+
$block = $layout->createBlock('core/text');
|
132 |
+
$tags[] = sprintf('<meta name="%s" content="%s">', 'JM-Account-Id', $customerSession->getCustomerId());
|
133 |
+
$tags[] = sprintf('<meta name="%s" content="%s">', 'JM-Account-Email', $customerSession->getCustomer()->getEmail());
|
134 |
+
$block->setText(join("\n", $tags));
|
135 |
+
$head->append($block, uniqid());
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
if ($request->getModuleName() == 'japi' && $request->getControllerName() == 'customer' && $request->getActionName() == 'register') {
|
140 |
+
/* @var $customerSession Mage_Customer_Model_Session */
|
141 |
+
$customerSession = Mage::getSingleton('customer/session');
|
142 |
+
if ($customerSession->getIsSubmit() && !$customerSession->getMessages()->getErrors()) {
|
143 |
+
$block = $layout->createBlock('core/text');
|
144 |
+
$tags[] = sprintf('<meta name="%s" content="%s">', 'JM-Account-Id', $customerSession->getCustomerId());
|
145 |
+
$tags[] = sprintf('<meta name="%s" content="%s">', 'JM-Account-Email', $customerSession->getCustomerEmail());
|
146 |
+
$tags[] = sprintf('<meta name="%s" content="%s">', 'JM-Confirmation-Required', $customerSession->getIsConfirmationRequired());
|
147 |
+
$tags[] = sprintf('<meta name="%s" content="%s">', 'JM-Session-Id', $customerSession->getSessionId());
|
148 |
+
$block->setText(join("\n", $tags));
|
149 |
+
$head->append($block, uniqid());
|
150 |
+
}
|
151 |
+
}
|
152 |
+
|
153 |
+
if ($request->getModuleName() == 'japi' && $request->getControllerName() == 'customer' && $request->getActionName() == 'address') {
|
154 |
+
/* @var $customerSession Mage_Customer_Model_Session */
|
155 |
+
$customerSession = Mage::getSingleton('customer/session');
|
156 |
+
if ($customerSession->getIsSubmit() && !$customerSession->getMessages()->getErrors()) {
|
157 |
+
$block = $layout->createBlock('core/text');
|
158 |
+
$tags[] = sprintf('<meta name="%s" content="%s">', 'JM-Account-Id', $customerSession->getCustomerId());
|
159 |
+
$tags[] = sprintf('<meta name="%s" content="%s">', 'JM-Account-Email', $customerSession->getCustomer()->getEmail());
|
160 |
+
$tags[] = sprintf('<meta name="%s" content="%s">', 'JM-Address-Id', $request->getParam('id'));
|
161 |
+
$block->setText(join("\n", $tags));
|
162 |
+
$head->append($block, uniqid());
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
public function customerRegisterSuccess($observe)
|
169 |
+
{
|
170 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
171 |
+
$customer = $observe->getEvent()->getCustomer();
|
172 |
+
if (!$customer->getId()) return;
|
173 |
+
$session = Mage::getSingleton('customer/session');
|
174 |
+
$session->setIsSubmit(true);
|
175 |
+
$session->setCustomerId($customer->getId());
|
176 |
+
$session->setCustomerEmail($customer->getEmail());
|
177 |
+
$session->setIsConfirmationRequired($customer->isConfirmationRequired());
|
178 |
+
}
|
179 |
+
|
180 |
+
public function controllerFrontInitBefore($observe)
|
181 |
+
{
|
182 |
+
/* @var $helper Jmango360_Japi_Helper_Data */
|
183 |
+
$helper = Mage::helper('japi');
|
184 |
+
if ($helper->isNeedByPassSessionValidation() || $helper->isNeedByPassMIMT() || !$helper->isUseSidFrontend()) {
|
185 |
+
/* @var $front Mage_Core_Controller_Varien_Front */
|
186 |
+
$front = $observe->getEvent()->getFront();
|
187 |
+
$request = $front->getRequest();
|
188 |
+
$route = explode('/', $request->getPathInfo());
|
189 |
+
if (in_array('system_config', $route)) return;
|
190 |
+
if (count($route) > 3 && $route[1] == 'japi') {
|
191 |
+
if ($route[2] == 'checkout' && $route[3] == 'onepage') {
|
192 |
+
return;
|
193 |
+
}
|
194 |
+
Mage::register('_singleton/core/session', Mage::getModel('japi/core_session', array('name' => 'frontend')), true);
|
195 |
+
} elseif (count($route) > 3 && in_array('japi', $route)) {
|
196 |
+
if (in_array('checkout', $route) && in_array('onepage', $route)) {
|
197 |
+
return;
|
198 |
+
}
|
199 |
+
Mage::register('_singleton/core/session', Mage::getModel('japi/core_session', array('name' => 'frontend')), true);
|
200 |
+
}
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
public function restAdminActionPreDispatch($observe)
|
205 |
+
{
|
206 |
+
/* @var $action Mage_Core_Controller_Varien_Action */
|
207 |
+
$action = $observe->getEvent()->getControllerAction();
|
208 |
+
switch ($action->getFullActionName()) {
|
209 |
+
case 'adminhtml_report_statistics_refreshRecent':
|
210 |
+
$codes = $this->_getRefreshStatisticCodes($action->getRequest());
|
211 |
+
if (in_array('sales', $codes)) {
|
212 |
+
$currentDate = Mage::app()->getLocale()->date();
|
213 |
+
$date = $currentDate->subHour(25);
|
214 |
+
Mage::getResourceModel('japi/sales_report_order')->aggregate($date);
|
215 |
+
}
|
216 |
+
break;
|
217 |
+
case 'adminhtml_report_statistics_refreshLifetime':
|
218 |
+
$codes = $this->_getRefreshStatisticCodes($action->getRequest());
|
219 |
+
if (in_array('sales', $codes)) {
|
220 |
+
Mage::getResourceModel('japi/sales_report_order')->aggregate();
|
221 |
+
}
|
222 |
+
break;
|
223 |
+
}
|
224 |
+
|
225 |
+
// Remove plugin update notification
|
226 |
+
//$this->checkPluginUpdate();
|
227 |
+
}
|
228 |
+
|
229 |
+
public function aggregateSalesReportOrderData()
|
230 |
+
{
|
231 |
+
try {
|
232 |
+
Mage::app()->getLocale()->emulate(0);
|
233 |
+
$currentDate = Mage::app()->getLocale()->date();
|
234 |
+
$now = clone $currentDate;
|
235 |
+
$date = $currentDate->subHour(25);
|
236 |
+
$this->_logCronjob(sprintf('Start from %s to %s', $date, $now));
|
237 |
+
Mage::getResourceModel('japi/sales_report_order')->aggregate($date);
|
238 |
+
Mage::app()->getLocale()->revert();
|
239 |
+
$this->_logCronjob("End\n");
|
240 |
+
return 1;
|
241 |
+
} catch (Exception $e) {
|
242 |
+
Mage::logException($e);
|
243 |
+
return 0;
|
244 |
+
}
|
245 |
+
}
|
246 |
+
|
247 |
+
protected function _logCronjob($str)
|
248 |
+
{
|
249 |
+
Mage::log($str, null, 'japi_cron.log');
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* @param $request Mage_Core_Controller_Request_Http
|
254 |
+
* @return array
|
255 |
+
*/
|
256 |
+
protected function _getRefreshStatisticCodes($request)
|
257 |
+
{
|
258 |
+
$codes = $request->getParam('code');
|
259 |
+
|
260 |
+
if (!is_array($codes) && strpos($codes, ',') === false) {
|
261 |
+
$codes = array($codes);
|
262 |
+
} elseif (!is_array($codes)) {
|
263 |
+
$codes = explode(',', $codes);
|
264 |
+
}
|
265 |
+
|
266 |
+
return $codes;
|
267 |
+
}
|
268 |
+
|
269 |
+
protected function checkPluginUpdate()
|
270 |
+
{
|
271 |
+
if (Mage::getSingleton('admin/session')->isLoggedIn()) {
|
272 |
+
/* @var $_helper Jmango360_Japi_Helper_Data */
|
273 |
+
$_helper = Mage::helper('japi');
|
274 |
+
|
275 |
+
/* @var $feedModel Mage_AdminNotification_Model_Feed */
|
276 |
+
$feedModel = Mage::getModel('adminnotification/feed');
|
277 |
+
if (($feedModel->getFrequency() + $_helper->getLastCheckUpdate()) > time()) {
|
278 |
+
return $this;
|
279 |
+
}
|
280 |
+
|
281 |
+
/* @var $session Mage_Adminhtml_Model_Session */
|
282 |
+
$session = Mage::getSingleton('adminhtml/session');
|
283 |
+
|
284 |
+
if ($session->getJapiCheckedUpdate() == 'checked') {
|
285 |
+
return $this;
|
286 |
+
}
|
287 |
+
|
288 |
+
$inboxModel = Mage::getModel('adminnotification/inbox');
|
289 |
+
$inboxResource = $inboxModel->getResource();
|
290 |
+
|
291 |
+
$_versionInfo = $_helper->getUpdateAvailable();
|
292 |
+
if (!$_versionInfo) {
|
293 |
+
return $this;
|
294 |
+
}
|
295 |
+
|
296 |
+
$_messageData = array(
|
297 |
+
'severity' => 4,
|
298 |
+
'date_added' => gmdate('Y-m-d H:i:s', time()),
|
299 |
+
'title' => Mage::helper('japi')->__('A new version of the JMango360 Mobile plugin %s is available. Please update.', $_versionInfo['connectVer']),
|
300 |
+
'description' => Mage::helper('japi')->__('A new version of the JMango360 Mobile plugin %s is available. Please update.', $_versionInfo['connectVer']),
|
301 |
+
'url' => 'https://www.magentocommerce.com/magento-connect/jmango360-rest-plugin.html'
|
302 |
+
);
|
303 |
+
|
304 |
+
/* @var $_coreResource Mage_Core_Model_Resource */
|
305 |
+
$_coreResource = Mage::getSingleton('core/resource');
|
306 |
+
|
307 |
+
if (!$_versionInfo['needUpdate']) { //If not need update
|
308 |
+
// Delete all our messages if have not need update version available
|
309 |
+
$write = $_coreResource->getConnection('core_write');
|
310 |
+
$write->delete(
|
311 |
+
$inboxResource->getMainTable(),
|
312 |
+
'url = "' . $_messageData['url'] . '"'
|
313 |
+
);
|
314 |
+
|
315 |
+
$session->setJapiNotificationData(null);
|
316 |
+
$session->setJapiCheckedUpdate('checked');
|
317 |
+
$_helper->setLastCheckUpdate();
|
318 |
+
return $this;
|
319 |
+
}
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Add new notification if not exist when new version update available
|
323 |
+
*/
|
324 |
+
$adapter = $_coreResource->getConnection('core_read');
|
325 |
+
$select = $adapter->select()
|
326 |
+
->from($inboxResource->getMainTable())
|
327 |
+
->order($inboxResource->getIdFieldName() . ' DESC')
|
328 |
+
->where('description = "' . $_messageData['description'] . '"')
|
329 |
+
->where('is_remove != 1')
|
330 |
+
->limit(1);
|
331 |
+
$data = $adapter->fetchRow($select);
|
332 |
+
if (!$data) {
|
333 |
+
$inboxModel->addNotice($_messageData['title'], $_messageData['description'], $_messageData['url']);
|
334 |
+
}
|
335 |
+
|
336 |
+
$session->setJapiNotificationData(null);
|
337 |
+
$session->setJapiCheckedUpdate('checked');
|
338 |
+
$_helper->setLastCheckUpdate();
|
339 |
+
}
|
340 |
+
}
|
341 |
+
|
342 |
+
/**
|
343 |
+
* Append new column to orders, customers grid
|
344 |
+
*/
|
345 |
+
public function coreBlockAbstractToHtmlBefore($observe)
|
346 |
+
{
|
347 |
+
/* @var $grid Mage_Adminhtml_Block_Widget_Grid */
|
348 |
+
$grid = $observe->getEvent()->getBlock();
|
349 |
+
/* @var $helper Jmango360_Japi_Helper_Data */
|
350 |
+
$helper = Mage::helper('japi');
|
351 |
+
|
352 |
+
switch ($grid->getType()) {
|
353 |
+
case 'adminhtml/sales_order_grid':
|
354 |
+
if (!Mage::getStoreConfigFlag('japi/jmango_rest_sales_settings/display_order_from')) {
|
355 |
+
return;
|
356 |
+
}
|
357 |
+
|
358 |
+
if (!$helper->hasJapiOrderData()) {
|
359 |
+
return;
|
360 |
+
}
|
361 |
+
|
362 |
+
$grid->addColumnAfter('japi', array(
|
363 |
+
'header' => $helper->__('Order From'),
|
364 |
+
'index' => 'japi',
|
365 |
+
'filter_index' => 'main_table.japi',
|
366 |
+
'type' => 'options',
|
367 |
+
'width' => '70px',
|
368 |
+
'options' => array(
|
369 |
+
1 => $helper->__('JMango360')
|
370 |
+
)
|
371 |
+
), 'real_order_id');
|
372 |
+
break;
|
373 |
+
case 'adminhtml/customer_grid':
|
374 |
+
if (!Mage::getStoreConfigFlag('japi/jmango_rest_customer_settings/display_customer_from')) {
|
375 |
+
return;
|
376 |
+
}
|
377 |
+
|
378 |
+
if (!$helper->hasJapiCustomerData()) {
|
379 |
+
return;
|
380 |
+
}
|
381 |
+
|
382 |
+
$grid->addColumnAfter('japi', array(
|
383 |
+
'header' => $helper->__('JMango360 User'),
|
384 |
+
'index' => 'japi',
|
385 |
+
'type' => 'options',
|
386 |
+
'width' => '70px',
|
387 |
+
'options' => array(
|
388 |
+
0 => $helper->__('No'),
|
389 |
+
1 => $helper->__('Yes')
|
390 |
+
),
|
391 |
+
'filter_condition_callback' => array($this, 'japiCustomerFilterConditionCallback')
|
392 |
+
), 'entity_id');
|
393 |
+
break;
|
394 |
+
}
|
395 |
+
}
|
396 |
+
|
397 |
+
/**
|
398 |
+
* Inject customer collection to join japi filter
|
399 |
+
*/
|
400 |
+
public function eavCollectionAbstractLoadBefore($observe)
|
401 |
+
{
|
402 |
+
/* @var $collection Varien_Data_Collection_Db */
|
403 |
+
$collection = $observe->getEvent()->getCollection();
|
404 |
+
if (!$collection) return;
|
405 |
+
|
406 |
+
if ($collection instanceof Mage_Customer_Model_Resource_Customer_Collection) {
|
407 |
+
$this->_addJapiToCustomerSelect($collection);
|
408 |
+
}
|
409 |
+
}
|
410 |
+
|
411 |
+
/**
|
412 |
+
* @param $collection Mage_Sales_Model_Resource_Order_Grid_Collection
|
413 |
+
* @param $column Mage_Adminhtml_Block_Widget_Grid_Column
|
414 |
+
*
|
415 |
+
* Customer mobile filter callback
|
416 |
+
*/
|
417 |
+
public function japiCustomerFilterConditionCallback($collection, $column)
|
418 |
+
{
|
419 |
+
$this->_addJapiToCustomerSelect($collection);
|
420 |
+
$collection->addAttributeToFilter('japi', array('eq' => $column->getFilter()->getValue()));
|
421 |
+
}
|
422 |
+
|
423 |
+
/**
|
424 |
+
* Add japi with ifnull condition to customer select
|
425 |
+
*
|
426 |
+
* @param Varien_Data_Collection_Db $collection
|
427 |
+
*/
|
428 |
+
protected function _addJapiToCustomerSelect($collection)
|
429 |
+
{
|
430 |
+
try {
|
431 |
+
$fromPart = $collection->getSelect()->getPart('from');
|
432 |
+
if (array_key_exists('at_japi', $fromPart)) return;
|
433 |
+
|
434 |
+
$adapter = $collection->getConnection();
|
435 |
+
$collection->addExpressionAttributeToSelect('japi', $adapter->getIfNullSql('{{japi}}', 0), array('japi'));
|
436 |
+
} catch (Exception $e) {
|
437 |
+
Mage::logException($e);
|
438 |
+
}
|
439 |
+
}
|
440 |
+
}
|
app/code/community/Jmango360/Japi/Model/Renderer.php
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Jmango360_Japi_Model_Renderer extends Mage_Api2_Model_Renderer
|
3 |
+
{
|
4 |
+
}
|
app/code/community/Jmango360/Japi/Model/Renderer/Json.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Renderer_Json extends Mage_Api2_Model_Renderer_Json
|
4 |
+
{
|
5 |
+
public function getMimeType()
|
6 |
+
{
|
7 |
+
return self::MIME_TYPE;
|
8 |
+
}
|
9 |
+
}
|
app/code/community/Jmango360/Japi/Model/Request.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Request extends Mage_Api2_Model_Request
|
4 |
+
{
|
5 |
+
const OPERATION_CREATE = 'post';
|
6 |
+
const OPERATION_RETRIEVE = 'get';
|
7 |
+
const OPERATION_UPDATE = 'put';
|
8 |
+
const OPERATION_DELETE = 'delete';
|
9 |
+
|
10 |
+
const HTTP_OK = 200;
|
11 |
+
const HTTP_CREATED = 201;
|
12 |
+
const HTTP_MULTI_STATUS = 207;
|
13 |
+
const HTTP_BAD_REQUEST = 400;
|
14 |
+
const HTTP_UNAUTHORIZED = 401;
|
15 |
+
const HTTP_FORBIDDEN = 403;
|
16 |
+
const HTTP_NOT_FOUND = 404;
|
17 |
+
const HTTP_METHOD_NOT_ALLOWED = 405;
|
18 |
+
const HTTP_NOT_ACCEPTABLE = 406;
|
19 |
+
const HTTP_INTERNAL_ERROR = 500;
|
20 |
+
|
21 |
+
const REST_SESSION_EXPIRED = 520;
|
22 |
+
const REST_INVALID_TOKEN = 521;
|
23 |
+
|
24 |
+
const REST_CUSTOMER_EXPIRED = 530;
|
25 |
+
const REST_CUSTOMER_LOGGED_IN = 531;
|
26 |
+
|
27 |
+
const RESOURCE_METHOD_NOT_IMPLEMENTED = 'Resource method not implemented yet.';
|
28 |
+
|
29 |
+
protected $_model = null;
|
30 |
+
|
31 |
+
public function getAcceptTypes()
|
32 |
+
{
|
33 |
+
return "application/json";
|
34 |
+
}
|
35 |
+
|
36 |
+
public function getModel()
|
37 |
+
{
|
38 |
+
return $this->_model;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function setModel($model)
|
42 |
+
{
|
43 |
+
$this->_model = $model;
|
44 |
+
return $this;
|
45 |
+
}
|
46 |
+
|
47 |
+
public function getOperation()
|
48 |
+
{
|
49 |
+
if (!$this->isGet() && !$this->isPost() && !$this->isPut() && !$this->isDelete()) {
|
50 |
+
throw new Mage_Api2_Exception('Invalid request method', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
|
51 |
+
}
|
52 |
+
// Map HTTP methods to classic CRUD verbs
|
53 |
+
$operationByMethod = array(
|
54 |
+
'GET' => self::OPERATION_RETRIEVE,
|
55 |
+
'POST' => self::OPERATION_CREATE,
|
56 |
+
'PUT' => self::OPERATION_UPDATE,
|
57 |
+
'DELETE' => self::OPERATION_DELETE
|
58 |
+
);
|
59 |
+
|
60 |
+
return $operationByMethod[$this->getMethod()];
|
61 |
+
}
|
62 |
+
|
63 |
+
public function getAction()
|
64 |
+
{
|
65 |
+
return Mage::app()->getRequest()->getActionName();
|
66 |
+
}
|
67 |
+
|
68 |
+
public function getParams()
|
69 |
+
{
|
70 |
+
return Mage::app()->getRequest()->getParams();
|
71 |
+
}
|
72 |
+
|
73 |
+
public function getParam($key, $default = null)
|
74 |
+
{
|
75 |
+
return Mage::app()->getRequest()->getParam($key, $default);
|
76 |
+
}
|
77 |
+
|
78 |
+
public function setParam($key, $value)
|
79 |
+
{
|
80 |
+
Mage::app()->getRequest()->setParam($key, $value);
|
81 |
+
}
|
82 |
+
}
|
app/code/community/Jmango360/Japi/Model/Resource/Catalog/Layer/Filter/Attribute.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Resource_Catalog_Layer_Filter_Attribute extends Mage_Catalog_Model_Resource_Layer_Filter_Attribute
|
4 |
+
{
|
5 |
+
|
6 |
+
}
|
app/code/community/Jmango360/Japi/Model/Resource/Catalog/Layer/Filter/Decimal.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Resource_Catalog_Layer_Filter_Decimal extends Mage_Catalog_Model_Resource_Layer_Filter_Decimal
|
4 |
+
{
|
5 |
+
|
6 |
+
}
|
app/code/community/Jmango360/Japi/Model/Resource/Catalog/Layer/Filter/Price.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Resource_Catalog_Layer_Filter_Price extends Mage_Catalog_Model_Resource_Layer_Filter_Price
|
4 |
+
{
|
5 |
+
|
6 |
+
}
|
app/code/community/Jmango360/Japi/Model/Resource/Report/Order/Collection.php
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Model_Resource_Report_Order_Collection extends Mage_Reports_Model_Resource_Order_Collection
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Prepare report summary
|
10 |
+
*
|
11 |
+
* @param string $range
|
12 |
+
* @param mixed $customStart
|
13 |
+
* @param mixed $customEnd
|
14 |
+
* @param boolean $live
|
15 |
+
* @return $this
|
16 |
+
*/
|
17 |
+
public function prepareSummary($range, $customStart, $customEnd, $live = false)
|
18 |
+
{
|
19 |
+
if ($live) {
|
20 |
+
$this->_prepareSummaryLiveData($range, $customStart, $customEnd);
|
21 |
+
} else {
|
22 |
+
$this->_prepareSummaryAggregatedData($range, $customStart, $customEnd);
|
23 |
+
}
|
24 |
+
|
25 |
+
return $this;
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Prepare report summary from live data
|
30 |
+
*
|
31 |
+
* @param string $range
|
32 |
+
* @param mixed $customStart
|
33 |
+
* @param mixed $customEnd
|
34 |
+
* @return $this
|
35 |
+
*/
|
36 |
+
protected function _prepareSummaryLiveData($range, $customStart, $customEnd)
|
37 |
+
{
|
38 |
+
$this->setMainTable('sales/order');
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Reset all columns, because result will group only by 'created_at' field
|
42 |
+
*/
|
43 |
+
$this->getSelect()->reset(Zend_Db_Select::COLUMNS);
|
44 |
+
|
45 |
+
$dateFrom = Mage::app()->getLocale()->date($customStart, Varien_Date::DATE_INTERNAL_FORMAT);
|
46 |
+
$dateFrom->setHour(0);
|
47 |
+
$dateFrom->setMinute(0);
|
48 |
+
$dateFrom->setSecond(0);
|
49 |
+
|
50 |
+
$dateTo = Mage::app()->getLocale()->date($customEnd, Varien_Date::DATE_INTERNAL_FORMAT);
|
51 |
+
$dateTo->setHour(23);
|
52 |
+
$dateTo->setMinute(59);
|
53 |
+
$dateTo->setSecond(59);
|
54 |
+
|
55 |
+
$tzRangeOffsetExpression = $this->_getTZRangeOffsetExpression(
|
56 |
+
$range, 'created_at', $dateFrom, $dateTo
|
57 |
+
);
|
58 |
+
|
59 |
+
$this->getSelect()
|
60 |
+
->columns(array(
|
61 |
+
'customers_count' => new Zend_Db_Expr(
|
62 |
+
sprintf('COUNT(DISTINCT %s)+SUM(if(%s IS NULL,1,0))',
|
63 |
+
'main_table.customer_id', 'main_table.customer_id'
|
64 |
+
)
|
65 |
+
),
|
66 |
+
'range' => $tzRangeOffsetExpression
|
67 |
+
))
|
68 |
+
->where('main_table.state NOT IN (?)', array(
|
69 |
+
Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
|
70 |
+
Mage_Sales_Model_Order::STATE_NEW
|
71 |
+
))
|
72 |
+
->where('main_table.japi = ?', 1)
|
73 |
+
->order('range', Zend_Db_Select::SQL_ASC)
|
74 |
+
->group($tzRangeOffsetExpression);
|
75 |
+
|
76 |
+
$this->addFieldToFilter('created_at', array(
|
77 |
+
'from' => $dateFrom,
|
78 |
+
'to' => $dateTo,
|
79 |
+
'datetime' => true
|
80 |
+
));
|
81 |
+
|
82 |
+
return $this;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Prepare report summary from aggregated data
|
87 |
+
*
|
88 |
+
* @param string $range
|
89 |
+
* @param mixed $customStart
|
90 |
+
* @param mixed $customEnd
|
91 |
+
* @return $this
|
92 |
+
*/
|
93 |
+
protected function _prepareSummaryAggregatedData($range, $customStart, $customEnd)
|
94 |
+
{
|
95 |
+
$this->setMainTable('japi/sales_order_aggregated');
|
96 |
+
/**
|
97 |
+
* Reset all columns, because result will group only by 'created_at' field
|
98 |
+
*/
|
99 |
+
$this->getSelect()->reset(Zend_Db_Select::COLUMNS);
|
100 |
+
$rangePeriod = $this->_getRangeExpressionForAttribute($range, 'main_table.period');
|
101 |
+
|
102 |
+
$tableName = $this->getConnection()->quoteIdentifier('main_table.period');
|
103 |
+
$rangePeriod2 = str_replace($tableName, "MIN($tableName)", $rangePeriod);
|
104 |
+
|
105 |
+
$this->getSelect()
|
106 |
+
->columns(array(
|
107 |
+
'quantity' => 'SUM(main_table.orders_count)',
|
108 |
+
'amount' => 'SUM(main_table.total_income_amount)',
|
109 |
+
'range' => $rangePeriod2
|
110 |
+
))
|
111 |
+
->order('range')
|
112 |
+
->group($rangePeriod);
|
113 |
+
|
114 |
+
$this->getSelect()->where(
|
115 |
+
$this->_getConditionSql('main_table.period', array(
|
116 |
+
'from' => $customStart,
|
117 |
+
'to' => $customEnd,
|
118 |
+
'datetime' => true
|
119 |
+
))
|
120 |
+
);
|
121 |
+
|
122 |
+
return $this;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Get range expression
|
127 |
+
*
|
128 |
+
* @param string $range
|
129 |
+
* @return Zend_Db_Expr
|
130 |
+
*/
|
131 |
+
protected function _getRangeExpression($range)
|
132 |
+
{
|
133 |
+
switch ($range) {
|
134 |
+
case 'day':
|
135 |
+
return $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d');
|
136 |
+
break;
|
137 |
+
default:
|
138 |
+
case 'month':
|
139 |
+
return $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m');
|
140 |
+
break;
|
141 |
+
case 'year':
|
142 |
+
return $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y');
|
143 |
+
break;
|
144 |
+
}
|
145 |
+
}
|
146 |
+
}
|
app/code/community/Jmango360/Japi/Model/Resource/Sales/Report/Order.php
ADDED
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Model_Resource_Sales_Report_Order
|
7 |
+
extends Mage_Sales_Model_Resource_Report_Abstract
|
8 |
+
{
|
9 |
+
/**
|
10 |
+
* Model initialization
|
11 |
+
*/
|
12 |
+
protected function _construct()
|
13 |
+
{
|
14 |
+
$this->_init('japi/sales_order_aggregated', 'id');
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Aggregate Orders data by order created at
|
19 |
+
*
|
20 |
+
* @param mixed $from
|
21 |
+
* @param mixed $to
|
22 |
+
* @return Jmango360_Japi_Model_Resource_Sales_Report_Order
|
23 |
+
*/
|
24 |
+
public function aggregate($from = null, $to = null)
|
25 |
+
{
|
26 |
+
return $this->_aggregateByField('created_at', $from, $to);
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Aggregate Orders data by custom field
|
31 |
+
*
|
32 |
+
* @throws Exception
|
33 |
+
* @param string $aggregationField
|
34 |
+
* @param mixed $from
|
35 |
+
* @param mixed $to
|
36 |
+
* @return Jmango360_Japi_Model_Resource_Sales_Report_Order
|
37 |
+
*/
|
38 |
+
protected function _aggregateByField($aggregationField, $from, $to)
|
39 |
+
{
|
40 |
+
// convert input dates to UTC to be comparable with DATETIME fields in DB
|
41 |
+
$from = $this->_dateToUtc($from);
|
42 |
+
$to = $this->_dateToUtc($to);
|
43 |
+
|
44 |
+
$this->_checkDates($from, $to);
|
45 |
+
$adapter = $this->_getWriteAdapter();
|
46 |
+
|
47 |
+
$adapter->beginTransaction();
|
48 |
+
try {
|
49 |
+
if ($from !== null || $to !== null) {
|
50 |
+
$subSelect = $this->_getTableDateRangeSelect(
|
51 |
+
$this->getTable('sales/order'),
|
52 |
+
$aggregationField, $aggregationField, $from, $to
|
53 |
+
);
|
54 |
+
} else {
|
55 |
+
$subSelect = null;
|
56 |
+
}
|
57 |
+
$this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect);
|
58 |
+
|
59 |
+
$periodExpr = $adapter->getDatePartSql($this->getStoreTZOffsetQuery(
|
60 |
+
array('o' => $this->getTable('sales/order')),
|
61 |
+
'o.' . $aggregationField,
|
62 |
+
$from, $to
|
63 |
+
));
|
64 |
+
|
65 |
+
// Columns list
|
66 |
+
$columns = array(
|
67 |
+
// convert dates from UTC to current admin timezone
|
68 |
+
'period' => $periodExpr,
|
69 |
+
'store_id' => 'o.store_id',
|
70 |
+
'order_status' => 'o.status',
|
71 |
+
'orders_count' => new Zend_Db_Expr('COUNT(o.entity_id)'),
|
72 |
+
'total_qty_ordered' => new Zend_Db_Expr('SUM(oi.total_qty_ordered)'),
|
73 |
+
'total_qty_invoiced' => new Zend_Db_Expr('SUM(oi.total_qty_invoiced)'),
|
74 |
+
'total_income_amount' => new Zend_Db_Expr(
|
75 |
+
sprintf('SUM((%s - %s) * %s)',
|
76 |
+
$adapter->getIfNullSql('o.base_grand_total', 0),
|
77 |
+
$adapter->getIfNullSql('o.base_total_canceled', 0),
|
78 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
79 |
+
)
|
80 |
+
),
|
81 |
+
'total_revenue_amount' => new Zend_Db_Expr(
|
82 |
+
sprintf('SUM((%s - %s - %s - (%s - %s - %s)) * %s)',
|
83 |
+
$adapter->getIfNullSql('o.base_total_invoiced', 0),
|
84 |
+
$adapter->getIfNullSql('o.base_tax_invoiced', 0),
|
85 |
+
$adapter->getIfNullSql('o.base_shipping_invoiced', 0),
|
86 |
+
$adapter->getIfNullSql('o.base_total_refunded', 0),
|
87 |
+
$adapter->getIfNullSql('o.base_tax_refunded', 0),
|
88 |
+
$adapter->getIfNullSql('o.base_shipping_refunded', 0),
|
89 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
90 |
+
)
|
91 |
+
),
|
92 |
+
'total_profit_amount' => new Zend_Db_Expr(
|
93 |
+
sprintf('SUM((%s - %s - %s - %s - %s) * %s)',
|
94 |
+
$adapter->getIfNullSql('o.base_total_paid', 0),
|
95 |
+
$adapter->getIfNullSql('o.base_total_refunded', 0),
|
96 |
+
$adapter->getIfNullSql('o.base_tax_invoiced', 0),
|
97 |
+
$adapter->getIfNullSql('o.base_shipping_invoiced', 0),
|
98 |
+
$adapter->getIfNullSql('o.base_total_invoiced_cost', 0),
|
99 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
100 |
+
)
|
101 |
+
),
|
102 |
+
'total_invoiced_amount' => new Zend_Db_Expr(
|
103 |
+
sprintf('SUM(%s * %s)',
|
104 |
+
$adapter->getIfNullSql('o.base_total_invoiced', 0),
|
105 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
106 |
+
)
|
107 |
+
),
|
108 |
+
'total_canceled_amount' => new Zend_Db_Expr(
|
109 |
+
sprintf('SUM(%s * %s)',
|
110 |
+
$adapter->getIfNullSql('o.base_total_canceled', 0),
|
111 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
112 |
+
)
|
113 |
+
),
|
114 |
+
'total_paid_amount' => new Zend_Db_Expr(
|
115 |
+
sprintf('SUM(%s * %s)',
|
116 |
+
$adapter->getIfNullSql('o.base_total_paid', 0),
|
117 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
118 |
+
)
|
119 |
+
),
|
120 |
+
'total_refunded_amount' => new Zend_Db_Expr(
|
121 |
+
sprintf('SUM(%s * %s)',
|
122 |
+
$adapter->getIfNullSql('o.base_total_refunded', 0),
|
123 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
124 |
+
)
|
125 |
+
),
|
126 |
+
'total_tax_amount' => new Zend_Db_Expr(
|
127 |
+
sprintf('SUM((%s - %s) * %s)',
|
128 |
+
$adapter->getIfNullSql('o.base_tax_amount', 0),
|
129 |
+
$adapter->getIfNullSql('o.base_tax_canceled', 0),
|
130 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
131 |
+
)
|
132 |
+
),
|
133 |
+
'total_tax_amount_actual' => new Zend_Db_Expr(
|
134 |
+
sprintf('SUM((%s -%s) * %s)',
|
135 |
+
$adapter->getIfNullSql('o.base_tax_invoiced', 0),
|
136 |
+
$adapter->getIfNullSql('o.base_tax_refunded', 0),
|
137 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
138 |
+
)
|
139 |
+
),
|
140 |
+
'total_shipping_amount' => new Zend_Db_Expr(
|
141 |
+
sprintf('SUM((%s - %s) * %s)',
|
142 |
+
$adapter->getIfNullSql('o.base_shipping_amount', 0),
|
143 |
+
$adapter->getIfNullSql('o.base_shipping_canceled', 0),
|
144 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
145 |
+
)
|
146 |
+
),
|
147 |
+
'total_shipping_amount_actual' => new Zend_Db_Expr(
|
148 |
+
sprintf('SUM((%s - %s) * %s)',
|
149 |
+
$adapter->getIfNullSql('o.base_shipping_invoiced', 0),
|
150 |
+
$adapter->getIfNullSql('o.base_shipping_refunded', 0),
|
151 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
152 |
+
)
|
153 |
+
),
|
154 |
+
'total_discount_amount' => new Zend_Db_Expr(
|
155 |
+
sprintf('SUM((ABS(%s) - %s) * %s)',
|
156 |
+
$adapter->getIfNullSql('o.base_discount_amount', 0),
|
157 |
+
$adapter->getIfNullSql('o.base_discount_canceled', 0),
|
158 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
159 |
+
)
|
160 |
+
),
|
161 |
+
'total_discount_amount_actual' => new Zend_Db_Expr(
|
162 |
+
sprintf('SUM((%s - %s) * %s)',
|
163 |
+
$adapter->getIfNullSql('o.base_discount_invoiced', 0),
|
164 |
+
$adapter->getIfNullSql('o.base_discount_refunded', 0),
|
165 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
166 |
+
)
|
167 |
+
)
|
168 |
+
);
|
169 |
+
|
170 |
+
$select = $adapter->select();
|
171 |
+
$selectOrderItem = $adapter->select();
|
172 |
+
|
173 |
+
$qtyCanceledExpr = $adapter->getIfNullSql('qty_canceled', 0);
|
174 |
+
$cols = array(
|
175 |
+
'order_id' => 'order_id',
|
176 |
+
'total_qty_ordered' => new Zend_Db_Expr("SUM(qty_ordered - {$qtyCanceledExpr})"),
|
177 |
+
'total_qty_invoiced' => new Zend_Db_Expr('SUM(qty_invoiced)'),
|
178 |
+
);
|
179 |
+
$selectOrderItem->from($this->getTable('sales/order_item'), $cols)
|
180 |
+
->where('parent_item_id IS NULL')
|
181 |
+
->group('order_id');
|
182 |
+
|
183 |
+
$select->from(array('o' => $this->getTable('sales/order')), $columns)
|
184 |
+
->join(array('oi' => $selectOrderItem), 'oi.order_id = o.entity_id', array())
|
185 |
+
->where('o.state NOT IN (?)', array(
|
186 |
+
Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
|
187 |
+
Mage_Sales_Model_Order::STATE_NEW
|
188 |
+
))
|
189 |
+
->where('o.japi = ?', 1);
|
190 |
+
|
191 |
+
if ($subSelect !== null) {
|
192 |
+
$select->having($this->_makeConditionFromDateRangeSelect($subSelect, 'period'));
|
193 |
+
}
|
194 |
+
|
195 |
+
$select->group(array(
|
196 |
+
$periodExpr,
|
197 |
+
'o.store_id',
|
198 |
+
'o.status'
|
199 |
+
));
|
200 |
+
|
201 |
+
$adapter->query($select->insertFromSelect($this->getMainTable(), array_keys($columns)));
|
202 |
+
|
203 |
+
// setup all columns to select SUM() except period, store_id and order_status
|
204 |
+
foreach ($columns as $k => $v) {
|
205 |
+
$columns[$k] = new Zend_Db_Expr('SUM(' . $k . ')');
|
206 |
+
}
|
207 |
+
$columns['period'] = 'period';
|
208 |
+
$columns['store_id'] = new Zend_Db_Expr(Mage_Core_Model_App::ADMIN_STORE_ID);
|
209 |
+
$columns['order_status'] = 'order_status';
|
210 |
+
|
211 |
+
$select->reset();
|
212 |
+
$select->from($this->getMainTable(), $columns)
|
213 |
+
->where('store_id <> 0');
|
214 |
+
|
215 |
+
if ($subSelect !== null) {
|
216 |
+
$select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period'));
|
217 |
+
}
|
218 |
+
|
219 |
+
$select->group(array(
|
220 |
+
'period',
|
221 |
+
'order_status'
|
222 |
+
));
|
223 |
+
$adapter->query($select->insertFromSelect($this->getMainTable(), array_keys($columns)));
|
224 |
+
$adapter->commit();
|
225 |
+
} catch (Exception $e) {
|
226 |
+
$adapter->rollBack();
|
227 |
+
throw $e;
|
228 |
+
}
|
229 |
+
|
230 |
+
return $this;
|
231 |
+
}
|
232 |
+
}
|
app/code/community/Jmango360/Japi/Model/Resource/Sales/Report/Order/Collection/Aggregated.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Model_Resource_Sales_Report_Order_Collection_Aggregated
|
7 |
+
extends Mage_Sales_Model_Resource_Report_Order_Collection
|
8 |
+
{
|
9 |
+
/**
|
10 |
+
* Aggregated Data Table
|
11 |
+
*
|
12 |
+
* @var string
|
13 |
+
*/
|
14 |
+
protected $_aggregationTable = 'japi/sales_order_aggregated';
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Get selected columns
|
18 |
+
*
|
19 |
+
* @return array
|
20 |
+
*/
|
21 |
+
protected function _getSelectedColumns()
|
22 |
+
{
|
23 |
+
$adapter = $this->getConnection();
|
24 |
+
if ('month' == $this->_period) {
|
25 |
+
$this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m');
|
26 |
+
} elseif ('year' == $this->_period) {
|
27 |
+
$this->_periodFormat = $adapter->getDateExtractSql('period', Varien_Db_Adapter_Interface::INTERVAL_YEAR);
|
28 |
+
} else {
|
29 |
+
$this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m-%d');
|
30 |
+
}
|
31 |
+
|
32 |
+
if (!$this->isTotals()) {
|
33 |
+
$this->_selectedColumns = array(
|
34 |
+
'period' => $this->_periodFormat,
|
35 |
+
'orders_count' => 'SUM(orders_count)',
|
36 |
+
'total_qty_ordered' => 'SUM(total_qty_ordered)',
|
37 |
+
'total_qty_invoiced' => 'SUM(total_qty_invoiced)',
|
38 |
+
'total_income_amount' => 'SUM(total_income_amount)',
|
39 |
+
'total_revenue_amount' => 'SUM(total_revenue_amount)',
|
40 |
+
'total_profit_amount' => 'SUM(total_profit_amount)',
|
41 |
+
'total_invoiced_amount' => 'SUM(total_invoiced_amount)',
|
42 |
+
'total_canceled_amount' => 'SUM(total_canceled_amount)',
|
43 |
+
'total_paid_amount' => 'SUM(total_paid_amount)',
|
44 |
+
'total_refunded_amount' => 'SUM(total_refunded_amount)',
|
45 |
+
'total_tax_amount' => 'SUM(total_tax_amount)',
|
46 |
+
'total_tax_amount_actual' => 'SUM(total_tax_amount_actual)',
|
47 |
+
'total_shipping_amount' => 'SUM(total_shipping_amount)',
|
48 |
+
'total_shipping_amount_actual' => 'SUM(total_shipping_amount_actual)',
|
49 |
+
'total_discount_amount' => 'SUM(total_discount_amount)',
|
50 |
+
'total_discount_amount_actual' => 'SUM(total_discount_amount_actual)'
|
51 |
+
);
|
52 |
+
}
|
53 |
+
|
54 |
+
if ($this->isTotals()) {
|
55 |
+
$this->_selectedColumns = $this->getAggregatedColumns();
|
56 |
+
}
|
57 |
+
|
58 |
+
return $this->_selectedColumns;
|
59 |
+
}
|
60 |
+
}
|
app/code/community/Jmango360/Japi/Model/Resource/Sales/Report/Order/Collection/Live.php
ADDED
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Model_Resource_Sales_Report_Order_Collection_Live
|
7 |
+
extends Mage_Sales_Model_Resource_Report_Order_Collection
|
8 |
+
{
|
9 |
+
/**
|
10 |
+
* Aggregated Data Table
|
11 |
+
*
|
12 |
+
* @var string
|
13 |
+
*/
|
14 |
+
protected $_aggregationTable = 'sales/order';
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Get selected columns
|
18 |
+
*
|
19 |
+
* @return array
|
20 |
+
*/
|
21 |
+
protected function _getSelectedColumns()
|
22 |
+
{
|
23 |
+
$adapter = $this->getConnection();
|
24 |
+
|
25 |
+
$this->_selectedColumns = array(
|
26 |
+
'store_id' => 'o.store_id',
|
27 |
+
'orders_count' => new Zend_Db_Expr('COUNT(o.entity_id)'),
|
28 |
+
'total_income_amount' => new Zend_Db_Expr(
|
29 |
+
sprintf('SUM((%s - %s) * %s)',
|
30 |
+
$adapter->getIfNullSql('o.base_grand_total', 0),
|
31 |
+
$adapter->getIfNullSql('o.base_total_canceled', 0),
|
32 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
33 |
+
)
|
34 |
+
),
|
35 |
+
'total_revenue_amount' => new Zend_Db_Expr(
|
36 |
+
sprintf('SUM((%s - %s - %s - (%s - %s - %s)) * %s)',
|
37 |
+
$adapter->getIfNullSql('o.base_total_invoiced', 0),
|
38 |
+
$adapter->getIfNullSql('o.base_tax_invoiced', 0),
|
39 |
+
$adapter->getIfNullSql('o.base_shipping_invoiced', 0),
|
40 |
+
$adapter->getIfNullSql('o.base_total_refunded', 0),
|
41 |
+
$adapter->getIfNullSql('o.base_tax_refunded', 0),
|
42 |
+
$adapter->getIfNullSql('o.base_shipping_refunded', 0),
|
43 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
44 |
+
)
|
45 |
+
),
|
46 |
+
'total_profit_amount' => new Zend_Db_Expr(
|
47 |
+
sprintf('SUM((%s - %s - %s - %s - %s) * %s)',
|
48 |
+
$adapter->getIfNullSql('o.base_total_paid', 0),
|
49 |
+
$adapter->getIfNullSql('o.base_total_refunded', 0),
|
50 |
+
$adapter->getIfNullSql('o.base_tax_invoiced', 0),
|
51 |
+
$adapter->getIfNullSql('o.base_shipping_invoiced', 0),
|
52 |
+
$adapter->getIfNullSql('o.base_total_invoiced_cost', 0),
|
53 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
54 |
+
)
|
55 |
+
),
|
56 |
+
'total_invoiced_amount' => new Zend_Db_Expr(
|
57 |
+
sprintf('SUM(%s * %s)',
|
58 |
+
$adapter->getIfNullSql('o.base_total_invoiced', 0),
|
59 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
60 |
+
)
|
61 |
+
),
|
62 |
+
'total_canceled_amount' => new Zend_Db_Expr(
|
63 |
+
sprintf('SUM(%s * %s)',
|
64 |
+
$adapter->getIfNullSql('o.base_total_canceled', 0),
|
65 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
66 |
+
)
|
67 |
+
),
|
68 |
+
'total_paid_amount' => new Zend_Db_Expr(
|
69 |
+
sprintf('SUM(%s * %s)',
|
70 |
+
$adapter->getIfNullSql('o.base_total_paid', 0),
|
71 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
72 |
+
)
|
73 |
+
),
|
74 |
+
'total_refunded_amount' => new Zend_Db_Expr(
|
75 |
+
sprintf('SUM(%s * %s)',
|
76 |
+
$adapter->getIfNullSql('o.base_total_refunded', 0),
|
77 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
78 |
+
)
|
79 |
+
),
|
80 |
+
'total_tax_amount' => new Zend_Db_Expr(
|
81 |
+
sprintf('SUM((%s - %s) * %s)',
|
82 |
+
$adapter->getIfNullSql('o.base_tax_amount', 0),
|
83 |
+
$adapter->getIfNullSql('o.base_tax_canceled', 0),
|
84 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
85 |
+
)
|
86 |
+
),
|
87 |
+
'total_tax_amount_actual' => new Zend_Db_Expr(
|
88 |
+
sprintf('SUM((%s -%s) * %s)',
|
89 |
+
$adapter->getIfNullSql('o.base_tax_invoiced', 0),
|
90 |
+
$adapter->getIfNullSql('o.base_tax_refunded', 0),
|
91 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
92 |
+
)
|
93 |
+
),
|
94 |
+
'total_shipping_amount' => new Zend_Db_Expr(
|
95 |
+
sprintf('SUM((%s - %s) * %s)',
|
96 |
+
$adapter->getIfNullSql('o.base_shipping_amount', 0),
|
97 |
+
$adapter->getIfNullSql('o.base_shipping_canceled', 0),
|
98 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
99 |
+
)
|
100 |
+
),
|
101 |
+
'total_shipping_amount_actual' => new Zend_Db_Expr(
|
102 |
+
sprintf('SUM((%s - %s) * %s)',
|
103 |
+
$adapter->getIfNullSql('o.base_shipping_invoiced', 0),
|
104 |
+
$adapter->getIfNullSql('o.base_shipping_refunded', 0),
|
105 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
106 |
+
)
|
107 |
+
),
|
108 |
+
'total_discount_amount' => new Zend_Db_Expr(
|
109 |
+
sprintf('SUM((ABS(%s) - %s) * %s)',
|
110 |
+
$adapter->getIfNullSql('o.base_discount_amount', 0),
|
111 |
+
$adapter->getIfNullSql('o.base_discount_canceled', 0),
|
112 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
113 |
+
)
|
114 |
+
),
|
115 |
+
'total_discount_amount_actual' => new Zend_Db_Expr(
|
116 |
+
sprintf('SUM((%s - %s) * %s)',
|
117 |
+
$adapter->getIfNullSql('o.base_discount_invoiced', 0),
|
118 |
+
$adapter->getIfNullSql('o.base_discount_refunded', 0),
|
119 |
+
$adapter->getIfNullSql('o.base_to_global_rate', 0)
|
120 |
+
)
|
121 |
+
),
|
122 |
+
'customers_count' => new Zend_Db_Expr(
|
123 |
+
sprintf('COUNT(DISTINCT %s) + SUM(IF(%s IS NULL, 1, 0))',
|
124 |
+
$adapter->quoteIdentifier('o.customer_id'),
|
125 |
+
$adapter->quoteIdentifier('o.customer_id')
|
126 |
+
)
|
127 |
+
)
|
128 |
+
);
|
129 |
+
|
130 |
+
return $this->_selectedColumns;
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Add selected data
|
135 |
+
*
|
136 |
+
* @return Mage_Sales_Model_Resource_Report_Order_Collection
|
137 |
+
*/
|
138 |
+
protected function _initSelect()
|
139 |
+
{
|
140 |
+
$this->getSelect()
|
141 |
+
->from(array('o' => $this->getResource()->getMainTable()), $this->_getSelectedColumns())
|
142 |
+
->where('o.state NOT IN (?)', array(
|
143 |
+
Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
|
144 |
+
Mage_Sales_Model_Order::STATE_NEW
|
145 |
+
))
|
146 |
+
->where('o.japi = ?', 1)
|
147 |
+
->group(array(
|
148 |
+
'o.store_id'
|
149 |
+
));
|
150 |
+
|
151 |
+
return $this;
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Apply date range filter
|
156 |
+
*
|
157 |
+
* @return Mage_Sales_Model_Resource_Report_Collection_Abstract
|
158 |
+
*/
|
159 |
+
protected function _applyDateRangeFilter()
|
160 |
+
{
|
161 |
+
if ($this->_period === null && $this->_to === null) {
|
162 |
+
return $this;
|
163 |
+
}
|
164 |
+
|
165 |
+
$dateFrom = Mage::app()->getLocale()->date($this->_from, Varien_Date::DATE_INTERNAL_FORMAT);
|
166 |
+
$dateFrom->setHour(0);
|
167 |
+
$dateFrom->setMinute(0);
|
168 |
+
$dateFrom->setSecond(0);
|
169 |
+
|
170 |
+
$dateTo = Mage::app()->getLocale()->date($this->_to, Varien_Date::DATE_INTERNAL_FORMAT);
|
171 |
+
$dateTo->setHour(23);
|
172 |
+
$dateTo->setMinute(59);
|
173 |
+
$dateTo->setSecond(59);
|
174 |
+
|
175 |
+
$this->getSelect()
|
176 |
+
->columns(array(
|
177 |
+
'period' => $this->_getTZRangeOffsetExpression(
|
178 |
+
$this->_period, 'created_at', $dateFrom, $dateTo
|
179 |
+
)
|
180 |
+
))
|
181 |
+
->where(
|
182 |
+
$this->_getConditionSql('o.created_at', array(
|
183 |
+
'from' => $dateFrom,
|
184 |
+
'to' => $dateTo,
|
185 |
+
'datetime' => true
|
186 |
+
))
|
187 |
+
)
|
188 |
+
->group('period');
|
189 |
+
|
190 |
+
return $this;
|
191 |
+
}
|
192 |
+
|
193 |
+
/**
|
194 |
+
* Retrieve query for attribute with timezone conversion
|
195 |
+
*
|
196 |
+
* @param string $range
|
197 |
+
* @param string $attribute
|
198 |
+
* @param mixed $from
|
199 |
+
* @param mixed $to
|
200 |
+
* @return string
|
201 |
+
*/
|
202 |
+
protected function _getTZRangeOffsetExpression($range, $attribute, $from = null, $to = null)
|
203 |
+
{
|
204 |
+
return str_replace(
|
205 |
+
'{{attribute}}',
|
206 |
+
Mage::getResourceModel('sales/report_order')
|
207 |
+
->getStoreTZOffsetQuery($this->getMainTable(), $attribute, $from, $to),
|
208 |
+
$this->_getRangeExpression($range)
|
209 |
+
);
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Get range expression
|
214 |
+
*
|
215 |
+
* @param string $range
|
216 |
+
* @return Zend_Db_Expr
|
217 |
+
*/
|
218 |
+
protected function _getRangeExpression($range)
|
219 |
+
{
|
220 |
+
switch ($range) {
|
221 |
+
case 'day':
|
222 |
+
return $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d');
|
223 |
+
break;
|
224 |
+
default:
|
225 |
+
case 'month':
|
226 |
+
return $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m');
|
227 |
+
break;
|
228 |
+
case 'year':
|
229 |
+
return $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y');
|
230 |
+
break;
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Custom filters application ability
|
236 |
+
*
|
237 |
+
* @return Mage_Reports_Model_Resource_Report_Collection_Abstract
|
238 |
+
*/
|
239 |
+
protected function _applyCustomFilter()
|
240 |
+
{
|
241 |
+
$this->_applyOrderStatusFilter();
|
242 |
+
|
243 |
+
if ($this->isTotals()) {
|
244 |
+
$subSelect = clone $this->getSelect();
|
245 |
+
$this->getSelect()
|
246 |
+
->reset()
|
247 |
+
->from(array('r' => $subSelect), $this->getAggregatedColumns());
|
248 |
+
}
|
249 |
+
|
250 |
+
return $this;
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Apply order status filter
|
255 |
+
*
|
256 |
+
* @return Mage_Sales_Model_Resource_Report_Collection_Abstract
|
257 |
+
*/
|
258 |
+
protected function _applyOrderStatusFilter()
|
259 |
+
{
|
260 |
+
if (is_null($this->_orderStatus)) {
|
261 |
+
return $this;
|
262 |
+
}
|
263 |
+
|
264 |
+
$orderStatus = $this->_orderStatus;
|
265 |
+
if (!is_array($orderStatus)) {
|
266 |
+
$orderStatus = array($orderStatus);
|
267 |
+
}
|
268 |
+
|
269 |
+
$this->getSelect()->where('o.status IN(?)', $orderStatus);
|
270 |
+
|
271 |
+
return $this;
|
272 |
+
}
|
273 |
+
}
|
app/code/community/Jmango360/Japi/Model/Resource/Setup.php
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Jmango360_Japi_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
|
3 |
+
{
|
4 |
+
}
|
app/code/community/Jmango360/Japi/Model/Response.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* see for response codes http://www.restapitutorial.com/httpstatuscodes.html
|
5 |
+
*
|
6 |
+
*/
|
7 |
+
class Jmango360_Japi_Model_Response extends Mage_Api2_Model_Response
|
8 |
+
{
|
9 |
+
protected $_skipToken = false;
|
10 |
+
|
11 |
+
public function setSkipToken($flag)
|
12 |
+
{
|
13 |
+
$this->_skipToken = (bool)$flag;
|
14 |
+
}
|
15 |
+
|
16 |
+
public function render(array $data)
|
17 |
+
{
|
18 |
+
if (!$this->_skipToken) {
|
19 |
+
$data['token'] = Mage::getSingleton('japi/server')->getToken();
|
20 |
+
}
|
21 |
+
|
22 |
+
header("access-control-allow-origin: *");
|
23 |
+
$this->setMimeType($this->getRenderer()->getMimeType())
|
24 |
+
->setBody($this->getRenderer()->render($data));
|
25 |
+
}
|
26 |
+
|
27 |
+
protected function getRenderer()
|
28 |
+
{
|
29 |
+
return Mage::getModel('japi/renderer_json');
|
30 |
+
}
|
31 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Cart.php
ADDED
@@ -0,0 +1,459 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Cart extends Mage_Checkout_Model_Cart
|
4 |
+
{
|
5 |
+
protected $_logname = 'rest_cart.log';
|
6 |
+
|
7 |
+
public function dispatch()
|
8 |
+
{
|
9 |
+
$action = $this->_getRequest()->getAction();
|
10 |
+
$operation = $this->_getRequest()->getOperation();
|
11 |
+
|
12 |
+
switch ($action . $operation) {
|
13 |
+
case 'updateCart' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
14 |
+
$this->_checkQuote();
|
15 |
+
$data = $this->_addCartItem();
|
16 |
+
$this->_getResponse()->render($data);
|
17 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
18 |
+
break;
|
19 |
+
case 'updateCart' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
20 |
+
$this->_checkQuote();
|
21 |
+
$data = $this->_updateCartItem();
|
22 |
+
$this->_getResponse()->render($data);
|
23 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
24 |
+
break;
|
25 |
+
case 'updateCart' . Jmango360_Japi_Model_Request::OPERATION_DELETE:
|
26 |
+
$this->_checkQuote();
|
27 |
+
$data = $this->_deleteCartItem();
|
28 |
+
$this->_getResponse()->render($data);
|
29 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
30 |
+
break;
|
31 |
+
case 'updateCartItem' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
32 |
+
$this->_checkQuote();
|
33 |
+
$data = $this->_updateCartItemOption();
|
34 |
+
$this->_getResponse()->render($data);
|
35 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
36 |
+
break;
|
37 |
+
case 'emptyCart' . Jmango360_Japi_Model_Request::OPERATION_DELETE:
|
38 |
+
$data = $this->_emptyCart();
|
39 |
+
$this->_getResponse()->render($data);
|
40 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
41 |
+
break;
|
42 |
+
case 'getCart' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
43 |
+
$data = $this->_getCart();
|
44 |
+
$this->_getResponse()->render($data);
|
45 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
46 |
+
break;
|
47 |
+
case 'updateCoupon' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
48 |
+
$data = $this->_addCoupon();
|
49 |
+
$this->_getResponse()->render($data);
|
50 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
51 |
+
break;
|
52 |
+
case 'updateCoupon' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
53 |
+
$data = $this->_updateCoupon();
|
54 |
+
$this->_getResponse()->render($data);
|
55 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
56 |
+
break;
|
57 |
+
case 'updateCoupon' . Jmango360_Japi_Model_Request::OPERATION_DELETE:
|
58 |
+
$data = $this->_deleteCoupon();
|
59 |
+
$this->_getResponse()->render($data);
|
60 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
61 |
+
break;
|
62 |
+
default:
|
63 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Resource method not implemented'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
64 |
+
break;
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
protected function _checkQuote()
|
69 |
+
{
|
70 |
+
$quoteId = $this->_getRequest()->getParam('quote_id', null);
|
71 |
+
if (!$quoteId) return;
|
72 |
+
|
73 |
+
$quote = Mage::getModel('sales/quote')->load($quoteId);
|
74 |
+
if (!$quote->getId()) return;
|
75 |
+
if (!$quote->getIsActive()) return;
|
76 |
+
|
77 |
+
$session = $this->_getSession();
|
78 |
+
if ($session->getQuoteId() == $quote->getId()) return;
|
79 |
+
|
80 |
+
$session->replaceQuote($quote);
|
81 |
+
}
|
82 |
+
|
83 |
+
public function getCartData()
|
84 |
+
{
|
85 |
+
// if mobile version < 2.9.0, we should throw any error found
|
86 |
+
$throwError = Mage::getSingleton('core/session')->getIsOffilneCart();
|
87 |
+
|
88 |
+
$this->_validateQuote(!$throwError);
|
89 |
+
$this->_validateMinimumAmount(!$throwError);
|
90 |
+
$this->_validateGuestCanCheckout(!$throwError);
|
91 |
+
|
92 |
+
$cart = $this->getQuote()->getData();
|
93 |
+
|
94 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
95 |
+
$helper = Mage::helper('japi/product');
|
96 |
+
/* @var $taxHelper Mage_Tax_Helper_Data */
|
97 |
+
$taxHelper = Mage::helper('tax');
|
98 |
+
|
99 |
+
$index = 0;
|
100 |
+
$recollect = false;
|
101 |
+
$cart['items'] = null;
|
102 |
+
foreach ($this->getQuote()->getAllVisibleItems() as $item) {
|
103 |
+
/* @var $item Mage_Sales_Model_Quote_Item */
|
104 |
+
$product = $helper->convertProductIdToApiResponseV2($item->getProductId());
|
105 |
+
|
106 |
+
// MPLUGIN-1259: Workaround to manual remove unavailable product
|
107 |
+
if (!$product) {
|
108 |
+
$this->removeItem($item->getId());
|
109 |
+
$recollect = true;
|
110 |
+
continue;
|
111 |
+
}
|
112 |
+
|
113 |
+
$cart['items'][$index] = $item->getData();
|
114 |
+
|
115 |
+
if ($taxHelper->displayCartPriceInclTax() || $taxHelper->displayCartBothPrices()) {
|
116 |
+
$cart['items'][$index]['price'] = $item->getData('price_incl_tax');
|
117 |
+
$cart['items'][$index]['row_total'] = $item->getData('row_total_incl_tax');
|
118 |
+
}
|
119 |
+
|
120 |
+
$cart['items'][$index]['has_messages'] = $this->_getQuoteItemMessages($item);
|
121 |
+
$cart['items'][$index]['product'] = array($product);
|
122 |
+
$cart['items'][$index]['buy_request'] = $helper->getCartProductBuyRequest($item, $product);
|
123 |
+
|
124 |
+
$index++;
|
125 |
+
}
|
126 |
+
|
127 |
+
if ($recollect) {
|
128 |
+
$this->save();
|
129 |
+
$this->_resetQuote();
|
130 |
+
return false;
|
131 |
+
}
|
132 |
+
|
133 |
+
// Move here to prevent being cached in cart object
|
134 |
+
$cart['items_count'] = $this->getSummaryQty();
|
135 |
+
|
136 |
+
/**
|
137 |
+
* MultiShipping is not supported yet. Always one shipping address is returned in the response
|
138 |
+
*/
|
139 |
+
foreach ($this->getQuote()->getAllAddresses() as $address) {
|
140 |
+
/* @var $address Mage_Sales_Model_Quote_Address */
|
141 |
+
$cart['addresses'][$address->getAddressType()] = $address->getData();
|
142 |
+
}
|
143 |
+
|
144 |
+
$cart['totals'] = Mage::helper('japi')->getTotals();
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Add the checkout methods
|
148 |
+
* -- as long as the order is not submitted changing the carts address and items
|
149 |
+
* -- can change the checkout methods
|
150 |
+
*/
|
151 |
+
/* @var $methods Jmango360_Japi_Model_Rest_Checkout_Methods */
|
152 |
+
$methods = Mage::getSingleton('japi/rest_checkout_methods');
|
153 |
+
$shippingMethods = $methods->getShippingmethods();
|
154 |
+
$cart['shipping_methods'] = empty($shippingMethods) ? new stdClass() : $shippingMethods;
|
155 |
+
$paymentMethods = $methods->getPaymentMethods();
|
156 |
+
$cart['payment_methods'] = empty($paymentMethods) ? new stdClass() : $paymentMethods;
|
157 |
+
|
158 |
+
$cart['methods_info'] = $methods->getErrors();
|
159 |
+
$cart['checkout_url'] = Mage::getUrl('japi/checkout/redirect', array(
|
160 |
+
'_query' => array(
|
161 |
+
'SID' => Mage::getSingleton('core/session')->getSessionId(),
|
162 |
+
'___store' => Mage::app()->getStore()->getCode()
|
163 |
+
),
|
164 |
+
'_secure' => true
|
165 |
+
));
|
166 |
+
|
167 |
+
return $cart;
|
168 |
+
}
|
169 |
+
|
170 |
+
protected function _resetQuote()
|
171 |
+
{
|
172 |
+
$quoteId = $this->getQuote()->getId();
|
173 |
+
$this->getCheckoutSession()->clear();
|
174 |
+
$this->getCheckoutSession()->setQuoteId($quoteId);
|
175 |
+
$this->unsetData('quote');
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* @param Mage_Sales_Model_Quote_Item $quoteItem
|
180 |
+
* @return array
|
181 |
+
*/
|
182 |
+
protected function _getQuoteItemMessages($quoteItem)
|
183 |
+
{
|
184 |
+
$messages = array();
|
185 |
+
|
186 |
+
// Add basic messages occuring during this page load
|
187 |
+
$baseMessages = $quoteItem->getMessage(false);
|
188 |
+
if ($baseMessages) {
|
189 |
+
foreach ($baseMessages as $message) {
|
190 |
+
$messages[] = array(
|
191 |
+
'message' => $message,
|
192 |
+
'type' => $quoteItem->getHasError() ? 2 : 1
|
193 |
+
);
|
194 |
+
}
|
195 |
+
}
|
196 |
+
|
197 |
+
// Add messages saved previously in checkout session
|
198 |
+
$checkoutSession = $this->getCheckoutSession();
|
199 |
+
if ($checkoutSession) {
|
200 |
+
/* @var $collection Mage_Core_Model_Message_Collection */
|
201 |
+
$collection = $checkoutSession->getQuoteItemMessages($quoteItem->getId(), true);
|
202 |
+
if ($collection) {
|
203 |
+
$additionalMessages = $collection->getItems();
|
204 |
+
foreach ($additionalMessages as $message) {
|
205 |
+
/* @var $message Mage_Core_Model_Message_Abstract */
|
206 |
+
$messages[] = array(
|
207 |
+
'message' => $message->getCode(),
|
208 |
+
'type' => ($message->getType() == Mage_Core_Model_Message::ERROR) ? 2 : 1
|
209 |
+
);
|
210 |
+
}
|
211 |
+
}
|
212 |
+
}
|
213 |
+
|
214 |
+
return $messages;
|
215 |
+
}
|
216 |
+
|
217 |
+
protected function _addCartItem()
|
218 |
+
{
|
219 |
+
/* @var $model Jmango360_Japi_Model_Rest_Cart_Update */
|
220 |
+
$model = Mage::getModel('japi/rest_cart_update');
|
221 |
+
$data = $model->addCartItem();
|
222 |
+
|
223 |
+
return $data;
|
224 |
+
}
|
225 |
+
|
226 |
+
protected function _updateCartItem()
|
227 |
+
{
|
228 |
+
/* @var $model Jmango360_Japi_Model_Rest_Cart_Update */
|
229 |
+
$model = Mage::getModel('japi/rest_cart_update');
|
230 |
+
$data = $model->updateCartItem();
|
231 |
+
|
232 |
+
return $data;
|
233 |
+
}
|
234 |
+
|
235 |
+
protected function _updateCartItemOption()
|
236 |
+
{
|
237 |
+
/* @var $model Jmango360_Japi_Model_Rest_Cart_Update */
|
238 |
+
$model = Mage::getModel('japi/rest_cart_update');
|
239 |
+
$data = $model->updateCartItemOption();
|
240 |
+
|
241 |
+
return $data;
|
242 |
+
}
|
243 |
+
|
244 |
+
protected function _deleteCartItem()
|
245 |
+
{
|
246 |
+
/* @var $model Jmango360_Japi_Model_Rest_Cart_Update */
|
247 |
+
$model = Mage::getModel('japi/rest_cart_update');
|
248 |
+
$data = $model->deleteCartItem();
|
249 |
+
|
250 |
+
return $data;
|
251 |
+
}
|
252 |
+
|
253 |
+
protected function _emptyCart()
|
254 |
+
{
|
255 |
+
/* @var $model Jmango360_Japi_Model_Rest_Cart_Update */
|
256 |
+
$model = Mage::getModel('japi/rest_cart_update');
|
257 |
+
$data = $model->emptyCart();
|
258 |
+
|
259 |
+
return $data;
|
260 |
+
}
|
261 |
+
|
262 |
+
protected function _getCart()
|
263 |
+
{
|
264 |
+
$throwError = Mage::getSingleton('core/session')->getIsOffilneCart();
|
265 |
+
|
266 |
+
if ($error1 = $this->_validateQuote(!$throwError))
|
267 |
+
$data['messages']['message'][] = array(
|
268 |
+
'code' => Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR,
|
269 |
+
'message' => $error1,
|
270 |
+
'type' => 1
|
271 |
+
);
|
272 |
+
|
273 |
+
if ($error2 = $this->_validateMinimumAmount(!$throwError))
|
274 |
+
$data['messages']['message'][] = array(
|
275 |
+
'code' => Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR,
|
276 |
+
'message' => $error2,
|
277 |
+
'type' => 1
|
278 |
+
);
|
279 |
+
|
280 |
+
if ($error3 = $this->_validateGuestCanCheckout(!$throwError))
|
281 |
+
$data['messages']['message'][] = array(
|
282 |
+
'code' => Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR,
|
283 |
+
'message' => $error3,
|
284 |
+
'type' => 1
|
285 |
+
);
|
286 |
+
|
287 |
+
$data['cart'] = $this->getCartData();
|
288 |
+
if ($data['cart'] === false) {
|
289 |
+
return $this->_getCart();
|
290 |
+
}
|
291 |
+
|
292 |
+
return $data;
|
293 |
+
}
|
294 |
+
|
295 |
+
protected function _initProduct()
|
296 |
+
{
|
297 |
+
/* @var $helper Mage_Core_Helper_Data */
|
298 |
+
$helper = Mage::helper('core');
|
299 |
+
|
300 |
+
$productId = (int)$this->_getRequest()->getParam('product_id');
|
301 |
+
if (!$productId) return false;
|
302 |
+
|
303 |
+
/* @var $product Mage_Catalog_Model_Product */
|
304 |
+
$product = Mage::getModel('catalog/product')
|
305 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
306 |
+
->load($productId);
|
307 |
+
|
308 |
+
if (!$product->getId()) return false;
|
309 |
+
|
310 |
+
/**
|
311 |
+
* Support OrganicInternet_SimpleConfigurableProducts
|
312 |
+
* which buy child product instead configurable product
|
313 |
+
*/
|
314 |
+
if ($helper->isModuleEnabled('OrganicInternet_SimpleConfigurableProducts') && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
|
315 |
+
$buyRequest = (array)$this->_getRequest()->getParam('super_attribute');
|
316 |
+
$usedProducts = $product->getTypeInstance(true)->getUsedProducts(null, $product);
|
317 |
+
$allowAttributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
|
318 |
+
foreach ($usedProducts as $item) {
|
319 |
+
$match = 0;
|
320 |
+
foreach ($allowAttributes as $attribute) {
|
321 |
+
$productAttribute = $attribute->getProductAttribute();
|
322 |
+
$attributeId = $productAttribute->getId();
|
323 |
+
$attributeCode = $productAttribute->getAttributeCode();
|
324 |
+
if (array_key_exists($attributeId, $buyRequest) && $item->getData($attributeCode) == $buyRequest[$attributeId]) {
|
325 |
+
$match += 1;
|
326 |
+
}
|
327 |
+
}
|
328 |
+
if ($match == count($buyRequest)) {
|
329 |
+
$product = Mage::getModel('catalog/product')
|
330 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
331 |
+
->load($item->getId());
|
332 |
+
break;
|
333 |
+
}
|
334 |
+
}
|
335 |
+
}
|
336 |
+
|
337 |
+
return $product;
|
338 |
+
}
|
339 |
+
|
340 |
+
protected function _addCoupon()
|
341 |
+
{
|
342 |
+
/* @var $model Jmango360_Japi_Model_Rest_Cart_Coupon */
|
343 |
+
$model = Mage::getModel('japi/rest_cart_coupon');
|
344 |
+
$data = $model->add();
|
345 |
+
|
346 |
+
return $data;
|
347 |
+
}
|
348 |
+
|
349 |
+
protected function _updateCoupon()
|
350 |
+
{
|
351 |
+
/* @var $model Jmango360_Japi_Model_Rest_Cart_Coupon */
|
352 |
+
$model = Mage::getModel('japi/rest_cart_coupon');
|
353 |
+
$data = $model->update();
|
354 |
+
|
355 |
+
return $data;
|
356 |
+
}
|
357 |
+
|
358 |
+
protected function _deleteCoupon()
|
359 |
+
{
|
360 |
+
/* @var $model Jmango360_Japi_Model_Rest_Cart_Coupon */
|
361 |
+
$model = Mage::getModel('japi/rest_cart_coupon');
|
362 |
+
$data = $model->remove();
|
363 |
+
|
364 |
+
return $data;
|
365 |
+
}
|
366 |
+
|
367 |
+
protected function _validateQuote($return = false)
|
368 |
+
{
|
369 |
+
$quote = $this->getQuote()->collectTotals();
|
370 |
+
if ($quote->getHasError()) {
|
371 |
+
$messages = array();
|
372 |
+
foreach ($quote->getMessages() as $message) {
|
373 |
+
$messages[] = $message->getCode();
|
374 |
+
}
|
375 |
+
if ($return)
|
376 |
+
return implode("\n", $messages);
|
377 |
+
else {
|
378 |
+
throw new Jmango360_Japi_Exception(
|
379 |
+
implode("\n", $messages),
|
380 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
381 |
+
);
|
382 |
+
}
|
383 |
+
}
|
384 |
+
}
|
385 |
+
|
386 |
+
public function getQuote()
|
387 |
+
{
|
388 |
+
$quote = parent::getQuote();
|
389 |
+
$storeId = Mage::app()->getStore()->getId();
|
390 |
+
if ($quote->getStoreId() != $storeId) {
|
391 |
+
$quote->setStoreId($storeId);
|
392 |
+
}
|
393 |
+
|
394 |
+
return $quote;
|
395 |
+
}
|
396 |
+
|
397 |
+
protected function _validateMinimumAmount($return = false)
|
398 |
+
{
|
399 |
+
if ($this->getQuote()->getItemsCount() && !$this->getQuote()->validateMinimumAmount()) {
|
400 |
+
$minimumAmount = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())
|
401 |
+
->toCurrency(Mage::getStoreConfig('sales/minimum_order/amount'));
|
402 |
+
|
403 |
+
$warning = Mage::getStoreConfig('sales/minimum_order/description')
|
404 |
+
? Mage::getStoreConfig('sales/minimum_order/description')
|
405 |
+
: Mage::helper('checkout')->__('Minimum order amount is %s', $minimumAmount);
|
406 |
+
|
407 |
+
if ($return) return $warning;
|
408 |
+
else throw new Jmango360_Japi_Exception($warning, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
409 |
+
}
|
410 |
+
}
|
411 |
+
|
412 |
+
protected function _validateGuestCanCheckout($return = false)
|
413 |
+
{
|
414 |
+
/* @var $helper Mage_Checkout_Helper_Data */
|
415 |
+
$helper = Mage::helper('checkout');
|
416 |
+
if (!$this->getQuote()->getCustomerId() && !$helper->isAllowedGuestCheckout($this->getQuote())) {
|
417 |
+
$message = Mage::helper('japi')->__('Guest checkout is not enabled');
|
418 |
+
|
419 |
+
if ($return) return $message;
|
420 |
+
else throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
421 |
+
}
|
422 |
+
}
|
423 |
+
|
424 |
+
public function getCouponData()
|
425 |
+
{
|
426 |
+
$data = $this->_getCart();
|
427 |
+
|
428 |
+
$quote = $this->getQuote();
|
429 |
+
$data['coupon'] = $quote->getCouponCode();
|
430 |
+
|
431 |
+
return $data;
|
432 |
+
}
|
433 |
+
|
434 |
+
/**
|
435 |
+
* @return Mage_Checkout_Model_Session
|
436 |
+
*/
|
437 |
+
protected function _getSession()
|
438 |
+
{
|
439 |
+
return Mage::getSingleton('checkout/session');
|
440 |
+
}
|
441 |
+
|
442 |
+
protected function _getRequest()
|
443 |
+
{
|
444 |
+
return $this->_getServer()->getRequest();
|
445 |
+
}
|
446 |
+
|
447 |
+
protected function _getResponse()
|
448 |
+
{
|
449 |
+
return $this->_getServer()->getResponse();
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* @return Jmango360_Japi_Model_Server
|
454 |
+
*/
|
455 |
+
protected function _getServer()
|
456 |
+
{
|
457 |
+
return Mage::getSingleton('japi/server');
|
458 |
+
}
|
459 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Cart/Coupon.php
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Jmango360_Japi_Model_Rest_Cart_Coupon extends Jmango360_Japi_Model_Rest_Cart
|
3 |
+
{
|
4 |
+
protected $_restCouponCode = null;
|
5 |
+
|
6 |
+
public function _construct()
|
7 |
+
{
|
8 |
+
$request = Mage::helper('japi')->getRequest();
|
9 |
+
$this->_restCouponCode = $request->getParam('coupon_code', null);
|
10 |
+
}
|
11 |
+
|
12 |
+
public function add()
|
13 |
+
{
|
14 |
+
$this->_applyCoupon();
|
15 |
+
|
16 |
+
return $this->getCouponData();
|
17 |
+
}
|
18 |
+
|
19 |
+
public function update()
|
20 |
+
{
|
21 |
+
$this->_applyCoupon();
|
22 |
+
|
23 |
+
return $this->getCouponData();
|
24 |
+
}
|
25 |
+
|
26 |
+
public function remove()
|
27 |
+
{
|
28 |
+
$this->_restCouponCode = '';
|
29 |
+
$this->_applyCoupon();
|
30 |
+
|
31 |
+
return $this->getCouponData();
|
32 |
+
}
|
33 |
+
|
34 |
+
protected function _applyCoupon()
|
35 |
+
{
|
36 |
+
$quote = $this->getQuote();
|
37 |
+
|
38 |
+
if (!$quote->getItemsCount()) {
|
39 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Cart is empty.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
40 |
+
}
|
41 |
+
|
42 |
+
try {
|
43 |
+
$quote->getShippingAddress()->setCollectShippingRates(true);
|
44 |
+
$quote->setCouponCode(strlen($this->_restCouponCode) ? $this->_restCouponCode : '')
|
45 |
+
->collectTotals()
|
46 |
+
->save();
|
47 |
+
} catch (Exception $e) {
|
48 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Coupon is not valid: ' . $e->getMessage()), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
49 |
+
}
|
50 |
+
|
51 |
+
if ($this->_restCouponCode) {
|
52 |
+
if ($this->_restCouponCode != $quote->getCouponCode()) {
|
53 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Coupon could not be applied.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
return $this;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
|
app/code/community/Jmango360/Japi/Model/Rest/Cart/Update.php
ADDED
@@ -0,0 +1,342 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Cart_Update extends Jmango360_Japi_Model_Rest_Cart
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* @throws Jmango360_Japi_Exception
|
7 |
+
* @return array
|
8 |
+
*/
|
9 |
+
public function addCartItem()
|
10 |
+
{
|
11 |
+
$params = $this->_getRequest()->getParams();
|
12 |
+
$isOfflineCart = Mage::getSingleton('core/session')->getIsOffilneCart();
|
13 |
+
|
14 |
+
// Clean params
|
15 |
+
unset($params['SID']);
|
16 |
+
unset($params['token']);
|
17 |
+
unset($params['quote_id']);
|
18 |
+
unset($params['version']);
|
19 |
+
|
20 |
+
if (isset($params['qty'])) {
|
21 |
+
$filter = new Zend_Filter_LocalizedToNormalized(
|
22 |
+
array('locale' => Mage::app()->getLocale()->getLocaleCode())
|
23 |
+
);
|
24 |
+
$params['qty'] = $filter->filter($params['qty']);
|
25 |
+
}
|
26 |
+
|
27 |
+
$product = $this->_initProduct();
|
28 |
+
if (!$product || $product->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
|
29 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Product not found.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
30 |
+
}
|
31 |
+
|
32 |
+
if ($isOfflineCart) {
|
33 |
+
/**
|
34 |
+
* Check minimum & maximum quantity allowed for sale
|
35 |
+
*/
|
36 |
+
if (($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE || $product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) && $product->getStockItem()) { //Check for Simple and Bundle products
|
37 |
+
$_minSaleQty = $product->getStockItem()->getMinSaleQty() ? $product->getStockItem()->getMinSaleQty() : 0;
|
38 |
+
if ($params['qty'] < $_minSaleQty) {
|
39 |
+
throw new Jmango360_Japi_Exception(Mage::helper('cataloginventory')->__('%s: Minimum quantity allowed for purchase is %s.', $product->getName(), $_minSaleQty * 1), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
40 |
+
}
|
41 |
+
|
42 |
+
$_maxSaleQty = $product->getStockItem()->getMaxSaleQty();
|
43 |
+
if ($_maxSaleQty && $params['qty'] > $_maxSaleQty) {
|
44 |
+
throw new Jmango360_Japi_Exception(Mage::helper('cataloginventory')->__('%s: Maximum quantity allowed for purchase is %s.', $product->getName(), $_maxSaleQty * 1), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
45 |
+
}
|
46 |
+
} else if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { //Check for Configurable products
|
47 |
+
if (isset($params['super_attribute'])) {
|
48 |
+
$childProduct = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($params['super_attribute'], $product);
|
49 |
+
if ($childProduct->getId() && $childProduct->getStockItem()) {
|
50 |
+
$_minSaleQty = $childProduct->getStockItem()->getMinSaleQty() ? $childProduct->getStockItem()->getMinSaleQty() : 0;
|
51 |
+
if ($params['qty'] < $_minSaleQty) {
|
52 |
+
throw new Jmango360_Japi_Exception(Mage::helper('cataloginventory')->__('%s: Minimum quantity allowed for purchase is %s.', $product->getName(), $_minSaleQty * 1), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
53 |
+
}
|
54 |
+
|
55 |
+
$_maxSaleQty = $childProduct->getStockItem()->getMaxSaleQty();
|
56 |
+
if ($_maxSaleQty && $params['qty'] > $_maxSaleQty) {
|
57 |
+
throw new Jmango360_Japi_Exception(Mage::helper('cataloginventory')->__('%s: Maximum quantity allowed for purchase is %s.', $product->getName(), $_maxSaleQty * 1), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
58 |
+
}
|
59 |
+
}
|
60 |
+
}
|
61 |
+
} else if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) { //Check for Group products
|
62 |
+
if (isset($params['super_group'])) {
|
63 |
+
$message = '';
|
64 |
+
$_superGroups = $params['super_group'];
|
65 |
+
foreach ($_superGroups as $key => $val) {
|
66 |
+
/* @var $_simpleProduct Mage_Catalog_Model_Product */
|
67 |
+
$_simpleProduct = Mage::getModel('catalog/product')->load((int)$key);
|
68 |
+
if ($_simpleProduct->getId() && $_simpleProduct->getStockItem()) {
|
69 |
+
$_minSaleQty = $_simpleProduct->getStockItem()->getMinSaleQty() ? $_simpleProduct->getStockItem()->getMinSaleQty() : 0;
|
70 |
+
if ($val < $_minSaleQty) {
|
71 |
+
$message .= Mage::helper('cataloginventory')->__('%s: Minimum quantity allowed for purchase is %s.', $_simpleProduct->getName(), $_minSaleQty * 1);
|
72 |
+
$message .= "\n";
|
73 |
+
}
|
74 |
+
|
75 |
+
$_maxSaleQty = $_simpleProduct->getStockItem()->getMaxSaleQty();
|
76 |
+
if ($_maxSaleQty && $val > $_maxSaleQty) {
|
77 |
+
$message .= Mage::helper('cataloginventory')->__('%s: Maximum quantity allowed for purchase is %s.', $_simpleProduct->getName(), $_maxSaleQty * 1);
|
78 |
+
$message .= "\n";
|
79 |
+
}
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
if ($message != '') {
|
84 |
+
throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
85 |
+
}
|
86 |
+
}
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
$related = $this->_getRequest()->getParam('related_product');
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Flag as JMango360 order
|
94 |
+
*/
|
95 |
+
$this->getQuote()->setData('japi', 1);
|
96 |
+
|
97 |
+
/**
|
98 |
+
* TODO: Workaround for some module tring save shipping address before quote saved
|
99 |
+
*/
|
100 |
+
if (Mage::helper('core')->isModuleEnabled('RapidCommerce_Defaultdestination')) {
|
101 |
+
$this->getQuote()->save();
|
102 |
+
}
|
103 |
+
|
104 |
+
$this->addProduct($product, $params);
|
105 |
+
if (!empty($related)) {
|
106 |
+
$this->addProductsByIds(explode(',', $related));
|
107 |
+
}
|
108 |
+
|
109 |
+
$this->save();
|
110 |
+
|
111 |
+
$this->_getSession()->setCartWasUpdated(true);
|
112 |
+
|
113 |
+
Mage::dispatchEvent('checkout_cart_add_product_complete',
|
114 |
+
array('product' => $product, 'request' => $this->_getRequest(), 'response' => $this->_getResponse())
|
115 |
+
);
|
116 |
+
|
117 |
+
$data['message'] = Mage::helper('japi')->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
|
118 |
+
$data['no_redirect_to_cart'] = $this->_getSession()->getNoCartRedirect();
|
119 |
+
$data['cart'] = $this->getCartData();
|
120 |
+
|
121 |
+
return $data;
|
122 |
+
}
|
123 |
+
|
124 |
+
public function updateCartItem()
|
125 |
+
{
|
126 |
+
$cartData = $this->_getRequest()->getParam('cart', null);
|
127 |
+
|
128 |
+
if (is_array($cartData) && !empty($cartData)) {
|
129 |
+
$filter = new Zend_Filter_LocalizedToNormalized(
|
130 |
+
array('locale' => Mage::app()->getLocale()->getLocaleCode())
|
131 |
+
);
|
132 |
+
|
133 |
+
foreach ($cartData as $index => $data) {
|
134 |
+
if (isset($data['qty'])) {
|
135 |
+
$cartData[$index]['qty'] = $filter->filter(trim($data['qty']));
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
if (!$this->getCustomerSession()->getCustomer()->getId() && $this->getQuote()->getCustomerId()) {
|
140 |
+
$this->getQuote()->setCustomerId(null);
|
141 |
+
}
|
142 |
+
|
143 |
+
$cartData = $this->suggestItemsQty($cartData);
|
144 |
+
$this->updateItems($cartData)->save();
|
145 |
+
$this->_resetQuote();
|
146 |
+
} else {
|
147 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('No cart data found.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
148 |
+
}
|
149 |
+
$this->_getSession()->setCartWasUpdated(true);
|
150 |
+
|
151 |
+
$data = $this->_getCart();
|
152 |
+
$data['message'] = Mage::helper('japi')->__('Your shopping cart has been updated.');
|
153 |
+
|
154 |
+
return $data;
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* @param $quoteItem
|
159 |
+
* @param $params
|
160 |
+
* @throws Jmango360_Japi_Exception
|
161 |
+
*/
|
162 |
+
protected function _validateQtyUpdate($quoteItem, $params)
|
163 |
+
{
|
164 |
+
/** @var Mage_Catalog_Model_Product $product */
|
165 |
+
$product = Mage::getModel('catalog/product')->load($quoteItem->getProductId());
|
166 |
+
if (($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE || $product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) && $product->getStockItem()) { //Check for Simple and Bundle products
|
167 |
+
$_minSaleQty = $product->getStockItem()->getMinSaleQty() ? $product->getStockItem()->getMinSaleQty() : 0;
|
168 |
+
if ($params['qty'] < $_minSaleQty) {
|
169 |
+
throw new Jmango360_Japi_Exception(Mage::helper('cataloginventory')->__('%s: Minimum quantity allowed for purchase is %s.', $product->getName(), $_minSaleQty * 1), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
170 |
+
}
|
171 |
+
$_maxSaleQty = $product->getStockItem()->getMaxSaleQty();
|
172 |
+
if ($_maxSaleQty && $params['qty'] > $_maxSaleQty) {
|
173 |
+
throw new Jmango360_Japi_Exception(Mage::helper('cataloginventory')->__('%s: Maximum quantity allowed for purchase is %s.', $product->getName(), $_maxSaleQty * 1), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
174 |
+
}
|
175 |
+
} else if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { //Check for Configurable products
|
176 |
+
$buy_request = Mage::helper('japi/product')->getCartProductBuyRequest($quoteItem, $product);
|
177 |
+
$childProduct = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($buy_request['super_attribute'], $product);
|
178 |
+
|
179 |
+
if ($childProduct->getId() && $childProduct->getStockItem()) {
|
180 |
+
$_minSaleQty = $childProduct->getStockItem()->getMinSaleQty() ? $childProduct->getStockItem()->getMinSaleQty() : 0;
|
181 |
+
if ($params['qty'] < $_minSaleQty) {
|
182 |
+
throw new Jmango360_Japi_Exception(Mage::helper('cataloginventory')->__('%s: Minimum quantity allowed for purchase is %s.', $product->getName(), $_minSaleQty * 1), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
183 |
+
}
|
184 |
+
|
185 |
+
$_maxSaleQty = $childProduct->getStockItem()->getMaxSaleQty();
|
186 |
+
if ($_maxSaleQty && $params['qty'] > $_maxSaleQty) {
|
187 |
+
throw new Jmango360_Japi_Exception(Mage::helper('cataloginventory')->__('%s: Maximum quantity allowed for purchase is %s.', $product->getName(), $_maxSaleQty * 1), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
188 |
+
}
|
189 |
+
}
|
190 |
+
}
|
191 |
+
}
|
192 |
+
|
193 |
+
protected function _updateCartOptions($params)
|
194 |
+
{
|
195 |
+
if (!isset($params['id'])) {
|
196 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('No bundle-product cart item ID found.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
197 |
+
}
|
198 |
+
|
199 |
+
$cart = $this->getQuote();
|
200 |
+
$item = $cart->getItemById($params['id']);
|
201 |
+
if (!is_object($item) || !$item->getProductId()) {
|
202 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__(' .'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
203 |
+
}
|
204 |
+
|
205 |
+
$params['product_id'] = $item->getProductId();
|
206 |
+
|
207 |
+
if (!isset($params['options'])) {
|
208 |
+
$params['options'] = array();
|
209 |
+
}
|
210 |
+
|
211 |
+
$item = Mage::getSingleton('checkout/cart')->updateItem($params['id'], new Varien_Object($params));
|
212 |
+
if (is_string($item)) {
|
213 |
+
throw new Jmango360_Japi_Exception($item, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
214 |
+
}
|
215 |
+
if ($item->getHasError()) {
|
216 |
+
throw new Jmango360_Japi_Exception($item->getMessage(), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
217 |
+
}
|
218 |
+
|
219 |
+
return $this;
|
220 |
+
}
|
221 |
+
|
222 |
+
public function deleteCartItem()
|
223 |
+
{
|
224 |
+
$id = (int)$this->_getRequest()->getParam('id', null);
|
225 |
+
$messages = array();
|
226 |
+
|
227 |
+
$check = $this->getQuote()->getItemById($id);
|
228 |
+
if (!is_object($check) || !$check->getId()) {
|
229 |
+
$message = Mage::helper('japi')->__('The product you are trying to delete could not be found in the cart (item id is %s not found in cart).', $id);
|
230 |
+
//Mage::log($message, Zend_Log::WARN, $this->_logname);
|
231 |
+
$messages[] = $message;
|
232 |
+
} else {
|
233 |
+
$this->removeItem($id)->save();
|
234 |
+
$this->_resetQuote();
|
235 |
+
}
|
236 |
+
|
237 |
+
if (empty($messages)) {
|
238 |
+
$messages[] = Mage::helper('japi')->__('The product has been deleted from your shopping cart.');
|
239 |
+
}
|
240 |
+
|
241 |
+
$data = $this->_getCart();
|
242 |
+
$data['message'] = implode("/n", $messages);
|
243 |
+
|
244 |
+
return $data;
|
245 |
+
}
|
246 |
+
|
247 |
+
public function emptyCart()
|
248 |
+
{
|
249 |
+
/* @var $cart Mage_Checkout_Model_Cart */
|
250 |
+
$cart = Mage::getSingleton('checkout/cart');
|
251 |
+
$cart->truncate()->save();
|
252 |
+
/* @var $session Mage_Checkout_Model_Session */
|
253 |
+
$session = Mage::getSingleton('checkout/session');
|
254 |
+
$session->setCartWasUpdated(true);
|
255 |
+
/* @var $quote Mage_Sales_Model_Quote */
|
256 |
+
$quote = $session->getQuote();
|
257 |
+
$quote->removePayment()->save();
|
258 |
+
$quote->getShippingAddress()->setShippingMethod('')->save();
|
259 |
+
|
260 |
+
$data = $this->_getCart();
|
261 |
+
return $data;
|
262 |
+
}
|
263 |
+
|
264 |
+
public function updateCartItemOption()
|
265 |
+
{
|
266 |
+
/* @var $cart Mage_Checkout_Model_Cart */
|
267 |
+
$cart = Mage::getSingleton('checkout/cart');
|
268 |
+
$id = (int)$this->_getRequest()->getParam('id');
|
269 |
+
$params = $this->_getRequest()->getParams();
|
270 |
+
|
271 |
+
if (!isset($params['options'])) {
|
272 |
+
$params['options'] = array();
|
273 |
+
}
|
274 |
+
|
275 |
+
try {
|
276 |
+
$quoteItem = $cart->getQuote()->getItemById($id);
|
277 |
+
if (!$quoteItem) {
|
278 |
+
throw new Jmango360_Japi_Exception(
|
279 |
+
Mage::helper('japi')->__('Quote item is not found.'),
|
280 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
281 |
+
);
|
282 |
+
}
|
283 |
+
|
284 |
+
if (isset($params['qty'])) {
|
285 |
+
$filter = new Zend_Filter_LocalizedToNormalized(
|
286 |
+
array('locale' => Mage::app()->getLocale()->getLocaleCode())
|
287 |
+
);
|
288 |
+
$params['qty'] = $filter->filter($params['qty']);
|
289 |
+
} else {
|
290 |
+
$params['qty'] = $quoteItem->getQty();
|
291 |
+
}
|
292 |
+
|
293 |
+
$item = $cart->updateItem($id, new Varien_Object($params));
|
294 |
+
if (is_string($item)) {
|
295 |
+
throw new Jmango360_Japi_Exception(
|
296 |
+
$item,
|
297 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
298 |
+
);
|
299 |
+
}
|
300 |
+
if ($item->getHasError()) {
|
301 |
+
throw new Jmango360_Japi_Exception(
|
302 |
+
$item->getMessage(),
|
303 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
304 |
+
);
|
305 |
+
}
|
306 |
+
|
307 |
+
$related = $this->_getRequest()->getParam('related_product');
|
308 |
+
if (!empty($related)) {
|
309 |
+
$cart->addProductsByIds(explode(',', $related));
|
310 |
+
}
|
311 |
+
|
312 |
+
$cart->save();
|
313 |
+
$this->_getSession()->setCartWasUpdated(true);
|
314 |
+
|
315 |
+
Mage::dispatchEvent('checkout_cart_update_item_complete',
|
316 |
+
array('item' => $item, 'request' => $this->_getRequest(), 'response' => $this->_getResponse())
|
317 |
+
);
|
318 |
+
|
319 |
+
if (!$cart->getQuote()->getHasError()) {
|
320 |
+
$data = $this->_getCart();
|
321 |
+
$data['message'] = Mage::helper('japi')->__(
|
322 |
+
'%s was updated in your shopping cart.',
|
323 |
+
Mage::helper('core')->escapeHtml($item->getProduct()->getName())
|
324 |
+
);
|
325 |
+
|
326 |
+
return $data;
|
327 |
+
}
|
328 |
+
} catch (Mage_Core_Exception $e) {
|
329 |
+
throw new Jmango360_Japi_Exception(
|
330 |
+
join("\n", array_unique(explode("\n", $e->getMessage()))),
|
331 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
332 |
+
);
|
333 |
+
} catch (Exception $e) {
|
334 |
+
throw new Jmango360_Japi_Exception(
|
335 |
+
$e->getMessage(),
|
336 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
337 |
+
);
|
338 |
+
}
|
339 |
+
|
340 |
+
return null;
|
341 |
+
}
|
342 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Catalog.php
ADDED
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Catalog extends Mage_Catalog_Model_Abstract
|
4 |
+
{
|
5 |
+
public function dispatch()
|
6 |
+
{
|
7 |
+
$action = $this->_getRequest()->getAction();
|
8 |
+
$operation = $this->_getRequest()->getOperation();
|
9 |
+
|
10 |
+
switch ($action . $operation) {
|
11 |
+
/*
|
12 |
+
* @DEPRICATED is going to be replaced by the getCatalogProductList
|
13 |
+
*/
|
14 |
+
case 'getAssignedProducts' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
15 |
+
$data = $this->_getAssignedProducts();
|
16 |
+
$this->_getResponse()->render($data);
|
17 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
18 |
+
break;
|
19 |
+
/*
|
20 |
+
* @TODO is going to replace the getAssigned products service call
|
21 |
+
*/
|
22 |
+
case 'getCatalogProductList' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
23 |
+
$data = $this->_getCatalogProductList();
|
24 |
+
$this->_getResponse()->render($data);
|
25 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
26 |
+
break;
|
27 |
+
case 'getLayerFilters' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
28 |
+
$data = $this->_getLayerFilters();
|
29 |
+
$this->_getResponse()->render($data);
|
30 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
31 |
+
break;
|
32 |
+
case 'getCategoryTree' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
33 |
+
$data = $this->_getCategoryTree();
|
34 |
+
$this->_getResponse()->render($data);
|
35 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
36 |
+
break;
|
37 |
+
case 'getStockItemList' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
38 |
+
$data = $this->_getStockItemList();
|
39 |
+
$this->_getResponse()->render($data);
|
40 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
41 |
+
break;
|
42 |
+
case 'searchProducts' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
43 |
+
$data = $this->_searchProducts();
|
44 |
+
$this->_getResponse()->render($data);
|
45 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
46 |
+
break;
|
47 |
+
case 'getProduct' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
48 |
+
$data = $this->_getProduct();
|
49 |
+
$this->_getResponse()->render($data);
|
50 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
51 |
+
break;
|
52 |
+
case 'getCategory' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
53 |
+
$data = $this->_getCategory();
|
54 |
+
$this->_getResponse()->render($data);
|
55 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
56 |
+
break;
|
57 |
+
case 'searchTerms' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
58 |
+
$data = $this->_getSearchTerms();
|
59 |
+
$this->_getResponse()->render($data);
|
60 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
61 |
+
break;
|
62 |
+
default:
|
63 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Resource method not implemented'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
64 |
+
break;
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
protected function _getSearchTerms()
|
69 |
+
{
|
70 |
+
/* @var $model Jmango360_Japi_Model_Rest_Catalog_Search_Terms */
|
71 |
+
$model = Mage::getModel('japi/rest_catalog_search_terms');
|
72 |
+
$data = $model->getTerms();
|
73 |
+
|
74 |
+
return $data;
|
75 |
+
}
|
76 |
+
|
77 |
+
protected function _searchProducts()
|
78 |
+
{
|
79 |
+
/* @var $model Jmango360_Japi_Model_Rest_Catalog_Search_Products */
|
80 |
+
$model = Mage::getModel('japi/rest_catalog_search_products');
|
81 |
+
$data = $model->getList();
|
82 |
+
|
83 |
+
return $data;
|
84 |
+
}
|
85 |
+
|
86 |
+
protected function _getProduct()
|
87 |
+
{
|
88 |
+
$id = $this->_getRequest()->getParam('product_id', 0);
|
89 |
+
|
90 |
+
if (!$id || !is_numeric($id) || $id <= 0) {
|
91 |
+
throw new Jmango360_Japi_Exception(
|
92 |
+
Mage::helper('japi')->__('Product ID invalid'),
|
93 |
+
Jmango360_Japi_Model_Request::HTTP_BAD_REQUEST
|
94 |
+
);
|
95 |
+
}
|
96 |
+
|
97 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
98 |
+
$helper = Mage::helper('japi/product');
|
99 |
+
$data['product'] = $helper->convertProductIdToApiResponse($id);
|
100 |
+
|
101 |
+
return $data;
|
102 |
+
}
|
103 |
+
|
104 |
+
protected function _getCategory()
|
105 |
+
{
|
106 |
+
$id = $this->_getRequest()->getParam('category_id', 0);
|
107 |
+
|
108 |
+
/* @var $model Jmango360_Japi_Model_Rest_Catalog_Category_Tree */
|
109 |
+
$model = Mage::getModel('japi/rest_catalog_category_tree');
|
110 |
+
$data = $model->category($id);
|
111 |
+
|
112 |
+
return $data;
|
113 |
+
}
|
114 |
+
|
115 |
+
protected function _getCategoryTree()
|
116 |
+
{
|
117 |
+
/* @var $model Jmango360_Japi_Model_Rest_Catalog_Category_Tree */
|
118 |
+
$model = Mage::getModel('japi/rest_catalog_category_tree');
|
119 |
+
$data = $model->tree();
|
120 |
+
|
121 |
+
return $data;
|
122 |
+
}
|
123 |
+
|
124 |
+
/*
|
125 |
+
* @DEPRICATED is going to be replaced by the getCatalogProductList
|
126 |
+
*/
|
127 |
+
protected function _getAssignedProducts()
|
128 |
+
{
|
129 |
+
/* @var $model Jmango360_Japi_Model_Rest_Catalog_Category_Assignedproducts */
|
130 |
+
$model = Mage::getModel('japi/rest_catalog_category_assignedproducts');
|
131 |
+
$data = $model->getAssignedProducts();
|
132 |
+
|
133 |
+
return $data;
|
134 |
+
}
|
135 |
+
|
136 |
+
/*
|
137 |
+
* @TODO is going to replace the getAssigned products service call
|
138 |
+
*/
|
139 |
+
protected function _getCatalogProductList()
|
140 |
+
{
|
141 |
+
/* @var $model Jmango360_Japi_Model_Rest_Catalog_Category_Products */
|
142 |
+
$model = Mage::getModel('japi/rest_catalog_category_products');
|
143 |
+
$data = $model->getlist();
|
144 |
+
|
145 |
+
return $data;
|
146 |
+
}
|
147 |
+
|
148 |
+
protected function _getLayerFilters()
|
149 |
+
{
|
150 |
+
/* @var $model Jmango360_Japi_Model_Rest_Catalog_Layer_Layerfilters */
|
151 |
+
$model = Mage::getModel('japi/rest_catalog_layer_layerfilters');
|
152 |
+
$data = $model->getLayerFilters();
|
153 |
+
|
154 |
+
return $data;
|
155 |
+
}
|
156 |
+
|
157 |
+
protected function _getStockItemList()
|
158 |
+
{
|
159 |
+
/* @var $model Jmango360_Japi_Model_Rest_Catalog_Stock_List */
|
160 |
+
$model = Mage::getModel('japi/rest_catalog_stock_list');
|
161 |
+
$data = $model->getItems();
|
162 |
+
|
163 |
+
return $data;
|
164 |
+
}
|
165 |
+
|
166 |
+
protected function _getRequest()
|
167 |
+
{
|
168 |
+
return $this->_getServer()->getRequest();
|
169 |
+
}
|
170 |
+
|
171 |
+
protected function _getResponse()
|
172 |
+
{
|
173 |
+
return $this->_getServer()->getResponse();
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* @return Jmango360_Japi_Model_Server
|
178 |
+
*/
|
179 |
+
protected function _getServer()
|
180 |
+
{
|
181 |
+
return Mage::getSingleton('japi/server');
|
182 |
+
}
|
183 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Catalog/Category/Assignedproducts.php
ADDED
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Catalog_Category_Assignedproducts extends Mage_Catalog_Model_Category
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Initialize requested category object
|
7 |
+
*
|
8 |
+
* @return Mage_Catalog_Model_Category
|
9 |
+
* @throws Jmango360_Japi_Exception
|
10 |
+
*/
|
11 |
+
public function getAssignedProducts()
|
12 |
+
{
|
13 |
+
$category = $this->_initCategory();
|
14 |
+
|
15 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
16 |
+
$helper = Mage::helper('japi/product');
|
17 |
+
|
18 |
+
if (is_object($category) && $category->getId()) {
|
19 |
+
$block = $this->_getListBlock();
|
20 |
+
$productCollection = $block->getLayer()->getProductCollection();
|
21 |
+
/* @var $resource Mage_Core_Model_Resource */
|
22 |
+
$resource = Mage::getSingleton('core/resource');
|
23 |
+
$productCollection->getSelect()
|
24 |
+
->join(
|
25 |
+
array('p' => $resource->getTableName('catalog/product')),
|
26 |
+
sprintf(
|
27 |
+
'e.entity_id = p.entity_id AND p.type_id IN (%s)',
|
28 |
+
join(',', array('"simple"', '"configurable"', '"grouped"', '"bundle"'))
|
29 |
+
),
|
30 |
+
null
|
31 |
+
);
|
32 |
+
|
33 |
+
if (!$productCollection->getSize()) {
|
34 |
+
$data['message'] = $helper->__('No products found.');
|
35 |
+
}
|
36 |
+
|
37 |
+
$data['filters'] = $this->_getFilters();
|
38 |
+
$helper->addPageSettings($productCollection);
|
39 |
+
$data['toolbar_info'] = $helper->getToolBarInfo($productCollection);
|
40 |
+
/**
|
41 |
+
* Add group by product's ID to collection
|
42 |
+
*/
|
43 |
+
if (version_compare(Mage::getVersion(), '1.9.2.1', '>')) {
|
44 |
+
$productCollection->getSelect()->group('e.entity_id');
|
45 |
+
}
|
46 |
+
|
47 |
+
$productCollection->clear();
|
48 |
+
$data['products'] = $helper->convertProductCollectionToApiResponse($productCollection);
|
49 |
+
} else {
|
50 |
+
throw new Jmango360_Japi_Exception(
|
51 |
+
$helper->__('Category not found.'),
|
52 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
53 |
+
);
|
54 |
+
}
|
55 |
+
|
56 |
+
return $data;
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* @return Jmango360_Japi_Block_Catalog_Layer_View|Mage_Catalog_Block_Navigation
|
61 |
+
*/
|
62 |
+
protected function _getLayerBlock()
|
63 |
+
{
|
64 |
+
//skip non-anchor category
|
65 |
+
$category = Mage::registry('current_category');
|
66 |
+
if ($category->getIsAnchor()) {
|
67 |
+
return Mage::helper('japi')->getBlock('Jmango360_Japi_Block_Catalog_Layer_View');
|
68 |
+
} else {
|
69 |
+
return Mage::helper('japi')->getBlock('Mage_Catalog_Block_Navigation');
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* @return Jmango360_Japi_Block_Catalog_Product_List
|
75 |
+
*/
|
76 |
+
protected function _getListBlock()
|
77 |
+
{
|
78 |
+
return Mage::helper('japi')->getBlock('Jmango360_Japi_Block_Catalog_Product_List');
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* @return Mage_Catalog_Block_Layer_State
|
83 |
+
*/
|
84 |
+
protected function _getStateBlock()
|
85 |
+
{
|
86 |
+
return Mage::helper('japi')->getBlock('Mage_Catalog_Block_Layer_State');
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* @return array
|
91 |
+
*/
|
92 |
+
protected function _getFilters()
|
93 |
+
{
|
94 |
+
$data = array();
|
95 |
+
$block = $this->_getLayerBlock();
|
96 |
+
$filters = $block->getFilters();
|
97 |
+
|
98 |
+
if (!$filters || !is_array($filters)) return $data;
|
99 |
+
|
100 |
+
foreach ($filters as $key => $filter) {
|
101 |
+
/* @var $filter Mage_Catalog_Block_Layer_Filter_Abstract */
|
102 |
+
if ($filter->getType() == 'catalog/layer_filter_category') {
|
103 |
+
continue;
|
104 |
+
}
|
105 |
+
if ($filter->getItemsCount()) {
|
106 |
+
$data[] = $this->_filterToArray($filter);
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
return $data;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Converts Mage_Catalog_Model_Layer_Filter_Abstract into array
|
115 |
+
*
|
116 |
+
* @param $filter Mage_Catalog_Model_Layer_Filter_Abstract
|
117 |
+
* @return array
|
118 |
+
*/
|
119 |
+
protected function _filterToArray($filter)
|
120 |
+
{
|
121 |
+
$data = array();
|
122 |
+
$data['name'] = Mage::helper('japi')->__($filter->getName());
|
123 |
+
$data['code'] = $filter->getAttributeModel()->getAttributeCode();
|
124 |
+
foreach ($filter->getItems() as $item) {
|
125 |
+
$data['items'][] = $this->_itemToArray($item, $data['code']);
|
126 |
+
}
|
127 |
+
|
128 |
+
return $data;
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Converts array Mage_Catalog_Model_Layer_Filter_Item into array
|
133 |
+
*
|
134 |
+
* @param $item Mage_Catalog_Model_Layer_Filter_Item
|
135 |
+
* @param $code
|
136 |
+
* @return array
|
137 |
+
*/
|
138 |
+
protected function _itemToArray($item, $code)
|
139 |
+
{
|
140 |
+
/**
|
141 |
+
* MPLUGIN-1144:
|
142 |
+
* Fix isse filter when installed "Gomage_Navigation"
|
143 |
+
* and set Use Friendly URLs to "Yes" in Admin config of this extension
|
144 |
+
*/
|
145 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
146 |
+
$helper = Mage::helper('japi/product');
|
147 |
+
$_label = (string)$item->getLabel();
|
148 |
+
$_value = (string)$item->getValue();
|
149 |
+
if ($helper->isModuleEnabled('GoMage_Navigation')) {
|
150 |
+
$_ignoreAttrCode = array('price');
|
151 |
+
if (!in_array($code, $_ignoreAttrCode)) {
|
152 |
+
$gomageHelper = Mage::helper('gomage_navigation');
|
153 |
+
if ($gomageHelper->isFrendlyUrl()) {
|
154 |
+
$_value = $gomageHelper->formatUrlValue($_label, $_value);
|
155 |
+
}
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
$data = array();
|
160 |
+
$data['count'] = (int)$item->getCount();
|
161 |
+
$data['label'] = $_label;
|
162 |
+
$data['value'] = $_value;
|
163 |
+
$data['url'] = null;
|
164 |
+
|
165 |
+
return $data;
|
166 |
+
}
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Initialize requested category object
|
170 |
+
*
|
171 |
+
* @return Mage_Catalog_Model_Category
|
172 |
+
* @throws Jmango360_Japi_Exception
|
173 |
+
*/
|
174 |
+
protected function _initCategory()
|
175 |
+
{
|
176 |
+
/* @var $server Jmango360_Japi_Model_Server */
|
177 |
+
$server = Mage::helper('japi')->getServer();
|
178 |
+
/* @var $controller Jmango360_Japi_Rest_CatalogController */
|
179 |
+
$controller = $server->getControllerInstance();
|
180 |
+
|
181 |
+
Mage::dispatchEvent('catalog_controller_category_init_before', array('controller_action' => $controller));
|
182 |
+
$categoryId = (int)Mage::helper('japi')->getRequest()->getParam('category_id', false);
|
183 |
+
if (!$categoryId) {
|
184 |
+
throw new Jmango360_Japi_Exception(
|
185 |
+
Mage::helper('japi')->__('Category not found.'),
|
186 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
187 |
+
);
|
188 |
+
}
|
189 |
+
|
190 |
+
/* @var $category Mage_Catalog_Model_Category */
|
191 |
+
$category = Mage::getModel('catalog/category')
|
192 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
193 |
+
->load($categoryId);
|
194 |
+
|
195 |
+
if (!Mage::helper('catalog/category')->canShow($category)) {
|
196 |
+
throw new Jmango360_Japi_Exception(
|
197 |
+
Mage::helper('japi')->__('Category not available.'),
|
198 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
199 |
+
);
|
200 |
+
}
|
201 |
+
|
202 |
+
Mage::getSingleton('catalog/session')->setLastVisitedCategoryId($category->getId());
|
203 |
+
Mage::register('current_category', $category);
|
204 |
+
Mage::register('current_entity_key', $category->getPath());
|
205 |
+
|
206 |
+
try {
|
207 |
+
Mage::dispatchEvent(
|
208 |
+
'catalog_controller_category_init_after',
|
209 |
+
array(
|
210 |
+
'category' => $category,
|
211 |
+
'controller_action' => $controller
|
212 |
+
)
|
213 |
+
);
|
214 |
+
} catch (Mage_Core_Exception $e) {
|
215 |
+
Mage::logException($e);
|
216 |
+
return false;
|
217 |
+
}
|
218 |
+
|
219 |
+
return $category;
|
220 |
+
}
|
221 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Catalog/Category/Tree.php
ADDED
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Catalog_Category_Tree extends Mage_Catalog_Model_Category
|
4 |
+
{
|
5 |
+
const MAXTREEDEPTH = 2;
|
6 |
+
const MAX_PRODUCT_COUNT = 3;
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Retrieve category tree of store
|
10 |
+
*
|
11 |
+
* @return array
|
12 |
+
*/
|
13 |
+
public function tree()
|
14 |
+
{
|
15 |
+
$storeId = Mage::helper('japi')->getRequest()->getParam('store_id', null);
|
16 |
+
if (!is_null($storeId)) {
|
17 |
+
Mage::app()->setCurrentStore($storeId);
|
18 |
+
}
|
19 |
+
|
20 |
+
return $this->_getActiveMenuArray();
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Retrieve category tree with specific root category
|
25 |
+
*
|
26 |
+
* @param int $id
|
27 |
+
* @return array
|
28 |
+
* @throws Jmango360_Japi_Exception
|
29 |
+
*/
|
30 |
+
public function category($id)
|
31 |
+
{
|
32 |
+
/* @var $category Mage_Catalog_Model_Category */
|
33 |
+
$category = Mage::getModel('catalog/category')->load($id);
|
34 |
+
if (!$category->getId()) {
|
35 |
+
throw new Jmango360_Japi_Exception(
|
36 |
+
Mage::helper('japi')->__('No category found.'),
|
37 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
38 |
+
);
|
39 |
+
}
|
40 |
+
|
41 |
+
$data['categories'] = $this->_getActiveMenuTree(array($category), 0);
|
42 |
+
return $data;
|
43 |
+
}
|
44 |
+
|
45 |
+
protected function _getActiveMenuArray()
|
46 |
+
{
|
47 |
+
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
|
48 |
+
$data['categories'] = array();
|
49 |
+
|
50 |
+
/* @var $category Mage_Catalog_Model_Category */
|
51 |
+
$category = Mage::getModel('catalog/category')->load($rootCategoryId);
|
52 |
+
|
53 |
+
if (!$category->getId()) {
|
54 |
+
/** Not nesscesary to throw an error, a workaround for Varnish */
|
55 |
+
//throw new Jmango360_Japi_Exception('No root category found.', Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
56 |
+
return $data;
|
57 |
+
}
|
58 |
+
|
59 |
+
$childrenCategories = $this->_getMenuChildren($category);
|
60 |
+
if (!$childrenCategories->count()) {
|
61 |
+
/** Not nesscesary to throw an error, a workaround for Varnish */
|
62 |
+
//throw new Jmango360_Japi_Exception('No active categories found.', Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
63 |
+
return $data;
|
64 |
+
}
|
65 |
+
|
66 |
+
$data['categories'] = $this->_getActiveMenuTree($childrenCategories);
|
67 |
+
|
68 |
+
return $data;
|
69 |
+
}
|
70 |
+
|
71 |
+
/*
|
72 |
+
* The childlevels are restricted to two levels
|
73 |
+
* -- Menu-item1
|
74 |
+
* -- -- Menu sub-item1
|
75 |
+
* -- -- Menu sub-item2
|
76 |
+
* -- Menu-item2
|
77 |
+
* -- -- Menu sub-item1
|
78 |
+
* (adjust MAXTREEDEPTH to get more tree depth)
|
79 |
+
*/
|
80 |
+
private function _getActiveMenuTree($categories, $indexLevel = 1)
|
81 |
+
{
|
82 |
+
$maxTreeDepth = Mage::helper('japi')->getRequest()->getParam('max_tree_depth', null);
|
83 |
+
if (is_null($maxTreeDepth)) {
|
84 |
+
$maxTreeDepth = self::MAXTREEDEPTH;
|
85 |
+
}
|
86 |
+
|
87 |
+
$data = array();
|
88 |
+
$index = 0;
|
89 |
+
foreach ($categories as $category) {
|
90 |
+
/* @var $category Mage_Catalog_Model_Category */
|
91 |
+
|
92 |
+
$data[$index] = $category->getData();
|
93 |
+
$data[$index]['thumbnail'] = $this->_getThumbnailUrl($category);
|
94 |
+
$data[$index]['image'] = $category->getImageUrl() ? $category->getImageUrl() : '';
|
95 |
+
//Backwards compatibility
|
96 |
+
$data[$index]['category_id'] = $data[$index]['entity_id'];
|
97 |
+
$data[$index]['children'] = array();
|
98 |
+
|
99 |
+
$childrenCategories = $this->_getMenuChildren($category);
|
100 |
+
if ($childrenCategories && $childrenCategories->count() && $indexLevel < $maxTreeDepth) {
|
101 |
+
$indexLevel++;
|
102 |
+
$data[$index]['children'] = $this->_getActiveMenuTree($childrenCategories, $indexLevel);
|
103 |
+
--$indexLevel;
|
104 |
+
}
|
105 |
+
|
106 |
+
$index++;
|
107 |
+
}
|
108 |
+
|
109 |
+
return $data;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Retrieve thumbnail URL
|
114 |
+
*
|
115 |
+
* @param $category Mage_Catalog_Model_Category
|
116 |
+
* @return string
|
117 |
+
*/
|
118 |
+
protected function _getThumbnailUrl($category)
|
119 |
+
{
|
120 |
+
if ($image = $category->getData('thumbnail')) {
|
121 |
+
return Mage::getBaseUrl('media') . 'catalog/category/' . $image;
|
122 |
+
} else {
|
123 |
+
if (!$category->getImageUrl()) {
|
124 |
+
return $this->_getImageFromChildrenProduct($category);
|
125 |
+
}
|
126 |
+
}
|
127 |
+
return '';
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Get image from first child product, if not get the next
|
132 |
+
*
|
133 |
+
* @param $category Mage_Catalog_Model_Category
|
134 |
+
* @return string
|
135 |
+
*/
|
136 |
+
protected function _getImageFromChildrenProduct($category)
|
137 |
+
{
|
138 |
+
$imageType = Mage::getStoreConfig('japi/jmango_rest_gallery_settings/catalog_image_default');
|
139 |
+
if (!$imageType) $imageType = 'thumbnail';
|
140 |
+
if ($imageType == 'none') return '';
|
141 |
+
|
142 |
+
/* @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
|
143 |
+
$productCollection = $category->getProductCollection();
|
144 |
+
$productCollection->setPageSize(3)->setCurPage(1);
|
145 |
+
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($productCollection);
|
146 |
+
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($productCollection);
|
147 |
+
if (!$productCollection->getSize()) return '';
|
148 |
+
|
149 |
+
$imageAttributes = array('image', 'small_image', 'thumbnail');
|
150 |
+
$imageSizeW = Mage::getStoreConfig('japi/jmango_rest_gallery_settings/thumbnail_width');
|
151 |
+
$imageSizeH = Mage::getStoreConfig('japi/jmango_rest_gallery_settings/thumbnail_height');
|
152 |
+
|
153 |
+
$productCollection->addAttributeToSelect($imageAttributes);
|
154 |
+
|
155 |
+
/* @var $catalogHelper Mage_Catalog_Helper_Image */
|
156 |
+
$catalogHelper = Mage::helper('catalog/image');
|
157 |
+
|
158 |
+
$url = '';
|
159 |
+
$ids = array();
|
160 |
+
foreach ($productCollection as $product) {
|
161 |
+
/* @var $product Mage_Catalog_Model_Product */
|
162 |
+
$ids[] = $product->getId();
|
163 |
+
|
164 |
+
if (!$product->getData($imageType) || $product->getData($imageType) == 'no_selection') {
|
165 |
+
continue;
|
166 |
+
}
|
167 |
+
|
168 |
+
$url = (string)$catalogHelper->init($product, $imageType)->resize($imageSizeW, $imageSizeH);
|
169 |
+
break;
|
170 |
+
}
|
171 |
+
|
172 |
+
// log for debugging
|
173 |
+
if (Mage::getStoreConfigFlag('japi/jmango_rest_developer_settings/enable')) {
|
174 |
+
Mage::log(sprintf("%d: %s", $category->getId(), implode(',', $ids)), null, 'japi_category_thumbnail.log');
|
175 |
+
}
|
176 |
+
|
177 |
+
return $url;
|
178 |
+
}
|
179 |
+
|
180 |
+
/**
|
181 |
+
* @param $category Mage_Catalog_Model_Category
|
182 |
+
* @return Mage_Catalog_Model_Resource_Category_Collection
|
183 |
+
*/
|
184 |
+
protected function _getMenuChildren($category)
|
185 |
+
{
|
186 |
+
/* @var $childrenCategories Mage_Catalog_Model_Resource_Category_Collection */
|
187 |
+
$childrenCategories = $category->getCollection()
|
188 |
+
->addAttributeToSelect(array('name', 'is_anchor', 'image', 'thumbnail'))
|
189 |
+
->addAttributeToFilter('is_active', 1)
|
190 |
+
->addIdFilter($category->getChildren())
|
191 |
+
->setOrder('position', Varien_Db_Select::SQL_ASC);
|
192 |
+
|
193 |
+
if (!Mage::getStoreConfigFlag('japi/jmango_rest_catalog_settings/include_all_active')) {
|
194 |
+
$childrenCategories->addAttributeToSelect('include_in_menu');
|
195 |
+
$childrenCategories->addAttributeToFilter('include_in_menu', array('eq' => 1));
|
196 |
+
}
|
197 |
+
|
198 |
+
return $childrenCategories;
|
199 |
+
}
|
200 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Catalog/Search/Products.php
ADDED
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Catalog_Search_Products extends Mage_CatalogSearch_Model_Query
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Catalog Product collection
|
7 |
+
*
|
8 |
+
* @var Mage_CatalogSearch_Model_Resource_Fulltext_Collection
|
9 |
+
*/
|
10 |
+
protected $_productCollection;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Get search result
|
14 |
+
*/
|
15 |
+
public function getList()
|
16 |
+
{
|
17 |
+
/* @var $searchHelper Mage_CatalogSearch_Helper_Data */
|
18 |
+
$searchHelper = Mage::helper('catalogsearch');
|
19 |
+
/* @var $query Mage_CatalogSearch_Model_Query */
|
20 |
+
$query = $searchHelper->getQuery();
|
21 |
+
|
22 |
+
$query->setStoreId(Mage::app()->getStore()->getId());
|
23 |
+
$data = array();
|
24 |
+
if ($query->getQueryText() != '') {
|
25 |
+
if ($searchHelper->isMinQueryLength()) {
|
26 |
+
$query->setId(0)
|
27 |
+
->setIsActive(1)
|
28 |
+
->setIsProcessed(1);
|
29 |
+
} else {
|
30 |
+
if ($query->getId()) {
|
31 |
+
$query->setPopularity($query->getPopularity() + 1);
|
32 |
+
} else {
|
33 |
+
$query->setPopularity(1);
|
34 |
+
}
|
35 |
+
|
36 |
+
$query->prepare();
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* By calling this block the Magento standard template load search layout is simulated
|
41 |
+
* -- this way different implementations of search engines and params will be active
|
42 |
+
* -- without code changes
|
43 |
+
*/
|
44 |
+
$helper = Mage::helper('japi/product');
|
45 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
46 |
+
$block = $this->_getSearchLayerBlock();
|
47 |
+
/* @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
|
48 |
+
$productCollection = $block->getLayer()->getProductCollection();
|
49 |
+
|
50 |
+
/* @var $resource Mage_Core_Model_Resource */
|
51 |
+
$resource = Mage::getSingleton('core/resource');
|
52 |
+
$productCollection->getSelect()->join(
|
53 |
+
array('p' => $resource->getTableName('catalog/product')),
|
54 |
+
sprintf(
|
55 |
+
'e.entity_id = p.entity_id AND p.type_id IN (%s)',
|
56 |
+
join(',', array('"simple"', '"configurable"', '"grouped"', '"bundle"'))
|
57 |
+
),
|
58 |
+
null
|
59 |
+
);
|
60 |
+
|
61 |
+
if (!$productCollection->getSize()) {
|
62 |
+
$data['message'] = $searchHelper->__('Your search returns no results.');
|
63 |
+
}
|
64 |
+
|
65 |
+
$data['filters'] = $this->_getFilters($block);
|
66 |
+
$helper->addPageSettings($productCollection);
|
67 |
+
$data['toolbar_info'] = $helper->getToolBarInfo($productCollection, true);
|
68 |
+
/**
|
69 |
+
* Add group by product's ID to collection
|
70 |
+
*/
|
71 |
+
if (version_compare(Mage::getVersion(), '1.9.2.1', '>')) {
|
72 |
+
$productCollection->getSelect()->group('e.entity_id');
|
73 |
+
}
|
74 |
+
$productCollection->clear();
|
75 |
+
$data['products'] = $helper->convertProductCollectionToApiResponse($productCollection);
|
76 |
+
|
77 |
+
$searchHelper->checkNotes();
|
78 |
+
$messages = $searchHelper->getNoteMessages();
|
79 |
+
if (!empty($messages)) {
|
80 |
+
$data['message'] .= implode("\n", (array)$messages);
|
81 |
+
}
|
82 |
+
|
83 |
+
if (!$searchHelper->isMinQueryLength()) {
|
84 |
+
$query->save();
|
85 |
+
}
|
86 |
+
} else {
|
87 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Query cannot be empty.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
88 |
+
}
|
89 |
+
|
90 |
+
return $data;
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* @return Mage_CatalogSearch_Block_Layer
|
95 |
+
*/
|
96 |
+
protected function _getSearchLayerBlock()
|
97 |
+
{
|
98 |
+
/* @var $coreHelper Mage_Core_Helper_Data */
|
99 |
+
$coreHelper = Mage::helper('core');
|
100 |
+
|
101 |
+
if ($coreHelper->isModuleEnabled('Smile_ElasticSearch')) {
|
102 |
+
return Mage::app()->getLayout()->createBlock('Smile_ElasticSearch_Block_Catalogsearch_Layer');
|
103 |
+
} else if ($coreHelper->isModuleEnabled('Amasty_Shopby')) {
|
104 |
+
Mage::app()->getRequest()->setModuleName('catalogsearch');
|
105 |
+
return Mage::app()->getLayout()->createBlock('Amasty_Shopby_Block_Search_Layer');
|
106 |
+
} else {
|
107 |
+
return Mage::app()->getLayout()->createBlock('Jmango360_Japi_Block_Catalogsearch_Layer');
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
protected function _getFilters($block)
|
112 |
+
{
|
113 |
+
$data = array();
|
114 |
+
|
115 |
+
$filters = $block->getFilters();
|
116 |
+
|
117 |
+
foreach ($filters as $key => $filter) {
|
118 |
+
/* @var $filter Mage_Catalog_Block_Layer_Filter_Abstract */
|
119 |
+
if (!$this->_shouldShow($filter)) {
|
120 |
+
continue;
|
121 |
+
}
|
122 |
+
|
123 |
+
if ($filter->getItemsCount()) {
|
124 |
+
$arrFilter = $this->_filterToArray($filter);
|
125 |
+
if ($arrFilter != null) {
|
126 |
+
$data[] = $arrFilter;
|
127 |
+
}
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
return $data;
|
132 |
+
}
|
133 |
+
|
134 |
+
protected function _shouldShow(Mage_Catalog_Block_Layer_Filter_Abstract $filter)
|
135 |
+
{
|
136 |
+
$code = $this->_getFilterCode($filter);
|
137 |
+
|
138 |
+
if (!$code) {
|
139 |
+
return false;
|
140 |
+
}
|
141 |
+
|
142 |
+
if ($filter->getRequest()->getParam($code)) {
|
143 |
+
if ($code != 'cat') {
|
144 |
+
return false;
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
if ($code == 'price') {
|
149 |
+
/* @var $helper Mage_Core_Helper_Data */
|
150 |
+
$helper = Mage::helper('core');
|
151 |
+
if ($helper->isModuleEnabled('Smile_ElasticSearch')) {
|
152 |
+
return false;
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
return true;
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Converts Mage_Catalog_Model_Layer_Filter_Abstract into array
|
161 |
+
*
|
162 |
+
* @param Mage_Catalog_Block_Layer_Filter_Abstract $filter
|
163 |
+
* @return array
|
164 |
+
*/
|
165 |
+
protected function _filterToArray(Mage_Catalog_Block_Layer_Filter_Abstract $filter)
|
166 |
+
{
|
167 |
+
$data = array();
|
168 |
+
$data['name'] = Mage::helper('japi')->__($filter->getName());
|
169 |
+
$data['code'] = $this->_getFilterCode($filter);
|
170 |
+
foreach ($filter->getItems() as $item) {
|
171 |
+
if ((int)$item->getCount() > 0) {
|
172 |
+
$data['items'][] = $this->_itemToArray($item, $data['code']);
|
173 |
+
}
|
174 |
+
}
|
175 |
+
if (empty($data['items'])) {
|
176 |
+
return null;
|
177 |
+
}
|
178 |
+
return $data;
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Due to an omission by Magento the Mage_Catalog_Block_Layer_Filter_Category is missing the method _prepareFilter where the attribute_model is set
|
183 |
+
* -- this function assumes like the other filter software that the code for the category is "cat"
|
184 |
+
*/
|
185 |
+
protected function _getFilterCode(Mage_Catalog_Block_Layer_Filter_Abstract $filter)
|
186 |
+
{
|
187 |
+
switch (get_class($filter)) {
|
188 |
+
case 'Mage_Catalog_Block_Layer_Filter_Category':
|
189 |
+
case 'Jmango360_Japi_Block_Catalog_Layer_Filter_Category':
|
190 |
+
case 'Smile_ElasticSearch_Block_Catalog_Layer_Filter_Category':
|
191 |
+
return 'cat';
|
192 |
+
break;
|
193 |
+
default:
|
194 |
+
if ($filter->getAttributeModel()) {
|
195 |
+
return (string)$filter->getAttributeModel()->getAttributeCode();
|
196 |
+
} else {
|
197 |
+
Mage::log(get_class($filter));
|
198 |
+
return null;
|
199 |
+
}
|
200 |
+
break;
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Converts array Mage_Catalog_Model_Layer_Filter_Item into array
|
206 |
+
*
|
207 |
+
* @param $item
|
208 |
+
* @param $code
|
209 |
+
* @return array
|
210 |
+
*/
|
211 |
+
protected function _itemToArray($item, $code)
|
212 |
+
{
|
213 |
+
/**
|
214 |
+
* MPLUGIN-1144:
|
215 |
+
* Fix isse filter when installed "Gomage_Navigation"
|
216 |
+
* and set Use Friendly URLs to "Yes" in Admin config of this extension
|
217 |
+
*/
|
218 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
219 |
+
$helper = Mage::helper('japi/product');
|
220 |
+
$_label = (string)$item->getLabel();
|
221 |
+
$_value = (string)$item->getValue();
|
222 |
+
if ($helper->isModuleEnabled('GoMage_Navigation')) {
|
223 |
+
$_ignoreAttrCode = array('price');
|
224 |
+
if (!in_array($code, $_ignoreAttrCode)) {
|
225 |
+
$gomageHelper = Mage::helper('gomage_navigation');
|
226 |
+
if ($gomageHelper->isFrendlyUrl()) {
|
227 |
+
$_value = $gomageHelper->formatUrlValue($_label, $_value);
|
228 |
+
}
|
229 |
+
}
|
230 |
+
}
|
231 |
+
|
232 |
+
$data = array();
|
233 |
+
$data['count'] = (int)$item->getCount();
|
234 |
+
$data['label'] = $_label;
|
235 |
+
$data['value'] = $_value;
|
236 |
+
|
237 |
+
return $data;
|
238 |
+
}
|
239 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Catalog/Search/Terms.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Catalog_Search_Terms
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Get fast search result
|
7 |
+
*/
|
8 |
+
public function getTerms()
|
9 |
+
{
|
10 |
+
$helper = Mage::helper('japi');
|
11 |
+
/* @var $helper Jmango360_Japi_Helper_Data */
|
12 |
+
$request = $helper->getRequest();
|
13 |
+
|
14 |
+
$data['result'] = array();
|
15 |
+
|
16 |
+
if ($request->getParam('q', false)) {
|
17 |
+
$data['result'] = $this->_getSuggestData();
|
18 |
+
} else {
|
19 |
+
$data['result'] = $this->_getSuggestData(true);
|
20 |
+
}
|
21 |
+
|
22 |
+
return $data;
|
23 |
+
}
|
24 |
+
|
25 |
+
protected function _getSuggestData($isAll = false)
|
26 |
+
{
|
27 |
+
if ($isAll) {
|
28 |
+
$collection = Mage::getResourceModel('catalogsearch/query_collection')
|
29 |
+
->setStoreId(Mage::app()->getStore()->getId());
|
30 |
+
} else {
|
31 |
+
$collection = Mage::helper('catalogsearch')->getSuggestCollection();
|
32 |
+
}
|
33 |
+
|
34 |
+
$query = Mage::helper('catalogsearch')->getQueryText();
|
35 |
+
$data = array();
|
36 |
+
foreach ($collection as $item) {
|
37 |
+
/* @var $item Mage_CatalogSearch_Model_Query */
|
38 |
+
$_data = $item->getQueryText();
|
39 |
+
|
40 |
+
if ($item->getQueryText() == $query) {
|
41 |
+
array_unshift($data, $_data);
|
42 |
+
} else {
|
43 |
+
$data[] = $_data;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
return $data;
|
48 |
+
}
|
49 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Checkout.php
ADDED
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Checkout extends Mage_Checkout_Model_Type_Onepage
|
4 |
+
{
|
5 |
+
protected $_logname = 'rest_checkout.log';
|
6 |
+
|
7 |
+
public function dispatch()
|
8 |
+
{
|
9 |
+
$action = $this->_getRequest()->getAction();
|
10 |
+
$operation = $this->_getRequest()->getOperation();
|
11 |
+
|
12 |
+
switch ($action . $operation) {
|
13 |
+
case 'getCheckoutMethods' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
14 |
+
$data = $this->_getCheckoutMethods();
|
15 |
+
$this->_getResponse()->render($data);
|
16 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
17 |
+
break;
|
18 |
+
case 'updateCartAddresses' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
19 |
+
$data = $this->_updateCartAddresses();
|
20 |
+
$this->_getResponse()->render($data);
|
21 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
22 |
+
break;
|
23 |
+
case 'collectTotals' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
24 |
+
$data = $this->_checkout();
|
25 |
+
$this->_getResponse()->render($data);
|
26 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
27 |
+
break;
|
28 |
+
case 'submitOrder' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
29 |
+
$data = $this->_submitOrder();
|
30 |
+
$this->_getResponse()->render($data);
|
31 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
32 |
+
break;
|
33 |
+
case 'getPaymentRedirect' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
34 |
+
$data = $this->_paymentRedirect();
|
35 |
+
$this->_getResponse()->render($data);
|
36 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
37 |
+
break;
|
38 |
+
case 'updateShippingMethod' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
39 |
+
$data = $this->_updateShippingMethod();
|
40 |
+
$this->_getResponse()->render($data);
|
41 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
42 |
+
break;
|
43 |
+
case 'updatePaymentMethod' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
44 |
+
$data = $this->_updatePaymentMethod();
|
45 |
+
$this->_getResponse()->render($data);
|
46 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
47 |
+
break;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* After a one page checkout payment to any provider the return url goes to the:
|
51 |
+
* - onepage/checkout/success (case: success) = the only real successfull payment
|
52 |
+
* - onepage/checkout/failure (case: failure)
|
53 |
+
* - checkout/cart/index (case: index)
|
54 |
+
*
|
55 |
+
* This can be used to tell the mobile App to show the success page, or another page based on the payment status
|
56 |
+
*/
|
57 |
+
case 'success' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
58 |
+
$data = $this->_paymentSuccessResponse();
|
59 |
+
$this->_getResponse()->render($data);
|
60 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
61 |
+
break;
|
62 |
+
case 'failure' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
63 |
+
$data = $this->_paymentFailureResponse();
|
64 |
+
$this->_getResponse()->render($data);
|
65 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
66 |
+
break;
|
67 |
+
case 'index' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
68 |
+
$data = $this->_paymentFailureResponse();
|
69 |
+
$this->_getResponse()->render($data);
|
70 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
71 |
+
break;
|
72 |
+
|
73 |
+
default:
|
74 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Resource method not implemented'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
75 |
+
break;
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
/*
|
80 |
+
* Recurring profiles (like monthly subscriptions) are not supported through the mobile App
|
81 |
+
*/
|
82 |
+
protected function _paymentSuccessResponse()
|
83 |
+
{
|
84 |
+
$data = array();
|
85 |
+
|
86 |
+
$session = $this->_getSession();
|
87 |
+
|
88 |
+
$lastSuccessQuoteId = $session->getLastSuccessQuoteId();
|
89 |
+
$lastQuoteId = $session->getLastQuoteId();
|
90 |
+
$lastOrderId = $session->getLastOrderId();
|
91 |
+
$lastRealOrderId = $session->getLastRealOrderId();
|
92 |
+
|
93 |
+
if (!$lastSuccessQuoteId || !$this->_getLastOrder($lastQuoteId, $lastOrderId, $lastRealOrderId)) {
|
94 |
+
throw new Jmango360_Japi_Exception(
|
95 |
+
Mage::helper('japi')->__('Something is wrong with the order.'),
|
96 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
97 |
+
);
|
98 |
+
}
|
99 |
+
|
100 |
+
$lastOrderId = $session->getLastOrderId();
|
101 |
+
$session->clear();
|
102 |
+
Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));
|
103 |
+
|
104 |
+
/* @var $order Mage_Sales_Model_Order */
|
105 |
+
$order = Mage::getModel('sales/order')->load($lastOrderId);
|
106 |
+
$data['order_id'] = $order->getIncrementId();
|
107 |
+
$data['payment_status'] = 'success';
|
108 |
+
$data['order_status'] = $order->getStatus();
|
109 |
+
|
110 |
+
$this->_getSession()->unsRedirectToPaymentIsActive();
|
111 |
+
$this->_getServer()->unsetIsRest();
|
112 |
+
|
113 |
+
return $data;
|
114 |
+
}
|
115 |
+
|
116 |
+
protected function _paymentFailureResponse()
|
117 |
+
{
|
118 |
+
$this->_getServer()->unsetIsRest();
|
119 |
+
$session = $this->_getSession();
|
120 |
+
|
121 |
+
$errors = $session->getMessages()->getErrors();
|
122 |
+
if (count($errors)) {
|
123 |
+
$messages = array();
|
124 |
+
foreach ($errors as $error) {
|
125 |
+
if (is_object($error)) {
|
126 |
+
$messages[] = $error->getCode();
|
127 |
+
}
|
128 |
+
}
|
129 |
+
if (count($messages)) {
|
130 |
+
throw new Jmango360_Japi_Exception(
|
131 |
+
implode(',', $messages),
|
132 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
133 |
+
);
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
$lastQuoteId = $session->getLastQuoteId();
|
138 |
+
$lastOrderId = $session->getLastOrderId();
|
139 |
+
$lastRealOrderId = $session->getLastRealOrderId();
|
140 |
+
|
141 |
+
if (!$this->_getLastOrder($lastQuoteId, $lastOrderId, $lastRealOrderId)) {
|
142 |
+
throw new Jmango360_Japi_Exception(
|
143 |
+
Mage::helper('japi')->__('Something is wrong with the quote or order.'),
|
144 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
145 |
+
);
|
146 |
+
}
|
147 |
+
|
148 |
+
$this->_reactivateQuote($lastQuoteId);
|
149 |
+
|
150 |
+
/* @var $order Mage_Sales_Model_Order */
|
151 |
+
$order = Mage::getModel('sales/order')->load($lastOrderId);
|
152 |
+
$data['order_id'] = $order->getIncrementId();
|
153 |
+
$data['payment_status'] = 'no_success';
|
154 |
+
$data['order_status'] = $order->getStatus();
|
155 |
+
|
156 |
+
$this->_getSession()->unsRedirectToPaymentIsActive();
|
157 |
+
|
158 |
+
return $data;
|
159 |
+
}
|
160 |
+
|
161 |
+
protected function _getLastOrder($lastQuoteId, $lastOrderId, $lastRealOrderId)
|
162 |
+
{
|
163 |
+
$session = $this->_getSession();
|
164 |
+
|
165 |
+
if ($lastRealOrderId) {
|
166 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($lastRealOrderId);
|
167 |
+
if (empty($lastQuoteId)) {
|
168 |
+
$session->setLastQuoteId($order->getQuoteId());
|
169 |
+
}
|
170 |
+
if (empty($lastOrderId)) {
|
171 |
+
$session->setLastOrderId($order->getId());
|
172 |
+
}
|
173 |
+
|
174 |
+
return true;
|
175 |
+
}
|
176 |
+
|
177 |
+
if ($lastOrderId) {
|
178 |
+
$order = Mage::getModel('sales/order')->load($lastOrderId);
|
179 |
+
if (empty($lastQuoteId)) {
|
180 |
+
$session->setLastQuoteId($order->getQuoteId());
|
181 |
+
}
|
182 |
+
if (empty($lastRealOrderId)) {
|
183 |
+
$session->setLastRealOrderId($order->getIncrementId());
|
184 |
+
}
|
185 |
+
|
186 |
+
return true;
|
187 |
+
}
|
188 |
+
|
189 |
+
return false;
|
190 |
+
}
|
191 |
+
|
192 |
+
protected function _reactivateQuote($quoteId)
|
193 |
+
{
|
194 |
+
$quote = Mage::getModel('sales/quote')->load($quoteId);
|
195 |
+
$quote->setIsActive(true)->save();
|
196 |
+
|
197 |
+
$this->_getSession()->replaceQuote($quote);
|
198 |
+
|
199 |
+
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
200 |
+
$this->_getSession()->setCustomer(Mage::getSingleton('customer/session')->getCustomer());
|
201 |
+
}
|
202 |
+
|
203 |
+
return $this;
|
204 |
+
}
|
205 |
+
|
206 |
+
protected function _paymentRedirect()
|
207 |
+
{
|
208 |
+
/* @var $model Jmango360_Japi_Model_Rest_Checkout_Redirect */
|
209 |
+
$model = Mage::getModel('japi/rest_checkout_redirect');
|
210 |
+
$data = $model->getPaymentRedirect();
|
211 |
+
|
212 |
+
return $data;
|
213 |
+
}
|
214 |
+
|
215 |
+
protected function _submitOrder()
|
216 |
+
{
|
217 |
+
$checkoutRedirectUrl = $this->getQuote()->getPayment()->getCheckoutRedirectUrl();
|
218 |
+
if ($checkoutRedirectUrl) {
|
219 |
+
return array(
|
220 |
+
'session_id' => Mage::getSingleton('core/session')->getSessionId(),
|
221 |
+
'online_payment' => true,
|
222 |
+
'payment_url' => Mage::helper('japi')->addJapiKey($checkoutRedirectUrl)
|
223 |
+
);
|
224 |
+
}
|
225 |
+
|
226 |
+
$quote = $this->getCheckout()->getQuote();
|
227 |
+
if (!$quote->getItemsCount()) {
|
228 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Cart is empty.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
229 |
+
}
|
230 |
+
|
231 |
+
/* @var $model Jmango360_Japi_Model_Rest_Checkout_Submit */
|
232 |
+
$model = Mage::getModel('japi/rest_checkout_submit');
|
233 |
+
$data = $model->submitOrder();
|
234 |
+
|
235 |
+
return $data;
|
236 |
+
}
|
237 |
+
|
238 |
+
protected function _updateCartAddresses()
|
239 |
+
{
|
240 |
+
$quote = $this->getCheckout()->getQuote();
|
241 |
+
if (!$quote->getItemsCount()) {
|
242 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Cart is empty.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
243 |
+
}
|
244 |
+
|
245 |
+
/* @var $model Jmango360_Japi_Model_Rest_Checkout_Onepage */
|
246 |
+
$model = Mage::getModel('japi/rest_checkout_onepage');
|
247 |
+
$data = $model->updateCartAddresses2();
|
248 |
+
|
249 |
+
Mage::getSingleton('core/session')->setData('is_address_update', true);
|
250 |
+
|
251 |
+
return $data;
|
252 |
+
}
|
253 |
+
|
254 |
+
/*
|
255 |
+
* Saving all data to the quote, colleting totals while writing prices, totals and costs to the quote
|
256 |
+
* and return totals in the response
|
257 |
+
* Multi shipping through the app is not implemented
|
258 |
+
*/
|
259 |
+
protected function _checkout()
|
260 |
+
{
|
261 |
+
/*
|
262 |
+
* Save all POST data for Buckaroo using later
|
263 |
+
*/
|
264 |
+
$POST = $this->_getRequest()->getParam('form', array());
|
265 |
+
$POST['payment']['method'] = $this->_getRequest()->getParam('payment_method');
|
266 |
+
$this->_getSession()->setData('POST', $POST);
|
267 |
+
|
268 |
+
$data = null;
|
269 |
+
|
270 |
+
/* Check if is multi-shipping
|
271 |
+
* - (Multishipping changes behaviour using more than one shipping_method in "sales_flat_quote_address"
|
272 |
+
* and only than using items per shipping method in "sales_flat_quote_address_item")
|
273 |
+
* Multi Shipping is not build in App yet (seldom used for standard use Magento)
|
274 |
+
*/
|
275 |
+
if ($this->getCheckout()->getIsMultiShipping()) {
|
276 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Multishipping not implemented yet.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
277 |
+
}
|
278 |
+
|
279 |
+
$quote = $this->getCheckout()->getQuote();
|
280 |
+
if (!$quote->getItemsCount()) {
|
281 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Cart is empty.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
282 |
+
}
|
283 |
+
|
284 |
+
/*
|
285 |
+
* Three possible methods:
|
286 |
+
* @Mage_Checkout_Model_Type_Onepage::METHOD_GUEST
|
287 |
+
* @Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER
|
288 |
+
* @Mage_Checkout_Model_Type_Onepage::METHOD_CUSTOMER
|
289 |
+
*
|
290 |
+
* Checks the method, set the checkout method to the quote and saves it to the sales_flat_quote
|
291 |
+
*/
|
292 |
+
$checkoutMethod = $this->_getRequest()->getParam('checkout_method', null);
|
293 |
+
if (empty($checkoutMethod)) {
|
294 |
+
$checkoutMethod = $this->getCheckoutMethod();
|
295 |
+
}
|
296 |
+
$this->saveCheckoutMethod($checkoutMethod);
|
297 |
+
|
298 |
+
$requestCheckoutMethod = $this->_getRequest()->getParam('checkout_method');
|
299 |
+
if ($requestCheckoutMethod != $checkoutMethod) {
|
300 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__("Checkout method is not synchronised. Requested method is %s and detected method is %s.", $requestCheckoutMethod, $checkoutMethod), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
301 |
+
}
|
302 |
+
|
303 |
+
switch ($checkoutMethod) {
|
304 |
+
case Mage_Checkout_Model_Type_Onepage::METHOD_GUEST:
|
305 |
+
/* @var $model Jmango360_Japi_Model_Rest_Checkout_Onepage */
|
306 |
+
$model = Mage::getModel('japi/rest_checkout_onepage');
|
307 |
+
$data = $model->checkout();
|
308 |
+
break;
|
309 |
+
case Mage_Checkout_Model_Type_Onepage::METHOD_CUSTOMER:
|
310 |
+
/* @var $model Jmango360_Japi_Model_Rest_Checkout_Onepage */
|
311 |
+
$model = Mage::getModel('japi/rest_checkout_onepage');
|
312 |
+
$data = $model->checkout();
|
313 |
+
break;
|
314 |
+
case Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER:
|
315 |
+
/* @var $model Jmango360_Japi_Model_Rest_Checkout_Onepage */
|
316 |
+
$model = Mage::getModel('japi/rest_checkout_onepage');
|
317 |
+
$data = $model->checkout();
|
318 |
+
break;
|
319 |
+
default:
|
320 |
+
throw new Jmango360_Japi_Exception(
|
321 |
+
Mage::helper('japi')->__('Checkout method not implemented yet: ' . $checkoutMethod),
|
322 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
323 |
+
);
|
324 |
+
break;
|
325 |
+
}
|
326 |
+
|
327 |
+
return $data;
|
328 |
+
}
|
329 |
+
|
330 |
+
protected function _updateShippingMethod()
|
331 |
+
{
|
332 |
+
/* @var $model Jmango360_Japi_Model_Rest_Checkout_Onepage */
|
333 |
+
$model = Mage::getModel('japi/rest_checkout_onepage');
|
334 |
+
$data = $model->updateShippingMethod();
|
335 |
+
|
336 |
+
return $data;
|
337 |
+
}
|
338 |
+
|
339 |
+
protected function _updatePaymentMethod()
|
340 |
+
{
|
341 |
+
/* @var $model Jmango360_Japi_Model_Rest_Checkout_Onepage */
|
342 |
+
$model = Mage::getModel('japi/rest_checkout_onepage');
|
343 |
+
$data = $model->updatePaymentMethod();
|
344 |
+
|
345 |
+
return $data;
|
346 |
+
}
|
347 |
+
|
348 |
+
protected function _getOnePage()
|
349 |
+
{
|
350 |
+
return Mage::getSingleton('checkout/type_onepage');
|
351 |
+
}
|
352 |
+
|
353 |
+
protected function _getCheckoutMethods()
|
354 |
+
{
|
355 |
+
$model = Mage::getModel('japi/rest_checkout_methods');
|
356 |
+
$data = $model->getCheckoutMethods();
|
357 |
+
|
358 |
+
return $data;
|
359 |
+
}
|
360 |
+
|
361 |
+
/**
|
362 |
+
* @return Mage_Checkout_Model_Session
|
363 |
+
*/
|
364 |
+
protected function _getSession()
|
365 |
+
{
|
366 |
+
return Mage::getSingleton('checkout/session');
|
367 |
+
}
|
368 |
+
|
369 |
+
/**
|
370 |
+
* @return Jmango360_Japi_Model_Request
|
371 |
+
*/
|
372 |
+
protected function _getRequest()
|
373 |
+
{
|
374 |
+
return Mage::helper('japi')->getRequest();
|
375 |
+
}
|
376 |
+
|
377 |
+
/**
|
378 |
+
* @return Jmango360_Japi_Model_Response
|
379 |
+
*/
|
380 |
+
protected function _getResponse()
|
381 |
+
{
|
382 |
+
return Mage::helper('japi')->getResponse();
|
383 |
+
}
|
384 |
+
|
385 |
+
/**
|
386 |
+
* @return Jmango360_Japi_Model_Server
|
387 |
+
*/
|
388 |
+
protected function _getServer()
|
389 |
+
{
|
390 |
+
return Mage::helper('japi')->getServer();
|
391 |
+
}
|
392 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Checkout/Methods.php
ADDED
@@ -0,0 +1,638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* TODO: Create a field mapper that maps custom made shipping and payment method fields to the response of getCheckoutMethods
|
5 |
+
* @author Administrator
|
6 |
+
*
|
7 |
+
*/
|
8 |
+
class Jmango360_Japi_Model_Rest_Checkout_Methods extends Jmango360_Japi_Model_Rest_Checkout
|
9 |
+
{
|
10 |
+
protected static $_carriers;
|
11 |
+
|
12 |
+
protected $_errors = array();
|
13 |
+
|
14 |
+
protected $_shippingMethodsDisplayed = null;
|
15 |
+
protected $_paymentMethodsDisplayed = null;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The method shows the basic information in the App for shipping
|
19 |
+
* all other parameters are used in /<module>/shipping to count the shipping price
|
20 |
+
* the final shipping price is responce of the collect totals call
|
21 |
+
* The "free shipping subtotal" can be displayed in the "specificerrmsg" if applicable.
|
22 |
+
* "Specific countries" is in the standard configuration but not used in standard Magento code.
|
23 |
+
* The show method (show not applicable shipping methods) is in configuration, however not used in the standard code.
|
24 |
+
* @TODO: create admin field mapper
|
25 |
+
*/
|
26 |
+
private $_shippingMethodFields = array(
|
27 |
+
/*
|
28 |
+
* Is the method active. If not active not in response.
|
29 |
+
*/
|
30 |
+
'active',
|
31 |
+
/*
|
32 |
+
* Display title
|
33 |
+
*/
|
34 |
+
'title',
|
35 |
+
/*
|
36 |
+
* Display name
|
37 |
+
*/
|
38 |
+
'name',
|
39 |
+
/*
|
40 |
+
* Price for shipping
|
41 |
+
*/
|
42 |
+
'price',
|
43 |
+
/*
|
44 |
+
* Message to show. Could be used as explanation of the price calculation in the App.
|
45 |
+
* The Magento standard text (not available...) is not used.
|
46 |
+
*/
|
47 |
+
'specificerrmsg',
|
48 |
+
/*
|
49 |
+
* The handling type and fee is not added. Is mainly used in packages and weight quanties.
|
50 |
+
* Seldom used bij simple shops and not technical shop owners.
|
51 |
+
* The handling fee still can be used, only the accounting is not shown in the App.
|
52 |
+
* The explanation of accounting the handling fee could be added in the specificerrmsg
|
53 |
+
*/
|
54 |
+
//'handling_type',
|
55 |
+
//'handling_fee',
|
56 |
+
/*
|
57 |
+
* Show the method even when it is not active
|
58 |
+
* use the specificerrmsg to explain why not active and why shown
|
59 |
+
*/
|
60 |
+
'showmethod',
|
61 |
+
/*
|
62 |
+
* Order in which the methods are shown
|
63 |
+
*/
|
64 |
+
'sort_order',
|
65 |
+
/*
|
66 |
+
* Only used in specific countries
|
67 |
+
* This is not in the response.
|
68 |
+
* countries are filtered out from the response if applicable
|
69 |
+
*/
|
70 |
+
//'sallowspecific',
|
71 |
+
//'specific_country',
|
72 |
+
);
|
73 |
+
|
74 |
+
/**
|
75 |
+
* The method shows the basic information in the App for billing
|
76 |
+
* all other parameters are used in /<module>/shipping to count the shipping price
|
77 |
+
* the final shipping price is response of the collect totals call
|
78 |
+
* @TODO: create admin field mapper
|
79 |
+
*/
|
80 |
+
private $_paymentMethodFields = array(
|
81 |
+
/*
|
82 |
+
* Is the method active. If not active not in response.
|
83 |
+
*/
|
84 |
+
'active',
|
85 |
+
/*
|
86 |
+
* Display title
|
87 |
+
*/
|
88 |
+
'title',
|
89 |
+
/*
|
90 |
+
* Message to show. Could be used as explanation of the price calculation in the App.
|
91 |
+
* The Magento standard text (not available...) is not used.
|
92 |
+
*/
|
93 |
+
'instructions',
|
94 |
+
/*
|
95 |
+
* Order in which the methods are shown
|
96 |
+
*/
|
97 |
+
'sort_order',
|
98 |
+
/*
|
99 |
+
* Only used in specific countries
|
100 |
+
* This is not in the response.
|
101 |
+
* countries are filtered out from the response if applicable
|
102 |
+
*/
|
103 |
+
//'sallowspecific',
|
104 |
+
//'specific_country',
|
105 |
+
);
|
106 |
+
|
107 |
+
public function getCheckoutMethods()
|
108 |
+
{
|
109 |
+
$data['shipping_methods'] = null;
|
110 |
+
$data['payment_methods'] = null;
|
111 |
+
|
112 |
+
if ($this->_validateMethods()) {
|
113 |
+
$data['shipping_methods'] = $this->_getShippingMethods();
|
114 |
+
$data['payment_methods'] = $this->_getPaymentMethods();
|
115 |
+
}
|
116 |
+
|
117 |
+
$data['methods_info'] = $this->getErrors();
|
118 |
+
|
119 |
+
return $data;
|
120 |
+
}
|
121 |
+
|
122 |
+
public function getShippingMethods()
|
123 |
+
{
|
124 |
+
$shippingMethods = null;
|
125 |
+
if ($this->_validateMethods()) {
|
126 |
+
$shippingMethods = $this->_getShippingMethods();
|
127 |
+
}
|
128 |
+
|
129 |
+
return $shippingMethods;
|
130 |
+
}
|
131 |
+
|
132 |
+
public function getPaymentMethods()
|
133 |
+
{
|
134 |
+
$paymentMethods = null;
|
135 |
+
if ($this->_validateMethods()) {
|
136 |
+
$paymentMethods = $this->_getPaymentMethods();
|
137 |
+
}
|
138 |
+
|
139 |
+
return $paymentMethods;
|
140 |
+
}
|
141 |
+
|
142 |
+
public function getValidatePaymentMethods($paymentMethod = null)
|
143 |
+
{
|
144 |
+
$paymentMethods = null;
|
145 |
+
if ($this->_validateMethods()) {
|
146 |
+
$paymentMethods = $this->_getValidatePaymentMethods($paymentMethod);
|
147 |
+
}
|
148 |
+
|
149 |
+
return $paymentMethods;
|
150 |
+
}
|
151 |
+
|
152 |
+
/*
|
153 |
+
* The getCheckoutMethods can give some of the methods applicable before address and cart is saved. But is prevented to do this by the validate below.
|
154 |
+
* -- To get All applicable and VALID methods and there price shipping address and cart have to be saved to quote tables
|
155 |
+
* -- The counts below prevent showing the incomplete methods
|
156 |
+
* -- Removing the count will use a temporary (fake) shipping request simulating some shipping address and item parameters
|
157 |
+
* -- This can be used in some custom made solutions, but by default it is prevented by the counts belwo
|
158 |
+
*/
|
159 |
+
private function _validateMethods()
|
160 |
+
{
|
161 |
+
$quote = $this->getQuote();
|
162 |
+
$valid = true;
|
163 |
+
$shippingAddress = $quote->getShippingAddress();
|
164 |
+
|
165 |
+
if (!is_object($shippingAddress) || !$shippingAddress->getLastname() || !$shippingAddress->getStreet() || !$shippingAddress->getCountryId()) {
|
166 |
+
$this->_errors[] = Mage::helper('japi')->__('Methods are not complete yet. Cart shipping address is not yet completed and saved.');
|
167 |
+
$valid = false;
|
168 |
+
}
|
169 |
+
|
170 |
+
if (!count($quote->getAllVisibleItems())) {
|
171 |
+
$this->_errors[] = Mage::helper('japi')->__('Methods are not complete yet. Cart is empty.');
|
172 |
+
$valid = false;
|
173 |
+
}
|
174 |
+
|
175 |
+
return $valid;
|
176 |
+
}
|
177 |
+
|
178 |
+
public function getErrors()
|
179 |
+
{
|
180 |
+
return $this->_errors;
|
181 |
+
}
|
182 |
+
|
183 |
+
/*
|
184 |
+
* Dilemma of showing all active shipping methods in the App before all information is collected
|
185 |
+
*
|
186 |
+
* The shipping method in the address table has to be a combination of the carrier and the carrier method
|
187 |
+
* In the configuration only the carrier code is given. The method is collected from the "collectRates" method
|
188 |
+
* from the carriers shipping model
|
189 |
+
*
|
190 |
+
* The shipping methods in magento filosofy can only be populated only if shipping address is known,
|
191 |
+
* because there price is shown next to the shipping method.
|
192 |
+
* Some of the prices can only be accounted if address (location), product items price, weight etc are known
|
193 |
+
* All information is available after the address and products are given
|
194 |
+
* The collect totals done before the App shows the product total prices in the checkout will show the right price
|
195 |
+
* Below is a work around by collectRates with a temporary request object (request object = shipping information for collect rates in collect totals)
|
196 |
+
*
|
197 |
+
* @TODO: look for a better "Magentic way"
|
198 |
+
*/
|
199 |
+
protected function _getShippingMethods()
|
200 |
+
{
|
201 |
+
$options = array();
|
202 |
+
/* @var $taxHelper Mage_Tax_Helper_Data */
|
203 |
+
$taxHelper = Mage::helper('tax');
|
204 |
+
/* @var $block Mage_Checkout_Block_Onepage_Shipping_Method_Available */
|
205 |
+
$block = Mage::helper('japi')->getBlock('checkout/onepage_shipping_method_available');
|
206 |
+
$_shippingRateGroups = $block->getShippingRates();
|
207 |
+
if (count($_shippingRateGroups)) {
|
208 |
+
foreach ($_shippingRateGroups as $code => $_rates) {
|
209 |
+
foreach ($_rates as $_rate) {
|
210 |
+
/* @var $_rate Mage_Sales_Model_Quote_Address_Rate */
|
211 |
+
if ($_rate->getErrorMessage()) {
|
212 |
+
$this->_errors[] = $_rate->getErrorMessage();
|
213 |
+
} else {
|
214 |
+
$method = $_rate->getmethod();
|
215 |
+
$carrier = $_rate->getCarrier();
|
216 |
+
if (empty($method)) {
|
217 |
+
$method = $carrier;
|
218 |
+
}
|
219 |
+
$shippingMethod = $_rate->getCode();
|
220 |
+
|
221 |
+
$options[$shippingMethod]['shipping_method'] = $shippingMethod;
|
222 |
+
$options[$shippingMethod]['carrier'] = $carrier;
|
223 |
+
$options[$shippingMethod]['carrier_title'] = $_rate->getCarrierTitle();
|
224 |
+
$options[$shippingMethod]['method'] = $method;
|
225 |
+
$options[$shippingMethod]['method_title'] = $_rate->getMethodTitle();
|
226 |
+
$options[$shippingMethod]['description'] = $_rate->getMethodDescription();
|
227 |
+
$options[$shippingMethod]['shipping_cost'] = $taxHelper->getShippingPrice(
|
228 |
+
$_rate->getPrice(),
|
229 |
+
$taxHelper->displayShippingPriceIncludingTax(),
|
230 |
+
$block->getAddress()
|
231 |
+
);
|
232 |
+
|
233 |
+
$_excl = strip_tags($block->getShippingPrice(
|
234 |
+
$_rate->getPrice(), $taxHelper->displayShippingPriceIncludingTax()
|
235 |
+
));
|
236 |
+
$options[$shippingMethod]['display_price_excl'] = $_excl;
|
237 |
+
|
238 |
+
$_incl = strip_tags($block->getShippingPrice($_rate->getPrice(), true));
|
239 |
+
if ($taxHelper->displayShippingBothPrices() && $_incl != $_excl) {
|
240 |
+
$options[$shippingMethod]['display_price_incl'] = strip_tags($block->getShippingPrice(
|
241 |
+
$_rate->getPrice(), $taxHelper->displayShippingPriceIncludingTax()
|
242 |
+
));
|
243 |
+
}
|
244 |
+
|
245 |
+
foreach ($this->_shippingMethodFields as $fieldName) {
|
246 |
+
if (empty($options[$shippingMethod][$fieldName])) {
|
247 |
+
$options[$shippingMethod][$fieldName] = Mage::getStoreConfig("carriers/$code/$fieldName");
|
248 |
+
}
|
249 |
+
}
|
250 |
+
|
251 |
+
if (empty($options[$shippingMethod]['title'])) {
|
252 |
+
$options[$shippingMethod]['title'] = trim(implode(' ', array($_rate->getCarrierTitle(), $_rate->getMethodTitle())));
|
253 |
+
}
|
254 |
+
|
255 |
+
// MPLUGIN-816
|
256 |
+
$options[$shippingMethod]['active'] = $options[$shippingMethod]['active'] ? '1' : '0';
|
257 |
+
}
|
258 |
+
}
|
259 |
+
}
|
260 |
+
} else {
|
261 |
+
/*
|
262 |
+
* In case you would like to catch shipping methods in an early stage, before having added the address or the first cart item.
|
263 |
+
* -- the method below simulates a shipping methods/rates request with an empty cart items array and some key values set to 1
|
264 |
+
* -- this will display most of the shipping methods with the correct shipping code
|
265 |
+
* -- it can not however count the correct prices
|
266 |
+
*/
|
267 |
+
$this->_setShippingMethodsDisplayed($this->_getDisplayedShippingMethods());
|
268 |
+
Mage::dispatchEvent('rest_checkout_shipping_methods', array('object' => $this));
|
269 |
+
|
270 |
+
foreach ($this->_getShippingMethodsDisplayed() as $code => $carrierContainer) {
|
271 |
+
$rates = $this->_getRates($code, $carrierContainer);
|
272 |
+
if ($rates) {
|
273 |
+
foreach ($rates as $rate) {
|
274 |
+
/* @var $rate Mage_Sales_Model_Quote_Address_Rate */
|
275 |
+
$method = $rate->getmethod();
|
276 |
+
$carrier = $rate->getCarrier();
|
277 |
+
if (empty($method)) {
|
278 |
+
$method = $carrier;
|
279 |
+
}
|
280 |
+
$shippingMethod = $carrier . '_' . $method;
|
281 |
+
|
282 |
+
$options[$shippingMethod]['shipping_method'] = $shippingMethod;
|
283 |
+
$options[$shippingMethod]['carrier'] = $rate->getCarrier();
|
284 |
+
$options[$shippingMethod]['carrier_title'] = $rate->getCarrierTitle();
|
285 |
+
$options[$shippingMethod]['method'] = $rate->getMethod();
|
286 |
+
$options[$shippingMethod]['method_title'] = $rate->getMethodTitle();
|
287 |
+
foreach ($this->_shippingMethodFields as $fieldName) {
|
288 |
+
if (empty($options[$shippingMethod][$fieldName]) && $fieldName != 'price') {
|
289 |
+
$options[$shippingMethod][$fieldName] = Mage::getStoreConfig("carriers/$code/$fieldName");
|
290 |
+
}
|
291 |
+
}
|
292 |
+
if (empty($options[$shippingMethod]['title'])) {
|
293 |
+
$options[$shippingMethod]['title'] = trim(implode(' ', array($rate->getCarrierTitle(), $rate->getMethodTitle())));
|
294 |
+
}
|
295 |
+
}
|
296 |
+
} else {
|
297 |
+
$message = Mage::helper('japi')->__('Shipping method has no shipping carrier object: %s', $code);
|
298 |
+
$this->_errors[] = $message;
|
299 |
+
//mage::log($message, Zend_Log::WARN, $this->_logname);
|
300 |
+
//throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
301 |
+
}
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
$excludedShippingMethods = explode(',', Mage::getStoreConfig('japi/jmango_rest_checkout_settings/shipping_excluded'));
|
306 |
+
foreach ($options as $code => $option) {
|
307 |
+
if (in_array($code, $excludedShippingMethods)) {
|
308 |
+
unset($options[$code]);
|
309 |
+
}
|
310 |
+
}
|
311 |
+
|
312 |
+
return $options;
|
313 |
+
}
|
314 |
+
|
315 |
+
/*
|
316 |
+
* Used in work around for _getShippingmethods
|
317 |
+
*/
|
318 |
+
protected function _getRates($code, $carrierContainer)
|
319 |
+
{
|
320 |
+
if (!method_exists($carrierContainer, 'collectRates')) {
|
321 |
+
$message = Mage::helper('japi')->__('Carrier object has no collectRates method: %s', $code);
|
322 |
+
$this->_errors[] = $message;
|
323 |
+
//mage::log($message, Zend_Log::WARN, $this->_logname);
|
324 |
+
//throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
325 |
+
return false;
|
326 |
+
}
|
327 |
+
|
328 |
+
/*
|
329 |
+
* Should be a populated collectRates request
|
330 |
+
* -- in this early stage the request info not available
|
331 |
+
*/
|
332 |
+
$request = $this->_getTempRequest();
|
333 |
+
|
334 |
+
try {
|
335 |
+
$carrierRates = $carrierContainer->collectRates($request);
|
336 |
+
} catch (Exception $e) {
|
337 |
+
$carrierRates = null;
|
338 |
+
$message = $e->getMessage();
|
339 |
+
$this->_errors[] = $message;
|
340 |
+
//mage::log($e->getMessage(), Zend_Log::WARN, $this->_logname);
|
341 |
+
}
|
342 |
+
|
343 |
+
if (!is_object($carrierRates)) {
|
344 |
+
$message = Mage::helper('japi')->__('Shipping method has no rates object: %s', $code);
|
345 |
+
$this->_errors[] = $message;
|
346 |
+
//mage::log($message, Zend_Log::WARN, $this->_logname);
|
347 |
+
//throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
348 |
+
return false;
|
349 |
+
}
|
350 |
+
|
351 |
+
if (!method_exists($carrierRates, 'getAllRates')) {
|
352 |
+
$message = Mage::helper('japi')->__('Shipping method has no getAllRates function: %s', $code);
|
353 |
+
$this->_errors[] = $message;
|
354 |
+
//mage::log($message, Zend_Log::WARN, $this->_logname);
|
355 |
+
//throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
356 |
+
return false;
|
357 |
+
}
|
358 |
+
|
359 |
+
$rates = $carrierRates->getAllRates();
|
360 |
+
if (!count($rates)) {
|
361 |
+
$message = Mage::helper('japi')->__('Shipping method has no rates: %s', $code);
|
362 |
+
$this->_errors[] = $message;
|
363 |
+
//mage::log($message, Zend_Log::WARN, $this->_logname);
|
364 |
+
//throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
365 |
+
return false;
|
366 |
+
}
|
367 |
+
|
368 |
+
return $rates;
|
369 |
+
}
|
370 |
+
|
371 |
+
/*
|
372 |
+
* Used in work around for _getShippingmethods
|
373 |
+
*/
|
374 |
+
protected function _getTempRequest()
|
375 |
+
{
|
376 |
+
/* @var $request Mage_Shipping_Model_Rate_Request */
|
377 |
+
$request = Mage::getModel('shipping/rate_request');
|
378 |
+
$request->setDestCountryId(Mage::getStoreConfig('general/country/default'));
|
379 |
+
$request->setPackageValue(1);
|
380 |
+
$request->setPackageValueWithDiscount(1);
|
381 |
+
$request->setPackageWeight(1);
|
382 |
+
$request->setPackageQty(1);
|
383 |
+
$request->setPackagePhysicalValue(1);
|
384 |
+
$request->setStoreId(Mage::app()->getStore()->getId());
|
385 |
+
$request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
|
386 |
+
$request->setFreeShipping(0);
|
387 |
+
$request->setBaseCurrency(Mage::app()->getStore()->getBaseCurrency());
|
388 |
+
$request->setPackageCurrency(Mage::app()->getStore()->getCurrentCurrency());
|
389 |
+
$request->setBaseSubtotalInclTax(1);
|
390 |
+
$request->setFreeShipping(true);
|
391 |
+
$request->setAllItems(array());
|
392 |
+
|
393 |
+
return $request;
|
394 |
+
}
|
395 |
+
|
396 |
+
protected function _getValidatePaymentMethods($paymentMethod = null)
|
397 |
+
{
|
398 |
+
$quote = $this->getQuote();
|
399 |
+
$store = $quote ? $quote->getStoreId() : null;
|
400 |
+
$options = array();
|
401 |
+
/* @var $block Mage_Checkout_Block_Onepage_Payment_Methods */
|
402 |
+
$block = Mage::helper('japi')->getBlock('checkout/onepage_payment_methods', NULL, array('quote' => $quote, 'store' => $store));
|
403 |
+
|
404 |
+
$paymentMethods = $block->getMethods();
|
405 |
+
|
406 |
+
$total = $quote->getBaseSubtotal() + $quote->getShippingAddress()->getBaseShippingAmount();
|
407 |
+
foreach ($paymentMethods as $method) {
|
408 |
+
/* @var $method Mage_Payment_Model_Method_Abstract */
|
409 |
+
if ($this->_canUsePaymentMethod($method) && ($total != 0 || $method->getCode() == 'free' || ($quote->hasRecurringItems() && $method->canManageRecurringProfiles()))) {
|
410 |
+
$code = $method->getCode();
|
411 |
+
$options[$code] = $method->toArray();
|
412 |
+
|
413 |
+
if ($paymentMethod == $method->getCode()) {
|
414 |
+
//get payment form html
|
415 |
+
$formBlockName = $method->getFormBlockType();
|
416 |
+
if (!empty($formBlockName)) {
|
417 |
+
// Because of ICEPAY issues, we need create new blocks, not reuse them
|
418 |
+
/* @var $formBlock Mage_Payment_Block_Form */
|
419 |
+
$formBlock = Mage::app()->getLayout()->createBlock($formBlockName);
|
420 |
+
$formBlock->setData('method', $method);
|
421 |
+
$formBlock->setParentBlock($block);
|
422 |
+
|
423 |
+
$html = $formBlock->toHtml();
|
424 |
+
if (!empty($html)) {
|
425 |
+
$options[$code]['form'] = $this->_parseHtmlPaymentForm($html);
|
426 |
+
}
|
427 |
+
}
|
428 |
+
}
|
429 |
+
}
|
430 |
+
}
|
431 |
+
|
432 |
+
$excludedPaymentMethods = explode(',', Mage::getStoreConfig('japi/jmango_rest_checkout_settings/payment_excluded'));
|
433 |
+
foreach ($options as $code => $option) {
|
434 |
+
if (in_array($code, $excludedPaymentMethods)) {
|
435 |
+
unset($options[$code]);
|
436 |
+
}
|
437 |
+
}
|
438 |
+
|
439 |
+
return $options;
|
440 |
+
}
|
441 |
+
|
442 |
+
protected function _getPaymentMethods()
|
443 |
+
{
|
444 |
+
$quote = $this->getQuote();
|
445 |
+
$store = $quote ? $quote->getStoreId() : null;
|
446 |
+
$options = array();
|
447 |
+
/* @var $block Mage_Checkout_Block_Onepage_Payment_Methods */
|
448 |
+
$block = Mage::helper('japi')->getBlock('checkout/onepage_payment_methods', NULL, array('quote' => $quote, 'store' => $store));
|
449 |
+
|
450 |
+
$paymentMethods = $block->getMethods();
|
451 |
+
|
452 |
+
$total = $quote->getBaseSubtotal() + $quote->getShippingAddress()->getBaseShippingAmount();
|
453 |
+
foreach ($paymentMethods as $method) {
|
454 |
+
/* @var $method Mage_Payment_Model_Method_Abstract */
|
455 |
+
if ($this->_canUsePaymentMethod($method) && ($total != 0 || $method->getCode() == 'free' || ($quote->hasRecurringItems() && $method->canManageRecurringProfiles()))) {
|
456 |
+
|
457 |
+
$this->_assignPaymentMethod($method);
|
458 |
+
$code = $method->getCode();
|
459 |
+
$options[$code] = $method->toArray();
|
460 |
+
$options[$code]['title'] = $this->_stripHtml($block->getMethodTitle($method));
|
461 |
+
if (is_object($method->getInfoInstance())) {
|
462 |
+
$options[$code]['payment'] = $method->getInfoInstance()->toArray();
|
463 |
+
}
|
464 |
+
|
465 |
+
/*
|
466 |
+
* The payment forms contain the information to select from in frontend payment page
|
467 |
+
*/
|
468 |
+
$formBlockName = $method->getFormBlockType();
|
469 |
+
if (!empty($formBlockName)) {
|
470 |
+
// Because of ICEPAY issues, we need create new blocks, not reuse them
|
471 |
+
/* @var $formBlock Mage_Payment_Block_Form */
|
472 |
+
$formBlock = Mage::app()->getLayout()->createBlock($formBlockName);
|
473 |
+
$formBlock->setData('method', $method);
|
474 |
+
$formBlock->setParentBlock($block);
|
475 |
+
|
476 |
+
$html = $formBlock->toHtml();
|
477 |
+
if (!empty($html)) {
|
478 |
+
$options[$code]['form'] = $this->_parseHtmlPaymentForm($html);
|
479 |
+
}
|
480 |
+
}
|
481 |
+
|
482 |
+
unset($options[$code]['info_instance']);
|
483 |
+
|
484 |
+
foreach ($this->_paymentMethodFields as $fieldName) {
|
485 |
+
if (empty($options[$code][$fieldName])) {
|
486 |
+
$value = Mage::getStoreConfig("payment/$code/$fieldName");
|
487 |
+
$options[$code][$fieldName] = $value;
|
488 |
+
}
|
489 |
+
}
|
490 |
+
|
491 |
+
if (empty($options[$code]['title'])) {
|
492 |
+
$options[$code]['title'] = $code;
|
493 |
+
}
|
494 |
+
|
495 |
+
// MPLUGIN-816
|
496 |
+
$options[$code]['active'] = $options[$code]['active'] ? '1' : '0';
|
497 |
+
}
|
498 |
+
}
|
499 |
+
|
500 |
+
$excludedPaymentMethods = explode(',', Mage::getStoreConfig('japi/jmango_rest_checkout_settings/payment_excluded'));
|
501 |
+
foreach ($options as $code => $option) {
|
502 |
+
if (in_array($code, $excludedPaymentMethods)) {
|
503 |
+
unset($options[$code]);
|
504 |
+
}
|
505 |
+
}
|
506 |
+
|
507 |
+
return $options;
|
508 |
+
}
|
509 |
+
|
510 |
+
protected function _stripHtml($html)
|
511 |
+
{
|
512 |
+
return trim(strip_tags(str_replace(' ', ' ', $html)), " \t\n\r\0\x0B-");
|
513 |
+
}
|
514 |
+
|
515 |
+
protected function _parseHtmlPaymentForm($html)
|
516 |
+
{
|
517 |
+
return Mage::helper('japi')->parseHtmlForm($html);
|
518 |
+
}
|
519 |
+
|
520 |
+
/**
|
521 |
+
* Check payment method model
|
522 |
+
*
|
523 |
+
* @param Mage_Payment_Model_Method_Abstract $method
|
524 |
+
* @return bool
|
525 |
+
*/
|
526 |
+
protected function _canUsePaymentMethod($method)
|
527 |
+
{
|
528 |
+
if (!$method->canUseForCountry($this->getQuote()->getBillingAddress()->getCountry())) {
|
529 |
+
return false;
|
530 |
+
}
|
531 |
+
|
532 |
+
if (!$method->canUseForCurrency($this->getQuote()->getStore()->getBaseCurrencyCode())) {
|
533 |
+
return false;
|
534 |
+
}
|
535 |
+
|
536 |
+
/**
|
537 |
+
* Checking for min/max order total for assigned payment method
|
538 |
+
*/
|
539 |
+
$total = $this->getQuote()->getBaseGrandTotal();
|
540 |
+
$minTotal = $method->getConfigData('min_order_total');
|
541 |
+
$maxTotal = $method->getConfigData('max_order_total');
|
542 |
+
|
543 |
+
if ((!empty($minTotal) && ($total < $minTotal)) || (!empty($maxTotal) && ($total > $maxTotal))) {
|
544 |
+
return false;
|
545 |
+
}
|
546 |
+
return true;
|
547 |
+
}
|
548 |
+
|
549 |
+
/**
|
550 |
+
* Check and prepare payment method model
|
551 |
+
*
|
552 |
+
* Redeclare this method in child classes for declaring method info instance
|
553 |
+
*
|
554 |
+
* @param Mage_Payment_Model_Method_Abstract $method
|
555 |
+
* @return bool
|
556 |
+
*/
|
557 |
+
protected function _assignPaymentMethod($method)
|
558 |
+
{
|
559 |
+
$method->setInfoInstance($this->getQuote()->getPayment());
|
560 |
+
return $this;
|
561 |
+
}
|
562 |
+
|
563 |
+
protected function _getDisplayedShippingMethods()
|
564 |
+
{
|
565 |
+
$carriers = array();
|
566 |
+
$config = Mage::getStoreConfig('carriers');
|
567 |
+
foreach ($config as $code => $carrierConfig) {
|
568 |
+
if (Mage::getStoreConfigFlag('carriers/' . $code . '/active') /*|| Mage::getStoreConfigFlag('carriers/'.$code.'/showmethod')*/) {
|
569 |
+
$carrierModel = $this->_getCarrier($code, $carrierConfig);
|
570 |
+
if ($carrierModel) {
|
571 |
+
$carriers[$code] = $carrierModel;
|
572 |
+
}
|
573 |
+
}
|
574 |
+
}
|
575 |
+
return $carriers;
|
576 |
+
}
|
577 |
+
|
578 |
+
public function _getDisplayedPaymentMethods()
|
579 |
+
{
|
580 |
+
$payment = array();
|
581 |
+
$config = Mage::getStoreConfig('payment');
|
582 |
+
foreach ($config as $code => $paymentConfig) {
|
583 |
+
if (Mage::getStoreConfigFlag('payment/' . $code . '/active')) {
|
584 |
+
$paymentModel = $this->_getCarrier($code, $paymentConfig);
|
585 |
+
if ($paymentModel) {
|
586 |
+
$payment[$code] = $paymentModel;
|
587 |
+
}
|
588 |
+
}
|
589 |
+
}
|
590 |
+
return $payment;
|
591 |
+
}
|
592 |
+
|
593 |
+
protected function _getCarrier($code, $config, $store = null)
|
594 |
+
{
|
595 |
+
if (!isset($config['model'])) {
|
596 |
+
return false;
|
597 |
+
}
|
598 |
+
$modelName = $config['model'];
|
599 |
+
|
600 |
+
/**
|
601 |
+
* Added protection from not existing models usage.
|
602 |
+
* Related with module uninstall process
|
603 |
+
*/
|
604 |
+
try {
|
605 |
+
$carrier = Mage::getModel($modelName);
|
606 |
+
} catch (Exception $e) {
|
607 |
+
Mage::logException($e);
|
608 |
+
return false;
|
609 |
+
}
|
610 |
+
$carrier->setId($code)->setStore($store);
|
611 |
+
self::$_carriers[$code] = $carrier;
|
612 |
+
return self::$_carriers[$code];
|
613 |
+
}
|
614 |
+
|
615 |
+
private function _setShippingMethodsDisplayed($methods)
|
616 |
+
{
|
617 |
+
$this->_shippingMethodsDisplayed = $methods;
|
618 |
+
|
619 |
+
return $this;
|
620 |
+
}
|
621 |
+
|
622 |
+
protected function _getShippingMethodsDisplayed()
|
623 |
+
{
|
624 |
+
return $this->_shippingMethodsDisplayed;
|
625 |
+
}
|
626 |
+
|
627 |
+
private function _setPaymentMethodsDisplayed($methods)
|
628 |
+
{
|
629 |
+
$this->_paymentMethodsDisplayed = $methods;
|
630 |
+
|
631 |
+
return $this;
|
632 |
+
}
|
633 |
+
|
634 |
+
protected function _getPaymentMethodsDisplayed()
|
635 |
+
{
|
636 |
+
return $this->_paymentMethodsDisplayed;
|
637 |
+
}
|
638 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Checkout/Onepage.php
ADDED
@@ -0,0 +1,787 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* TODO: Create a field mapper that maps custom made shipping and payment method fields to the response of getCheckoutMethods
|
5 |
+
* @author Administrator
|
6 |
+
*
|
7 |
+
*/
|
8 |
+
class Jmango360_Japi_Model_Rest_Checkout_Onepage extends Jmango360_Japi_Model_Rest_Checkout
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Saved in the scope of the obeject duing vaildation of payment form data
|
12 |
+
* -- used in saving and checking credit card
|
13 |
+
* -- flat added to the request as issuer data
|
14 |
+
*/
|
15 |
+
protected $_paymentFormInfo = null;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Credit card number is not saved in the database but checked in creditcard check
|
19 |
+
*/
|
20 |
+
protected $_extraPaymentFields = array(
|
21 |
+
'cc_number'
|
22 |
+
);
|
23 |
+
|
24 |
+
protected $_resetPaymentFieldnames = array(
|
25 |
+
'cc_type',
|
26 |
+
'cc_number_enc',
|
27 |
+
'cc_last4',
|
28 |
+
'cc_owner',
|
29 |
+
'cc_exp_month',
|
30 |
+
'cc_exp_year',
|
31 |
+
'method_instance'
|
32 |
+
);
|
33 |
+
|
34 |
+
public function updateCartAddresses2()
|
35 |
+
{
|
36 |
+
$isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
|
37 |
+
|
38 |
+
$billingData = $this->_getRequest()->getParam('billing_address', array());
|
39 |
+
$customerBillingAddressId = $isLoggedIn ? $this->_getRequest()->getParam('billing_address_id', false) : false;
|
40 |
+
|
41 |
+
if ($billingData || $customerBillingAddressId) {
|
42 |
+
if (!isset($billingData['email'])) {
|
43 |
+
$billingData['email'] = trim($this->_getRequest()->getParam('email'));
|
44 |
+
}
|
45 |
+
|
46 |
+
$billingResult = $this->saveBilling($billingData, $customerBillingAddressId);
|
47 |
+
if (isset($billingResult['error'])) {
|
48 |
+
throw new Jmango360_Japi_Exception($this->_convertMessage(@$billingResult['message']), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
$shippingData = $this->_getRequest()->getParam('shipping_address', array());
|
53 |
+
$customerShippingAddressId = $isLoggedIn ? $this->_getRequest()->getParam('shipping_address_id', false) : false;
|
54 |
+
|
55 |
+
if ($shippingData || $customerShippingAddressId) {
|
56 |
+
$shippingResult = $this->saveShipping($shippingData, $customerShippingAddressId);
|
57 |
+
if (isset($shippingResult['error'])) {
|
58 |
+
throw new Jmango360_Japi_Exception($this->_convertMessage(@$shippingResult['message']), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
return $this->_getCheckoutData();
|
63 |
+
}
|
64 |
+
|
65 |
+
protected function _convertMessage($message)
|
66 |
+
{
|
67 |
+
if (!$message) return '';
|
68 |
+
if (is_array($message)) return join("\n", $message);
|
69 |
+
if (is_string($message)) return $message;
|
70 |
+
return '';
|
71 |
+
}
|
72 |
+
|
73 |
+
public function updateCartAddresses()
|
74 |
+
{
|
75 |
+
/**
|
76 |
+
* Creata a valid checkout for this session
|
77 |
+
* Also check if customer is logged in
|
78 |
+
* - if so, assign customer
|
79 |
+
*/
|
80 |
+
$this->initCheckout();
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Now apply billing and shipping address as set by customer and requested by REST call
|
84 |
+
*/
|
85 |
+
$quote = $this->getQuote();
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Add billing address to quote
|
89 |
+
*/
|
90 |
+
if ($billingAddress = $this->_getBillingAddress()) {
|
91 |
+
$quote->setBillingAddress($billingAddress);
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Add shipping address to quote
|
96 |
+
*/
|
97 |
+
if (!$quote->isVirtual()) {
|
98 |
+
if ($shippingAddress = $this->_getShippingAddress()) {
|
99 |
+
$quote->setShippingAddress($shippingAddress);
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Collect totals
|
105 |
+
*/
|
106 |
+
$quote->collectTotals()->save();
|
107 |
+
if (!$quote->isVirtual()) {
|
108 |
+
// Recollect Shipping rates for shipping methods
|
109 |
+
$quote->getShippingAddress()->setCollectShippingRates(true);
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Get quote data
|
114 |
+
*/
|
115 |
+
$data = $this->_getCheckoutData();
|
116 |
+
|
117 |
+
return $data;
|
118 |
+
}
|
119 |
+
|
120 |
+
public function checkout()
|
121 |
+
{
|
122 |
+
/**
|
123 |
+
* Saving the quote saves also quote related objects.
|
124 |
+
* @var Mage_Sales_Model_Quote::_afterSave
|
125 |
+
*/
|
126 |
+
$this->_saveAddresses();
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Get payment forms from request params and validate all send payment data
|
130 |
+
* -- translate form params to flat request params
|
131 |
+
* -- save payment form params in database
|
132 |
+
* -- save payment info in session for next step (submit)
|
133 |
+
* In general trying to simulate the onestp checkout payment template and the data return
|
134 |
+
* -- from the payment templates in the POST
|
135 |
+
*/
|
136 |
+
$this->_preparePayment();
|
137 |
+
|
138 |
+
/**
|
139 |
+
* After setting shipping method in shipping address row, collect and set the totals and save
|
140 |
+
*/
|
141 |
+
$this->getQuote()->setTotalsCollectedFlag(false);
|
142 |
+
$this->getQuote()->collectTotals()->save();
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Save payment POST in session to use in submit method
|
146 |
+
*/
|
147 |
+
Mage::getSingleton('core/session')->setPaymentPostUsedInSubmit($this->_getRequest()->getParam('payment'));
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Set response data
|
151 |
+
*/
|
152 |
+
$data = $this->_getCheckoutData();
|
153 |
+
|
154 |
+
/**
|
155 |
+
* If the checkout was with register (new customer) method, the customer is logged in during checkout
|
156 |
+
* -- the session id is refreshed after login
|
157 |
+
*/
|
158 |
+
$data['session_id'] = Mage::getSingleton('core/session')->getSessionId();
|
159 |
+
|
160 |
+
return $data;
|
161 |
+
}
|
162 |
+
|
163 |
+
public function updateShippingMethod()
|
164 |
+
{
|
165 |
+
$data = $this->_getRequest()->getParam('shipping_method', '');
|
166 |
+
$result = $this->saveShippingMethod($data);
|
167 |
+
|
168 |
+
if (!$result) {
|
169 |
+
Mage::dispatchEvent(
|
170 |
+
'checkout_controller_onepage_save_shipping_method',
|
171 |
+
array(
|
172 |
+
'request' => $this->_getRequest(),
|
173 |
+
'quote' => $this->getQuote()
|
174 |
+
)
|
175 |
+
);
|
176 |
+
|
177 |
+
/**
|
178 |
+
* Set the quote basic customer info
|
179 |
+
*/
|
180 |
+
$this->_setQuoteCustomerInfo();
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Collect totals
|
184 |
+
*/
|
185 |
+
$this->getQuote()->collectTotals()->save();
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Return quote data
|
189 |
+
*/
|
190 |
+
return $this->_getCheckoutData();
|
191 |
+
} else {
|
192 |
+
throw new Jmango360_Japi_Exception(
|
193 |
+
$result['message'],
|
194 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
195 |
+
);
|
196 |
+
}
|
197 |
+
}
|
198 |
+
|
199 |
+
public function updatePaymentMethod()
|
200 |
+
{
|
201 |
+
/**
|
202 |
+
* Save all POST data for Buckaroo using later
|
203 |
+
*/
|
204 |
+
$POST = $this->_getRequest()->getParam('form', array());
|
205 |
+
$POST['payment']['method'] = $this->_getRequest()->getParam('payment_method');
|
206 |
+
$this->_getSession()->setData('POST', $POST);
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Save payment
|
210 |
+
*/
|
211 |
+
$this->_preparePayment();
|
212 |
+
|
213 |
+
/**
|
214 |
+
* Collect totals
|
215 |
+
*/
|
216 |
+
$this->getQuote()->collectTotals()->save();
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Return quote data
|
220 |
+
*/
|
221 |
+
return $this->_getCheckoutData();
|
222 |
+
}
|
223 |
+
|
224 |
+
protected function _saveAddresses()
|
225 |
+
{
|
226 |
+
$request = $this->_getRequest();
|
227 |
+
|
228 |
+
/**
|
229 |
+
* If no carrier and method are known the quote can be saved but cannot collect all totals
|
230 |
+
*/
|
231 |
+
$shippingMethod = $request->getParam('shipping_method', null);
|
232 |
+
if (empty($shippingMethod)) {
|
233 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Shipping method can not be empty.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Check if shipping method exists and active
|
238 |
+
*/
|
239 |
+
$availableMethods = Mage::getModel('japi/rest_checkout_methods')->getShippingMethods();
|
240 |
+
if (empty($availableMethods)) {
|
241 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('No valid shipping methods available yet.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
242 |
+
}
|
243 |
+
if (empty($availableMethods[$shippingMethod])) {
|
244 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('This shipping method is currently not available.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* Set the specific quote data
|
249 |
+
*/
|
250 |
+
$quote = $this->getQuote();
|
251 |
+
$quote->setShippingMethod($shippingMethod);
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Virtual products ar not supported yet
|
255 |
+
*/
|
256 |
+
$quote->setIsVirtual($request->getParam('is_virtual', false));
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Virtual products ar not supported yet
|
260 |
+
*/
|
261 |
+
$quote->setIsMultiShipping($request->getParam('is_multishipping', false));
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Add billing address the the quote
|
265 |
+
*/
|
266 |
+
$billingAddress = $this->_getBillingAddress();
|
267 |
+
$quote->setBillingAddress($billingAddress);
|
268 |
+
|
269 |
+
/**
|
270 |
+
* Add shipping address to quote
|
271 |
+
*/
|
272 |
+
if (!$quote->isVirtual()) {
|
273 |
+
$shippingAddress = $this->_getShippingAddress();
|
274 |
+
$shippingAddress->setShippingMethod($shippingMethod);
|
275 |
+
$quote->setShippingAddress($shippingAddress);
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Set the quote basic customer info
|
280 |
+
*/
|
281 |
+
$this->_setQuoteCustomerInfo();
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Saving the quote and collecting the totals finished; send back all quote, price and totals information
|
285 |
+
* -- setStepData shipping complete is checked by saveBilling; if not set "setCollectShippingRates" is not set to true
|
286 |
+
*/
|
287 |
+
$this->getCheckout()
|
288 |
+
->setStepData('shipping', 'complete', true)
|
289 |
+
->setStepData('shipping_method', 'allow', true);
|
290 |
+
|
291 |
+
return $this;
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* @return Mage_Sales_Model_Quote_Address
|
296 |
+
* @throws Exception
|
297 |
+
* @throws Jmango360_Japi_Exception
|
298 |
+
*/
|
299 |
+
protected function _getShippingAddress()
|
300 |
+
{
|
301 |
+
$request = $this->_getRequest();
|
302 |
+
$quote = $this->getQuote();
|
303 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
304 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Used if "same_as_billing" is set to true in request
|
308 |
+
*/
|
309 |
+
$billingAddress = $quote->getBillingAddress();
|
310 |
+
|
311 |
+
/**
|
312 |
+
* $requestBillingAddress below in the request is optional in collectTotals, ass address is saved before in updateCartAddress
|
313 |
+
* -- this function (public getBillingAddress) is used by updateCartAddress to save the address in the http request!
|
314 |
+
*/
|
315 |
+
$requestBillingAddress = $request->getParam('billing_address', array());
|
316 |
+
$customerBillingAddress = $customer->getAddressById($request->getParam('billing_address_id'));
|
317 |
+
|
318 |
+
$shippingAddress = $quote->getShippingAddress();
|
319 |
+
|
320 |
+
/**
|
321 |
+
* $address below in the request is optional in collectTotals, ass address is saved before in updateCartAddress
|
322 |
+
* -- this function (public getBillingAddress) is used by updateCartAddress to save the address in the http request!
|
323 |
+
*/
|
324 |
+
$address = $request->getParam('shipping_address', array());
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Now we have a choice using: $shippingAddress (quote); $address (request); $customerShippingAddress (customer)
|
328 |
+
* -- same-as-billing:
|
329 |
+
* -- -- Priority to fill shipping address is (1) billing in request (2) billing address from quote (3) billing address from customer
|
330 |
+
* -- shipping address (not same as billing)
|
331 |
+
* -- -- Priority choosen is (1) customer; (2) request; (3) quote
|
332 |
+
*/
|
333 |
+
if (!empty($address['same_as_billing']) || (is_object($billingAddress) && $billingAddress->getUseForShipping())) {
|
334 |
+
if ($customerBillingAddress && $customerBillingAddress->getId()) {
|
335 |
+
$shippingAddress->importCustomerAddress($customerBillingAddress);
|
336 |
+
} else {
|
337 |
+
if (!empty($requestBillingAddress)) {
|
338 |
+
$shippingAddress->addData($requestBillingAddress);
|
339 |
+
} else {
|
340 |
+
$customerBillingAddress = $customer->getDefaultBillingAddress();
|
341 |
+
if ((!$shippingAddress || !$shippingAddress->getId()) && $customerBillingAddress && $customerBillingAddress->getId()) {
|
342 |
+
$shippingAddress->importCustomerAddress($customerBillingAddress);
|
343 |
+
}
|
344 |
+
}
|
345 |
+
}
|
346 |
+
} else {
|
347 |
+
if (empty($address)) return null;
|
348 |
+
|
349 |
+
$customerShippingAddress = $customer->getAddressById($request->getParam('shipping_address_id'));
|
350 |
+
if ($customerShippingAddress && $customerShippingAddress->getId()) {
|
351 |
+
$shippingAddress->importCustomerAddress($customerShippingAddress);
|
352 |
+
} else {
|
353 |
+
if (!empty($address)) {
|
354 |
+
$shippingAddress->addData($address);
|
355 |
+
} else {
|
356 |
+
$customerShippingAddress = $customer->getDefaultShippingAddress();
|
357 |
+
if ((!$shippingAddress || !$shippingAddress->getId()) && $customerShippingAddress && $customerShippingAddress->getId()) {
|
358 |
+
$shippingAddress->importCustomerAddress($customerShippingAddress);
|
359 |
+
}
|
360 |
+
}
|
361 |
+
}
|
362 |
+
}
|
363 |
+
|
364 |
+
if (!is_object($shippingAddress) || !$shippingAddress->getId()) {
|
365 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__("Customer shipping address not found."), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
366 |
+
}
|
367 |
+
|
368 |
+
if (!$shippingAddress->getEmail() || $request->getParam('email', false)) {
|
369 |
+
$shippingAddress->setEmail($request->getParam('email', null));
|
370 |
+
if (!$shippingAddress->getEmail() && (is_object($customerShippingAddress) && $customerShippingAddress->getEmail())) {
|
371 |
+
$shippingAddress->setEmail($customerShippingAddress->getEmail());
|
372 |
+
}
|
373 |
+
}
|
374 |
+
|
375 |
+
$shippingAddress->implodeStreetAddress();
|
376 |
+
$shippingAddress->setSaveInAddressBook(!empty($address['save_in_address_book']));
|
377 |
+
$shippingAddress->setUseForShipping(!empty($address['same_as_billing']));
|
378 |
+
$shippingAddress->setCustomerAddressId($request->getParam('shipping_address_id', null));
|
379 |
+
|
380 |
+
/**
|
381 |
+
* If not set setCollectShippingRates(true) the shippingRates table is not populated
|
382 |
+
*/
|
383 |
+
$shippingAddress->setCollectShippingRates(true);
|
384 |
+
|
385 |
+
$errors = $this->_checkAddressData($shippingAddress);
|
386 |
+
if (!empty($errors['error'])) {
|
387 |
+
$message = implode("\n", $errors['message']);
|
388 |
+
throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
389 |
+
}
|
390 |
+
|
391 |
+
return $shippingAddress->save();
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* @return Mage_Sales_Model_Quote_Address
|
396 |
+
* @throws Exception
|
397 |
+
* @throws Jmango360_Japi_Exception
|
398 |
+
*/
|
399 |
+
protected function _getBillingAddress()
|
400 |
+
{
|
401 |
+
$request = $this->_getRequest();
|
402 |
+
$quote = $this->getQuote();
|
403 |
+
$billingAddress = $quote->getBillingAddress();
|
404 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
405 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
406 |
+
|
407 |
+
/**
|
408 |
+
* $address in the request is optional in collectTotals, ass address is saved before in updateCartAddress
|
409 |
+
* -- this function (public getBillingAddress) is used by updateCartAddress to save the address in the http request!
|
410 |
+
*/
|
411 |
+
$address = $request->getParam('billing_address', array());
|
412 |
+
if (empty($address)) return null;
|
413 |
+
|
414 |
+
/**
|
415 |
+
* Now we have a choice using: $billingAddress (quote); $address (request); $customerBillingAddress (customer)
|
416 |
+
* -- Priority choosen is (1) customer; (2) request; (3) quote
|
417 |
+
*/
|
418 |
+
$customerBillingAddress = $customer->getAddressById($request->getParam('billing_address_id'));
|
419 |
+
|
420 |
+
if ($customerBillingAddress && $customerBillingAddress->getId()) {
|
421 |
+
$billingAddress->importCustomerAddress($customerBillingAddress);
|
422 |
+
} else {
|
423 |
+
if (!empty($address)) {
|
424 |
+
$billingAddress->addData($address);
|
425 |
+
} else {
|
426 |
+
$customerBillingAddress = $customer->getDefaultBillingAddress();
|
427 |
+
if ((!$billingAddress || !$billingAddress->getId()) && $customerBillingAddress && $customerBillingAddress->getId()) {
|
428 |
+
$billingAddress->importCustomerAddress($customerBillingAddress);
|
429 |
+
}
|
430 |
+
}
|
431 |
+
}
|
432 |
+
|
433 |
+
if (!is_object($billingAddress) || !$billingAddress->getId()) {
|
434 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__("Customer billing address not found."), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
435 |
+
}
|
436 |
+
|
437 |
+
$billingAddress->implodeStreetAddress();
|
438 |
+
$billingAddress->setSaveInAddressBook(!empty($address['save_in_address_book']));
|
439 |
+
$billingAddress->setCustomerAddressId($request->getParam('billing_address_id', null));
|
440 |
+
$billingAddress->setUseForShipping(!empty($address['use_for_shipping']));
|
441 |
+
|
442 |
+
if (!$billingAddress->getEmail()) {
|
443 |
+
$billingAddress->setEmail($request->getParam('email', null));
|
444 |
+
}
|
445 |
+
|
446 |
+
/**
|
447 |
+
* MPLUGIN-1218: Set data customer name to quote from param 'billing_address
|
448 |
+
*/
|
449 |
+
$quote->setCustomerFirstname(@$address['firstname']);
|
450 |
+
$quote->setCustomerMiddlename(@$address['middlename']);
|
451 |
+
$quote->setCustomerLastname(@$address['lastname']);
|
452 |
+
|
453 |
+
$errors = $this->_checkAddressData($billingAddress);
|
454 |
+
if (!empty($errors['error'])) {
|
455 |
+
$message = implode("\n", $errors['message']);
|
456 |
+
throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
457 |
+
}
|
458 |
+
|
459 |
+
return $billingAddress->save();
|
460 |
+
}
|
461 |
+
|
462 |
+
protected function _setQuoteCustomerInfo()
|
463 |
+
{
|
464 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
465 |
+
$quote = $this->getQuote();
|
466 |
+
$request = $this->_getRequest();
|
467 |
+
|
468 |
+
$quote->setCustomerEmail($request->getParam('email', null));
|
469 |
+
if (!$quote->getCustomerEmail() && (is_object($customer) && $customer->getId())) {
|
470 |
+
$quote->setCustomerEmail($customer->getEmail());
|
471 |
+
}
|
472 |
+
|
473 |
+
$quote->setCustomerDob($request->getParam('dob', null));
|
474 |
+
if (!$quote->getCustomerDob() && (is_object($customer) && $customer->getId())) {
|
475 |
+
$quote->setCustomerDob($customer->getDob());
|
476 |
+
}
|
477 |
+
|
478 |
+
$billingAddress = $quote->getBillingAddress();
|
479 |
+
|
480 |
+
$quote->setCustomerNote($request->getParam('note', null));
|
481 |
+
|
482 |
+
$quote->setCustomerPrefix($billingAddress->getPrefix());
|
483 |
+
$quote->setCustomerFirstname($billingAddress->getFirstname());
|
484 |
+
$quote->setCustomerLastname($billingAddress->getLastname());
|
485 |
+
$quote->setCustomerMiddlename($billingAddress->getMiddlename());
|
486 |
+
$quote->setCustomerPostfix($billingAddress->getPostfix());
|
487 |
+
}
|
488 |
+
|
489 |
+
protected function _preparePayment()
|
490 |
+
{
|
491 |
+
$request = $this->_getRequest();
|
492 |
+
$paymentMethod = $request->getParam('payment_method', null);
|
493 |
+
if (empty($paymentMethod)) {
|
494 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Payment method cannot be empty.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
495 |
+
}
|
496 |
+
|
497 |
+
$this->_validatePaymentMethod($paymentMethod);
|
498 |
+
$data['method'] = $paymentMethod;
|
499 |
+
|
500 |
+
/**
|
501 |
+
* If ccsave is the chosen method
|
502 |
+
* -- no method check so it could be used for another creditcard save method
|
503 |
+
*/
|
504 |
+
foreach ($request->getParam('payment_info', array()) as $key => $value) {
|
505 |
+
if ($value !== '') {
|
506 |
+
$data[$key] = $value;
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
/**
|
511 |
+
* For some reason Magento chose to empty the request and only add "$data" to the request
|
512 |
+
* -- possible security reasons
|
513 |
+
* thats why the billing address ahs to be set here again in $data
|
514 |
+
* -- not sure even of it is used; swithed of because dont think it is saved in the payment table anyway
|
515 |
+
* @TODO: remove with next update
|
516 |
+
*/
|
517 |
+
// $quoteBillingAddressData = $this->getQuote()->getBillingAddress();
|
518 |
+
// foreach ($quoteBillingAddressData as $key => $value) {
|
519 |
+
// if ($value !== '') {
|
520 |
+
// $data[$key] = $value;
|
521 |
+
// }
|
522 |
+
// }
|
523 |
+
$data['email'] = $request->getParam('email', null);
|
524 |
+
if (empty($data['email'])) {
|
525 |
+
$data['email'] = $this->getQuote()->getBillingAddress()->getEmail();
|
526 |
+
}
|
527 |
+
if (empty($data['email'])) {
|
528 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Email cannot be empty.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
529 |
+
}
|
530 |
+
|
531 |
+
/**
|
532 |
+
* Get payment populates the quote _payments; this is used in the saveAfter saving the quote related objects
|
533 |
+
* -- triggers saving the payment
|
534 |
+
*/
|
535 |
+
$this->_savePaymentInfo($data);
|
536 |
+
|
537 |
+
return $this;
|
538 |
+
}
|
539 |
+
|
540 |
+
/**
|
541 |
+
* There are no templates for creditcard data and issuerlists using the RESTfull interface
|
542 |
+
* -- to create dynamic forms and add this additional data in the service call the getMethods
|
543 |
+
* -- returns the form elements attributes and value to the RESTfull user-application and
|
544 |
+
* -- returns them in the request as the array param "form"
|
545 |
+
* When validating the form data (in the http request) the form data is saved in this object property "_paymentFormInfo"
|
546 |
+
* -- this is add to the payment data and send through to the standard Magento payment validation method
|
547 |
+
* -- called by "$this->savePayment($data);"
|
548 |
+
* Validate the payment method and related getValueFromParam extracts the data and validates before it is
|
549 |
+
* sent through to the "$this->savePayment($data);"
|
550 |
+
*/
|
551 |
+
protected function _savePaymentInfo($data)
|
552 |
+
{
|
553 |
+
/**
|
554 |
+
* Form data from the http request put in _paymentFormInfo during validation
|
555 |
+
*/
|
556 |
+
$info = $this->_paymentFormInfo;
|
557 |
+
if (!empty($info) || is_array($info)) {
|
558 |
+
|
559 |
+
/**
|
560 |
+
* Get all existing fieldnames from payment table
|
561 |
+
*/
|
562 |
+
$paymentData = $this->getQuote()->getPayment()->getData();
|
563 |
+
$paymentFields = array_keys($paymentData);
|
564 |
+
|
565 |
+
/**
|
566 |
+
* And extra fields not in payment table but used in payment data checks
|
567 |
+
*/
|
568 |
+
foreach ($this->_extraPaymentFields as $extraFieldname) {
|
569 |
+
$paymentFields[] = $extraFieldname;
|
570 |
+
}
|
571 |
+
|
572 |
+
/**
|
573 |
+
* Add all params from request (Paypal Billing Agreement)
|
574 |
+
*/
|
575 |
+
foreach ($info as $key => $value) {
|
576 |
+
if (!in_array($key, $paymentFields)) {
|
577 |
+
$paymentFields[] = $key;
|
578 |
+
}
|
579 |
+
}
|
580 |
+
|
581 |
+
/**
|
582 |
+
* Add the payment form info in the request collected in $this->_paymentFormInfo during validation
|
583 |
+
*/
|
584 |
+
foreach ($paymentFields as $fieldname) {
|
585 |
+
/**
|
586 |
+
* If the same name in the request payment-form-fields is set
|
587 |
+
* -- add the value to data
|
588 |
+
*/
|
589 |
+
if (isset($info[$fieldname]) && !empty($info[$fieldname])) {
|
590 |
+
$data[$fieldname] = $info[$fieldname];
|
591 |
+
}
|
592 |
+
}
|
593 |
+
}
|
594 |
+
|
595 |
+
/**
|
596 |
+
* Save all found payment data
|
597 |
+
*/
|
598 |
+
$this->_resetPayment($data)->savePayment($data);
|
599 |
+
}
|
600 |
+
|
601 |
+
/**
|
602 |
+
* If the quote payment row before is added with CC data
|
603 |
+
* -- and the customer cancels and tries to use another method
|
604 |
+
* -- the saved CC data can frustrate the payment checks (General Magento problem)
|
605 |
+
* This why the data is reset first
|
606 |
+
*/
|
607 |
+
protected function _resetPayment($data)
|
608 |
+
{
|
609 |
+
$payment = $this->getQuote()->getPayment();
|
610 |
+
foreach ($this->_resetPaymentFieldnames as $fieldname) {
|
611 |
+
$payment->setData($fieldname, null);
|
612 |
+
}
|
613 |
+
$payment->setData('method', $data['method']);
|
614 |
+
$payment->save();
|
615 |
+
|
616 |
+
return $this;
|
617 |
+
}
|
618 |
+
|
619 |
+
/**
|
620 |
+
* Validate the payment method and related getValueFromParam extracts the data and validates before it is
|
621 |
+
* sent through to the "$this->savePayment($data);"
|
622 |
+
*/
|
623 |
+
protected function _validatePaymentMethod($paymentMethod)
|
624 |
+
{
|
625 |
+
$errors = array();
|
626 |
+
|
627 |
+
/**
|
628 |
+
* Check if shipping method exists and active
|
629 |
+
*/
|
630 |
+
/* @var $checkoutMethods Jmango360_Japi_Model_Rest_Checkout_Methods */
|
631 |
+
$checkoutMethods = Mage::getModel('japi/rest_checkout_methods');
|
632 |
+
$availableMethods = $checkoutMethods->getValidatePaymentMethods($paymentMethod);
|
633 |
+
|
634 |
+
if (empty($availableMethods[$paymentMethod])) {
|
635 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('This payment method is currently not available.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
636 |
+
}
|
637 |
+
$method = $availableMethods[$paymentMethod];
|
638 |
+
|
639 |
+
if (!empty($method['form'])) {
|
640 |
+
foreach ($method['form'] as $element) {
|
641 |
+
if (empty($element['label']) && !empty($element['id'])) {
|
642 |
+
$element['label'] = $element['id'];
|
643 |
+
}
|
644 |
+
if (empty($element['name']) && !empty($element['id'])) {
|
645 |
+
$element['name'] = $element['id'];
|
646 |
+
}
|
647 |
+
$value = $this->_getValueFromParam($element['name']);
|
648 |
+
/**
|
649 |
+
* MPLUGIN-1146:
|
650 |
+
* Ignore validate value when installed "Netresearch_OPS" extension
|
651 |
+
* And using payment method "ops_cc" or "ops_dc" - this method not validate request data at server tier.
|
652 |
+
*/
|
653 |
+
$helper = Mage::helper('japi');
|
654 |
+
$_needCheckValue = true;
|
655 |
+
if ($helper->isModuleEnabled('Netresearch_OPS')) {
|
656 |
+
if ($paymentMethod == Netresearch_OPS_Model_Payment_Cc::CODE || $paymentMethod == 'ops_dc')
|
657 |
+
$_needCheckValue = false;
|
658 |
+
}
|
659 |
+
|
660 |
+
if ($_needCheckValue && empty($value)) {
|
661 |
+
if (!empty($element['class']) && stristr($element['class'], 'required-entry')) {
|
662 |
+
$errors[] = Mage::helper('japi')->__('Please add ') . trim($element['label'], '* \'"');
|
663 |
+
}
|
664 |
+
}
|
665 |
+
}
|
666 |
+
}
|
667 |
+
|
668 |
+
if (!empty($errors)) {
|
669 |
+
throw new Jmango360_Japi_Exception(implode("\n", $errors), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
670 |
+
}
|
671 |
+
|
672 |
+
return $this;
|
673 |
+
}
|
674 |
+
|
675 |
+
/**
|
676 |
+
* Validate the payment method and related getValueFromParam extracts the data and validates before it is
|
677 |
+
* sent through to the "$this->savePayment($data);"
|
678 |
+
*/
|
679 |
+
protected function _getValueFromParam($name)
|
680 |
+
{
|
681 |
+
$value = null;
|
682 |
+
$request = $this->_getRequest();
|
683 |
+
|
684 |
+
$requestForm = $request->getParam('form', array());
|
685 |
+
if (empty($requestForm)) {
|
686 |
+
return $value;
|
687 |
+
}
|
688 |
+
|
689 |
+
if (stristr($name, '[')) {
|
690 |
+
$parts = explode('[', trim($name, ']'));
|
691 |
+
if (!empty($parts[0]) && !empty($parts[1])) {
|
692 |
+
$namespace = $parts[0];
|
693 |
+
$name = $parts[1];
|
694 |
+
if (!empty($requestForm[$namespace])) {
|
695 |
+
if (!empty($requestForm[$namespace][$name])) {
|
696 |
+
$value = $requestForm[$namespace][$name];
|
697 |
+
$param[$namespace] = $request->getParam($namespace, array());
|
698 |
+
$param[$namespace][$name] = $value;
|
699 |
+
$request->setParam($namespace, $param[$namespace]);
|
700 |
+
$this->_paymentFormInfo[$name] = $value;
|
701 |
+
}
|
702 |
+
}
|
703 |
+
}
|
704 |
+
} else {
|
705 |
+
$value = $requestForm[$name];
|
706 |
+
$request->setParam($name, $value);
|
707 |
+
}
|
708 |
+
|
709 |
+
return $value;
|
710 |
+
}
|
711 |
+
|
712 |
+
protected function _checkAddressData($address)
|
713 |
+
{
|
714 |
+
/* @var $addressForm Mage_Customer_Model_Form */
|
715 |
+
$addressForm = Mage::getModel('customer/form');
|
716 |
+
$addressForm->setFormCode('customer_address_edit')
|
717 |
+
->setEntityType('customer_address')
|
718 |
+
->setIsAjaxRequest(false);
|
719 |
+
$addressForm->setEntity($address);
|
720 |
+
$addressErrors = $addressForm->validateData($address->getData());
|
721 |
+
if ($addressErrors !== true) {
|
722 |
+
return array('error' => 1, 'message' => $addressErrors);
|
723 |
+
}
|
724 |
+
return array('error' => 0, 'message' => array());
|
725 |
+
}
|
726 |
+
|
727 |
+
/**
|
728 |
+
* Multi shipping is not supported
|
729 |
+
*/
|
730 |
+
protected function _getCheckoutData()
|
731 |
+
{
|
732 |
+
$quote = $this->getQuote();
|
733 |
+
$data['cart'] = $quote->getData();
|
734 |
+
|
735 |
+
/**
|
736 |
+
* Items are separated by product id instead of item ID
|
737 |
+
* -- the product ID is known in the App in the downloaded catalog
|
738 |
+
*/
|
739 |
+
$index = 0;
|
740 |
+
|
741 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
742 |
+
$helper = Mage::helper('japi/product');
|
743 |
+
|
744 |
+
foreach ($quote->getAllVisibleItems() as $item) {
|
745 |
+
/* @var $item Mage_Sales_Model_Quote_Item */
|
746 |
+
$data['cart']['items'][$index] = $item->getData();
|
747 |
+
$product = $helper->convertProductIdToApiResponseV2($item->getProductId());
|
748 |
+
$data['cart']['items'][$index]['product'] = array($product);
|
749 |
+
$data['cart']['items'][$index]['buy_request'] = $helper->getCartProductBuyRequest($item, $product);
|
750 |
+
$index++;
|
751 |
+
}
|
752 |
+
|
753 |
+
/**
|
754 |
+
* Multishipping could have more than 1 address and probably more than 1 totals
|
755 |
+
* -- multischipping is not supported yet --
|
756 |
+
* The totals are sorted in the right order, so can be displayed in this order too
|
757 |
+
*/
|
758 |
+
foreach ($quote->getAllAddresses() as $address) {
|
759 |
+
/* @var $address Mage_Sales_Model_Quote_Address */
|
760 |
+
$data['cart']['addresses'][$address->getAddressType()] = $address->getData();
|
761 |
+
}
|
762 |
+
|
763 |
+
/**
|
764 |
+
* Get totals
|
765 |
+
*/
|
766 |
+
$data['cart']['totals'] = Mage::helper('japi')->getTotals($quote);
|
767 |
+
|
768 |
+
/**
|
769 |
+
* Add the checkout methods
|
770 |
+
* -- as long as the order is not submitted changing the carts address and items
|
771 |
+
* -- can change the checkout methods
|
772 |
+
*/
|
773 |
+
/* @var $checkoutMethods Jmango360_Japi_Model_Rest_Checkout_Methods */
|
774 |
+
$checkoutMethods = Mage::getModel('japi/rest_checkout_methods');
|
775 |
+
$shippingMethods = $checkoutMethods->getShippingmethods();
|
776 |
+
$data['cart']['shipping_methods'] = empty($shippingMethods) ? new stdClass() : $shippingMethods;
|
777 |
+
$paymentMethods = $checkoutMethods->getPaymentMethods();
|
778 |
+
$data['cart']['payment_methods'] = empty($paymentMethods) ? new stdClass() : $paymentMethods;
|
779 |
+
|
780 |
+
$data['cart']['checkout_url'] = Mage::getUrl('japi/checkout/redirect', array(
|
781 |
+
'_secure' => true,
|
782 |
+
'_query' => array('SID' => Mage::getSingleton('core/session')->getSessionId())
|
783 |
+
));
|
784 |
+
|
785 |
+
return $data;
|
786 |
+
}
|
787 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Checkout/Redirect.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Checkout_Redirect extends Jmango360_Japi_Model_Rest_Checkout
|
4 |
+
{
|
5 |
+
public function getPaymentRedirect()
|
6 |
+
{
|
7 |
+
$data = array();
|
8 |
+
|
9 |
+
$lastOrderId = $this->_getRequest()->getParam('last_order_id');
|
10 |
+
if ($this->getCheckout()->getLastOrderId() != $lastOrderId) {
|
11 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Request info not matches the order.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
12 |
+
}
|
13 |
+
|
14 |
+
$sid = Mage::getSingleton('core/session')->getSessionId();
|
15 |
+
$paymentUrl = $this->_getRequest()->getParam('payment_url');
|
16 |
+
if (empty($paymentUrl)) {
|
17 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('No payment provider to redirect found.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
18 |
+
}
|
19 |
+
|
20 |
+
$this->_getSession()->setRedirectToPaymentIsActive(true);
|
21 |
+
|
22 |
+
$data['iframe'] = "<iframe width=\"100%\" height=\"100%\" src=\"{$paymentUrl}?SID={$sid}\"></iframe>";
|
23 |
+
|
24 |
+
return $data;
|
25 |
+
}
|
26 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Checkout/Submit.php
ADDED
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Checkout_Submit extends Jmango360_Japi_Model_Rest_Checkout
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* If "makeCartInactiveAfterSubmit" is false;
|
7 |
+
* -- every new convertToOrder of the same cart will cancel the former order for this cart
|
8 |
+
* If "makeCartInactiveAfterSubmit" is true
|
9 |
+
* -- the cart will be inactive after submit and the next submit wil warn the customer that the cart is empty
|
10 |
+
*/
|
11 |
+
protected $_makeCartInactiveAfterSubmit = false;
|
12 |
+
|
13 |
+
public function submitOrder()
|
14 |
+
{
|
15 |
+
/**
|
16 |
+
* Populate data in session for Buckaroo
|
17 |
+
*/
|
18 |
+
$POST = $this->_getSession()->getData('POST');
|
19 |
+
if (is_array($POST)) {
|
20 |
+
foreach ($POST as $key => $value) {
|
21 |
+
if (!isset($_POST[$key])) {
|
22 |
+
$_POST[$key] = $value;
|
23 |
+
}
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* MPLUGIN-673
|
29 |
+
* Validate last order increment id of current store
|
30 |
+
* TODO: Need improvement
|
31 |
+
*/
|
32 |
+
//$this->_validateLastIncrementId();
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Specific for payment forms some data from the ost from collect totals is used in the submit POST
|
36 |
+
*/
|
37 |
+
$this->_callbackPaymentPostUsedInSubmit();
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Import payment data again
|
41 |
+
*/
|
42 |
+
$payment = $this->_getRequest()->getParam('payment');
|
43 |
+
if (!empty($payment['method'])) {
|
44 |
+
$this->getCheckout()->getQuote()->getPayment()->importData($payment);
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Security checks on quote
|
49 |
+
*/
|
50 |
+
$quote = $this->getCheckout()->getQuote();
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Flag as JMango360 order
|
54 |
+
*/
|
55 |
+
$quote->setData('japi', 1);
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Security check parameters
|
59 |
+
* -- the (quote) ID can not be used tot collect the quote.
|
60 |
+
* -- if the quote is not already in the session something is wrong! Could be session is not set or wrong session.
|
61 |
+
*/
|
62 |
+
$request = $this->_getRequest();
|
63 |
+
$requestSubtotal = (float)$request->getParam('subtotal', null);
|
64 |
+
$requestQuoteId = (int)$request->getParam('id', null);
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Collect totals flag has to be set before convert quot to order
|
68 |
+
* -- after collect totals check grandtotal again
|
69 |
+
*/
|
70 |
+
$quote->collectTotals()->save();
|
71 |
+
$quoteSubtotal = (float)$this->_getTotal('subtotal');
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Added (int) because in 1.7 the type differs; now it is checking the subtotal without the decimals, but that should be enough to avoid the risk having mixed up carts
|
75 |
+
*/
|
76 |
+
if ($requestSubtotal === "" || $requestQuoteId === "" || ((int)$requestSubtotal != (int)$quoteSubtotal) || ($requestQuoteId != $quote->getId())) {
|
77 |
+
throw new Jmango360_Japi_Exception(
|
78 |
+
Mage::helper('japi')->__('Request info does not match the quote. Probably the cart is ordered or the session is expired.'),
|
79 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
80 |
+
);
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Check if card stil active
|
85 |
+
*/
|
86 |
+
if (!$quote->getIsActive()) {
|
87 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Cart is no longer active.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Validat the quote before being converted to order
|
92 |
+
*/
|
93 |
+
$this->validateOrder();
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Cancel order if order with this quote ID already exists
|
97 |
+
*/
|
98 |
+
$makeCartInactiveAfterSubmit = $request->getParam('make_cart_inactive_after_submit', $this->_makeCartInactiveAfterSubmit);
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Convert the quote to order
|
102 |
+
*/
|
103 |
+
$this->saveOrder();
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Inactivate card
|
107 |
+
* -- This behaviour could be changed:
|
108 |
+
* -- -- inactivating the card creates a new cart the next time the cart is touched
|
109 |
+
* -- -- If anything goes wrong with the payment the cart is not automatically activated
|
110 |
+
* -- -- another way to deal with this is to cancel the existing order the next time the App calls the submitOrder function
|
111 |
+
* -- -- and automticaly create a new order.
|
112 |
+
* -- -- In order to do this uncomment the "this->cancelOrder" above before the this->saveOrder
|
113 |
+
* -- -- and switch off the setIsActive below.
|
114 |
+
* -- -- setIsActive has to be added to the success function after payment
|
115 |
+
* Added a parameter so behaviour cab be inluenced by parameters in the call
|
116 |
+
*/
|
117 |
+
if ($makeCartInactiveAfterSubmit) {
|
118 |
+
$quote->setIsActive(false);
|
119 |
+
}
|
120 |
+
|
121 |
+
// Save quote to apply any changes
|
122 |
+
$quote->save();
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Return payment data
|
126 |
+
*/
|
127 |
+
$data = $this->_getPaymentData();
|
128 |
+
|
129 |
+
// Clear checkout session
|
130 |
+
$this->_getSession()->clear();
|
131 |
+
|
132 |
+
return $data;
|
133 |
+
}
|
134 |
+
|
135 |
+
protected function _callbackPaymentPostUsedInSubmit()
|
136 |
+
{
|
137 |
+
$request = $this->_getRequest();
|
138 |
+
$payment = array();
|
139 |
+
|
140 |
+
$paymentPost = Mage::getSingleton('core/session')->getPaymentPostUsedInSubmit();
|
141 |
+
if (empty($paymentPost) || !is_array($paymentPost)) {
|
142 |
+
return $this;
|
143 |
+
}
|
144 |
+
|
145 |
+
foreach ($paymentPost as $key => $value) {
|
146 |
+
$payment[$key] = $value;
|
147 |
+
}
|
148 |
+
|
149 |
+
$request->setPost('payment', $payment);
|
150 |
+
|
151 |
+
return $this;
|
152 |
+
}
|
153 |
+
|
154 |
+
protected function _cancelFormerOrder()
|
155 |
+
{
|
156 |
+
$quote = $this->getCheckout()->getQuote();
|
157 |
+
$orderId = $this->getCheckout()->getLastOrderId();
|
158 |
+
if (!empty($orderId)) {
|
159 |
+
$order = Mage::getModel('sales/order')->load($orderId);
|
160 |
+
if ($quote->getId() && ($order->getQuoteId() == $quote->getId())) {
|
161 |
+
$comment = Mage::helper('japi')->__('Replaced by new order.');
|
162 |
+
$order->setState($order::STATE_CANCELED, true, $comment, false)->save();
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
/*
|
168 |
+
* Multi shipping totals not supported in App
|
169 |
+
*/
|
170 |
+
protected function _getTotal($name = null)
|
171 |
+
{
|
172 |
+
/* @var $taxConfig Mage_Tax_Model_Config */
|
173 |
+
$taxConfig = Mage::getSingleton('tax/config');
|
174 |
+
$quote = $this->getCheckout()->getQuote();
|
175 |
+
$totals = $quote->getTotals();
|
176 |
+
$data = null;
|
177 |
+
|
178 |
+
foreach ($totals as $total) {
|
179 |
+
/* @var $total Mage_Sales_Model_Quote_Address_Total_Abstract */
|
180 |
+
if ($total->getCode() != $name) continue;
|
181 |
+
|
182 |
+
switch ($name) {
|
183 |
+
case 'subtotal':
|
184 |
+
if ($taxConfig->displayCartSubtotalBoth()) {
|
185 |
+
$data = $total->getValueExclTax();
|
186 |
+
} else {
|
187 |
+
$data = $total->getValue();
|
188 |
+
}
|
189 |
+
break;
|
190 |
+
}
|
191 |
+
}
|
192 |
+
|
193 |
+
return $data;
|
194 |
+
}
|
195 |
+
|
196 |
+
/*
|
197 |
+
* Multi shipping is not supported!
|
198 |
+
*/
|
199 |
+
protected function _getPaymentData()
|
200 |
+
{
|
201 |
+
$checkout = $this->getCheckout();
|
202 |
+
|
203 |
+
$data = array();
|
204 |
+
if (!$checkout->getRedirectUrl()) {
|
205 |
+
$data['online_payment'] = false;
|
206 |
+
$data['payment_url'] = '';
|
207 |
+
} else {
|
208 |
+
$data['online_payment'] = true;
|
209 |
+
|
210 |
+
/**
|
211 |
+
* MPLUGIN-707: Fix for "https://www.vetcoolshops.nl/webshop/" with customer's module "Mage_Ideal"
|
212 |
+
* MPLUGIN-828: Update - Always use Japi redirect for payment gate way Url
|
213 |
+
*/
|
214 |
+
$_paymentUrl = $checkout->getRedirectUrl();
|
215 |
+
$_paymentUrl = urldecode($_paymentUrl);
|
216 |
+
$data['payment_url'] = Mage::getUrl('japi/rest_mage/redirect', array(
|
217 |
+
'_query' => array('url' => $_paymentUrl),
|
218 |
+
'_secure' => true
|
219 |
+
));
|
220 |
+
}
|
221 |
+
$data['last_order_id'] = $checkout->getLastOrderId();
|
222 |
+
$data['last_real_order_id'] = $checkout->getLastRealOrderId();
|
223 |
+
|
224 |
+
$data['session_id'] = Mage::getSingleton('core/session')->getSessionId();
|
225 |
+
|
226 |
+
return $data;
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Fix for issue last increment id of store not updated
|
231 |
+
*/
|
232 |
+
protected function _validateLastIncrementId()
|
233 |
+
{
|
234 |
+
/* @var $_coreResource Mage_Core_Model_Resource */
|
235 |
+
$_coreResource = Mage::getSingleton('core/resource');
|
236 |
+
$adapter = $_coreResource->getConnection('core_read');
|
237 |
+
|
238 |
+
/* @var $eavEntityTypeResource Mage_Eav_Model_Resource_Entity_Type */
|
239 |
+
$eavEntityTypeResource = Mage::getResourceModel('eav/entity_type');
|
240 |
+
$eavEntityType = $adapter->select()
|
241 |
+
->from($eavEntityTypeResource->getMainTable())
|
242 |
+
->where('entity_type_code = ?', Mage_Sales_Model_Order::ENTITY)
|
243 |
+
->where('entity_model = ?', 'sales/order')
|
244 |
+
->limit(1);
|
245 |
+
|
246 |
+
$dataEntityType = $adapter->fetchRow($eavEntityType);
|
247 |
+
if ($dataEntityType) {
|
248 |
+
$entityTypeId = (int)$dataEntityType['entity_type_id'];
|
249 |
+
$lastIncrementStore = null;
|
250 |
+
$lastOrderIncrement = null;
|
251 |
+
if ($entityTypeId > 0) {
|
252 |
+
/* @var $eavEntityStoreResource Mage_Eav_Model_Resource_Entity_Store */
|
253 |
+
$eavEntityStoreResource = Mage::getResourceModel('eav/entity_store');
|
254 |
+
$selectEntityStore = $adapter->select()
|
255 |
+
->from($eavEntityStoreResource->getMainTable())
|
256 |
+
->where('entity_type_id = ?', $entityTypeId)
|
257 |
+
->where('store_id = ?', Mage::app()->getStore()->getStoreId())
|
258 |
+
->limit(1);
|
259 |
+
|
260 |
+
$dataEntityStore = $adapter->fetchRow($selectEntityStore);
|
261 |
+
if ($dataEntityStore) {
|
262 |
+
$lastIncrementStore = $dataEntityStore['increment_last_id'];
|
263 |
+
}
|
264 |
+
|
265 |
+
/* @var $orderResource Mage_Sales_Model_Resource_Order */
|
266 |
+
$orderResource = Mage::getResourceModel('sales/order');
|
267 |
+
$selectOrder = $adapter->select()
|
268 |
+
->from($orderResource->getMainTable())
|
269 |
+
->where('store_id = ?', Mage::app()->getStore()->getStoreId())
|
270 |
+
->order('created_at DESC')
|
271 |
+
->order('increment_id DESC')
|
272 |
+
->order($orderResource->getIdFieldName() . ' DESC')
|
273 |
+
->limit(1);
|
274 |
+
|
275 |
+
$dataOrder = $adapter->fetchRow($selectOrder);
|
276 |
+
if ($dataOrder) {
|
277 |
+
$lastOrderIncrement = $dataOrder['increment_id'];
|
278 |
+
}
|
279 |
+
|
280 |
+
if ($lastIncrementStore != null && $lastOrderIncrement != null && ($lastIncrementStore != $lastOrderIncrement)) {
|
281 |
+
$write = $_coreResource->getConnection('core_write');
|
282 |
+
$data = array("increment_last_id" => $lastOrderIncrement);
|
283 |
+
$where = 'entity_type_id = ' . $entityTypeId;
|
284 |
+
$where .= ' AND store_id = ' . Mage::app()->getStore()->getStoreId();
|
285 |
+
$write->update($eavEntityStoreResource->getMainTable(), $data, $where);
|
286 |
+
}
|
287 |
+
}
|
288 |
+
}
|
289 |
+
}
|
290 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Cms.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Cms extends Mage_Core_Model_Abstract
|
4 |
+
{
|
5 |
+
public function dispatch()
|
6 |
+
{
|
7 |
+
$action = $this->_getRequest()->getAction();
|
8 |
+
$operation = $this->_getRequest()->getOperation();
|
9 |
+
|
10 |
+
switch ($action . $operation) {
|
11 |
+
case 'getCmsPageList' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
12 |
+
$data = $this->_getCmsPageList();
|
13 |
+
$this->_getResponse()->render($data);
|
14 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
15 |
+
break;
|
16 |
+
default:
|
17 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Resource method not implemented'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
18 |
+
break;
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
protected function _getCmsPageList()
|
23 |
+
{
|
24 |
+
/* @var $model Jmango360_Japi_Model_Rest_Cms_Page */
|
25 |
+
$model = Mage::getModel('japi/rest_cms_page');
|
26 |
+
$data = $model->getList();
|
27 |
+
|
28 |
+
return $data;
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* @return Jmango360_Japi_Model_Request
|
33 |
+
*/
|
34 |
+
protected function _getRequest()
|
35 |
+
{
|
36 |
+
return Mage::helper('japi')->getRequest();
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* @return Jmango360_Japi_Model_Response
|
41 |
+
*/
|
42 |
+
protected function _getResponse()
|
43 |
+
{
|
44 |
+
return Mage::helper('japi')->getResponse();
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @return Jmango360_Japi_Model_Server
|
49 |
+
*/
|
50 |
+
protected function _getServer()
|
51 |
+
{
|
52 |
+
return Mage::helper('japi')->getServer();
|
53 |
+
}
|
54 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Cms/Page.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Cms_Page extends Mage_Cms_Model_Page
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Used for retrieving cms pages
|
7 |
+
*
|
8 |
+
* @param null|int $storeId
|
9 |
+
* @return array
|
10 |
+
*/
|
11 |
+
public function getList($storeId = null)
|
12 |
+
{
|
13 |
+
$cmsPages = Mage::getModel('cms/page')->getCollection();
|
14 |
+
if (!is_null($storeId)) {
|
15 |
+
$cmsPages->addStoreFilter($storeId);
|
16 |
+
}
|
17 |
+
|
18 |
+
$pagesResult = array();
|
19 |
+
$processor = Mage::helper('cms')->getPageTemplateProcessor();
|
20 |
+
foreach ($cmsPages as $page) {
|
21 |
+
$pagesResult[] = $this->_prepareCmsPageData($page, $processor);
|
22 |
+
}
|
23 |
+
|
24 |
+
$data['pages'] = $pagesResult;
|
25 |
+
|
26 |
+
return $data;
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Prepares CMS Page Data for returning
|
31 |
+
*
|
32 |
+
* @param Mage_Cms_Model_Page $page
|
33 |
+
* @param Varien_Filter_Template $processor
|
34 |
+
* @return mixed
|
35 |
+
*/
|
36 |
+
protected function _prepareCmsPageData(Mage_Cms_Model_Page $page, Varien_Filter_Template $processor)
|
37 |
+
{
|
38 |
+
$result['title'] = $page->getTitle();
|
39 |
+
$result['urlKey'] = $page->getIdentifier();
|
40 |
+
$result['active'] = $page->getIsActive();
|
41 |
+
$result['created_at'] = $page->getCreationTime();
|
42 |
+
$result['updated_at'] = $page->getUpdateTime();
|
43 |
+
$result['content'] = $processor->filter($page->getContent());
|
44 |
+
|
45 |
+
$pageStoreIds = array();
|
46 |
+
|
47 |
+
$_page = Mage::getModel('cms/page')->load($page->getId());
|
48 |
+
$page_StoreIds = $_page['store_id'];
|
49 |
+
foreach ($page_StoreIds as $storeId) {
|
50 |
+
$pageStoreIds[] = $storeId;
|
51 |
+
}
|
52 |
+
$result['storeIds'] = $pageStoreIds;
|
53 |
+
|
54 |
+
return $result;
|
55 |
+
}
|
56 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Customer.php
ADDED
@@ -0,0 +1,354 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Customer extends Mage_Customer_Model_Customer
|
4 |
+
{
|
5 |
+
public function dispatch()
|
6 |
+
{
|
7 |
+
$action = $this->_getRequest()->getAction();
|
8 |
+
$operation = $this->_getRequest()->getOperation();
|
9 |
+
|
10 |
+
switch ($action . $operation) {
|
11 |
+
case 'getCustomer' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
12 |
+
$this->_checkSession();
|
13 |
+
$data = $this->_getCustomer();
|
14 |
+
$this->_getResponse()->render($data);
|
15 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
16 |
+
break;
|
17 |
+
case 'register' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
18 |
+
$data = $this->_register();
|
19 |
+
$this->_getResponse()->render($data);
|
20 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
21 |
+
break;
|
22 |
+
case 'edit' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
23 |
+
$this->_checkSession();
|
24 |
+
$data = $this->_edit();
|
25 |
+
$this->_getResponse()->render($data);
|
26 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
27 |
+
break;
|
28 |
+
case 'passwordreset' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
29 |
+
$data = $this->_passwordreset();
|
30 |
+
$this->_getResponse()->render($data);
|
31 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
32 |
+
break;
|
33 |
+
|
34 |
+
case 'login' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
35 |
+
$data = $this->_login();
|
36 |
+
$this->_getResponse()->render($data);
|
37 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
38 |
+
break;
|
39 |
+
case 'logout' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
40 |
+
$this->_checkSession();
|
41 |
+
$data = $this->_logout();
|
42 |
+
$this->_getResponse()->render($data);
|
43 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
44 |
+
break;
|
45 |
+
|
46 |
+
case 'getList' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
47 |
+
$data = $this->_customerList();
|
48 |
+
$this->_getResponse()->render($data);
|
49 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
50 |
+
break;
|
51 |
+
|
52 |
+
case 'address' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
53 |
+
$this->_checkSession();
|
54 |
+
$data = $this->_createAddress();
|
55 |
+
$this->_getResponse()->render($data);
|
56 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
57 |
+
break;
|
58 |
+
case 'address' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
59 |
+
$this->_checkSession();
|
60 |
+
$data = $this->_updateAddress();
|
61 |
+
$this->_getResponse()->render($data);
|
62 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
63 |
+
break;
|
64 |
+
case 'address' . Jmango360_Japi_Model_Request::OPERATION_DELETE:
|
65 |
+
$this->_checkSession();
|
66 |
+
$data = $this->_deleteAddress();
|
67 |
+
$this->_getResponse()->render($data);
|
68 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
69 |
+
break;
|
70 |
+
|
71 |
+
case 'getCustomerOrderList' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
72 |
+
$this->_checkSession();
|
73 |
+
$data = $this->_getCustomerOrderList();
|
74 |
+
$this->_getResponse()->render($data);
|
75 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
76 |
+
break;
|
77 |
+
case 'getCustomerOrderDetails' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
78 |
+
$this->_checkSession();
|
79 |
+
$data = $this->_getCustomerOrderDetails();
|
80 |
+
$this->_getResponse()->render($data);
|
81 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
82 |
+
break;
|
83 |
+
|
84 |
+
case 'orders' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
85 |
+
$this->_checkSession();
|
86 |
+
$data = $this->_getOrders();
|
87 |
+
$this->_getResponse()->render($data);
|
88 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
89 |
+
break;
|
90 |
+
case 'orderDetails' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
91 |
+
$this->_checkSession();
|
92 |
+
$data = $this->_getOrderDetails();
|
93 |
+
$this->_getResponse()->render($data);
|
94 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
95 |
+
break;
|
96 |
+
|
97 |
+
case 'groups' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
98 |
+
$data = $this->_getCustomerGroups();
|
99 |
+
$this->_getResponse()->render($data);
|
100 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
101 |
+
break;
|
102 |
+
case 'group' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
103 |
+
$data = $this->_getGroupCustomers();
|
104 |
+
$this->_getResponse()->render($data);
|
105 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
106 |
+
break;
|
107 |
+
case 'search' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
108 |
+
$data = $this->_getSearchCustomers();
|
109 |
+
$this->_getResponse()->render($data);
|
110 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
111 |
+
break;
|
112 |
+
|
113 |
+
default:
|
114 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Resource method not implemented'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
115 |
+
break;
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
protected function _getSearchCustomers()
|
120 |
+
{
|
121 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Group */
|
122 |
+
$model = Mage::getModel('japi/rest_customer_group');
|
123 |
+
return $model->search();
|
124 |
+
}
|
125 |
+
|
126 |
+
protected function _getCustomerGroups()
|
127 |
+
{
|
128 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Group */
|
129 |
+
$model = Mage::getModel('japi/rest_customer_group');
|
130 |
+
return $model->getList();
|
131 |
+
}
|
132 |
+
|
133 |
+
protected function _getGroupCustomers()
|
134 |
+
{
|
135 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Group */
|
136 |
+
$model = Mage::getModel('japi/rest_customer_group');
|
137 |
+
return $model->getCustomers();
|
138 |
+
}
|
139 |
+
|
140 |
+
protected function _getCustomerOrderList()
|
141 |
+
{
|
142 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Order */
|
143 |
+
$model = Mage::getModel('japi/rest_customer_order');
|
144 |
+
$data = $model->getCustomerOrderList();
|
145 |
+
|
146 |
+
return $data;
|
147 |
+
}
|
148 |
+
|
149 |
+
protected function _getOrders()
|
150 |
+
{
|
151 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Order_List */
|
152 |
+
$model = Mage::getModel('japi/rest_customer_order_list');
|
153 |
+
$data = $model->getOrderList();
|
154 |
+
|
155 |
+
return $data;
|
156 |
+
}
|
157 |
+
|
158 |
+
protected function _getCustomerOrderDetails()
|
159 |
+
{
|
160 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Order */
|
161 |
+
$model = Mage::getModel('japi/rest_customer_order');
|
162 |
+
$data = $model->getCustomerOrderDetails();
|
163 |
+
|
164 |
+
return $data;
|
165 |
+
}
|
166 |
+
|
167 |
+
protected function _getOrderDetails()
|
168 |
+
{
|
169 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Order_List */
|
170 |
+
$model = Mage::getModel('japi/rest_customer_order_list');
|
171 |
+
$data = $model->getOrderDetails();
|
172 |
+
|
173 |
+
return $data;
|
174 |
+
}
|
175 |
+
|
176 |
+
protected function _createAddress()
|
177 |
+
{
|
178 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Address */
|
179 |
+
$model = Mage::getModel('japi/rest_customer_address');
|
180 |
+
$data = $model->update();
|
181 |
+
|
182 |
+
return $data;
|
183 |
+
}
|
184 |
+
|
185 |
+
protected function _updateAddress()
|
186 |
+
{
|
187 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Address */
|
188 |
+
$model = Mage::getModel('japi/rest_customer_address');
|
189 |
+
$data = $model->update();
|
190 |
+
|
191 |
+
return $data;
|
192 |
+
}
|
193 |
+
|
194 |
+
protected function _deleteAddress()
|
195 |
+
{
|
196 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Address */
|
197 |
+
$model = Mage::getModel('japi/rest_customer_address');
|
198 |
+
$data = $model->delete();
|
199 |
+
|
200 |
+
return $data;
|
201 |
+
}
|
202 |
+
|
203 |
+
protected function _customerList()
|
204 |
+
{
|
205 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_List */
|
206 |
+
$model = Mage::getModel('japi/rest_customer_list');
|
207 |
+
$data = $model->getList();
|
208 |
+
|
209 |
+
return $data;
|
210 |
+
}
|
211 |
+
|
212 |
+
protected function _register()
|
213 |
+
{
|
214 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Register */
|
215 |
+
$model = Mage::getModel('japi/rest_customer_register');
|
216 |
+
$data = $model->register();
|
217 |
+
|
218 |
+
return $data;
|
219 |
+
}
|
220 |
+
|
221 |
+
protected function _edit()
|
222 |
+
{
|
223 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Edit */
|
224 |
+
$model = Mage::getModel('japi/rest_customer_edit');
|
225 |
+
$data = $model->edit();
|
226 |
+
|
227 |
+
return $data;
|
228 |
+
}
|
229 |
+
|
230 |
+
protected function _passwordreset()
|
231 |
+
{
|
232 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Password */
|
233 |
+
$model = Mage::getModel('japi/rest_customer_password');
|
234 |
+
$data = $model->passwordreset();
|
235 |
+
|
236 |
+
return $data;
|
237 |
+
}
|
238 |
+
|
239 |
+
protected function _login()
|
240 |
+
{
|
241 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Login */
|
242 |
+
$model = Mage::getModel('japi/rest_customer_login');
|
243 |
+
$data = $model->login();
|
244 |
+
|
245 |
+
return $data;
|
246 |
+
}
|
247 |
+
|
248 |
+
protected function _logout()
|
249 |
+
{
|
250 |
+
$this->_getSession()->logout()->renewSession();
|
251 |
+
if ($this->_getSession()->isLoggedIn()) {
|
252 |
+
throw new Jmango360_Japi_Exception(
|
253 |
+
Mage::helper('japi')->__('Could not log-out customer'),
|
254 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
255 |
+
);
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Fix for MPLUGIN-980: make sure session's data "customer_id" and "id" is delete when customer logged-in
|
260 |
+
*/
|
261 |
+
$this->_getSession()->setData('customer_id', null);
|
262 |
+
$this->_getSession()->setData('id', null);
|
263 |
+
|
264 |
+
//Mage::log('refreshed session for the customer is logged out', null, 'token.log');
|
265 |
+
$data['status'] = 'logged_out';
|
266 |
+
$data['session_id'] = Mage::getSingleton('core/session')->getSessionId();
|
267 |
+
|
268 |
+
return $data;
|
269 |
+
}
|
270 |
+
|
271 |
+
protected function _checkSession()
|
272 |
+
{
|
273 |
+
if (!$this->_getSession()->isLoggedIn()) {
|
274 |
+
throw new Jmango360_Japi_Exception(
|
275 |
+
Mage::helper('japi')->__('Please login.'),
|
276 |
+
Jmango360_Japi_Model_Request::REST_CUSTOMER_EXPIRED
|
277 |
+
);
|
278 |
+
}
|
279 |
+
}
|
280 |
+
|
281 |
+
protected function _getCustomer()
|
282 |
+
{
|
283 |
+
return array('customer' => $this->_getCustomerData());
|
284 |
+
}
|
285 |
+
|
286 |
+
protected function _getCustomerData()
|
287 |
+
{
|
288 |
+
$data = array();
|
289 |
+
if (!$this->_getSession()->isLoggedIn()) {
|
290 |
+
return $data;
|
291 |
+
}
|
292 |
+
|
293 |
+
/*
|
294 |
+
* It can happen that after saving customer the customer is not set in session
|
295 |
+
* -- and some saved data is not shown
|
296 |
+
* -- to be sure the customer is loaded again before setting the response
|
297 |
+
*/
|
298 |
+
$customerId = $this->_getSession()->getCustomerId();
|
299 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
300 |
+
$customer = Mage::getModel('customer/customer')->load($customerId);
|
301 |
+
|
302 |
+
$data = $customer->getData();
|
303 |
+
$data['addresses'] = array();
|
304 |
+
$index = 0;
|
305 |
+
/* @var $helper Jmango360_Japi_Helper_Data */
|
306 |
+
$helper = Mage::helper('japi');
|
307 |
+
foreach ($customer->getAddressesCollection() as $address) {
|
308 |
+
/* @var $address Mage_Customer_Model_Address */
|
309 |
+
$data['addresses'][$index] = $address->getData();
|
310 |
+
$data['addresses'][$index]['country'] = $helper->getCountryById($address->getCountryId());
|
311 |
+
//$data['addresses'][$index]['region'] = $helper->getRegionById($address->getCountryId(), $address->getRegionId());
|
312 |
+
$data['addresses'][$index]['region'] = $address->getRegion();
|
313 |
+
$index++;
|
314 |
+
}
|
315 |
+
|
316 |
+
if (empty($data['default_billing'])) {
|
317 |
+
$defaultBillingAddress = $customer->getDefaultBillingAddress();
|
318 |
+
$data['default_billing'] = (is_object($defaultBillingAddress) && $defaultBillingAddress->getId()) ? $defaultBillingAddress->getId() : null;
|
319 |
+
}
|
320 |
+
|
321 |
+
if (empty($data['default_shipping'])) {
|
322 |
+
$defaultShippingAddress = $customer->getDefaultShippingAddress();
|
323 |
+
$data['default_shipping'] = (is_object($defaultShippingAddress) && $defaultShippingAddress->getId()) ? $defaultShippingAddress->getId() : null;
|
324 |
+
}
|
325 |
+
|
326 |
+
return $data;
|
327 |
+
}
|
328 |
+
|
329 |
+
/**
|
330 |
+
* @return Mage_Customer_Model_Session
|
331 |
+
*/
|
332 |
+
protected function _getSession()
|
333 |
+
{
|
334 |
+
return Mage::getSingleton('customer/session');
|
335 |
+
}
|
336 |
+
|
337 |
+
protected function _getRequest()
|
338 |
+
{
|
339 |
+
return $this->_getServer()->getRequest();
|
340 |
+
}
|
341 |
+
|
342 |
+
protected function _getResponse()
|
343 |
+
{
|
344 |
+
return $this->_getServer()->getResponse();
|
345 |
+
}
|
346 |
+
|
347 |
+
/**
|
348 |
+
* @return Jmango360_Japi_Model_Server
|
349 |
+
*/
|
350 |
+
protected function _getServer()
|
351 |
+
{
|
352 |
+
return Mage::getSingleton('japi/server');
|
353 |
+
}
|
354 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Customer/Address.php
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Customer_Address extends Jmango360_Japi_Model_Rest_Customer
|
4 |
+
{
|
5 |
+
public function update()
|
6 |
+
{
|
7 |
+
$request = Mage::helper('japi')->getRequest();
|
8 |
+
$this->_setAddressInRequest();
|
9 |
+
|
10 |
+
$data = array();
|
11 |
+
|
12 |
+
$customer = $this->_getSession()->getCustomer();
|
13 |
+
/* @var $address Mage_Customer_Model_Address */
|
14 |
+
$address = Mage::getModel('customer/address');
|
15 |
+
$addressId = $request->getParam('address_id');
|
16 |
+
if ($addressId) {
|
17 |
+
$existsAddress = $customer->getAddressById($addressId);
|
18 |
+
if ($existsAddress->getId() && $existsAddress->getCustomerId() == $customer->getId()) {
|
19 |
+
$address->setId($existsAddress->getId());
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
$errors = array();
|
24 |
+
|
25 |
+
/* @var $addressForm Mage_Customer_Model_Form */
|
26 |
+
$addressForm = Mage::getModel('customer/form');
|
27 |
+
$addressForm->setFormCode('customer_address_edit')
|
28 |
+
->setEntity($address);
|
29 |
+
$addressData = $addressForm->extractData($request);
|
30 |
+
$addressErrors = $addressForm->validateData($addressData);
|
31 |
+
if ($addressErrors !== true) {
|
32 |
+
$errors = $addressErrors;
|
33 |
+
}
|
34 |
+
|
35 |
+
try {
|
36 |
+
$addressForm->compactData($addressData);
|
37 |
+
$address->setCustomerId($customer->getId())
|
38 |
+
->setIsDefaultBilling($request->getParam('default_billing', false))
|
39 |
+
->setIsDefaultShipping($request->getParam('default_shipping', false));
|
40 |
+
|
41 |
+
$addressErrors = $address->validate();
|
42 |
+
if ($addressErrors !== true) {
|
43 |
+
$errors = array_merge($errors, $addressErrors);
|
44 |
+
}
|
45 |
+
|
46 |
+
if (count($errors) === 0) {
|
47 |
+
$address->save();
|
48 |
+
} else {
|
49 |
+
$message = implode("\n", $errors);
|
50 |
+
throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
51 |
+
}
|
52 |
+
} catch (Mage_Core_Exception $e) {
|
53 |
+
throw new Jmango360_Japi_Exception($e->getMessage(), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
54 |
+
} catch (Exception $e) {
|
55 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Cannot save the address: ' . $e->getMessage()), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
56 |
+
}
|
57 |
+
|
58 |
+
$data['customer'] = $this->_getCustomerData();
|
59 |
+
|
60 |
+
return $data;
|
61 |
+
}
|
62 |
+
|
63 |
+
/*
|
64 |
+
* Address data can be sent in a flat request
|
65 |
+
* -- in case if it is sent in the way "register" sends it, it is in the array address
|
66 |
+
* -- in that case the address array is set to the flat request
|
67 |
+
*/
|
68 |
+
protected function _setAddressInRequest()
|
69 |
+
{
|
70 |
+
$addressInfo = Mage::helper('japi')->getRequest()->getParam('address', array());
|
71 |
+
if (!empty($addressInfo)) {
|
72 |
+
foreach ($addressInfo as $name => $value) {
|
73 |
+
Mage::app()->getRequest()->setParam($name, $value);
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
return $this;
|
78 |
+
}
|
79 |
+
|
80 |
+
public function delete()
|
81 |
+
{
|
82 |
+
$request = Mage::helper('japi')->getRequest();
|
83 |
+
$addressId = $request->getParam('address_id', false);
|
84 |
+
$customer = $this->_getSession()->getCustomer();
|
85 |
+
$defaultShippingAddress = $customer->getDefaultShippingAddress();
|
86 |
+
$defaultBillingAddress = $customer->getDefaultBillingAddress();
|
87 |
+
$message = '';
|
88 |
+
|
89 |
+
if ($addressId) {
|
90 |
+
$address = Mage::getModel('customer/address')->load($addressId);
|
91 |
+
|
92 |
+
// Validate address_id <=> customer_id
|
93 |
+
if ($address->getCustomerId() != $this->_getSession()->getCustomerId()) {
|
94 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('The address does not belong to this customer.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
95 |
+
}
|
96 |
+
if (is_object($defaultBillingAddress) && $address->getId() == $defaultBillingAddress->getId()) {
|
97 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Default billing address can not be removed.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
98 |
+
}
|
99 |
+
if (is_object($defaultShippingAddress) && $address->getId() == $defaultShippingAddress->getId()) {
|
100 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Default shipping address can not be removed.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
101 |
+
}
|
102 |
+
|
103 |
+
try {
|
104 |
+
$address->delete();
|
105 |
+
$message = 'The address has been deleted.';
|
106 |
+
} catch (Exception $e) {
|
107 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('An error occurred while deleting the address.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
108 |
+
}
|
109 |
+
} else {
|
110 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Address ID can not be empty.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
111 |
+
}
|
112 |
+
|
113 |
+
$data['customer'] = $this->_getCustomerData();
|
114 |
+
$data['message'] = $message;
|
115 |
+
|
116 |
+
return $data;
|
117 |
+
}
|
118 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Customer/Edit.php
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Customer_Edit extends Jmango360_Japi_Model_Rest_Customer
|
4 |
+
{
|
5 |
+
public function edit()
|
6 |
+
{
|
7 |
+
if (!$this->_getSession()->isLoggedIn()) {
|
8 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Please login.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
9 |
+
}
|
10 |
+
|
11 |
+
/** @var $customer Mage_Customer_Model_Customer */
|
12 |
+
$customer = $this->_getSession()->getCustomer();
|
13 |
+
|
14 |
+
/** @var $customerForm Mage_Customer_Model_Form */
|
15 |
+
$customerForm = Mage::getModel('customer/form');
|
16 |
+
$customerForm->setFormCode('customer_account_edit')
|
17 |
+
->setEntity($customer);
|
18 |
+
|
19 |
+
$customerData = $customerForm->extractData($this->_getRequest());
|
20 |
+
|
21 |
+
$errors = array();
|
22 |
+
$customerErrors = $customerForm->validateData($customerData);
|
23 |
+
if ($customerErrors !== true) {
|
24 |
+
$errors = array_merge($customerErrors, $errors);
|
25 |
+
} else {
|
26 |
+
$customerForm->compactData($customerData);
|
27 |
+
$errors = array();
|
28 |
+
|
29 |
+
// If password change was requested then add it to common validation scheme
|
30 |
+
if ($this->_getRequest()->getParam('change_password')) {
|
31 |
+
$currPass = $this->_getRequest()->getParam('current_password');
|
32 |
+
$newPass = $this->_getRequest()->getParam('password');
|
33 |
+
$confPass = $this->_getRequest()->getParam('confirmation');
|
34 |
+
|
35 |
+
$oldPass = $this->_getSession()->getCustomer()->getPasswordHash();
|
36 |
+
if ($this->_getHelper('core/string')->strpos($oldPass, ':')) {
|
37 |
+
list($_salt, $salt) = explode(':', $oldPass);
|
38 |
+
} else {
|
39 |
+
$salt = false;
|
40 |
+
}
|
41 |
+
|
42 |
+
if ($customer->hashPassword($currPass, $salt) == $oldPass) {
|
43 |
+
if (strlen($newPass)) {
|
44 |
+
/**
|
45 |
+
* Set entered password and its confirmation - they
|
46 |
+
* will be validated later to match each other and be of right length
|
47 |
+
*/
|
48 |
+
$customer->setPassword($newPass);
|
49 |
+
|
50 |
+
/*
|
51 |
+
* Looks like both password_confirmation and confirmation are used due to version differences
|
52 |
+
*/
|
53 |
+
$customer->setConfirmation($confPass);
|
54 |
+
$customer->setPasswordConfirmation($confPass);
|
55 |
+
|
56 |
+
} else {
|
57 |
+
$errors[] = Mage::helper('japi')->__('New password field cannot be empty.');
|
58 |
+
}
|
59 |
+
} else {
|
60 |
+
$errors[] = Mage::helper('japi')->__('Invalid current password');
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
// Validate account and compose list of errors if any
|
65 |
+
$customerErrors = $customer->validate();
|
66 |
+
if (is_array($customerErrors)) {
|
67 |
+
$errors = array_merge($errors, $customerErrors);
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
if (!empty($errors)) {
|
72 |
+
$message = implode("\n", $errors);
|
73 |
+
throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
74 |
+
}
|
75 |
+
|
76 |
+
try {
|
77 |
+
$this->cleanPasswordsValidationData($customer);
|
78 |
+
$customer->save();
|
79 |
+
$this->_getSession()->setCustomer($customer);
|
80 |
+
$data['message'] = Mage::helper('japi')->__('The account information has been saved.');
|
81 |
+
$data['customer'] = $this->_getCustomerData();
|
82 |
+
|
83 |
+
return $data;
|
84 |
+
|
85 |
+
} catch (Mage_Core_Exception $e) {
|
86 |
+
throw new Jmango360_Japi_Exception($e->getMessage(), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
87 |
+
} catch (Exception $e) {
|
88 |
+
throw new Jmango360_Japi_Exception($e->getMessage(), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
/* Clean password's validation data (password, password_confirmation)
|
93 |
+
*
|
94 |
+
* @return Mage_Customer_Model_Customer
|
95 |
+
*/
|
96 |
+
public function cleanPasswordsValidationData($customer)
|
97 |
+
{
|
98 |
+
/*
|
99 |
+
* Looks like both password_confirmation and confirmation are used due to version differences
|
100 |
+
*/
|
101 |
+
$customer->setData('password', null);
|
102 |
+
$customer->setData('confirmation', null);
|
103 |
+
$customer->setData('password_confirmation', null);
|
104 |
+
|
105 |
+
return $this;
|
106 |
+
}
|
107 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Customer/Group.php
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Customer_Group extends Jmango360_Japi_Model_Rest_Customer
|
4 |
+
{
|
5 |
+
protected $_customerAttributes = array(
|
6 |
+
'firstname', 'lastname'
|
7 |
+
);
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Retrieve customer groups
|
11 |
+
*/
|
12 |
+
public function getList()
|
13 |
+
{
|
14 |
+
/* @var $collection Mage_Customer_Model_Resource_Group_Collection */
|
15 |
+
$collection = Mage::getResourceModel('customer/group_collection');
|
16 |
+
|
17 |
+
$data = array();
|
18 |
+
foreach ($collection as $group) {
|
19 |
+
/* @var $group Mage_Customer_Model_Group */
|
20 |
+
$data['groups'][] = array(
|
21 |
+
'id' => $group->getId(),
|
22 |
+
'code' => $group->getCode(),
|
23 |
+
'label' => $group->getCode()
|
24 |
+
);
|
25 |
+
}
|
26 |
+
|
27 |
+
return $data;
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Retrieve group customers
|
32 |
+
*/
|
33 |
+
public function getCustomers()
|
34 |
+
{
|
35 |
+
$groupId = (int)$this->_getRequest()->getParam('group_id', 0);
|
36 |
+
if (!is_numeric($groupId)) {
|
37 |
+
throw new Jmango360_Japi_Exception(
|
38 |
+
Mage::helper('japi')->__('Group ID not found.'),
|
39 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
40 |
+
);
|
41 |
+
}
|
42 |
+
|
43 |
+
if ($groupId === 0) {
|
44 |
+
return array('customers' => array());
|
45 |
+
}
|
46 |
+
|
47 |
+
/* @var $group Mage_Customer_Model_Customer */
|
48 |
+
$group = Mage::getModel('customer/group')->load($groupId);
|
49 |
+
if (!$group->getId()) {
|
50 |
+
throw new Jmango360_Japi_Exception(
|
51 |
+
Mage::helper('japi')->__('Group not found.'),
|
52 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
53 |
+
);
|
54 |
+
}
|
55 |
+
|
56 |
+
/* @var $collection Mage_Customer_Model_Resource_Customer_Collection */
|
57 |
+
$collection = Mage::getResourceModel('customer/customer_collection');
|
58 |
+
$collection->addAttributeToSelect($this->_customerAttributes);
|
59 |
+
$collection->addFieldToFilter('group_id', $group->getId());
|
60 |
+
|
61 |
+
return $this->convertCollectionToResponse($collection);
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Search customers
|
66 |
+
*/
|
67 |
+
public function search()
|
68 |
+
{
|
69 |
+
$query = $this->_getRequest()->getParam('q');
|
70 |
+
if (!$query) {
|
71 |
+
throw new Jmango360_Japi_Exception(
|
72 |
+
Mage::helper('japi')->__('Query cannot be empty.'),
|
73 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
74 |
+
);
|
75 |
+
}
|
76 |
+
|
77 |
+
/* @var $collection Mage_Customer_Model_Resource_Customer_Collection */
|
78 |
+
$collection = Mage::getResourceModel('customer/customer_collection');
|
79 |
+
$collection->addAttributeToSelect($this->_customerAttributes);
|
80 |
+
$collection->addAttributeToFilter(array(
|
81 |
+
array(
|
82 |
+
'attribute' => 'firstname',
|
83 |
+
'like' => '%' . $query . '%'
|
84 |
+
),
|
85 |
+
array(
|
86 |
+
'attribute' => 'lastname',
|
87 |
+
'like' => '%' . $query . '%'
|
88 |
+
),
|
89 |
+
array(
|
90 |
+
'attribute' => 'email',
|
91 |
+
'like' => '%' . $query . '%'
|
92 |
+
)
|
93 |
+
));
|
94 |
+
|
95 |
+
return $this->convertCollectionToResponse($collection);
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* @param $collection Mage_Customer_Model_Resource_Customer_Collection
|
100 |
+
* @return array
|
101 |
+
*/
|
102 |
+
protected function convertCollectionToResponse($collection)
|
103 |
+
{
|
104 |
+
$page = $this->_getRequest()->getParam('p', 1);
|
105 |
+
$page = is_numeric($page) ? $page : 1;
|
106 |
+
$limit = $this->_getRequest()->getParam('limit', 20);
|
107 |
+
$limit = is_numeric($limit) ? $limit : 20;
|
108 |
+
$collection->setPage($page, $limit);
|
109 |
+
|
110 |
+
$data = array(
|
111 |
+
'page_num' => $collection->getCurPage(),
|
112 |
+
'page_size' => $collection->getPageSize(),
|
113 |
+
'page_total' => $collection->getLastPageNumber(),
|
114 |
+
'customers' => array()
|
115 |
+
);
|
116 |
+
|
117 |
+
foreach ($collection as $customer) {
|
118 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
119 |
+
$data['customers'][] = array(
|
120 |
+
'firstname' => $customer->getData('firstname'),
|
121 |
+
'lastname' => $customer->getData('lastname'),
|
122 |
+
'email' => $customer->getData('email')
|
123 |
+
);
|
124 |
+
}
|
125 |
+
|
126 |
+
return $data;
|
127 |
+
}
|
128 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Customer/List.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Customer_List extends Jmango360_Japi_Model_Rest_Customer
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Retrieve customers data
|
7 |
+
* @return array
|
8 |
+
*/
|
9 |
+
public function getList()
|
10 |
+
{
|
11 |
+
$request = Mage::helper('japi')->getRequest();
|
12 |
+
$email = $request->getParam('email', null);
|
13 |
+
$name = $request->getParam('name_search', null);
|
14 |
+
$customerIds = $request->getParam('customer_ids', array());
|
15 |
+
$customerGroupIds = $request->getParam('customer_group_ids', array());
|
16 |
+
|
17 |
+
$collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
|
18 |
+
|
19 |
+
try {
|
20 |
+
if (! empty($email)) {
|
21 |
+
$collection->addFieldToFilter('email', array('like'=>$email));
|
22 |
+
}
|
23 |
+
|
24 |
+
if (! empty($name)) {
|
25 |
+
$collection->addAttributeToFilter(
|
26 |
+
array(
|
27 |
+
array('attribute'=> 'firstname','like' => $name),
|
28 |
+
array('attribute'=> 'lastname','like' => $name),
|
29 |
+
)
|
30 |
+
);
|
31 |
+
}
|
32 |
+
|
33 |
+
if (!empty($customerIds)) {
|
34 |
+
$collection->addFieldToFilter('entity_id', array('IN'=>$customerIds));
|
35 |
+
}
|
36 |
+
|
37 |
+
if (!empty($customerGroupIds)) {
|
38 |
+
$collection->addFieldToFilter('group_id', array('IN'=>$customerGroupIds));
|
39 |
+
}
|
40 |
+
} catch (Mage_Core_Exception $e) {
|
41 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Could not retrieve list: ' . $e->getMessage()), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
42 |
+
}
|
43 |
+
|
44 |
+
$data = array();
|
45 |
+
foreach ($collection as $customer) {
|
46 |
+
$customer->unsPasswordHash();
|
47 |
+
$row = $customer->toArray();
|
48 |
+
foreach($customer->getAddresses() as $key => $address) {
|
49 |
+
$row['adresses'][$key] = $address->toArray();
|
50 |
+
}
|
51 |
+
$data['customers'][] = $row;
|
52 |
+
}
|
53 |
+
|
54 |
+
return $data;
|
55 |
+
}
|
56 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Customer/Login.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Customer_Login extends Jmango360_Japi_Model_Rest_Customer
|
4 |
+
{
|
5 |
+
public function login()
|
6 |
+
{
|
7 |
+
$session = $this->_getSession();
|
8 |
+
$data = array();
|
9 |
+
|
10 |
+
if ($session->isLoggedIn()) {
|
11 |
+
$login = $this->_getRequest()->getParam('login');
|
12 |
+
if (!empty($login['username']) && $this->_getSession()->getCustomer()->getEmail() != $login['username']) {
|
13 |
+
throw new Jmango360_Japi_Exception(
|
14 |
+
Mage::helper('japi')->__('Customer is already logged in.'),
|
15 |
+
Jmango360_Japi_Model_Request::REST_CUSTOMER_LOGGED_IN
|
16 |
+
);
|
17 |
+
}
|
18 |
+
} else {
|
19 |
+
if ($this->_getRequest()->isPost()) {
|
20 |
+
$login = $this->_getRequest()->getParam('login');
|
21 |
+
if (!empty($login['username']) && !empty($login['password'])) {
|
22 |
+
try {
|
23 |
+
$session->login($login['username'], $login['password']);
|
24 |
+
} catch (Mage_Core_Exception $e) {
|
25 |
+
switch ($e->getCode()) {
|
26 |
+
case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
|
27 |
+
$data = array(
|
28 |
+
'messages' => array(
|
29 |
+
'message' => array(
|
30 |
+
array(
|
31 |
+
'code' => Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED,
|
32 |
+
'message' => Mage::helper('japi')->__('Account is created. Please check email to confirm.'),
|
33 |
+
'type' => 1
|
34 |
+
)
|
35 |
+
)
|
36 |
+
)
|
37 |
+
);
|
38 |
+
return $data;
|
39 |
+
/*throw new Jmango360_Japi_Exception(
|
40 |
+
Mage::helper('japi')->__('Account is created. Please check email to confirm.'),
|
41 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
42 |
+
);*/
|
43 |
+
break;
|
44 |
+
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
|
45 |
+
throw new Jmango360_Japi_Exception($e->getMessage(), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
46 |
+
break;
|
47 |
+
default:
|
48 |
+
throw new Jmango360_Japi_Exception($e->getMessage(), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
49 |
+
}
|
50 |
+
} catch (Exception $e) {
|
51 |
+
throw new Jmango360_Japi_Exception(
|
52 |
+
Mage::helper('japi')->__('Could not login') . ': ' . $e->getMessage(),
|
53 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
54 |
+
);
|
55 |
+
}
|
56 |
+
} else {
|
57 |
+
throw new Jmango360_Japi_Exception(
|
58 |
+
Mage::helper('japi')->__('Login and password are required.'),
|
59 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
60 |
+
);
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
if ($this->_getSession()->isLoggedIn()) {
|
66 |
+
/* @var $session Mage_Customer_Model_Session */
|
67 |
+
$session = Mage::getSingleton('customer/session');
|
68 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
69 |
+
$customer = $this->_getSession()->getCustomer();
|
70 |
+
|
71 |
+
// Flag mobile user
|
72 |
+
if (!$customer->getData('japi')) {
|
73 |
+
$customer->setData('japi', 1)->save();
|
74 |
+
}
|
75 |
+
|
76 |
+
$session->setCustomerId($session->getId());
|
77 |
+
$session->setCustomerGroupId($customer->getGroupId());
|
78 |
+
|
79 |
+
$data['status'] = 'logged_in';
|
80 |
+
$data['session_id'] = Mage::getSingleton('core/session')->getSessionId();
|
81 |
+
$data['customer'] = $this->_getCustomerData();
|
82 |
+
} else {
|
83 |
+
throw new Jmango360_Japi_Exception(
|
84 |
+
Mage::helper('japi')->__('Could not login'),
|
85 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
86 |
+
);
|
87 |
+
}
|
88 |
+
|
89 |
+
return $data;
|
90 |
+
}
|
91 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Customer/Order.php
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Customer_Order extends Mage_Customer_Model_Customer
|
4 |
+
{
|
5 |
+
public function getCustomerOrderList()
|
6 |
+
{
|
7 |
+
$data['orders'] = $this->_getOrderList();
|
8 |
+
|
9 |
+
return $data;
|
10 |
+
}
|
11 |
+
|
12 |
+
public function getCustomerOrderDetails()
|
13 |
+
{
|
14 |
+
$request = $this->_getRequest();
|
15 |
+
$incrementId = $request->getParam('increment_id', null);
|
16 |
+
$orderId = $request->getParam('order_id', null);
|
17 |
+
|
18 |
+
if (!empty($orderId)) {
|
19 |
+
$data = $this->_getOrderById($orderId);
|
20 |
+
} elseif (!empty($incrementId)) {
|
21 |
+
$data = $this->_getOrderByRealId($incrementId);
|
22 |
+
} else {
|
23 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Order not found (no ID).'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
24 |
+
}
|
25 |
+
|
26 |
+
return $data;
|
27 |
+
}
|
28 |
+
|
29 |
+
protected function _getOrderById($orderId)
|
30 |
+
{
|
31 |
+
return $this->_getOrderList($orderId, null, true);
|
32 |
+
}
|
33 |
+
|
34 |
+
protected function _getOrderByRealId($incrementId)
|
35 |
+
{
|
36 |
+
return $this->_getOrderList(null, $incrementId, true);
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Retrieve list of orders.
|
41 |
+
* Filtration could be applied
|
42 |
+
*
|
43 |
+
* @param $orderId
|
44 |
+
* @param $incrementId
|
45 |
+
* @param $addDetails
|
46 |
+
* @return array
|
47 |
+
*/
|
48 |
+
protected function _getOrderList($orderId = null, $incrementId = null, $addDetails = false)
|
49 |
+
{
|
50 |
+
$data = array();
|
51 |
+
|
52 |
+
/* @var $orderCollection Mage_Sales_Model_Resource_Order_Collection */
|
53 |
+
$orderCollection = Mage::getModel("sales/order")->getCollection()
|
54 |
+
->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
|
55 |
+
->setOrder('created_at', 'desc');
|
56 |
+
|
57 |
+
$customerId = Mage::getSingleton('customer/session')->getCustomerId();
|
58 |
+
if (!empty($customerId)) {
|
59 |
+
$orderCollection->addFieldToFilter('customer_id', $customerId);
|
60 |
+
}
|
61 |
+
if (!empty($orderId)) {
|
62 |
+
$orderCollection->addFieldToFilter('entity_id', $orderId);
|
63 |
+
}
|
64 |
+
if (!empty($incrementId)) {
|
65 |
+
$orderCollection->addFieldToFilter('increment_id', $incrementId);
|
66 |
+
}
|
67 |
+
|
68 |
+
$orderCollection->addExpressionFieldToSelect(
|
69 |
+
'customer_name',
|
70 |
+
'concat(ifnull({{prefix}}, ""), ifnull({{firstname}}, ""), if({{middlename}} is null or {{middlename}} = "", " ", concat(" ",{{middlename}}," ")), ifnull({{lastname}},""), ifnull({{suffix}}, ""))',
|
71 |
+
array('prefix' => 'customer_prefix', 'firstname' => 'customer_firstname', 'middlename' => 'customer_middlename', 'lastname' => 'customer_lastname', 'suffix' => 'customer_suffix')
|
72 |
+
);
|
73 |
+
|
74 |
+
foreach ($orderCollection as $order) {
|
75 |
+
/* @var $order Mage_Sales_Model_Order */
|
76 |
+
if ($addDetails) {
|
77 |
+
$orderData = $this->_getOrderDetails($order);
|
78 |
+
} else {
|
79 |
+
$orderData = $order->toArray();
|
80 |
+
}
|
81 |
+
|
82 |
+
$orderData['status'] = $order->getStatusLabel();
|
83 |
+
$orderData['shipping_description'] = str_replace('<br><br>', ', ', $orderData['shipping_description']);
|
84 |
+
$orderData['shipping_description'] = str_replace('<br>', ', ', $orderData['shipping_description']);
|
85 |
+
$orderData['shipping_description'] = strip_tags($orderData['shipping_description']);
|
86 |
+
$orderData['shipping_description'] = trim($orderData['shipping_description'], ",\t\n ");
|
87 |
+
|
88 |
+
foreach ($order->getAllItems() as $item) {
|
89 |
+
/* @var $item Mage_Sales_Model_Order_Item */
|
90 |
+
if (!$item->getParentItemId()) {
|
91 |
+
$orderData['products'][$item->getProductId()]['name'] = $item->getName();
|
92 |
+
$orderData['products'][$item->getProductId()]['qty'] = $item->getQtyOrdered();
|
93 |
+
$orderData['products'][$item->getProductId()]['price'] = $item->getPrice();
|
94 |
+
$orderData['products'][$item->getProductId()]['price_incl_tax'] = $item->getPriceInclTax();
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
if ($order->getPayment()) {
|
99 |
+
try {
|
100 |
+
$orderData['payment']['method'] = $order->getPayment()->getMethodInstance()->getTitle();
|
101 |
+
} catch (Exception $e) {
|
102 |
+
$orderData['payment']['method'] = '';
|
103 |
+
Mage::logException($e);
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
+
$data['orders'][] = $orderData;
|
108 |
+
}
|
109 |
+
|
110 |
+
return $data;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Retrieve full order information
|
115 |
+
*
|
116 |
+
* @param Mage_Sales_Model_Order $order
|
117 |
+
* @return array
|
118 |
+
*/
|
119 |
+
public function _getOrderDetails($order)
|
120 |
+
{
|
121 |
+
if ($order->getGiftMessageId() > 0) {
|
122 |
+
$order->setGiftMessage(Mage::getSingleton('giftmessage/message')->load($order->getGiftMessageId())
|
123 |
+
->getMessage());
|
124 |
+
}
|
125 |
+
|
126 |
+
$data = $order->toArray();
|
127 |
+
|
128 |
+
$data['shipping_address'] = $order->getShippingAddress()->toArray();
|
129 |
+
$data['billing_address'] = $order->getBillingAddress()->toArray();
|
130 |
+
$data['items'] = array();
|
131 |
+
|
132 |
+
foreach ($order->getAllItems() as $item) {
|
133 |
+
/* @var $item Mage_Sales_Model_Order_Item */
|
134 |
+
if ($item->getGiftMessageId() > 0) {
|
135 |
+
$item->setGiftMessage(Mage::getSingleton('giftmessage/message')->load($item->getGiftMessageId())
|
136 |
+
->getMessage());
|
137 |
+
}
|
138 |
+
|
139 |
+
$data['items'][$item->getId()] = $item->toArray();
|
140 |
+
$data['items'][$item->getId()]['product'] = Mage::getModel('catalog/product')->load($item->getProductId());
|
141 |
+
}
|
142 |
+
|
143 |
+
$data['payment'] = $order->getPayment()->toArray();
|
144 |
+
|
145 |
+
$data['status_history'] = array();
|
146 |
+
|
147 |
+
foreach ($order->getAllStatusHistory() as $history) {
|
148 |
+
$data['status_history'][$history->getId()] = $history->toArray();
|
149 |
+
}
|
150 |
+
|
151 |
+
return $data;
|
152 |
+
}
|
153 |
+
|
154 |
+
protected function _getSession()
|
155 |
+
{
|
156 |
+
return Mage::getSingleton('customer/session');
|
157 |
+
}
|
158 |
+
|
159 |
+
protected function _getRequest()
|
160 |
+
{
|
161 |
+
return $this->_getServer()->getRequest();
|
162 |
+
}
|
163 |
+
|
164 |
+
protected function _getResponse()
|
165 |
+
{
|
166 |
+
return $this->_getServer()->getResponse();
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* @return Jmango360_Japi_Model_Server
|
171 |
+
*/
|
172 |
+
protected function _getServer()
|
173 |
+
{
|
174 |
+
return Mage::getSingleton('japi/server');
|
175 |
+
}
|
176 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Customer/Order/List.php
ADDED
@@ -0,0 +1,436 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Customer_Order_List extends Mage_Customer_Model_Customer
|
4 |
+
{
|
5 |
+
|
6 |
+
protected $countJapiOders = 0;
|
7 |
+
|
8 |
+
public function getOrderList()
|
9 |
+
{
|
10 |
+
$limit = $this->_getRequest()->getParam('limit');
|
11 |
+
$page = $this->_getRequest()->getParam('p');
|
12 |
+
$data['orders'] = $this->_getOrderList(null, null, false, $limit, $page);
|
13 |
+
|
14 |
+
return $data;
|
15 |
+
}
|
16 |
+
|
17 |
+
public function getOrderDetails()
|
18 |
+
{
|
19 |
+
$request = $this->_getRequest();
|
20 |
+
$incrementId = $request->getParam('increment_id', null);
|
21 |
+
$orderId = $request->getParam('order_id', null);
|
22 |
+
|
23 |
+
if (!empty($orderId)) {
|
24 |
+
$data = $this->_getOrderById($orderId);
|
25 |
+
} elseif (!empty($incrementId)) {
|
26 |
+
$data = $this->_getOrderByRealId($incrementId);
|
27 |
+
} else {
|
28 |
+
throw new Jmango360_Japi_Exception(
|
29 |
+
Mage::helper('japi')->__('Order not found (no ID).'),
|
30 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
31 |
+
);
|
32 |
+
}
|
33 |
+
|
34 |
+
return array('order' => count($data) ? $data[0] : new stdClass());
|
35 |
+
}
|
36 |
+
|
37 |
+
public function getJapiOrders()
|
38 |
+
{
|
39 |
+
$limit = $this->_getRequest()->getParam('limit', 20);
|
40 |
+
$page = $this->_getRequest()->getParam('p', 1);
|
41 |
+
$date = $this->_getRequest()->getParam('date');
|
42 |
+
$quoteIds = $this->_getRequest()->getParam('quote_ids');
|
43 |
+
$data['orders'] = $this->_getJapiOrderList($limit, $page, true, $date, $quoteIds);
|
44 |
+
$data['total_orders'] = $this->countJapiOders;
|
45 |
+
|
46 |
+
return $data;
|
47 |
+
}
|
48 |
+
|
49 |
+
protected function _getOrderById($orderId)
|
50 |
+
{
|
51 |
+
return $this->_getOrderList($orderId, null, true);
|
52 |
+
}
|
53 |
+
|
54 |
+
protected function _getOrderByRealId($incrementId)
|
55 |
+
{
|
56 |
+
return $this->_getOrderList(null, $incrementId, true);
|
57 |
+
}
|
58 |
+
|
59 |
+
protected function _getOrderList($orderId = null, $incrementId = null, $showDetails = false, $limit = null, $page = null)
|
60 |
+
{
|
61 |
+
$data = array();
|
62 |
+
|
63 |
+
/* @var $orderCollection Mage_Sales_Model_Resource_Order_Collection */
|
64 |
+
$orderCollection = Mage::getModel('sales/order')->getCollection()
|
65 |
+
->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
|
66 |
+
->setOrder('created_at', 'desc');
|
67 |
+
|
68 |
+
if ($limit && $page) {
|
69 |
+
$orderCollection
|
70 |
+
->setPageSize($limit)
|
71 |
+
->setCurPage($page);
|
72 |
+
}
|
73 |
+
|
74 |
+
$customerId = $this->_getSession()->getCustomerId();
|
75 |
+
if (!empty($customerId)) {
|
76 |
+
$orderCollection->addFieldToFilter('customer_id', $customerId);
|
77 |
+
}
|
78 |
+
|
79 |
+
if (!empty($orderId)) {
|
80 |
+
$orderCollection->addFieldToFilter('entity_id', $orderId);
|
81 |
+
}
|
82 |
+
|
83 |
+
if (!empty($incrementId)) {
|
84 |
+
$orderCollection->addFieldToFilter('increment_id', $incrementId);
|
85 |
+
}
|
86 |
+
|
87 |
+
foreach ($orderCollection as $order) {
|
88 |
+
/* @var $order Mage_Sales_Model_Order */
|
89 |
+
if ($showDetails) {
|
90 |
+
$orderData = $this->_getOrderDetails($order);
|
91 |
+
} else {
|
92 |
+
$orderData = array(
|
93 |
+
'entity_id' => (int)$order->getData('entity_id'),
|
94 |
+
'increment_id' => $order->getData('increment_id'),
|
95 |
+
'created_at' => $order->getData('created_at'),
|
96 |
+
'grand_total' => (float)$order->getData('grand_total'),
|
97 |
+
'formatted_grand_total' => $order->getOrderCurrency()->formatPrecision($order->getData('grand_total'), 2, array(), false, false)
|
98 |
+
);
|
99 |
+
}
|
100 |
+
|
101 |
+
$orderData['status'] = $order->getStatusLabel();
|
102 |
+
|
103 |
+
$data[] = $orderData;
|
104 |
+
}
|
105 |
+
|
106 |
+
return $data;
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Get Japi Orders list
|
111 |
+
*
|
112 |
+
* @param null $limit
|
113 |
+
* @param null $page
|
114 |
+
* @param bool $showDetails
|
115 |
+
* @param null $date
|
116 |
+
* @param null $quoteIds
|
117 |
+
* @return array
|
118 |
+
*/
|
119 |
+
protected function _getJapiOrderList($limit = null, $page = null, $showDetails = false, $date = null, $quoteIds = null)
|
120 |
+
{
|
121 |
+
$data = array();
|
122 |
+
|
123 |
+
/* @var $orderCollection Mage_Sales_Model_Resource_Order_Collection */
|
124 |
+
$orderCollection = Mage::getModel('sales/order')->getCollection()
|
125 |
+
->addFieldToFilter('japi', '1')
|
126 |
+
->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
|
127 |
+
->setOrder('created_at', 'desc');
|
128 |
+
|
129 |
+
if ($limit && $page) {
|
130 |
+
$orderCollection
|
131 |
+
->setPageSize($limit)
|
132 |
+
->setCurPage($page);
|
133 |
+
}
|
134 |
+
|
135 |
+
if (!empty($date)) {
|
136 |
+
$date = date('Y-m-d H:i:s', strtotime($date));
|
137 |
+
$orderCollection->addAttributeToFilter('created_at', array('to' => $date));
|
138 |
+
}
|
139 |
+
|
140 |
+
if (!empty($quoteIds)) {
|
141 |
+
$quoteIds = explode(',', $quoteIds);
|
142 |
+
if (count($quoteIds)) {
|
143 |
+
$orderCollection->addAttributeToFilter('quote_id', array('in' => $quoteIds));
|
144 |
+
}
|
145 |
+
}
|
146 |
+
|
147 |
+
foreach ($orderCollection as $order) {
|
148 |
+
/* @var $order Mage_Sales_Model_Order */
|
149 |
+
if ($showDetails) {
|
150 |
+
$orderData = $this->_getOrderDetails($order);
|
151 |
+
} else {
|
152 |
+
$orderData = array(
|
153 |
+
'entity_id' => (int)$order->getData('entity_id'),
|
154 |
+
'increment_id' => $order->getData('increment_id'),
|
155 |
+
'created_at' => $order->getData('created_at'),
|
156 |
+
'quote_id' => $order->getQuoteId(),
|
157 |
+
'grand_total' => (float)$order->getData('grand_total'),
|
158 |
+
'formatted_grand_total' => $order->getOrderCurrency()->formatPrecision($order->getData('grand_total'), 2, array(), false, false)
|
159 |
+
);
|
160 |
+
}
|
161 |
+
|
162 |
+
$orderData['status'] = $order->getStatusLabel();
|
163 |
+
|
164 |
+
$this->countJapiOders = $orderCollection->getSize();
|
165 |
+
|
166 |
+
$data[] = $orderData;
|
167 |
+
}
|
168 |
+
|
169 |
+
return $data;
|
170 |
+
}
|
171 |
+
|
172 |
+
public function _getOrderDetails(Mage_Sales_Model_Order $order)
|
173 |
+
{
|
174 |
+
Mage::register('current_order', $order, true);
|
175 |
+
|
176 |
+
if ($order->getGiftMessageId() > 0) {
|
177 |
+
$order->setGiftMessage(Mage::getSingleton('giftmessage/message')->load($order->getGiftMessageId())->getMessage());
|
178 |
+
}
|
179 |
+
|
180 |
+
$data = $order->toArray();
|
181 |
+
|
182 |
+
$data['shipping_address'] = $order->getShippingAddress()->toArray();
|
183 |
+
$data['billing_address'] = $order->getBillingAddress()->toArray();
|
184 |
+
$data['shipping_title'] = $this->_getOrderShippingMethod($order);
|
185 |
+
$data['payment_title'] = $this->_getOrderPaymentMethod($order);
|
186 |
+
|
187 |
+
try {
|
188 |
+
$data = $this->_getOrderItemsAndTotals($data, $order);
|
189 |
+
} catch (Exception $e) {
|
190 |
+
Mage::logException($e);
|
191 |
+
$data['totals'] = array();
|
192 |
+
}
|
193 |
+
|
194 |
+
return $data;
|
195 |
+
}
|
196 |
+
|
197 |
+
protected function _getOrderItemsAndTotals(array $data, Mage_Sales_Model_Order $order)
|
198 |
+
{
|
199 |
+
/* @var $helper Jmango360_Japi_Helper_Data */
|
200 |
+
$helper = Mage::helper('japi');
|
201 |
+
/* @var $layout Mage_Core_Model_Layout */
|
202 |
+
$layout = $helper->loadLayout('sales_order_view');
|
203 |
+
if (!$layout) return $data;
|
204 |
+
|
205 |
+
foreach ($layout->getAllBlocks() as $block) {
|
206 |
+
/* @var $block Mage_Core_Model_Template */
|
207 |
+
if ($block->getType() == 'sales/order_totals') {
|
208 |
+
$totalsBlock = $block;
|
209 |
+
}
|
210 |
+
if ($block->getType() == 'sales/order_items') {
|
211 |
+
$itemsBlock = $block;
|
212 |
+
}
|
213 |
+
}
|
214 |
+
|
215 |
+
if (!empty($itemsBlock)) {
|
216 |
+
/* @var $itemsBlock Mage_Sales_Block_Order_Items */
|
217 |
+
$itemsCollection = $order->getItemsCollection();
|
218 |
+
$items = array();
|
219 |
+
|
220 |
+
foreach ($itemsCollection as $itemModel) {
|
221 |
+
/* @var $itemModel Mage_Sales_Model_Order_Item */
|
222 |
+
if ($itemModel->getParentItem()) continue;
|
223 |
+
|
224 |
+
$item = $itemModel->toArray();
|
225 |
+
/* @var $block Mage_Sales_Block_Order_Item_Renderer_Default */
|
226 |
+
$block = $itemsBlock->getItemRenderer($itemModel->getProductType())->setItem($itemModel);
|
227 |
+
if ($itemModel->getProductType() == 'bundle') {
|
228 |
+
$options = array();
|
229 |
+
$childenItems = $itemModel->getChildrenItems();
|
230 |
+
foreach ($childenItems as $childenItem) {
|
231 |
+
$attributes = $this->_getSelectionAttributes($childenItem);
|
232 |
+
if (empty($attributes)) continue;
|
233 |
+
|
234 |
+
if (!isset($options[$attributes['option_id']])) {
|
235 |
+
$options[$attributes['option_id']] = array(
|
236 |
+
'label' => $helper->escapeHtml($attributes['option_label']),
|
237 |
+
'value' => $this->_getSelectionHtml($childenItem, $attributes, $order)
|
238 |
+
);
|
239 |
+
} else {
|
240 |
+
$options[$attributes['option_id']]['value'] .= "\n" . $this->_getSelectionHtml($childenItem, $attributes, $order);
|
241 |
+
}
|
242 |
+
}
|
243 |
+
$item['options'] = array_values($options);
|
244 |
+
} else {
|
245 |
+
$item['options'] = $block->getItemOptions();
|
246 |
+
}
|
247 |
+
|
248 |
+
$items[] = $item;
|
249 |
+
}
|
250 |
+
|
251 |
+
$data['items'] = $items;
|
252 |
+
}
|
253 |
+
|
254 |
+
if (!empty($totalsBlock)) {
|
255 |
+
/* @var $totalsBlock Mage_Sales_Block_Order_Totals */
|
256 |
+
$totalsBlock->setOrder($order);
|
257 |
+
$totalsBlock->toHtml();
|
258 |
+
|
259 |
+
$totals = array();
|
260 |
+
foreach ($totalsBlock->getTotals() as $total) {
|
261 |
+
/* @var $total Varien_Object */
|
262 |
+
$blockName = $total->getData('block_name');
|
263 |
+
|
264 |
+
if ($blockName == 'tax') {
|
265 |
+
$totals = array_merge($totals, $this->_getTaxTotals($order));
|
266 |
+
} elseif ($blockName) {
|
267 |
+
$html = $totalsBlock->getChildHtml($blockName);
|
268 |
+
$totals = array_merge($totals, $this->_getHtmlTotals($html));
|
269 |
+
} else {
|
270 |
+
if (isset($total['value'])) {
|
271 |
+
$total->setData('formatted_value', $order->getOrderCurrency()->formatPrecision($total['value'], 2, array(), false));
|
272 |
+
}
|
273 |
+
$totals[] = $total->toArray();
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
+
$data['totals'] = $totals;
|
278 |
+
}
|
279 |
+
|
280 |
+
return $data;
|
281 |
+
}
|
282 |
+
|
283 |
+
protected function _getSelectionHtml($childenItem, $attributes, $order)
|
284 |
+
{
|
285 |
+
return sprintf('%d x %s (%s)',
|
286 |
+
$attributes['qty'],
|
287 |
+
$childenItem->getName(),
|
288 |
+
$order->getOrderCurrency()->formatPrecision($attributes['price'], 2, array(), false)
|
289 |
+
);
|
290 |
+
}
|
291 |
+
|
292 |
+
protected function _getSelectionAttributes($item)
|
293 |
+
{
|
294 |
+
if ($item instanceof Mage_Sales_Model_Order_Item) {
|
295 |
+
$options = $item->getProductOptions();
|
296 |
+
} else {
|
297 |
+
$options = $item->getOrderItem()->getProductOptions();
|
298 |
+
}
|
299 |
+
if (isset($options['bundle_selection_attributes'])) {
|
300 |
+
return unserialize($options['bundle_selection_attributes']);
|
301 |
+
}
|
302 |
+
return null;
|
303 |
+
}
|
304 |
+
|
305 |
+
protected function _getHtmlTotals($html)
|
306 |
+
{
|
307 |
+
if (!$html) return array();
|
308 |
+
|
309 |
+
$dom = new DOMDocument();
|
310 |
+
$dom->loadHTML($html);
|
311 |
+
$xpath = new DOMXPath($dom);
|
312 |
+
$rows = $xpath->query('//tr');
|
313 |
+
$totals = array();
|
314 |
+
|
315 |
+
foreach ($rows as $index => $row) {
|
316 |
+
$total = array('code' => 'total_' . $index);
|
317 |
+
$columns = $xpath->query('descendant::td', $row);
|
318 |
+
foreach ($columns as $i => $column) {
|
319 |
+
if ($i == 0) {
|
320 |
+
$total['label'] = trim($column->nodeValue);
|
321 |
+
} else {
|
322 |
+
$total['value'] = (float)preg_replace('/[^0-9.,]/', '', trim($column->nodeValue));
|
323 |
+
$total['formatted_value'] = trim($column->nodeValue);
|
324 |
+
}
|
325 |
+
}
|
326 |
+
|
327 |
+
$totals[] = $total;
|
328 |
+
}
|
329 |
+
|
330 |
+
return $totals;
|
331 |
+
}
|
332 |
+
|
333 |
+
protected function _getTaxTotals(Mage_Sales_Model_Order $order)
|
334 |
+
{
|
335 |
+
/* @var $taxConfig Mage_Tax_Model_Config */
|
336 |
+
$taxConfig = Mage::getSingleton('tax/config');
|
337 |
+
$totals = array();
|
338 |
+
|
339 |
+
if ($taxConfig->displaySalesFullSummary($order->getStore())) {
|
340 |
+
$fullInfo = $order->getFullTaxInfo();
|
341 |
+
if (!is_array($fullInfo)) return array();
|
342 |
+
|
343 |
+
foreach ($fullInfo as $info) {
|
344 |
+
if (isset($info['hidden']) && $info['hidden']) continue;
|
345 |
+
|
346 |
+
$rates = $info['rates'];
|
347 |
+
foreach ($rates as $rate) {
|
348 |
+
$total = array();
|
349 |
+
$total['code'] = $rate['code'];
|
350 |
+
$total['label'] = Mage::helper('japi')->escapeHtml($rate['title']);
|
351 |
+
if (!is_null($rate['percent'])) {
|
352 |
+
$total['label'] .= sprintf(' (%s%%)', (float)$rate['percent']);
|
353 |
+
}
|
354 |
+
$total['value'] = (float)$info['amount'];
|
355 |
+
$total['formatted_value'] = $order->getOrderCurrency()->formatPrecision($info['amount'], 2, array(), false);
|
356 |
+
|
357 |
+
$totals[] = $total;
|
358 |
+
}
|
359 |
+
}
|
360 |
+
|
361 |
+
$weees = Mage::helper('tax')->getAllWeee($order);
|
362 |
+
if (!is_array($weees)) return $totals;
|
363 |
+
|
364 |
+
$weeIndex = 0;
|
365 |
+
foreach ($weees as $weeeTitle => $weeeAmount) {
|
366 |
+
$totals[] = array(
|
367 |
+
'code' => 'wee_' . $weeIndex++,
|
368 |
+
'label' => Mage::helper('japi')->escapeHtml($weeeTitle),
|
369 |
+
'value' => (float)$weeeAmount,
|
370 |
+
'formatted_value' => $order->getOrderCurrency()->formatPrecision($weeeAmount, 2, array(), false)
|
371 |
+
);
|
372 |
+
}
|
373 |
+
}
|
374 |
+
|
375 |
+
$totals[] = array(
|
376 |
+
'code' => 'tax',
|
377 |
+
'label' => Mage::helper('tax')->__('Tax'),
|
378 |
+
'value' => (float)$order->getTaxAmount(),
|
379 |
+
'formatted_value' => $order->getOrderCurrency()->formatPrecision($order->getTaxAmount(), 2, array(), false)
|
380 |
+
);
|
381 |
+
|
382 |
+
return $totals;
|
383 |
+
}
|
384 |
+
|
385 |
+
protected function _getOrderShippingMethod(Mage_Sales_Model_Order $order)
|
386 |
+
{
|
387 |
+
$shippingMethod = $order->getData('shipping_description');
|
388 |
+
if (!$shippingMethod) return '';
|
389 |
+
|
390 |
+
$shippingMethod = str_replace('<br><br>', ', ', $shippingMethod);
|
391 |
+
$shippingMethod = str_replace('<br>', ', ', $shippingMethod);
|
392 |
+
$shippingMethod = strip_tags($shippingMethod);
|
393 |
+
$shippingMethod = trim($shippingMethod, ",\t\n ");
|
394 |
+
|
395 |
+
return $shippingMethod;
|
396 |
+
}
|
397 |
+
|
398 |
+
protected function _getOrderPaymentMethod(Mage_Sales_Model_Order $order)
|
399 |
+
{
|
400 |
+
if ($order->getPayment()) {
|
401 |
+
try {
|
402 |
+
return $order->getPayment()->getMethodInstance()->getTitle();
|
403 |
+
} catch (Exception $e) {
|
404 |
+
Mage::logException($e);
|
405 |
+
}
|
406 |
+
}
|
407 |
+
|
408 |
+
return '';
|
409 |
+
}
|
410 |
+
|
411 |
+
/**
|
412 |
+
* @return Mage_Customer_Model_Session
|
413 |
+
*/
|
414 |
+
protected function _getSession()
|
415 |
+
{
|
416 |
+
return Mage::getSingleton('customer/session');
|
417 |
+
}
|
418 |
+
|
419 |
+
protected function _getRequest()
|
420 |
+
{
|
421 |
+
return $this->_getServer()->getRequest();
|
422 |
+
}
|
423 |
+
|
424 |
+
protected function _getResponse()
|
425 |
+
{
|
426 |
+
return $this->_getServer()->getResponse();
|
427 |
+
}
|
428 |
+
|
429 |
+
/**
|
430 |
+
* @return Jmango360_Japi_Model_Server
|
431 |
+
*/
|
432 |
+
protected function _getServer()
|
433 |
+
{
|
434 |
+
return Mage::getSingleton('japi/server');
|
435 |
+
}
|
436 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Customer/Password.php
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Customer_Password extends Jmango360_Japi_Model_Rest_Customer
|
4 |
+
{
|
5 |
+
public function passwordreset()
|
6 |
+
{
|
7 |
+
$email = (string)$this->_getRequest()->getParam('email');
|
8 |
+
$data = array();
|
9 |
+
|
10 |
+
if ($email) {
|
11 |
+
if (!Zend_Validate::is($email, 'EmailAddress')) {
|
12 |
+
throw new Jmango360_Japi_Exception(
|
13 |
+
Mage::helper('customer')->__('Invalid email address.'),
|
14 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
15 |
+
);
|
16 |
+
}
|
17 |
+
|
18 |
+
/** @var $customer Mage_Customer_Model_Customer */
|
19 |
+
$customer = Mage::getSingleton('customer/customer')
|
20 |
+
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
|
21 |
+
->loadByEmail($email);
|
22 |
+
|
23 |
+
if ($customer->getId()) {
|
24 |
+
try {
|
25 |
+
$newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();
|
26 |
+
$customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
|
27 |
+
$customer->sendPasswordResetConfirmationEmail();
|
28 |
+
} catch (Exception $exception) {
|
29 |
+
throw new Jmango360_Japi_Exception(
|
30 |
+
$exception->getMessage(),
|
31 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
32 |
+
);
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
$data = array(
|
37 |
+
'messages' => array(
|
38 |
+
'message' => array(
|
39 |
+
array(
|
40 |
+
'code' => Jmango360_Japi_Model_Request::HTTP_OK,
|
41 |
+
'message' => Mage::helper('customer')->__(
|
42 |
+
'If there is an account associated with %s you will receive an email with a link to reset your password.',
|
43 |
+
Mage::helper('customer')->escapeHtml($email)
|
44 |
+
),
|
45 |
+
'type' => 1
|
46 |
+
)
|
47 |
+
)
|
48 |
+
)
|
49 |
+
);
|
50 |
+
} else {
|
51 |
+
throw new Jmango360_Japi_Exception(
|
52 |
+
Mage::helper('customer')->__('Please enter your email.'),
|
53 |
+
Jmango360_Japi_Model_Request::HTTP_BAD_REQUEST
|
54 |
+
);
|
55 |
+
}
|
56 |
+
|
57 |
+
return $data;
|
58 |
+
}
|
59 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Customer/Register.php
ADDED
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Customer_Register extends Jmango360_Japi_Model_Rest_Customer
|
4 |
+
{
|
5 |
+
public function register()
|
6 |
+
{
|
7 |
+
$this->_filterDates(array('dob'));
|
8 |
+
|
9 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
10 |
+
$customer = Mage::getModel('customer/customer');
|
11 |
+
|
12 |
+
if ($this->_getRequest()->getParam('is_subscribed', false)) {
|
13 |
+
$customer->setIsSubscribed(1);
|
14 |
+
}
|
15 |
+
$customer->getGroupId();
|
16 |
+
|
17 |
+
$errors = $this->_getCustomerErrors($customer);
|
18 |
+
if (empty($errors)) {
|
19 |
+
$this->cleanPasswordsValidationData($customer);
|
20 |
+
|
21 |
+
// Flag mobile user
|
22 |
+
$customer->setData('japi', 1);
|
23 |
+
|
24 |
+
$customer->save();
|
25 |
+
$this->_dispatchRegisterSuccess($customer);
|
26 |
+
$this->_successProcessRegistration($customer);
|
27 |
+
} else {
|
28 |
+
$message = implode("\n", $errors);
|
29 |
+
throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
30 |
+
}
|
31 |
+
|
32 |
+
if ($customer->isConfirmationRequired()) {
|
33 |
+
$data = array(
|
34 |
+
'messages' => array(
|
35 |
+
'message' => array(
|
36 |
+
array(
|
37 |
+
'code' => Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED,
|
38 |
+
'message' => Mage::helper('japi')->__('Account is created. Please check email to confirm.'),
|
39 |
+
'type' => 1
|
40 |
+
)
|
41 |
+
)
|
42 |
+
)
|
43 |
+
);
|
44 |
+
/*throw new Jmango360_Japi_Exception(
|
45 |
+
Mage::helper('japi')->__('Account is created. Please check email to confirm.'),
|
46 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
47 |
+
);*/
|
48 |
+
} else {
|
49 |
+
$data['customer'] = $this->_getCustomerData();
|
50 |
+
}
|
51 |
+
|
52 |
+
/*
|
53 |
+
* Customer is logged in and therefor has a new session ID
|
54 |
+
*/
|
55 |
+
$data['session_id'] = Mage::getSingleton('core/session')->getSessionId();
|
56 |
+
|
57 |
+
return $data;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Convert dates in array from localized to internal format
|
62 |
+
*/
|
63 |
+
protected function _filterDates($dateFields)
|
64 |
+
{
|
65 |
+
$map = array(
|
66 |
+
'D' => 'j',
|
67 |
+
'MMMM' => 'm',
|
68 |
+
'MMM' => 'm',
|
69 |
+
'MM' => 'm',
|
70 |
+
'M' => 'm',
|
71 |
+
'dd' => 'd',
|
72 |
+
'd' => 'd',
|
73 |
+
'yyyy' => 'Y',
|
74 |
+
'yy' => 'Y',
|
75 |
+
'y' => 'Y'
|
76 |
+
);
|
77 |
+
$dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
|
78 |
+
foreach ($map as $search => $replace) {
|
79 |
+
$dateFormat = preg_replace('/(^|[^%])' . $search . '/', '$1' . $replace, $dateFormat);
|
80 |
+
}
|
81 |
+
$request = $this->_getRequest();
|
82 |
+
if (!is_array($dateFields)) {
|
83 |
+
$dateFields = array($dateFields);
|
84 |
+
}
|
85 |
+
foreach ($dateFields as $dateField) {
|
86 |
+
if (!empty($dateField) && $data = $request->getParam($dateField)) {
|
87 |
+
$request->setParam($dateField, date($dateFormat, strtotime($data)));
|
88 |
+
}
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
protected function _getCustomerErrors($customer)
|
93 |
+
{
|
94 |
+
$errors = array();
|
95 |
+
$request = $this->_getRequest();
|
96 |
+
|
97 |
+
if ($request->getParam('create_address') || $request->getParam('country_id') || $request->getParam('street')) {
|
98 |
+
$errors = $this->_getErrorsOnCustomerAddress($customer);
|
99 |
+
}
|
100 |
+
$customerForm = $this->_getCustomerForm($customer);
|
101 |
+
/*
|
102 |
+
* the customer data from the request
|
103 |
+
*/
|
104 |
+
$customerData = $customerForm->extractData($request);
|
105 |
+
$customerErrors = $customerForm->validateData($customerData);
|
106 |
+
if ($customerErrors !== true) {
|
107 |
+
$errors = array_merge($customerErrors, $errors);
|
108 |
+
} else {
|
109 |
+
$customerForm->compactData($customerData);
|
110 |
+
$customer->setPassword($request->getParam('password'));
|
111 |
+
|
112 |
+
/*
|
113 |
+
* Looks like both password_confirmation and confirmation are used due to version differences
|
114 |
+
*/
|
115 |
+
$customer->setConfirmation($request->getParam('confirmation'));
|
116 |
+
$customer->setPasswordConfirmation($request->getParam('confirmation'));
|
117 |
+
|
118 |
+
$customerErrors = $customer->validate();
|
119 |
+
if (is_array($customerErrors)) {
|
120 |
+
$errors = array_merge($customerErrors, $errors);
|
121 |
+
}
|
122 |
+
}
|
123 |
+
return $errors;
|
124 |
+
}
|
125 |
+
|
126 |
+
protected function _getErrorsOnCustomerAddress($customer)
|
127 |
+
{
|
128 |
+
$errors = array();
|
129 |
+
/* @var $address Mage_Customer_Model_Address */
|
130 |
+
$address = Mage::getModel('customer/address');
|
131 |
+
/* @var $addressForm Mage_Customer_Model_Form */
|
132 |
+
$addressForm = Mage::getModel('customer/form');
|
133 |
+
$addressForm->setFormCode('customer_register_address')->setEntity($address);
|
134 |
+
|
135 |
+
$addressData = $addressForm->extractData($this->_getRequest(), 'address', false);
|
136 |
+
$addressErrors = $addressForm->validateData($addressData);
|
137 |
+
if (is_array($addressErrors)) {
|
138 |
+
$errors = array_merge($errors, $addressErrors);
|
139 |
+
}
|
140 |
+
$address->setId(null)
|
141 |
+
->setIsDefaultBilling($this->_getRequest()->getParam('default_billing', false))
|
142 |
+
->setIsDefaultShipping($this->_getRequest()->getParam('default_shipping', false));
|
143 |
+
$addressForm->compactData($addressData);
|
144 |
+
$customer->addAddress($address);
|
145 |
+
|
146 |
+
$addressErrors = $address->validate();
|
147 |
+
if (is_array($addressErrors)) {
|
148 |
+
$errors = array_merge($errors, $addressErrors);
|
149 |
+
}
|
150 |
+
return $errors;
|
151 |
+
}
|
152 |
+
|
153 |
+
protected function _getCustomerForm($customer)
|
154 |
+
{
|
155 |
+
/* @var $customerForm Mage_Customer_Model_Form */
|
156 |
+
$customerForm = Mage::getModel('customer/form');
|
157 |
+
$customerForm->setFormCode('customer_account_create');
|
158 |
+
$customerForm->setEntity($customer);
|
159 |
+
return $customerForm;
|
160 |
+
}
|
161 |
+
|
162 |
+
protected function _dispatchRegisterSuccess($customer)
|
163 |
+
{
|
164 |
+
$controller = $this->_getServer()->getControllerInstance();
|
165 |
+
Mage::dispatchEvent('customer_register_success',
|
166 |
+
array('account_controller' => $controller, 'customer' => $customer));
|
167 |
+
}
|
168 |
+
|
169 |
+
protected function _successProcessRegistration(Mage_Customer_Model_Customer $customer)
|
170 |
+
{
|
171 |
+
$session = $this->_getSession();
|
172 |
+
if ($customer->isConfirmationRequired()) {
|
173 |
+
/** @var $app Mage_Core_Model_App */
|
174 |
+
$app = Mage::app();
|
175 |
+
/** @var $store Mage_Core_Model_Store */
|
176 |
+
$store = $app->getStore();
|
177 |
+
$customer->sendNewAccountEmail(
|
178 |
+
'confirmation',
|
179 |
+
null,
|
180 |
+
$store->getId()
|
181 |
+
);
|
182 |
+
$customerHelper = Mage::helper('customer');
|
183 |
+
$session->addSuccess(Mage::helper('japi')->__("Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href='%s'>click here</a>.",
|
184 |
+
$customerHelper->getEmailConfirmationUrl($customer->getEmail())));
|
185 |
+
/*
|
186 |
+
* Because this is the App its not always possible to confirm through email.
|
187 |
+
* -- The customer is logged in and gets an email to confirm anyway
|
188 |
+
* -- The next time the customer want to logg in he gets a warning "not confirmed"
|
189 |
+
*/
|
190 |
+
}
|
191 |
+
$session->setCustomerAsLoggedIn($customer);
|
192 |
+
|
193 |
+
return $this;
|
194 |
+
}
|
195 |
+
|
196 |
+
/* Clean password's validation data (password, password_confirmation)
|
197 |
+
*
|
198 |
+
* @return Mage_Customer_Model_Customer
|
199 |
+
*/
|
200 |
+
public function cleanPasswordsValidationData($customer)
|
201 |
+
{
|
202 |
+
/*
|
203 |
+
* Looks like both password_confirmation and confirmation are used due to version differences
|
204 |
+
*/
|
205 |
+
$customer->setData('password', null);
|
206 |
+
$customer->setData('confirmation', null);
|
207 |
+
$customer->setData('password_confirmation', null);
|
208 |
+
|
209 |
+
return $this;
|
210 |
+
}
|
211 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Mage.php
ADDED
@@ -0,0 +1,819 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Mage extends Mage_Core_Model_Abstract
|
4 |
+
{
|
5 |
+
const APIUSERPATH = 'japi/jmango_rest_api/apiuser';
|
6 |
+
const APIKEYPATH = 'japi/jmango_rest_api/apikey';
|
7 |
+
const USEFRONTENDSIDPATH = 'web/session/use_frontend_sid';
|
8 |
+
|
9 |
+
const PATH_CURRENCY_BASE = 'currency/options/base';
|
10 |
+
const PATH_CURRENCY_DEFAULT = 'currency/options/default';
|
11 |
+
const PATH_CURRENCY_ALLOW = 'currency/options/allow';
|
12 |
+
const PATH_DEFAULT_COUNTRY = 'general/country/default';
|
13 |
+
const PATH_IDEV_DEFAULT_COUNTRY = 'onestepcheckout/general/default_country';
|
14 |
+
const PATH_COUNTRY_ALLOW = 'general/country/allow';
|
15 |
+
const PATH_OPTIONAL_POSTCODE = 'general/country/optional_zip_countries';
|
16 |
+
const PATH_STATE_REQUIRED = 'general/region/state_required';
|
17 |
+
const PATH_DISPLAY_ALL = 'general/region/display_all';
|
18 |
+
const PATH_TIMEZONE = 'general/locale/timezone';
|
19 |
+
const PATH_LOCALE = 'general/locale/code';
|
20 |
+
const PATH_GUEST_CHECKOUT = 'checkout/options/guest_checkout';
|
21 |
+
const PATH_WSI_COMPLIANCE = 'api/config/compliance_wsi';
|
22 |
+
//const PATH_SHOW_STOCK_INFO = 'cataloginventory/options/display_product_stock_status';
|
23 |
+
const PATH_SHOW_STOCK_INFO = 'japi/jmango_rest_stock_settings/display_product_stock_status';
|
24 |
+
const PATH_THEME_CONFIG = 'japi/jmango_rest_theme/data';
|
25 |
+
|
26 |
+
protected $_attributes = array();
|
27 |
+
protected $_excludeCustomerAttributes = array(
|
28 |
+
'prefix', 'firstname', 'middlename', 'suffix', 'lastname', 'email', 'dob', 'taxvat', 'gender'
|
29 |
+
);
|
30 |
+
protected $_excludeAddressAttributes = array(
|
31 |
+
'prefix', 'firstname', 'middlename', 'suffix', 'lastname', 'company', 'street', 'city', 'country_id',
|
32 |
+
'region', 'region_id', 'postcode', 'telephone', 'fax', 'vat_id'
|
33 |
+
);
|
34 |
+
|
35 |
+
public function dispatch()
|
36 |
+
{
|
37 |
+
$action = $this->_getRequest()->getAction();
|
38 |
+
$operation = $this->_getRequest()->getOperation();
|
39 |
+
|
40 |
+
switch ($action . $operation) {
|
41 |
+
case 'store' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
42 |
+
$data = $this->_store();
|
43 |
+
$this->_getResponse()->render($data);
|
44 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
45 |
+
break;
|
46 |
+
case 'store' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
47 |
+
$data = $this->_store(true);
|
48 |
+
$this->_getResponse()->render($data);
|
49 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
50 |
+
break;
|
51 |
+
case 'getSession' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
52 |
+
$data = $this->_getNewSessionId();
|
53 |
+
$this->_getResponse()->render($data);
|
54 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
55 |
+
break;
|
56 |
+
case 'getMagentoInfo' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
57 |
+
$data = $this->_getMagentoInfo();
|
58 |
+
$this->_getResponse()->render($data);
|
59 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
60 |
+
break;
|
61 |
+
case 'getPluginVersion' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
62 |
+
$data = $this->_getPluginVersion();
|
63 |
+
$this->_getResponse()->render($data);
|
64 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
65 |
+
break;
|
66 |
+
case 'getConfigInfo' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
67 |
+
$data = $this->_getConfigInfo();
|
68 |
+
$this->_getResponse()->render($data);
|
69 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
70 |
+
break;
|
71 |
+
case 'getDirectoryCountryList' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
72 |
+
$data = $this->_getDirectoryCountryList();
|
73 |
+
$this->_getResponse()->render($data);
|
74 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
75 |
+
break;
|
76 |
+
case 'getDirectoryRegionList' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
77 |
+
$data = $this->_getDirectoryRegionList();
|
78 |
+
$this->_getResponse()->render($data);
|
79 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
80 |
+
break;
|
81 |
+
case 'getToken' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
82 |
+
$data = $this->_getNewToken();
|
83 |
+
$this->_getResponse()->render($data);
|
84 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_CREATED);
|
85 |
+
break;
|
86 |
+
case 'getMagentoModules' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
87 |
+
$data = $this->_getModules();
|
88 |
+
$this->_getResponse()->render($data);
|
89 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
90 |
+
break;
|
91 |
+
case 'getModuleRewrites' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
92 |
+
$data = $this->_getRewrites();
|
93 |
+
$this->_getResponse()->render($data);
|
94 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
95 |
+
break;
|
96 |
+
case 'updateTheme' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
97 |
+
$data = $this->_updateTheme();
|
98 |
+
$this->_getResponse()->render($data);
|
99 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
100 |
+
break;
|
101 |
+
case 'getTheme' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
102 |
+
$data = $this->_getTheme();
|
103 |
+
$this->_getResponse()->render($data);
|
104 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
105 |
+
break;
|
106 |
+
case 'orders' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
107 |
+
$data = $this->_getOrders();
|
108 |
+
$this->_getResponse()->render($data);
|
109 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
110 |
+
break;
|
111 |
+
default:
|
112 |
+
throw new Jmango360_Japi_Exception('Resource method not implemented', Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
113 |
+
break;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
protected function _getModules()
|
118 |
+
{
|
119 |
+
$modules = Mage::getConfig()->getNode('modules')->children();
|
120 |
+
$output = array();
|
121 |
+
|
122 |
+
foreach ($modules as $name => $module) {
|
123 |
+
$output['modules'][] = array(
|
124 |
+
'name' => $name,
|
125 |
+
'active' => (string)$module->active == 'true' ? true : false,
|
126 |
+
'version' => (string)$module->version
|
127 |
+
);
|
128 |
+
}
|
129 |
+
|
130 |
+
return $output;
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Return rewrites data
|
135 |
+
*/
|
136 |
+
protected function _getRewrites()
|
137 |
+
{
|
138 |
+
$rewrites = $this->_loadRewrites();
|
139 |
+
$data['rewrites'] = array();
|
140 |
+
|
141 |
+
foreach ($rewrites as $rewriteNodes) {
|
142 |
+
foreach ($rewriteNodes as $node) {
|
143 |
+
$nParent = $node->xpath('..');
|
144 |
+
$module = (string)$nParent[0]->getName();
|
145 |
+
$nSubParent = $nParent[0]->xpath('..');
|
146 |
+
$component = (string)$nSubParent[0]->getName();
|
147 |
+
if (!in_array($component, array('blocks', 'helpers', 'models'))) {
|
148 |
+
continue;
|
149 |
+
}
|
150 |
+
$pathNodes = $node->children();
|
151 |
+
foreach ($pathNodes as $pathNode) {
|
152 |
+
$path = (string)$pathNode->getName();
|
153 |
+
$completePath = $module . '/' . $path;
|
154 |
+
$rewriteClassName = (string)$pathNode;
|
155 |
+
$instance = Mage::getConfig()->getGroupedClassName(
|
156 |
+
substr($component, 0, -1),
|
157 |
+
$completePath
|
158 |
+
);
|
159 |
+
$data['rewrites'][] = array(
|
160 |
+
'path' => $completePath,
|
161 |
+
'rewrite_class' => $rewriteClassName,
|
162 |
+
'active_class' => $instance,
|
163 |
+
'status' => ($instance == $rewriteClassName)
|
164 |
+
);
|
165 |
+
}
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
return $data;
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Return all rewrites from XML
|
174 |
+
*
|
175 |
+
* @return array All rwrites
|
176 |
+
*/
|
177 |
+
protected function _loadRewrites()
|
178 |
+
{
|
179 |
+
$fileName = 'config.xml';
|
180 |
+
$modules = Mage::getConfig()->getNode('modules')->children();
|
181 |
+
$return = array();
|
182 |
+
foreach ($modules as $modName => $module) {
|
183 |
+
if ($module->is('active')) {
|
184 |
+
$configFile = Mage::getConfig()->getModuleDir('etc', $modName) . DS . $fileName;
|
185 |
+
if (file_exists($configFile)) {
|
186 |
+
$xml = file_get_contents($configFile);
|
187 |
+
$xml = simplexml_load_string($xml);
|
188 |
+
if ($xml instanceof SimpleXMLElement) {
|
189 |
+
$return[$modName] = $xml->xpath('//rewrite');
|
190 |
+
}
|
191 |
+
}
|
192 |
+
}
|
193 |
+
}
|
194 |
+
return $return;
|
195 |
+
}
|
196 |
+
|
197 |
+
protected function _getDirectoryCountryList()
|
198 |
+
{
|
199 |
+
$collection = Mage::getModel('directory/country')->getCollection();
|
200 |
+
|
201 |
+
$countries = array();
|
202 |
+
foreach ($collection as $country) {
|
203 |
+
/* @var $country Mage_Directory_Model_Country */
|
204 |
+
$country->getName(); // Loading name in default locale
|
205 |
+
$countries[] = $country->toArray(array('country_id', 'iso2_code', 'iso3_code', 'name'));
|
206 |
+
}
|
207 |
+
|
208 |
+
$data['countries'] = $countries;
|
209 |
+
|
210 |
+
return $data;
|
211 |
+
}
|
212 |
+
|
213 |
+
protected function _getDirectoryRegionList()
|
214 |
+
{
|
215 |
+
$country = $this->_getRequest()->getParam('country_code', null);
|
216 |
+
if (is_null($country)) {
|
217 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Country code cannot be empty'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
218 |
+
}
|
219 |
+
|
220 |
+
try {
|
221 |
+
/* @var $country Mage_Directory_Model_Country */
|
222 |
+
$country = Mage::getModel('directory/country')->loadByCode($country);
|
223 |
+
} catch (Mage_Core_Exception $e) {
|
224 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Country not exists: ' . $e->getMessage()), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
225 |
+
}
|
226 |
+
|
227 |
+
if (!$country->getId()) {
|
228 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Country not exists'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
229 |
+
}
|
230 |
+
|
231 |
+
$regions = array();
|
232 |
+
foreach ($country->getRegions() as $region) {
|
233 |
+
/* @var $region Mage_Directory_Model_Region */
|
234 |
+
$regionData = $region->toArray(array('region_id', 'code', 'name'));
|
235 |
+
$regionData['name'] = $region->getName();
|
236 |
+
$regions[] = $regionData;
|
237 |
+
}
|
238 |
+
|
239 |
+
$data['regions'] = $regions;
|
240 |
+
|
241 |
+
return $data;
|
242 |
+
}
|
243 |
+
|
244 |
+
protected function _getConfigInfo()
|
245 |
+
{
|
246 |
+
$request = $this->_getRequest();
|
247 |
+
$store_id = $request->getParam('store_id', null);
|
248 |
+
$store = Mage::app()->getStore($store_id);
|
249 |
+
|
250 |
+
if (!is_object($store) || !$store->getId()) {
|
251 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Store not found'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
252 |
+
}
|
253 |
+
|
254 |
+
Mage::app()->setCurrentStore($store);
|
255 |
+
$storeId = $store->getId();
|
256 |
+
|
257 |
+
$data = array();
|
258 |
+
$data['store'] = $store->toArray();
|
259 |
+
$data['currency'] = $this->getCurrency($storeId);
|
260 |
+
$data['general'] = $this->getGeneralInfo($storeId);
|
261 |
+
|
262 |
+
$data['shipping_methods'] = null;
|
263 |
+
$data['payment_methods'] = null;
|
264 |
+
|
265 |
+
$data['catalog'] = $this->_getCatalogInfo($storeId);
|
266 |
+
$data['signup_options'] = null;
|
267 |
+
$data['address_options'] = null;
|
268 |
+
|
269 |
+
return $data;
|
270 |
+
}
|
271 |
+
|
272 |
+
public function getCustomerAttributes()
|
273 |
+
{
|
274 |
+
$attributes = $this->_getCustomerAttributes();
|
275 |
+
foreach ($attributes as $k => $attribute) {
|
276 |
+
if (in_array($attribute['key'], $this->_excludeCustomerAttributes)) {
|
277 |
+
unset($attributes[$k]);
|
278 |
+
}
|
279 |
+
}
|
280 |
+
return $attributes;
|
281 |
+
}
|
282 |
+
|
283 |
+
public function getAddressAttributes()
|
284 |
+
{
|
285 |
+
$attributes = $this->_getAddressAttributes();
|
286 |
+
$checkoutAddress = $this->_getCheckoutAddress();
|
287 |
+
foreach ($checkoutAddress as $attribute) {
|
288 |
+
if (!array_key_exists($attribute['key'], $attributes)) {
|
289 |
+
$attributes[$attribute['key']] = $attribute;
|
290 |
+
}
|
291 |
+
}
|
292 |
+
foreach ($attributes as $k => $attribute) {
|
293 |
+
if (in_array($attribute['key'], $this->_excludeAddressAttributes) || in_array($attribute['key'], $this->_excludeCustomerAttributes)) {
|
294 |
+
unset($attributes[$k]);
|
295 |
+
}
|
296 |
+
}
|
297 |
+
return $attributes;
|
298 |
+
}
|
299 |
+
|
300 |
+
protected function _getCheckoutAddress()
|
301 |
+
{
|
302 |
+
/** @var $customerForm Mage_Customer_Model_Form */
|
303 |
+
$customerForm = Mage::getModel('customer/form');
|
304 |
+
$customerForm->setFormCode('checkout_register');
|
305 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
306 |
+
$customer = Mage::getModel('customer/customer');
|
307 |
+
$customerForm->setEntity($customer);
|
308 |
+
$attributes = array();
|
309 |
+
foreach ($customerForm->getAttributes() as $attribute) {
|
310 |
+
if ($item = $this->_processAttribute($attribute)) {
|
311 |
+
$attributes[$item['key']] = $item;
|
312 |
+
}
|
313 |
+
}
|
314 |
+
return $attributes;
|
315 |
+
}
|
316 |
+
|
317 |
+
protected function _getCustomerAttributes($storeId = null)
|
318 |
+
{
|
319 |
+
$attributes = array();
|
320 |
+
/* @var $customerForm Mage_Customer_Model_Form */
|
321 |
+
$customerForm = Mage::getModel('customer/form');
|
322 |
+
$customerForm->setFormCode('customer_account_create');
|
323 |
+
foreach ($customerForm->getAttributes() as $attribute) {
|
324 |
+
if ($item = $this->_processAttribute($attribute)) {
|
325 |
+
$attributes[$item['key']] = $item;
|
326 |
+
}
|
327 |
+
}
|
328 |
+
return $attributes;
|
329 |
+
}
|
330 |
+
|
331 |
+
protected function _getAddressAttributes($storeId = null)
|
332 |
+
{
|
333 |
+
$attributes = array();
|
334 |
+
/* @var $addressForm Mage_Customer_Model_Form */
|
335 |
+
$address = Mage::getModel('customer/address');
|
336 |
+
$addressForm = Mage::getModel('customer/form');
|
337 |
+
$addressForm->setFormCode('customer_register_address');
|
338 |
+
$addressForm->setEntity($address);
|
339 |
+
foreach ($addressForm->getAttributes() as $attribute) {
|
340 |
+
if ($item = $this->_processAttribute($attribute)) {
|
341 |
+
if ($item['key'] == 'street') {
|
342 |
+
$item['display_type'] = 'multi_line';
|
343 |
+
$lines = Mage::helper('customer/address')->getStreetLines();
|
344 |
+
$lines = $lines < 0 ? 1 : $lines;
|
345 |
+
for ($i = 1; $i <= $lines; $i++) {
|
346 |
+
$item['options'][$i] = $item['label'] . ' ' . $i;
|
347 |
+
}
|
348 |
+
$attributes[$item['key']] = $item;
|
349 |
+
} else {
|
350 |
+
$attributes[$item['key']] = $item;
|
351 |
+
}
|
352 |
+
}
|
353 |
+
}
|
354 |
+
return $attributes;
|
355 |
+
}
|
356 |
+
|
357 |
+
protected function _getAdditionalAttributes($storeId = null)
|
358 |
+
{
|
359 |
+
$attributes = array();
|
360 |
+
|
361 |
+
if (Mage::helper('core')->isModuleOutputEnabled('Mage_Newsletter') && !in_array('is_subscribed', $this->_attributes)) {
|
362 |
+
$attributes['is_subscribed'] = array(
|
363 |
+
'key' => 'is_subscribed',
|
364 |
+
'label' => Mage::helper('japi')->__('Sign Up for Newsletter'),
|
365 |
+
'enable' => true,
|
366 |
+
'display_type' => 'checkbox',
|
367 |
+
'required' => false
|
368 |
+
);
|
369 |
+
}
|
370 |
+
|
371 |
+
if (!in_array('password', $this->_attributes)) {
|
372 |
+
$attributes['password'] = array(
|
373 |
+
'key' => 'password',
|
374 |
+
'label' => Mage::helper('japi')->__('Password'),
|
375 |
+
'enable' => true,
|
376 |
+
'display_type' => 'password',
|
377 |
+
'required' => true
|
378 |
+
);
|
379 |
+
}
|
380 |
+
|
381 |
+
if (!in_array('confirmation', $this->_attributes)) {
|
382 |
+
$attributes['confirmation'] = array(
|
383 |
+
'key' => 'confirmation',
|
384 |
+
'label' => Mage::helper('japi')->__('Confirm Password'),
|
385 |
+
'enable' => true,
|
386 |
+
'display_type' => 'password',
|
387 |
+
'required' => true
|
388 |
+
);
|
389 |
+
}
|
390 |
+
|
391 |
+
return $attributes;
|
392 |
+
}
|
393 |
+
|
394 |
+
protected function _getSignupOptions($storeId = null)
|
395 |
+
{
|
396 |
+
$attributes = $this->_getCustomerAttributes($storeId);
|
397 |
+
$includeCustomerAttributes = explode(',', Mage::getStoreConfig('japi/jmango_rest_customer_settings/attributes'));
|
398 |
+
foreach ($attributes as $k => $attribute) {
|
399 |
+
if (!in_array($attribute['key'], $this->_excludeCustomerAttributes) && !in_array($attribute['key'], $includeCustomerAttributes)) {
|
400 |
+
unset($attributes[$k]);
|
401 |
+
}
|
402 |
+
}
|
403 |
+
|
404 |
+
if (Mage::getStoreConfigFlag('japi/jmango_rest_customer_settings/enable_address')) {
|
405 |
+
$addressAttributes = $this->_getAddressAttributes($storeId);
|
406 |
+
$includeAddressAttributes = explode(',', Mage::getStoreConfig('japi/jmango_rest_customer_settings/address_attributes'));
|
407 |
+
foreach ($addressAttributes as $k => $attribute) {
|
408 |
+
if (!in_array($attribute['key'], $this->_excludeAddressAttributes) && !in_array($attribute['key'], $includeAddressAttributes)) {
|
409 |
+
unset($attributes[$k]);
|
410 |
+
}
|
411 |
+
}
|
412 |
+
}
|
413 |
+
|
414 |
+
$additinalAttributes = $this->_getAdditionalAttributes($storeId);
|
415 |
+
foreach ($additinalAttributes as $attribute) {
|
416 |
+
$includeAttributes[] = $attribute['key'];
|
417 |
+
if (!array_key_exists($attribute['key'], $attributes)) {
|
418 |
+
$attributes[$attribute['key']] = $attribute;
|
419 |
+
}
|
420 |
+
}
|
421 |
+
|
422 |
+
return array_values($attributes);
|
423 |
+
}
|
424 |
+
|
425 |
+
public function getAddressField()
|
426 |
+
{
|
427 |
+
return $this->_getAddressOptions();
|
428 |
+
}
|
429 |
+
|
430 |
+
protected function _getAddressOptions($storeId = null)
|
431 |
+
{
|
432 |
+
$attributes = $this->_getAddressAttributes($storeId);
|
433 |
+
$includeAttributes = explode(',', Mage::getStoreConfig('japi/jmango_rest_customer_settings/address_attributes'));
|
434 |
+
foreach ($attributes as $k => $attribute) {
|
435 |
+
if (!in_array($attribute['key'], $this->_excludeAddressAttributes) && !in_array($attribute['key'], $includeAttributes)) {
|
436 |
+
unset($attributes[$k]);
|
437 |
+
}
|
438 |
+
}
|
439 |
+
|
440 |
+
return array_values($attributes);
|
441 |
+
}
|
442 |
+
|
443 |
+
/**
|
444 |
+
* @param $attribute $attribute Mage_Customer_Model_Attribute
|
445 |
+
* @return array|null
|
446 |
+
*/
|
447 |
+
protected function _processAttribute($attribute)
|
448 |
+
{
|
449 |
+
/* @var $eavConfig Mage_Eav_Model_Config */
|
450 |
+
$eavConfig = Mage::getSingleton('eav/config');
|
451 |
+
/* @var $helper Jmango360_Japi_Helper_Data */
|
452 |
+
$helper = Mage::helper('japi');
|
453 |
+
|
454 |
+
try {
|
455 |
+
/* @var $attribute Mage_Customer_Model_Attribute */
|
456 |
+
$attributeCode = $attribute->getAttributeCode();
|
457 |
+
if (!in_array($attributeCode, $this->_attributes)) {
|
458 |
+
$this->_attributes[] = $attributeCode;
|
459 |
+
}
|
460 |
+
/* @var $entityType Mage_Eav_Model_Entity_Type */
|
461 |
+
$entityType = $attribute->getEntityType();
|
462 |
+
$attributeLabel = $helper->__(
|
463 |
+
$eavConfig->getAttribute($entityType->getEntityTypeCode(), $attributeCode)->getStoreLabel()
|
464 |
+
);
|
465 |
+
|
466 |
+
switch ($attribute->getFrontendInput()) {
|
467 |
+
case 'select':
|
468 |
+
$item = array(
|
469 |
+
'key' => $attributeCode,
|
470 |
+
'display_type' => 'drop_down',
|
471 |
+
'label' => $attributeLabel,
|
472 |
+
'enable' => true,
|
473 |
+
'required' => (bool)$attribute->getIsRequired()
|
474 |
+
);
|
475 |
+
if ($attribute->getSource()) {
|
476 |
+
foreach ($attribute->getSource()->getAllOptions() as $option) {
|
477 |
+
$item['options'][$option['value']] = $helper->__($option['label']);
|
478 |
+
}
|
479 |
+
}
|
480 |
+
break;
|
481 |
+
case 'text':
|
482 |
+
$item = array(
|
483 |
+
'key' => $attributeCode,
|
484 |
+
'display_type' => 'field',
|
485 |
+
'label' => $attributeLabel,
|
486 |
+
'enable' => true,
|
487 |
+
'required' => (bool)$attribute->getIsRequired()
|
488 |
+
);
|
489 |
+
break;
|
490 |
+
case 'boolean':
|
491 |
+
$item = array(
|
492 |
+
'key' => $attributeCode,
|
493 |
+
'display_type' => 'checkbox',
|
494 |
+
'label' => $attributeLabel,
|
495 |
+
'enable' => true,
|
496 |
+
'required' => (bool)$attribute->getIsRequired()
|
497 |
+
);
|
498 |
+
break;
|
499 |
+
case 'date':
|
500 |
+
$item = array(
|
501 |
+
'key' => $attributeCode,
|
502 |
+
'display_type' => 'date',
|
503 |
+
'label' => $attributeLabel,
|
504 |
+
'enable' => true,
|
505 |
+
'required' => (bool)$attribute->getIsRequired()
|
506 |
+
);
|
507 |
+
break;
|
508 |
+
case 'multiline':
|
509 |
+
$item = array(
|
510 |
+
'key' => $attributeCode,
|
511 |
+
'display_type' => 'multi_line',
|
512 |
+
'label' => $attributeLabel,
|
513 |
+
'enable' => true,
|
514 |
+
'required' => (bool)$attribute->getIsRequired()
|
515 |
+
);
|
516 |
+
break;
|
517 |
+
case 'multiselect':
|
518 |
+
$item = array(
|
519 |
+
'key' => $attributeCode,
|
520 |
+
'display_type' => 'multi_select',
|
521 |
+
'label' => $attributeLabel,
|
522 |
+
'enable' => true,
|
523 |
+
'required' => (bool)$attribute->getIsRequired()
|
524 |
+
);
|
525 |
+
if ($attribute->getSource()) {
|
526 |
+
foreach ($attribute->getSource()->getAllOptions() as $option) {
|
527 |
+
$item['options'][$option['value']] = $helper->__($option['label']);
|
528 |
+
}
|
529 |
+
}
|
530 |
+
break;
|
531 |
+
default:
|
532 |
+
$item = array(
|
533 |
+
'key' => $attributeCode,
|
534 |
+
'display_type' => 'field',
|
535 |
+
'label' => $attributeLabel,
|
536 |
+
'enable' => true,
|
537 |
+
'required' => (bool)$attribute->getIsRequired()
|
538 |
+
);
|
539 |
+
}
|
540 |
+
|
541 |
+
/* @var $nameBlock Mage_Customer_Block_Widget_Name */
|
542 |
+
$nameBlock = $helper->getBlock('customer/widget_name');
|
543 |
+
$nameBlock->setForceUseCustomerAttributes(true);
|
544 |
+
switch ($attributeCode) {
|
545 |
+
case 'prefix':
|
546 |
+
if (!$nameBlock->showPrefix()) {
|
547 |
+
return null;
|
548 |
+
}
|
549 |
+
if ($nameBlock->getPrefixOptions()) {
|
550 |
+
$item['display_type'] = 'drop_down';
|
551 |
+
foreach ($nameBlock->getPrefixOptions() as $option) {
|
552 |
+
$item['options'][$option] = $option;
|
553 |
+
}
|
554 |
+
}
|
555 |
+
break;
|
556 |
+
case 'middlename':
|
557 |
+
if (!$nameBlock->showMiddlename()) {
|
558 |
+
return null;
|
559 |
+
}
|
560 |
+
break;
|
561 |
+
case 'suffix':
|
562 |
+
if (!$nameBlock->showSuffix()) {
|
563 |
+
return null;
|
564 |
+
}
|
565 |
+
if ($nameBlock->getSuffixOptions()) {
|
566 |
+
$item['display_type'] = 'drop_down';
|
567 |
+
foreach ($nameBlock->getSuffixOptions() as $option) {
|
568 |
+
$item['options'][$option] = $option;
|
569 |
+
}
|
570 |
+
}
|
571 |
+
break;
|
572 |
+
case 'dob':
|
573 |
+
/* @var $dobBlock Mage_Customer_Block_Widget_Dob */
|
574 |
+
$dobBlock = $helper->getBlock('customer/widget_dob');
|
575 |
+
if (!$dobBlock->isEnabled()) {
|
576 |
+
return null;
|
577 |
+
}
|
578 |
+
break;
|
579 |
+
case 'taxvat':
|
580 |
+
/* @var $taxBlock Mage_Customer_Block_Widget_Taxvat */
|
581 |
+
$taxBlock = $helper->getBlock('customer/widget_taxvat');
|
582 |
+
if (!$taxBlock->isEnabled()) {
|
583 |
+
return null;
|
584 |
+
}
|
585 |
+
break;
|
586 |
+
case 'gender':
|
587 |
+
/* @var $genderBlock Mage_Customer_Block_Widget_Gender */
|
588 |
+
$genderBlock = $helper->getBlock('customer/widget_gender');
|
589 |
+
if (!$genderBlock->isEnabled()) {
|
590 |
+
return null;
|
591 |
+
}
|
592 |
+
break;
|
593 |
+
}
|
594 |
+
|
595 |
+
return $item;
|
596 |
+
} catch (Exception $e) {
|
597 |
+
Mage::logException($e);
|
598 |
+
}
|
599 |
+
|
600 |
+
return null;
|
601 |
+
}
|
602 |
+
|
603 |
+
protected function getCurrency($storeId)
|
604 |
+
{
|
605 |
+
$data = array();
|
606 |
+
$data['base'] = Mage::getStoreConfig(self::PATH_CURRENCY_BASE, $storeId);
|
607 |
+
$data['default'] = Mage::getStoreConfig(self::PATH_CURRENCY_DEFAULT, $storeId);
|
608 |
+
$data['allow'] = Mage::getStoreConfig(self::PATH_CURRENCY_ALLOW, $storeId);
|
609 |
+
|
610 |
+
return $data;
|
611 |
+
}
|
612 |
+
|
613 |
+
protected function getGeneralInfo($storeId)
|
614 |
+
{
|
615 |
+
$data = array();
|
616 |
+
|
617 |
+
/* @var $coreHelper Mage_Core_Helper_Data */
|
618 |
+
$coreHelper = Mage::helper('core');
|
619 |
+
if ($coreHelper->isModuleEnabled('Idev_OneStepCheckout') && $coreHelper->isModuleOutputEnabled('Idev_OneStepCheckout')) {
|
620 |
+
$data['default_country'] = Mage::getStoreConfig(self::PATH_IDEV_DEFAULT_COUNTRY, $storeId);
|
621 |
+
if (!$data['default_country']) {
|
622 |
+
$data['default_country'] = Mage::getStoreConfig(self::PATH_DEFAULT_COUNTRY, $storeId);
|
623 |
+
}
|
624 |
+
} else {
|
625 |
+
$data['default_country'] = Mage::getStoreConfig(self::PATH_DEFAULT_COUNTRY, $storeId);
|
626 |
+
}
|
627 |
+
$data['allow_countries'] = Mage::getStoreConfig(self::PATH_COUNTRY_ALLOW, $storeId);
|
628 |
+
$data['optional_zip_countries'] = Mage::getStoreConfig(self::PATH_OPTIONAL_POSTCODE, $storeId);
|
629 |
+
$data['state_required'] = Mage::getStoreConfig(self::PATH_STATE_REQUIRED, $storeId);
|
630 |
+
$data['display_not_required_state'] = Mage::getStoreConfig(self::PATH_DISPLAY_ALL, $storeId);
|
631 |
+
$data['timezone'] = Mage::getStoreConfig(self::PATH_TIMEZONE, $storeId);
|
632 |
+
$data['locale'] = Mage::getStoreConfig(self::PATH_LOCALE, $storeId);
|
633 |
+
$data['guest_checkout'] = Mage::getStoreConfig(self::PATH_GUEST_CHECKOUT, $storeId);
|
634 |
+
|
635 |
+
// Check wishlist available
|
636 |
+
/* @var $helper Mage_Wishlist_Helper_Data */
|
637 |
+
$helper = Mage::helper('wishlist');
|
638 |
+
$data['enable_wishlist'] = $helper->isAllow() ? 1 : 0;
|
639 |
+
|
640 |
+
return $data;
|
641 |
+
}
|
642 |
+
|
643 |
+
protected function _getPluginVersion()
|
644 |
+
{
|
645 |
+
$class = get_class($this);
|
646 |
+
$parts = explode('_', $class);
|
647 |
+
$module = ucfirst($parts[0]) . '_' . ucfirst($parts[1]);
|
648 |
+
|
649 |
+
$data['result'] = (string)Mage::getConfig()->getNode('modules')->$module->version;
|
650 |
+
|
651 |
+
return $data;
|
652 |
+
}
|
653 |
+
|
654 |
+
protected function _getMagentoInfo()
|
655 |
+
{
|
656 |
+
$data['magento_version'] = Mage::getVersion();
|
657 |
+
$data['magento_edition'] = version_compare(Mage::getVersion(), '1.7.0', '<') ? 'Community' : Mage::getEdition();
|
658 |
+
|
659 |
+
return $data;
|
660 |
+
}
|
661 |
+
|
662 |
+
protected function _getNewSessionId()
|
663 |
+
{
|
664 |
+
$this->_validateRestApiUser();
|
665 |
+
|
666 |
+
/* @var $session Mage_Core_Model_Session */
|
667 |
+
$session = Mage::getSingleton('core/session');
|
668 |
+
$data['session_id'] = $session->getSessionId();
|
669 |
+
|
670 |
+
return $data;
|
671 |
+
}
|
672 |
+
|
673 |
+
protected function _getNewToken()
|
674 |
+
{
|
675 |
+
$this->_validateRestApiUser();
|
676 |
+
|
677 |
+
/*
|
678 |
+
* Token is auto added in the server response
|
679 |
+
*/
|
680 |
+
$data = array();
|
681 |
+
|
682 |
+
return $data;
|
683 |
+
}
|
684 |
+
|
685 |
+
protected function _validateRestApiUser()
|
686 |
+
{
|
687 |
+
/*
|
688 |
+
* @TODO: Maybe move the user test to a rest user class or symply to a japi helper
|
689 |
+
* -- After decided on how complex or simple the user check is going to be
|
690 |
+
*/
|
691 |
+
$request = $this->_getRequest();
|
692 |
+
$requestApiUser = $request->getParam('api_user', null);
|
693 |
+
$requestApiKey = $request->getParam('api_key', null);
|
694 |
+
$systemApiUser = Mage::getStoreConfig(self::APIUSERPATH);
|
695 |
+
$systemApiKey = Mage::getStoreConfig(self::APIKEYPATH);
|
696 |
+
if ($requestApiUser != $systemApiUser || $requestApiKey != $systemApiKey) {
|
697 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Not allowed.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
698 |
+
}
|
699 |
+
|
700 |
+
return true;
|
701 |
+
}
|
702 |
+
|
703 |
+
protected function _store($set = false)
|
704 |
+
{
|
705 |
+
$data = array();
|
706 |
+
|
707 |
+
if ($set) {
|
708 |
+
$option = $this->_getRequest()->getParam('option', null);
|
709 |
+
if (!empty($option)) {
|
710 |
+
switch ($option) {
|
711 |
+
case 'set_current_store':
|
712 |
+
$data = $this->_setCurrentStore();
|
713 |
+
break;
|
714 |
+
default:
|
715 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Set store option %s not found', $option), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
716 |
+
}
|
717 |
+
} else {
|
718 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('Set store option cannot be empty.'), Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
719 |
+
}
|
720 |
+
}
|
721 |
+
|
722 |
+
$storeData = Mage::app()->getStore()->getData();
|
723 |
+
$storeData['store_url'] = Mage::getStoreConfig('web/unsecure/base_url');
|
724 |
+
$storeData['root_category_id'] = Mage::app()->getStore()->getRootCategoryId();
|
725 |
+
|
726 |
+
$data['current'] = $storeData;
|
727 |
+
$data['list'] = array();
|
728 |
+
|
729 |
+
foreach (Mage::app()->getStores() as $storeId => $store) {
|
730 |
+
/* @var $store Mage_Core_Model_Store */
|
731 |
+
$d = $store->getData();
|
732 |
+
$d['store_url'] = Mage::getStoreConfig('web/unsecure/base_url', $store);
|
733 |
+
$d['root_category_id'] = $store->getRootCategoryId();
|
734 |
+
|
735 |
+
$data['list'][] = $d;
|
736 |
+
}
|
737 |
+
|
738 |
+
return $data;
|
739 |
+
}
|
740 |
+
|
741 |
+
protected function _setCurrentStore($data = array())
|
742 |
+
{
|
743 |
+
$storeId = $this->_getRequest()->getParam('store_id', null);
|
744 |
+
if (!is_null($storeId)) {
|
745 |
+
Mage::app()->setCurrentStore($storeId);
|
746 |
+
$data['store_url'] = Mage::getUrl(null, array('_nosid' => true));
|
747 |
+
$data['store_switch'] = '___store=' . Mage::app()->getStore()->getCode();
|
748 |
+
}
|
749 |
+
|
750 |
+
return $data;
|
751 |
+
}
|
752 |
+
|
753 |
+
protected function _getRequest()
|
754 |
+
{
|
755 |
+
return $this->_getServer()->getRequest();
|
756 |
+
}
|
757 |
+
|
758 |
+
protected function _getResponse()
|
759 |
+
{
|
760 |
+
return $this->_getServer()->getResponse();
|
761 |
+
}
|
762 |
+
|
763 |
+
/**
|
764 |
+
* @return Jmango360_Japi_Model_Server
|
765 |
+
*/
|
766 |
+
protected function _getServer()
|
767 |
+
{
|
768 |
+
return Mage::getSingleton('japi/server');
|
769 |
+
}
|
770 |
+
|
771 |
+
protected function _getCatalogInfo($storeId)
|
772 |
+
{
|
773 |
+
$data = array();
|
774 |
+
$data['show_stock_info'] = Mage::getStoreConfigFlag(self::PATH_SHOW_STOCK_INFO, $storeId) ? 1 : 0;
|
775 |
+
|
776 |
+
return $data;
|
777 |
+
}
|
778 |
+
|
779 |
+
protected function _updateTheme()
|
780 |
+
{
|
781 |
+
$this->_validateRestApiUser();
|
782 |
+
|
783 |
+
$data = $this->_getRequest()->getRawBody();
|
784 |
+
|
785 |
+
$config = Mage::app()->getConfig();
|
786 |
+
$config->saveConfig(self::PATH_THEME_CONFIG, $data);
|
787 |
+
$cache = Mage::app()->getCache();
|
788 |
+
$cache->save($data, 'japi_checkout_theme', array(Mage_Core_Model_Config::CACHE_TAG), null);
|
789 |
+
|
790 |
+
$out = array('success' => true, 'message' => 'OK');
|
791 |
+
return $out;
|
792 |
+
}
|
793 |
+
|
794 |
+
protected function _getTheme()
|
795 |
+
{
|
796 |
+
$cache = Mage::app()->getCache();
|
797 |
+
$data = $cache->load('japi_checkout_theme');
|
798 |
+
if (!$data) {
|
799 |
+
$data = Mage::getStoreConfig(self::PATH_THEME_CONFIG, 0);
|
800 |
+
}
|
801 |
+
|
802 |
+
return array('data' => $data);
|
803 |
+
}
|
804 |
+
|
805 |
+
public function getThemeData()
|
806 |
+
{
|
807 |
+
$result = $this->_getTheme();
|
808 |
+
return isset($result['data']) ? $result['data'] : '{}';
|
809 |
+
}
|
810 |
+
|
811 |
+
protected function _getOrders()
|
812 |
+
{
|
813 |
+
/* @var $model Jmango360_Japi_Model_Rest_Customer_Order_List */
|
814 |
+
$model = Mage::getModel('japi/rest_customer_order_list');
|
815 |
+
$data = $model->getJapiOrders();
|
816 |
+
return $data;
|
817 |
+
}
|
818 |
+
|
819 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Product.php
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Product extends Mage_Core_Model_Abstract
|
4 |
+
{
|
5 |
+
public function dispatch()
|
6 |
+
{
|
7 |
+
$action = $this->_getRequest()->getAction();
|
8 |
+
$operation = $this->_getRequest()->getOperation();
|
9 |
+
|
10 |
+
switch ($action . $operation) {
|
11 |
+
case 'list' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
12 |
+
$data = $this->_getProductList();
|
13 |
+
$this->_getResponse()->render($data);
|
14 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
15 |
+
break;
|
16 |
+
case 'detail' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
17 |
+
$data = $this->_getProductDetail();
|
18 |
+
$this->_getResponse()->render($data);
|
19 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
20 |
+
break;
|
21 |
+
case 'search' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
22 |
+
$data = $this->_getProductSearch();
|
23 |
+
$this->_getResponse()->render($data);
|
24 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
25 |
+
break;
|
26 |
+
case 'getRecentlyViewed' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
27 |
+
$data = $this->_getRecentlyViewed();
|
28 |
+
$this->_getResponse()->render($data);
|
29 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
30 |
+
break;
|
31 |
+
case 'getRecentlyPurchased' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
32 |
+
$data = $this->_getRecentlyPurchased();
|
33 |
+
$this->_getResponse()->render($data);
|
34 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
35 |
+
break;
|
36 |
+
case 'suggest' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
37 |
+
$data = $this->_getProductSuggest();
|
38 |
+
$this->_getResponse()->render($data);
|
39 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
40 |
+
break;
|
41 |
+
default:
|
42 |
+
throw new Jmango360_Japi_Exception(
|
43 |
+
Mage::helper('japi')->__('Resource method not implemented'),
|
44 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
45 |
+
);
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
protected function _getProductList()
|
50 |
+
{
|
51 |
+
/* @var $model Jmango360_Japi_Model_Rest_Product_List */
|
52 |
+
$model = Mage::getModel('japi/rest_product_list');
|
53 |
+
$data = $model->getList();
|
54 |
+
|
55 |
+
return $data;
|
56 |
+
}
|
57 |
+
|
58 |
+
protected function _getProductSearch()
|
59 |
+
{
|
60 |
+
/* @var $model Jmango360_Japi_Model_Rest_Product_Search */
|
61 |
+
$model = Mage::getModel('japi/rest_product_search');
|
62 |
+
$data = $model->getList();
|
63 |
+
|
64 |
+
return $data;
|
65 |
+
}
|
66 |
+
|
67 |
+
protected function _getProductSuggest()
|
68 |
+
{
|
69 |
+
/* @var $model Jmango360_Japi_Model_Rest_Product_Search */
|
70 |
+
$model = Mage::getModel('japi/rest_product_search');
|
71 |
+
$data = $model->getSuggest();
|
72 |
+
|
73 |
+
return $data;
|
74 |
+
}
|
75 |
+
|
76 |
+
protected function _getProductDetail()
|
77 |
+
{
|
78 |
+
$id = $this->_getRequest()->getParam('product_id', 0);
|
79 |
+
|
80 |
+
if (!$id || !is_numeric($id) || $id <= 0) {
|
81 |
+
throw new Jmango360_Japi_Exception(
|
82 |
+
Mage::helper('japi')->__('Product ID invalid'),
|
83 |
+
Jmango360_Japi_Model_Request::HTTP_BAD_REQUEST
|
84 |
+
);
|
85 |
+
}
|
86 |
+
|
87 |
+
$product = Mage::getModel('catalog/product')->load($id, array('sku'));
|
88 |
+
if (!$product->getId()) {
|
89 |
+
throw new Jmango360_Japi_Exception(
|
90 |
+
Mage::helper('japi')->__('Product not found'),
|
91 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
92 |
+
);
|
93 |
+
}
|
94 |
+
|
95 |
+
Mage::dispatchEvent('catalog_controller_product_view', array('product' => $product));
|
96 |
+
|
97 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
98 |
+
$helper = Mage::helper('japi/product');
|
99 |
+
$data['product'] = $helper->convertProductIdToApiResponseV2($id);
|
100 |
+
if (!$data['product']) {
|
101 |
+
throw new Jmango360_Japi_Exception(
|
102 |
+
Mage::helper('japi')->__('Product not found'),
|
103 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
104 |
+
);
|
105 |
+
}
|
106 |
+
|
107 |
+
return $data;
|
108 |
+
}
|
109 |
+
|
110 |
+
protected function _getRecentlyViewed()
|
111 |
+
{
|
112 |
+
/* @var $model Jmango360_Japi_Model_Rest_Product_Viewed */
|
113 |
+
$model = Mage::getModel('japi/rest_product_viewed');
|
114 |
+
$data = $model->getList();
|
115 |
+
|
116 |
+
return $data;
|
117 |
+
}
|
118 |
+
|
119 |
+
protected function _getRecentlyPurchased()
|
120 |
+
{
|
121 |
+
if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
|
122 |
+
throw new Jmango360_Japi_Exception(
|
123 |
+
Mage::helper('japi')->__('Please login first!'),
|
124 |
+
Jmango360_Japi_Model_Request::HTTP_BAD_REQUEST
|
125 |
+
);
|
126 |
+
}
|
127 |
+
/* @var $model Jmango360_Japi_Model_Rest_Product_Purchased */
|
128 |
+
$model = Mage::getModel('japi/rest_product_purchased');
|
129 |
+
$data = $model->getList();
|
130 |
+
|
131 |
+
return $data;
|
132 |
+
}
|
133 |
+
|
134 |
+
protected function _getRequest()
|
135 |
+
{
|
136 |
+
return $this->_getServer()->getRequest();
|
137 |
+
}
|
138 |
+
|
139 |
+
protected function _getResponse()
|
140 |
+
{
|
141 |
+
return $this->_getServer()->getResponse();
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* @return Jmango360_Japi_Model_Server
|
146 |
+
*/
|
147 |
+
protected function _getServer()
|
148 |
+
{
|
149 |
+
return Mage::getSingleton('japi/server');
|
150 |
+
}
|
151 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Product/List.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Product_List extends Jmango360_Japi_Model_Rest_Catalog_Category_Assignedproducts
|
4 |
+
{
|
5 |
+
public function getList()
|
6 |
+
{
|
7 |
+
$category = $this->_initCategory();
|
8 |
+
|
9 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
10 |
+
$helper = Mage::helper('japi/product');
|
11 |
+
|
12 |
+
if (is_object($category) && $category->getId()) {
|
13 |
+
$block = $this->_getListBlock();
|
14 |
+
$productCollection = $block->getLayer()->getProductCollection();
|
15 |
+
|
16 |
+
/* @var $resource Mage_Core_Model_Resource */
|
17 |
+
$resource = Mage::getSingleton('core/resource');
|
18 |
+
$productCollection->getSelect()
|
19 |
+
->join(
|
20 |
+
array('p' => $resource->getTableName('catalog/product')),
|
21 |
+
sprintf(
|
22 |
+
'e.entity_id = p.entity_id AND p.type_id IN (%s)',
|
23 |
+
join(',', array('"simple"', '"configurable"', '"grouped"', '"bundle"'))
|
24 |
+
),
|
25 |
+
null
|
26 |
+
);
|
27 |
+
|
28 |
+
if (!$productCollection->getSize()) {
|
29 |
+
$data['message'] = Mage::helper('japi')->__('No products found.');
|
30 |
+
}
|
31 |
+
|
32 |
+
$data['filters'] = $this->_getFilters();
|
33 |
+
$helper->addPageSettings($productCollection);
|
34 |
+
$data['toolbar_info'] = $helper->getToolBarInfo($productCollection);
|
35 |
+
/**
|
36 |
+
* Add group by product's ID to collection
|
37 |
+
*/
|
38 |
+
if (version_compare(Mage::getVersion(), '1.9.2.1', '>')) {
|
39 |
+
$productCollection->getSelect()->group('e.entity_id');
|
40 |
+
}
|
41 |
+
|
42 |
+
$productCollection->clear();
|
43 |
+
$data['products'] = $helper->convertProductCollectionToApiResponseV2($productCollection);
|
44 |
+
} else {
|
45 |
+
throw new Jmango360_Japi_Exception(
|
46 |
+
Mage::helper('japi')->__('Category not found.'),
|
47 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
48 |
+
);
|
49 |
+
}
|
50 |
+
|
51 |
+
return $data;
|
52 |
+
}
|
53 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Product/Purchased.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Product_Purchased extends Jmango360_Japi_Model_Rest_Product
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Get list purchased products of current logged in customer
|
7 |
+
* @return array
|
8 |
+
* @throws Jmango360_Japi_Exception
|
9 |
+
*/
|
10 |
+
public function getList()
|
11 |
+
{
|
12 |
+
$data = array();
|
13 |
+
|
14 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
15 |
+
$helper = Mage::helper('japi/product');
|
16 |
+
$_productIds = $this->_getPurchasedProductIds();
|
17 |
+
if (!count($_productIds)) {
|
18 |
+
$data['message'] = $helper->__('No products found.');
|
19 |
+
}
|
20 |
+
|
21 |
+
$data['products'] = $helper->convertProductIdsToApiResponse($_productIds);
|
22 |
+
|
23 |
+
return $data;
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Get recently purchased product IDs of current logged in customer
|
28 |
+
* @return array
|
29 |
+
* @throws Jmango360_Japi_Exception
|
30 |
+
*/
|
31 |
+
protected function _getPurchasedProductIds()
|
32 |
+
{
|
33 |
+
$_data = array();
|
34 |
+
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
35 |
+
if (!Mage::getSingleton('customer/session')->getCustomer()->getId()) {
|
36 |
+
throw new Jmango360_Japi_Exception(
|
37 |
+
Mage::helper('japi')->__('Cannot find customer ID, please try again!'),
|
38 |
+
Jmango360_Japi_Model_Request::HTTP_BAD_REQUEST
|
39 |
+
);
|
40 |
+
}
|
41 |
+
|
42 |
+
$_customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
|
43 |
+
$orders = Mage::getModel('sales/order')->getCollection()
|
44 |
+
->addAttributeToFilter('customer_id', $_customerId)
|
45 |
+
->setOrder('entity_id', 'DESC');
|
46 |
+
|
47 |
+
foreach ($orders as $order) {
|
48 |
+
if (count($_data) >= 5) {
|
49 |
+
break;
|
50 |
+
}
|
51 |
+
|
52 |
+
/* @var $order Mage_Sales_Model_Order */
|
53 |
+
$order = Mage::getModel("sales/order")->load($order->getId());
|
54 |
+
$items = $order->getAllVisibleItems();
|
55 |
+
|
56 |
+
foreach ($items as $item) {
|
57 |
+
/* @var $item Mage_Sales_Model_Order_Item */
|
58 |
+
if ($item->getProductId() && !in_array($item->getProductId(), $_data)) {
|
59 |
+
$_data[] = $item->getProductId();
|
60 |
+
}
|
61 |
+
if (count($_data) >= 5) {
|
62 |
+
break;
|
63 |
+
}
|
64 |
+
}
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
return $_data;
|
69 |
+
}
|
70 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Product/Search.php
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Product_Search extends Jmango360_Japi_Model_Rest_Catalog_Search_Products
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Get search result
|
7 |
+
*/
|
8 |
+
public function getList()
|
9 |
+
{
|
10 |
+
/* @var $searchHelper Mage_CatalogSearch_Helper_Data */
|
11 |
+
$searchHelper = Mage::helper('catalogsearch');
|
12 |
+
/* @var $query Mage_CatalogSearch_Model_Query */
|
13 |
+
$query = $searchHelper->getQuery();
|
14 |
+
|
15 |
+
$query->setStoreId(Mage::app()->getStore()->getId());
|
16 |
+
$data = array();
|
17 |
+
if ($query->getQueryText() != '') {
|
18 |
+
if ($searchHelper->isMinQueryLength()) {
|
19 |
+
$query->setId(0)
|
20 |
+
->setIsActive(1)
|
21 |
+
->setIsProcessed(1);
|
22 |
+
} else {
|
23 |
+
if ($query->getId()) {
|
24 |
+
$query->setPopularity($query->getPopularity() + 1);
|
25 |
+
} else {
|
26 |
+
$query->setPopularity(1);
|
27 |
+
}
|
28 |
+
|
29 |
+
$query->prepare();
|
30 |
+
}
|
31 |
+
|
32 |
+
$helper = Mage::helper('japi/product');
|
33 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
34 |
+
$block = $this->_getSearchLayerBlock();
|
35 |
+
/* @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
|
36 |
+
$productCollection = $block->getLayer()->getProductCollection();
|
37 |
+
|
38 |
+
/* @var $resource Mage_Core_Model_Resource */
|
39 |
+
$resource = Mage::getSingleton('core/resource');
|
40 |
+
$productCollection->getSelect()->join(
|
41 |
+
array('p' => $resource->getTableName('catalog/product')),
|
42 |
+
sprintf(
|
43 |
+
'e.entity_id = p.entity_id AND p.type_id IN (%s)',
|
44 |
+
join(',', array('"simple"', '"configurable"', '"grouped"', '"bundle"'))
|
45 |
+
),
|
46 |
+
null
|
47 |
+
);
|
48 |
+
|
49 |
+
if (!$productCollection->getSize()) {
|
50 |
+
$data['message'] = $searchHelper->__('Your search returns no results.');
|
51 |
+
}
|
52 |
+
|
53 |
+
$data['filters'] = $this->_getFilters($block);
|
54 |
+
$helper->addPageSettings($productCollection);
|
55 |
+
$data['toolbar_info'] = $helper->getToolBarInfo($productCollection, true);
|
56 |
+
/**
|
57 |
+
* Add group by product's ID to collection
|
58 |
+
*/
|
59 |
+
if (version_compare(Mage::getVersion(), '1.9.2.1', '>')) {
|
60 |
+
$productCollection->getSelect()->group('e.entity_id');
|
61 |
+
}
|
62 |
+
|
63 |
+
$productCollection->clear();
|
64 |
+
$data['products'] = $helper->convertProductCollectionToApiResponseV2($productCollection);
|
65 |
+
|
66 |
+
$searchHelper->checkNotes();
|
67 |
+
$messages = $searchHelper->getNoteMessages();
|
68 |
+
if (!empty($messages)) {
|
69 |
+
$data['message'] .= implode("\n", (array)$messages);
|
70 |
+
}
|
71 |
+
|
72 |
+
if (!$searchHelper->isMinQueryLength()) {
|
73 |
+
$query->save();
|
74 |
+
}
|
75 |
+
} else {
|
76 |
+
throw new Jmango360_Japi_Exception(
|
77 |
+
$searchHelper->__('Query cannot be empty.'),
|
78 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
79 |
+
);
|
80 |
+
}
|
81 |
+
|
82 |
+
return $data;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Get fast search result
|
87 |
+
*/
|
88 |
+
public function getSuggest()
|
89 |
+
{
|
90 |
+
/* @var $searchHelper Mage_CatalogSearch_Helper_Data */
|
91 |
+
$searchHelper = Mage::helper('catalogsearch');
|
92 |
+
/* @var $query Mage_CatalogSearch_Model_Query */
|
93 |
+
$query = $searchHelper->getQuery();
|
94 |
+
$query->setStoreId(Mage::app()->getStore()->getId());
|
95 |
+
$data = array();
|
96 |
+
|
97 |
+
if ($query->getQueryText() != '') {
|
98 |
+
if ($searchHelper->isMinQueryLength()) {
|
99 |
+
$query->setId(0)->setIsActive(1)->setIsProcessed(1);
|
100 |
+
} else {
|
101 |
+
if ($query->getId()) {
|
102 |
+
$query->setPopularity($query->getPopularity() + 1);
|
103 |
+
} else {
|
104 |
+
$query->setPopularity(1);
|
105 |
+
}
|
106 |
+
$query->prepare();
|
107 |
+
}
|
108 |
+
|
109 |
+
$helper = Mage::helper('japi/product');
|
110 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
111 |
+
$block = $this->_getSearchLayerBlock();
|
112 |
+
/* @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
|
113 |
+
$productCollection = $block->getLayer()->getProductCollection();
|
114 |
+
/* @var $resource Mage_Core_Model_Resource */
|
115 |
+
$resource = Mage::getSingleton('core/resource');
|
116 |
+
|
117 |
+
$productCollection->getSelect()->join(
|
118 |
+
array('p' => $resource->getTableName('catalog/product')),
|
119 |
+
sprintf(
|
120 |
+
'e.entity_id = p.entity_id AND p.type_id IN (%s)',
|
121 |
+
join(',', array('"simple"', '"configurable"', '"grouped"', '"bundle"'))
|
122 |
+
),
|
123 |
+
null
|
124 |
+
);
|
125 |
+
|
126 |
+
if (!$productCollection->getSize()) {
|
127 |
+
$data['message'] = $searchHelper->__('Your search returns no results.');
|
128 |
+
}
|
129 |
+
|
130 |
+
$helper->addPageSettings($productCollection);
|
131 |
+
$helper->getToolBarInfo($productCollection, true);
|
132 |
+
|
133 |
+
$data['products'] = $helper->convertSuggestProductCollectionToApiResponse($productCollection);
|
134 |
+
|
135 |
+
$searchHelper->checkNotes();
|
136 |
+
$messages = $searchHelper->getNoteMessages();
|
137 |
+
if (!empty($messages)) {
|
138 |
+
$data['message'] .= implode("\n", (array)$messages);
|
139 |
+
}
|
140 |
+
|
141 |
+
if (!$searchHelper->isMinQueryLength()) {
|
142 |
+
$query->save();
|
143 |
+
}
|
144 |
+
} else {
|
145 |
+
throw new Jmango360_Japi_Exception(
|
146 |
+
$searchHelper->__('Query cannot be empty.'),
|
147 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
148 |
+
);
|
149 |
+
}
|
150 |
+
|
151 |
+
return $data;
|
152 |
+
}
|
153 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Product/Viewed.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Product_Viewed extends Jmango360_Japi_Model_Rest_Product
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Get list recently viewed products
|
7 |
+
* @return array
|
8 |
+
*/
|
9 |
+
public function getList()
|
10 |
+
{
|
11 |
+
$data = array();
|
12 |
+
|
13 |
+
$block = $this->_getViewedBlock();
|
14 |
+
|
15 |
+
/* @var $_collection Mage_Reports_Model_Resource_Product_Index_Collection_Abstract */
|
16 |
+
$_collection = $block->getItemsCollection();
|
17 |
+
|
18 |
+
if (!$_collection->getSize()) {
|
19 |
+
$data['message'] = Mage::helper('japi')->__('No products found.');
|
20 |
+
}
|
21 |
+
|
22 |
+
foreach ($_collection as $item) {
|
23 |
+
/* @var $item Mage_Catalog_Model_Product */
|
24 |
+
if ($item->getId()) {
|
25 |
+
$ids[] = $item->getId();
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
if (!empty($ids)) {
|
30 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
31 |
+
$helper = Mage::helper('japi/product');
|
32 |
+
$data['products'][] = $helper->convertProductIdsToApiResponse($ids);
|
33 |
+
}
|
34 |
+
|
35 |
+
return $data;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @return Mage_Reports_Block_Product_Viewed
|
40 |
+
*/
|
41 |
+
protected function _getViewedBlock()
|
42 |
+
{
|
43 |
+
return Mage::app()->getLayout()->createBlock('Mage_Reports_Block_Product_Viewed');
|
44 |
+
}
|
45 |
+
}
|
app/code/community/Jmango360/Japi/Model/Rest/Wishlist.php
ADDED
@@ -0,0 +1,662 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Rest_Wishlist extends Mage_Core_Model_Abstract
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Filter to convert localized values to internal ones
|
7 |
+
* @var Zend_Filter_LocalizedToNormalized
|
8 |
+
*/
|
9 |
+
protected $_localFilter = null;
|
10 |
+
|
11 |
+
protected $_wishlist;
|
12 |
+
|
13 |
+
public function dispatch()
|
14 |
+
{
|
15 |
+
$action = $this->_getRequest()->getAction();
|
16 |
+
$operation = $this->_getRequest()->getOperation();
|
17 |
+
|
18 |
+
switch ($action . $operation) {
|
19 |
+
case 'getItems' . Jmango360_Japi_Model_Request::OPERATION_RETRIEVE:
|
20 |
+
$data = $this->_getItems();
|
21 |
+
$this->_getResponse()->render($data);
|
22 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
23 |
+
break;
|
24 |
+
case 'add' . Jmango360_Japi_Model_Request::OPERATION_CREATE:
|
25 |
+
$data = $this->_addItem();
|
26 |
+
$this->_getResponse()->render($data);
|
27 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
28 |
+
break;
|
29 |
+
case 'update' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
30 |
+
$data = $this->_updateItem();
|
31 |
+
$this->_getResponse()->render($data);
|
32 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
33 |
+
break;
|
34 |
+
case 'remove' . Jmango360_Japi_Model_Request::OPERATION_DELETE:
|
35 |
+
$data = $this->_removeItem();
|
36 |
+
$this->_getResponse()->render($data);
|
37 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
38 |
+
break;
|
39 |
+
case 'updateItemOptions' . Jmango360_Japi_Model_Request::OPERATION_UPDATE:
|
40 |
+
$data = $this->_updateItemOptions();
|
41 |
+
$this->_getResponse()->render($data);
|
42 |
+
$this->_getResponse()->setHttpResponseCode(Jmango360_Japi_Model_Server::HTTP_OK);
|
43 |
+
break;
|
44 |
+
default:
|
45 |
+
throw new Jmango360_Japi_Exception(
|
46 |
+
Mage::helper('japi')->__('Resource method not implemented'),
|
47 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
48 |
+
);
|
49 |
+
break;
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
protected function _updateItemOptions()
|
54 |
+
{
|
55 |
+
$wishlist = $this->_getWishlist();
|
56 |
+
$productId = (int)$this->_getRequest()->getParam('product');
|
57 |
+
$product = Mage::getModel('catalog/product')->load($productId);
|
58 |
+
if (!$product->getId() || !$product->isVisibleInCatalog()) {
|
59 |
+
throw new Jmango360_Japi_Exception(
|
60 |
+
Mage::helper('wishlist')->__('Cannot specify product.'),
|
61 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
62 |
+
);
|
63 |
+
}
|
64 |
+
|
65 |
+
try {
|
66 |
+
$id = (int)$this->_getRequest()->getParam('id');
|
67 |
+
/* @var $item Mage_Wishlist_Model_Item */
|
68 |
+
$item = Mage::getModel('wishlist/item')->load($id);
|
69 |
+
|
70 |
+
if (!$item->getId()) {
|
71 |
+
throw new Jmango360_Japi_Exception(
|
72 |
+
Mage::helper('wishlist')->__('Item not found'),
|
73 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
74 |
+
);
|
75 |
+
}
|
76 |
+
|
77 |
+
$buyRequest = new Varien_Object($this->_getRequest()->getParams());
|
78 |
+
$result = $this->updateWishlistItem($wishlist, $id, $buyRequest);
|
79 |
+
|
80 |
+
Mage::helper('wishlist')->calculate();
|
81 |
+
Mage::dispatchEvent('wishlist_update_item', array(
|
82 |
+
'wishlist' => $wishlist, 'product' => $product, 'item' => $wishlist->getItem($id)
|
83 |
+
));
|
84 |
+
Mage::helper('wishlist')->calculate();
|
85 |
+
|
86 |
+
$data = array(
|
87 |
+
'messages' => array(
|
88 |
+
'success' => array(
|
89 |
+
array(
|
90 |
+
'code' => Jmango360_Japi_Model_Request::HTTP_OK,
|
91 |
+
'message' => Mage::helper('japi')->__('%1$s has been updated in your wishlist.', $product->getName())
|
92 |
+
)
|
93 |
+
)
|
94 |
+
),
|
95 |
+
'item' => $this->_convertWishlistItemToApiResponse($result)
|
96 |
+
);
|
97 |
+
} catch (Jmango360_Japi_Exception $e) {
|
98 |
+
throw new Jmango360_Japi_Exception(
|
99 |
+
Mage::helper('japi')->__($e->getMessage()),
|
100 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
101 |
+
);
|
102 |
+
} catch (Exception $e) {
|
103 |
+
throw new Jmango360_Japi_Exception(
|
104 |
+
Mage::helper('japi')->__('An error occurred while updating wishlist.'),
|
105 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
106 |
+
);
|
107 |
+
}
|
108 |
+
|
109 |
+
return $data;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Update wishlist Item and set data from request
|
114 |
+
*
|
115 |
+
* $params sets how current item configuration must be taken into account and additional options.
|
116 |
+
* It's passed to Mage_Catalog_Helper_Product->addParamsToBuyRequest() to compose resulting buyRequest.
|
117 |
+
*
|
118 |
+
* Basically it can hold
|
119 |
+
* - 'current_config', Varien_Object or array - current buyRequest that configures product in this item,
|
120 |
+
* used to restore currently attached files
|
121 |
+
* - 'files_prefix': string[a-z0-9_] - prefix that was added at frontend to names of file options (file inputs), so they won't
|
122 |
+
* intersect with other submitted options
|
123 |
+
*
|
124 |
+
* For more options see Mage_Catalog_Helper_Product->addParamsToBuyRequest()
|
125 |
+
*
|
126 |
+
* @param Mage_Wishlist_Model_Wishlist $wishlist
|
127 |
+
* @param int|Mage_Wishlist_Model_Item $itemId
|
128 |
+
* @param Varien_Object $buyRequest
|
129 |
+
* @param null|array|Varien_Object $params
|
130 |
+
* @return null|Mage_Wishlist_Model_Item
|
131 |
+
*
|
132 |
+
* @see Mage_Catalog_Helper_Product::addParamsToBuyRequest()
|
133 |
+
*/
|
134 |
+
protected function updateWishlistItem($wishlist, $itemId, $buyRequest, $params = null)
|
135 |
+
{
|
136 |
+
$item = null;
|
137 |
+
if ($itemId instanceof Mage_Wishlist_Model_Item) {
|
138 |
+
$item = $itemId;
|
139 |
+
} else {
|
140 |
+
$item = $wishlist->getItem((int)$itemId);
|
141 |
+
}
|
142 |
+
if (!$item) {
|
143 |
+
Mage::throwException(Mage::helper('wishlist')->__('Cannot specify your wishlist item.'));
|
144 |
+
}
|
145 |
+
|
146 |
+
$product = $item->getProduct();
|
147 |
+
$productId = $product->getId();
|
148 |
+
if ($productId) {
|
149 |
+
if (!$params) {
|
150 |
+
$params = new Varien_Object();
|
151 |
+
} else if (is_array($params)) {
|
152 |
+
$params = new Varien_Object($params);
|
153 |
+
}
|
154 |
+
$params->setCurrentConfig($item->getBuyRequest());
|
155 |
+
$buyRequest = Mage::helper('catalog/product')->addParamsToBuyRequest($buyRequest, $params);
|
156 |
+
|
157 |
+
$product->setWishlistStoreId($item->getStoreId());
|
158 |
+
$items = $wishlist->getItemCollection();
|
159 |
+
$isForceSetQuantity = true;
|
160 |
+
foreach ($items as $_item) {
|
161 |
+
/* @var $_item Mage_Wishlist_Model_Item */
|
162 |
+
if ($_item->getProductId() == $product->getId()
|
163 |
+
&& $_item->representProduct($product)
|
164 |
+
&& $_item->getId() != $item->getId()
|
165 |
+
) {
|
166 |
+
// We do not add new wishlist item, but updating the existing one
|
167 |
+
$isForceSetQuantity = false;
|
168 |
+
}
|
169 |
+
}
|
170 |
+
$resultItem = $wishlist->addNewItem($product, $buyRequest, $isForceSetQuantity);
|
171 |
+
/**
|
172 |
+
* Error message
|
173 |
+
*/
|
174 |
+
if (is_string($resultItem)) {
|
175 |
+
Mage::throwException(Mage::helper('checkout')->__($resultItem));
|
176 |
+
}
|
177 |
+
|
178 |
+
if ($resultItem->getId() != $itemId) {
|
179 |
+
if ($resultItem->getDescription() != $item->getDescription()) {
|
180 |
+
$resultItem->setDescription($item->getDescription())->save();
|
181 |
+
}
|
182 |
+
$item->isDeleted(true);
|
183 |
+
$wishlist->setDataChanges(true);
|
184 |
+
} else {
|
185 |
+
$resultItem->setQty($buyRequest->getQty() * 1);
|
186 |
+
$resultItem->setOrigData('qty', 0);
|
187 |
+
}
|
188 |
+
|
189 |
+
$wishlist->save();
|
190 |
+
return $resultItem;
|
191 |
+
} else {
|
192 |
+
Mage::throwException(Mage::helper('checkout')->__('The product does not exist.'));
|
193 |
+
}
|
194 |
+
}
|
195 |
+
|
196 |
+
protected function _removeItem()
|
197 |
+
{
|
198 |
+
$wishlist = $this->_getWishlist();
|
199 |
+
|
200 |
+
$id = (int)$this->_getRequest()->getParam('item');
|
201 |
+
$item = Mage::getModel('wishlist/item')->load($id);
|
202 |
+
if (!$item->getId()) {
|
203 |
+
throw new Jmango360_Japi_Exception(
|
204 |
+
Mage::helper('wishlist')->__('Item not found'),
|
205 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
206 |
+
);
|
207 |
+
}
|
208 |
+
|
209 |
+
/* @var $helper Mage_Wishlist_Helper_Data */
|
210 |
+
$helper = Mage::helper('wishlist');
|
211 |
+
|
212 |
+
try {
|
213 |
+
$item->delete();
|
214 |
+
$wishlist->save();
|
215 |
+
$data = array(
|
216 |
+
'messages' => array(
|
217 |
+
'success' => array(
|
218 |
+
array(
|
219 |
+
'code' => Jmango360_Japi_Model_Request::HTTP_OK,
|
220 |
+
'message' => Mage::helper('japi')->__('Wishlist item removed')
|
221 |
+
)
|
222 |
+
)
|
223 |
+
),
|
224 |
+
'items' => $this->_getWishlistData()
|
225 |
+
);
|
226 |
+
} catch (Mage_Core_Exception $e) {
|
227 |
+
throw new Jmango360_Japi_Exception(
|
228 |
+
$helper->__('An error occurred while deleting the item from wishlist: %s', $e->getMessage()),
|
229 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
230 |
+
);
|
231 |
+
} catch (Exception $e) {
|
232 |
+
throw new Jmango360_Japi_Exception(
|
233 |
+
$helper->__('An error occurred while deleting the item from wishlist.'),
|
234 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
235 |
+
);
|
236 |
+
}
|
237 |
+
|
238 |
+
$helper->calculate();
|
239 |
+
|
240 |
+
return $data;
|
241 |
+
}
|
242 |
+
|
243 |
+
protected function _updateItem()
|
244 |
+
{
|
245 |
+
$wishlist = $this->_getWishlist();
|
246 |
+
$post = $this->_getRequest()->getParams();
|
247 |
+
$updatedItems = 0;
|
248 |
+
|
249 |
+
if ($post && isset($post['description']) && is_array($post['description'])) {
|
250 |
+
foreach ($post['description'] as $itemId => $description) {
|
251 |
+
/* @var $item Mage_Wishlist_Model_Item */
|
252 |
+
$item = Mage::getModel('wishlist/item')->load($itemId);
|
253 |
+
if ($item->getWishlistId() != $wishlist->getId()) {
|
254 |
+
continue;
|
255 |
+
}
|
256 |
+
|
257 |
+
// Extract new values
|
258 |
+
$description = (string)$description;
|
259 |
+
|
260 |
+
// Check that we need to save
|
261 |
+
if ($item->getDescription() == $description) {
|
262 |
+
continue;
|
263 |
+
}
|
264 |
+
|
265 |
+
try {
|
266 |
+
$item->setDescription($description)->save();
|
267 |
+
$updatedItems++;
|
268 |
+
} catch (Exception $e) {
|
269 |
+
throw new Jmango360_Japi_Exception(
|
270 |
+
Mage::helper('wishlist')->__(
|
271 |
+
'Can\'t save description %s',
|
272 |
+
Mage::helper('core')->escapeHtml($description)
|
273 |
+
),
|
274 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
275 |
+
);
|
276 |
+
}
|
277 |
+
}
|
278 |
+
}
|
279 |
+
|
280 |
+
if ($post && isset($post['qty']) && is_array($post['qty'])) {
|
281 |
+
foreach ($post['qty'] as $itemId => $qty) {
|
282 |
+
/* @var $item Mage_Wishlist_Model_Item */
|
283 |
+
$item = Mage::getModel('wishlist/item')->load($itemId);
|
284 |
+
if ($item->getWishlistId() != $wishlist->getId()) {
|
285 |
+
continue;
|
286 |
+
}
|
287 |
+
|
288 |
+
// Extract new values
|
289 |
+
$qty = $this->_processLocalizedQty($qty);
|
290 |
+
|
291 |
+
if (is_null($qty)) {
|
292 |
+
$qty = $item->getQty();
|
293 |
+
if (!$qty) {
|
294 |
+
$qty = 1;
|
295 |
+
}
|
296 |
+
} elseif (0 == $qty) {
|
297 |
+
try {
|
298 |
+
$item->delete();
|
299 |
+
} catch (Exception $e) {
|
300 |
+
throw new Jmango360_Japi_Exception(
|
301 |
+
Mage::helper('wishlist')->__('Can\'t delete item from wishlist'),
|
302 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
303 |
+
);
|
304 |
+
}
|
305 |
+
}
|
306 |
+
|
307 |
+
// Check that we need to save
|
308 |
+
if ($item->getQty() == $qty) {
|
309 |
+
continue;
|
310 |
+
}
|
311 |
+
|
312 |
+
try {
|
313 |
+
$item->setQty($qty)->save();
|
314 |
+
$updatedItems++;
|
315 |
+
} catch (Exception $e) {
|
316 |
+
throw new Jmango360_Japi_Exception(
|
317 |
+
Mage::helper('wishlist')->__(
|
318 |
+
'Can\'t save qty %s',
|
319 |
+
Mage::helper('core')->escapeHtml($qty)
|
320 |
+
),
|
321 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
322 |
+
);
|
323 |
+
}
|
324 |
+
}
|
325 |
+
}
|
326 |
+
|
327 |
+
// save wishlist model for setting date of last update
|
328 |
+
if ($updatedItems) {
|
329 |
+
try {
|
330 |
+
$wishlist->save();
|
331 |
+
Mage::helper('wishlist')->calculate();
|
332 |
+
$data = array(
|
333 |
+
'messages' => array(
|
334 |
+
'success' => array(
|
335 |
+
array(
|
336 |
+
'code' => Jmango360_Japi_Model_Request::HTTP_OK,
|
337 |
+
'message' => Mage::helper('wishlist')->__('Wishlist updated successfully')
|
338 |
+
)
|
339 |
+
)
|
340 |
+
)
|
341 |
+
);
|
342 |
+
} catch (Exception $e) {
|
343 |
+
throw new Jmango360_Japi_Exception(
|
344 |
+
Mage::helper('wishlist')->__('Can\'t update wishlist'),
|
345 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
346 |
+
);
|
347 |
+
}
|
348 |
+
} else {
|
349 |
+
$data = array(
|
350 |
+
'messages' => array(
|
351 |
+
'success' => array(
|
352 |
+
array(
|
353 |
+
'code' => Jmango360_Japi_Model_Request::HTTP_OK,
|
354 |
+
'message' => Mage::helper('wishlist')->__('No item updated')
|
355 |
+
)
|
356 |
+
)
|
357 |
+
)
|
358 |
+
);
|
359 |
+
}
|
360 |
+
|
361 |
+
return $data;
|
362 |
+
}
|
363 |
+
|
364 |
+
/**
|
365 |
+
* Processes localized qty (entered by user at frontend) into internal php format
|
366 |
+
*
|
367 |
+
* @param string $qty
|
368 |
+
* @return float|int|null
|
369 |
+
*/
|
370 |
+
protected function _processLocalizedQty($qty)
|
371 |
+
{
|
372 |
+
if (!$this->_localFilter) {
|
373 |
+
$this->_localFilter = new Zend_Filter_LocalizedToNormalized(
|
374 |
+
array('locale' => Mage::app()->getLocale()->getLocaleCode())
|
375 |
+
);
|
376 |
+
}
|
377 |
+
$qty = $this->_localFilter->filter((float)$qty);
|
378 |
+
if ($qty < 0) {
|
379 |
+
$qty = null;
|
380 |
+
}
|
381 |
+
return $qty;
|
382 |
+
}
|
383 |
+
|
384 |
+
protected function _addItem()
|
385 |
+
{
|
386 |
+
$wishlist = $this->_getWishlist();
|
387 |
+
|
388 |
+
$productId = (int)$this->_getRequest()->getParam('product');
|
389 |
+
/* @var $product Mage_Catalog_Model_Product */
|
390 |
+
$product = Mage::getModel('catalog/product')->load($productId);
|
391 |
+
if (!$product->getId()) {
|
392 |
+
throw new Jmango360_Japi_Exception(
|
393 |
+
Mage::helper('japi')->__('Cannot specify product'),
|
394 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
395 |
+
);
|
396 |
+
}
|
397 |
+
|
398 |
+
/* @var $helper Mage_Wishlist_Helper_Data */
|
399 |
+
$helper = Mage::helper('wishlist');
|
400 |
+
|
401 |
+
try {
|
402 |
+
$requestParams = $this->_getRequest()->getParams();
|
403 |
+
$buyRequest = new Varien_Object($requestParams);
|
404 |
+
|
405 |
+
$result = $wishlist->addNewItem($product, $buyRequest);
|
406 |
+
if (is_string($result)) {
|
407 |
+
throw new Jmango360_Japi_Exception($result, Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR);
|
408 |
+
}
|
409 |
+
$wishlist->save();
|
410 |
+
|
411 |
+
Mage::dispatchEvent(
|
412 |
+
'wishlist_add_product',
|
413 |
+
array(
|
414 |
+
'wishlist' => $wishlist,
|
415 |
+
'product' => $product,
|
416 |
+
'item' => $result
|
417 |
+
)
|
418 |
+
);
|
419 |
+
|
420 |
+
$helper->calculate();
|
421 |
+
$data = array(
|
422 |
+
'messages' => array(
|
423 |
+
'success' => array(
|
424 |
+
array(
|
425 |
+
'code' => Jmango360_Japi_Model_Request::HTTP_CREATED,
|
426 |
+
'message' => $helper->__('%s has been added to your wishlist.', $product->getName())
|
427 |
+
)
|
428 |
+
)
|
429 |
+
),
|
430 |
+
'item' => $this->_convertWishlistItemToApiResponse($result)
|
431 |
+
);
|
432 |
+
} catch (Mage_Core_Exception $e) {
|
433 |
+
throw new Jmango360_Japi_Exception(
|
434 |
+
$helper->__('An error occurred while adding item to your wishlist: %s', $e->getMessage()),
|
435 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
436 |
+
);
|
437 |
+
} catch (Exception $e) {
|
438 |
+
throw new Jmango360_Japi_Exception(
|
439 |
+
$helper->__('An error occurred while adding item to your wishlist'),
|
440 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
441 |
+
);
|
442 |
+
}
|
443 |
+
|
444 |
+
return $data;
|
445 |
+
}
|
446 |
+
|
447 |
+
protected function _getItems()
|
448 |
+
{
|
449 |
+
$page = (int)$this->_getRequest()->getParam('p', 1);
|
450 |
+
$limit = (int)$this->_getRequest()->getParam('limit', 10);
|
451 |
+
return array('items' => $this->_getWishlistData($page, $limit));
|
452 |
+
}
|
453 |
+
|
454 |
+
protected function _getWishlistData($page = 1, $limit = 10)
|
455 |
+
{
|
456 |
+
$wishlist = $this->_getWishlist();
|
457 |
+
$items = $this->_getWishlistItems($wishlist, $page, $limit);
|
458 |
+
|
459 |
+
$data = array();
|
460 |
+
foreach ($items as $item) {
|
461 |
+
/* @var $item Mage_Wishlist_Model_Item */
|
462 |
+
$data[] = $this->_convertWishlistItemToApiResponse($item);
|
463 |
+
}
|
464 |
+
|
465 |
+
return $data;
|
466 |
+
}
|
467 |
+
|
468 |
+
protected function _convertWishlistItemToApiResponse(Mage_Wishlist_Model_Item $item)
|
469 |
+
{
|
470 |
+
/* @var $helper Jmango360_Japi_Helper_Product */
|
471 |
+
$helper = Mage::helper('japi/product');
|
472 |
+
$data = $item->toArray();
|
473 |
+
// MPLUGIN-758: Grouped product should return qty 1
|
474 |
+
if ($item->getProduct()->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE) {
|
475 |
+
$data['qty'] = 1;
|
476 |
+
}
|
477 |
+
$data['price'] = $item->getProduct()->getFinalPrice();
|
478 |
+
$data['options'] = $this->_getWishlistItemOptions($item);
|
479 |
+
$data['product'] = $helper->convertProductIdToApiResponse($item->getProduct()->getId());
|
480 |
+
if (is_array($data['product']) && $data['product']['type_id'] == 'configurable_scp') {
|
481 |
+
$data['product']['type'] = Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
|
482 |
+
$data['product']['type_id'] = Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
|
483 |
+
}
|
484 |
+
return $data;
|
485 |
+
}
|
486 |
+
|
487 |
+
protected function _getWishlistItemOptions(Mage_Wishlist_Model_Item $item)
|
488 |
+
{
|
489 |
+
$options = array();
|
490 |
+
foreach ($item->getOptions() as $option) {
|
491 |
+
if ($option->getCode() != 'info_buyRequest') {
|
492 |
+
continue;
|
493 |
+
}
|
494 |
+
|
495 |
+
$data = $option->toArray();
|
496 |
+
unset($data['option_id']);
|
497 |
+
unset($data['code']);
|
498 |
+
|
499 |
+
try {
|
500 |
+
$value = unserialize($option->getValue());
|
501 |
+
$data['value'] = $this->_processItemOptions($value, $item);
|
502 |
+
} catch (Exception $e) {
|
503 |
+
Mage::logException($e);
|
504 |
+
$data['value'] = new stdClass();
|
505 |
+
}
|
506 |
+
|
507 |
+
$options = $data;
|
508 |
+
}
|
509 |
+
|
510 |
+
return empty($options) ? new stdClass() : $options;
|
511 |
+
}
|
512 |
+
|
513 |
+
protected function _processItemOptions($options = array(), Mage_Wishlist_Model_Item $item)
|
514 |
+
{
|
515 |
+
switch ($item->getProduct()->getTypeId()) {
|
516 |
+
case 'bundle':
|
517 |
+
if (isset($options['bundle_option']) && is_array($options['bundle_option'])) {
|
518 |
+
foreach ($options['bundle_option'] as $key => $value) {
|
519 |
+
if (empty($value)) {
|
520 |
+
unset($options['bundle_option'][$key]);
|
521 |
+
} elseif (!is_array($value)) {
|
522 |
+
$options['bundle_option'][$key] = array($value);
|
523 |
+
}
|
524 |
+
}
|
525 |
+
}
|
526 |
+
$options['bundle_option'] = empty($options['bundle_option']) ? new stdClass() : $options['bundle_option'];
|
527 |
+
break;
|
528 |
+
case 'grouped':
|
529 |
+
$options['super_group'] = empty($options['super_group']) ? new stdClass() : $options['super_group'];
|
530 |
+
break;
|
531 |
+
case 'configurable':
|
532 |
+
$options['super_attribute'] = empty($options['super_attribute']) ? new stdClass() : $options['super_attribute'];
|
533 |
+
break;
|
534 |
+
}
|
535 |
+
|
536 |
+
if (isset($options['options'])) {
|
537 |
+
foreach ($options['options'] as $key => $value) {
|
538 |
+
if (empty($value)) {
|
539 |
+
unset($options['options'][$key]);
|
540 |
+
} elseif (!is_array($value)) {
|
541 |
+
$options['options'][$key] = array($value);
|
542 |
+
} elseif (isset($value['hour']) || isset($value['day']) || isset($value['type'])) {
|
543 |
+
unset($options['options'][$key]);
|
544 |
+
}
|
545 |
+
}
|
546 |
+
$options['options'] = empty($options['options']) ? new stdClass() : $options['options'];
|
547 |
+
}
|
548 |
+
|
549 |
+
return $options;
|
550 |
+
}
|
551 |
+
|
552 |
+
/**
|
553 |
+
* @param Mage_Wishlist_Model_Wishlist $wishlist
|
554 |
+
* @return Mage_Wishlist_Model_Resource_Item_Collection
|
555 |
+
*/
|
556 |
+
protected function _getItemCollection(Mage_Wishlist_Model_Wishlist $wishlist)
|
557 |
+
{
|
558 |
+
return Mage::getResourceModel('wishlist/item_collection')
|
559 |
+
->addWishlistFilter($wishlist)
|
560 |
+
->addStoreFilter($wishlist->getStore()->getId())
|
561 |
+
->setVisibilityFilter();
|
562 |
+
}
|
563 |
+
|
564 |
+
protected function _getWishlistItems(Mage_Wishlist_Model_Wishlist $wishlist, $page = 1, $limit = 10)
|
565 |
+
{
|
566 |
+
if (!$wishlist) return null;
|
567 |
+
|
568 |
+
/* @var $collection Mage_Wishlist_Model_Resource_Item_Collection */
|
569 |
+
$collection = $wishlist->getItemCollection()
|
570 |
+
->setInStockFilter(true)
|
571 |
+
->setOrder('added_at', 'DESC');
|
572 |
+
|
573 |
+
/* @var $resource Mage_Core_Model_Resource */
|
574 |
+
$resource = Mage::getSingleton('core/resource');
|
575 |
+
$collection->getSelect()
|
576 |
+
->join(
|
577 |
+
array('catalog_product' => $resource->getTableName('catalog/product')),
|
578 |
+
sprintf(
|
579 |
+
'main_table.product_id = catalog_product.entity_id AND catalog_product.type_id IN (%s)',
|
580 |
+
join(',', array('"simple"', '"configurable"', '"grouped"', '"bundle"'))
|
581 |
+
),
|
582 |
+
array('type_id')
|
583 |
+
);
|
584 |
+
|
585 |
+
$collection->getSelect()->limitPage($page, $limit);
|
586 |
+
$collection->setCurPage($page);
|
587 |
+
|
588 |
+
return $collection;
|
589 |
+
}
|
590 |
+
|
591 |
+
protected function _getWishlist($customerId = null)
|
592 |
+
{
|
593 |
+
if (!$this->_isAllow()) {
|
594 |
+
throw new Jmango360_Japi_Exception(
|
595 |
+
Mage::helper('japi')->__('Wishlist not allowed'),
|
596 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
597 |
+
);
|
598 |
+
}
|
599 |
+
|
600 |
+
if (!$this->_wishlist) {
|
601 |
+
if (!$customerId) {
|
602 |
+
$customerId = $this->_getCustomerId();
|
603 |
+
}
|
604 |
+
|
605 |
+
/* @var Mage_Wishlist_Model_Wishlist $wishlist */
|
606 |
+
$wishlist = Mage::getModel('wishlist/wishlist');
|
607 |
+
$wishlist->loadByCustomer($customerId, true);
|
608 |
+
|
609 |
+
if (!$wishlist->getId() || $wishlist->getCustomerId() != $customerId) {
|
610 |
+
throw new Jmango360_Japi_Exception(
|
611 |
+
Mage::helper('japi')->__("Wishlist doesn't exist"),
|
612 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
613 |
+
);
|
614 |
+
}
|
615 |
+
|
616 |
+
$this->_wishlist = $wishlist;
|
617 |
+
}
|
618 |
+
|
619 |
+
return $this->_wishlist;
|
620 |
+
}
|
621 |
+
|
622 |
+
protected function _isAllow()
|
623 |
+
{
|
624 |
+
return Mage::helper('wishlist')->isAllow();
|
625 |
+
}
|
626 |
+
|
627 |
+
protected function _getCustomerId()
|
628 |
+
{
|
629 |
+
$customerId = Mage::getSingleton('customer/session')->getCustomerId();
|
630 |
+
if (!$customerId) {
|
631 |
+
throw new Jmango360_Japi_Exception(
|
632 |
+
Mage::helper('japi')->__('Customer not logged in'),
|
633 |
+
Jmango360_Japi_Model_Request::HTTP_INTERNAL_ERROR
|
634 |
+
);
|
635 |
+
}
|
636 |
+
return $customerId;
|
637 |
+
}
|
638 |
+
|
639 |
+
/**
|
640 |
+
* @return Jmango360_Japi_Model_Request
|
641 |
+
*/
|
642 |
+
protected function _getRequest()
|
643 |
+
{
|
644 |
+
return $this->_getServer()->getRequest();
|
645 |
+
}
|
646 |
+
|
647 |
+
/**
|
648 |
+
* @return Jmango360_Japi_Model_Response
|
649 |
+
*/
|
650 |
+
protected function _getResponse()
|
651 |
+
{
|
652 |
+
return $this->_getServer()->getResponse();
|
653 |
+
}
|
654 |
+
|
655 |
+
/**
|
656 |
+
* @return Jmango360_Japi_Model_Server
|
657 |
+
*/
|
658 |
+
protected function _getServer()
|
659 |
+
{
|
660 |
+
return Mage::helper('japi')->getServer();
|
661 |
+
}
|
662 |
+
}
|
app/code/community/Jmango360/Japi/Model/Server.php
ADDED
@@ -0,0 +1,441 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_Server extends Mage_Api2_Model_Server
|
4 |
+
{
|
5 |
+
const SESSIONIDACTIONNAME = 'getSession';
|
6 |
+
const TOKENACTIONNAME = 'getToken';
|
7 |
+
const CATEGORYCONTROLLERNAME = 'rest_category';
|
8 |
+
const USETOKENPATH = 'japi/jmango_rest_api/use_token';
|
9 |
+
|
10 |
+
protected $_excludeActionFromTokenValidation = array(
|
11 |
+
self::SESSIONIDACTIONNAME,
|
12 |
+
self::TOKENACTIONNAME,
|
13 |
+
'getPluginVersion',
|
14 |
+
'getMagentoInfo',
|
15 |
+
'updateTheme',
|
16 |
+
'success'
|
17 |
+
);
|
18 |
+
|
19 |
+
protected $_excludeControllerFromTokenValidation = array(
|
20 |
+
self::CATEGORYCONTROLLERNAME,
|
21 |
+
);
|
22 |
+
|
23 |
+
protected $_excludeActionFromTokenReturn = array(
|
24 |
+
'getPluginVersion',
|
25 |
+
'getMagentoInfo',
|
26 |
+
'updateTheme'
|
27 |
+
);
|
28 |
+
|
29 |
+
protected $_controllerInstance = null;
|
30 |
+
|
31 |
+
protected $_model;
|
32 |
+
|
33 |
+
public function run()
|
34 |
+
{
|
35 |
+
$request = Mage::app()->getRequest();
|
36 |
+
|
37 |
+
// Log request if needed
|
38 |
+
if (Mage::getStoreConfigFlag('japi/jmango_rest_developer_settings/enable')) {
|
39 |
+
$debug['uri'] = $request->getMethod() . ' ' . $request->getRequestUri();
|
40 |
+
|
41 |
+
/* @var $session Mage_Core_Model_Session */
|
42 |
+
$session = Mage::getSingleton('core/session');
|
43 |
+
$debug['session_id'] = $session->getSessionId();
|
44 |
+
$debug['params'] = $request->getParams();
|
45 |
+
$debug['body'] = $request->getRawBody();
|
46 |
+
|
47 |
+
Mage::log($debug, NULL, 'japi_request.log');
|
48 |
+
}
|
49 |
+
|
50 |
+
// Set current store if exist
|
51 |
+
$storeId = $request->getParam('store_id', null);
|
52 |
+
if ($storeId) {
|
53 |
+
$this->_setCurrentStore($storeId);
|
54 |
+
Mage::getSingleton('core/session')->setData('store_id', $storeId);
|
55 |
+
} else {
|
56 |
+
if ($storeId = Mage::getSingleton('core/session')->getData('store_id')) {
|
57 |
+
$this->_setCurrentStore($storeId);
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
foreach (Mage::app()->getWebsite()->getStores() as $store) {
|
62 |
+
//Storing Flat product config value
|
63 |
+
$session = Mage::getSingleton('core/session');
|
64 |
+
$_flatConfig = Mage::getStoreConfigFlag(Mage_Catalog_Helper_Product_Flat::XML_PATH_USE_PRODUCT_FLAT);
|
65 |
+
$session->setData('use_flat_product_' . $store->getId(), $_flatConfig);
|
66 |
+
|
67 |
+
// Bypass flat product check
|
68 |
+
Mage::app()->getStore($store)->setConfig(Mage_Catalog_Helper_Product_Flat::XML_PATH_USE_PRODUCT_FLAT, 0);
|
69 |
+
|
70 |
+
// Bypass flat category check
|
71 |
+
Mage::app()->getStore($store)->setConfig(Mage_Catalog_Helper_Category_Flat::XML_PATH_IS_ENABLED_FLAT_CATALOG_CATEGORY, 0);
|
72 |
+
}
|
73 |
+
|
74 |
+
// Checkout mobile version
|
75 |
+
$mobileVersion = $request->getParam('version');
|
76 |
+
$isOfflineCart = $mobileVersion ? version_compare($mobileVersion, '2.9', '<') : true;
|
77 |
+
Mage::getSingleton('core/session')->setIsOffilneCart($isOfflineCart);
|
78 |
+
|
79 |
+
// Flag can be used to determine if it is a REST service call
|
80 |
+
$this->_setIsRest();
|
81 |
+
|
82 |
+
// Can not use response object case
|
83 |
+
try {
|
84 |
+
/** @var $response Jmango360_Japi_Model_Response */
|
85 |
+
$response = Mage::getSingleton('japi/response');
|
86 |
+
} catch (Exception $e) {
|
87 |
+
Mage::logException($e);
|
88 |
+
|
89 |
+
if (!headers_sent()) {
|
90 |
+
header('HTTP/1.1 ' . self::HTTP_INTERNAL_ERROR);
|
91 |
+
}
|
92 |
+
|
93 |
+
echo 'Service temporary unavailable';
|
94 |
+
exit;
|
95 |
+
}
|
96 |
+
|
97 |
+
// Can not render errors case
|
98 |
+
try {
|
99 |
+
/** @var $request Jmango360_Japi_Model_Request */
|
100 |
+
$request = Mage::getSingleton('japi/request');
|
101 |
+
/** @var $renderer Jmango360_Japi_Model_Renderer_Json */
|
102 |
+
$renderer = Mage::getModel('japi/renderer_json');
|
103 |
+
} catch (Exception $e) {
|
104 |
+
Mage::logException($e);
|
105 |
+
|
106 |
+
if (!headers_sent()) {
|
107 |
+
header('HTTP/1.1 ' . self::HTTP_INTERNAL_ERROR);
|
108 |
+
}
|
109 |
+
|
110 |
+
echo 'Service temporary unavailable';
|
111 |
+
exit;
|
112 |
+
}
|
113 |
+
|
114 |
+
// Validate the token
|
115 |
+
try {
|
116 |
+
if (!$this->_validateToken()) {
|
117 |
+
$message = Mage::helper('japi')->__('Invalid token');
|
118 |
+
throw new Jmango360_Japi_Exception($message, Jmango360_Japi_Model_Request::REST_INVALID_TOKEN);
|
119 |
+
}
|
120 |
+
} catch (Exception $e) {
|
121 |
+
$this->_renderException($e, $renderer, $response);
|
122 |
+
}
|
123 |
+
|
124 |
+
// Check if the right session ID is set
|
125 |
+
try {
|
126 |
+
if (!$this->_validateSessionId()) {
|
127 |
+
throw new Jmango360_Japi_Exception(
|
128 |
+
Mage::helper('japi')->__('Session expired.'),
|
129 |
+
Jmango360_Japi_Model_Request::REST_SESSION_EXPIRED
|
130 |
+
);
|
131 |
+
}
|
132 |
+
} catch (Exception $e) {
|
133 |
+
$this->_renderException($e, $renderer, $response);
|
134 |
+
}
|
135 |
+
|
136 |
+
try {
|
137 |
+
/*
|
138 |
+
* $response could have an exception in session or token check
|
139 |
+
*/
|
140 |
+
if (!$response->isException()) {
|
141 |
+
$this->_setRequest($request);
|
142 |
+
$this->_setResponse($response);
|
143 |
+
|
144 |
+
if (!$this->getRestDispatchModel() || !is_object($this->getRestDispatchModel())) {
|
145 |
+
throw new Jmango360_Japi_Exception(Mage::helper('japi')->__('No rest model found.'), self::HTTP_INTERNAL_ERROR);
|
146 |
+
}
|
147 |
+
|
148 |
+
$action = Mage::app()->getRequest()->getActionName();
|
149 |
+
if (in_array($action, $this->_excludeActionFromTokenReturn)) {
|
150 |
+
$response->setSkipToken(true);
|
151 |
+
}
|
152 |
+
|
153 |
+
$request->setModel($this->getRestDispatchModel());
|
154 |
+
/* @var $dispatcher Jmango360_Japi_Model_Dispatcher */
|
155 |
+
$dispatcher = Mage::getModel('japi/dispatcher');
|
156 |
+
$dispatcher->dispatch($request, $response);
|
157 |
+
}
|
158 |
+
} catch (Exception $e) {
|
159 |
+
Mage::logException($e);
|
160 |
+
$this->_renderException($e, $renderer, $response);
|
161 |
+
}
|
162 |
+
|
163 |
+
Varien_Profiler::start('japi::server::send_response');
|
164 |
+
$response->sendResponse();
|
165 |
+
Varien_Profiler::stop('japi::server::send_response');
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Remove objects from core/session
|
169 |
+
* -- objects cannot be serialized and the core/session is written/=serialized in the Mage_Core_Model_Resource_Session::__destruct
|
170 |
+
*/
|
171 |
+
$this->unsRequest();
|
172 |
+
$this->unsResponse();
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Make sure response is not send again by Mage, because using the controller function; exit after send response.
|
176 |
+
* -- This prefends some __destruct triggers to work like $this->_saveCollectedStat() in varien autoload
|
177 |
+
* -- this doesnt seem to be a problem
|
178 |
+
* -- With errors the header(location:...) will not be passed, but that is something you cannot use because you dont use a webbrowser
|
179 |
+
* -- Zend_Log writers are not emptied. But these will be populated with the next call.
|
180 |
+
*/
|
181 |
+
exit();
|
182 |
+
}
|
183 |
+
|
184 |
+
protected function _setCurrentStore($storeId)
|
185 |
+
{
|
186 |
+
if (!$storeId) return;
|
187 |
+
if ($storeId == Mage::app()->getStore()->getId()) return;
|
188 |
+
|
189 |
+
// Reset store ID
|
190 |
+
Mage::app()->setCurrentStore($storeId);
|
191 |
+
|
192 |
+
// Reset locale
|
193 |
+
$locale = Mage::app()->getLocale();
|
194 |
+
$locale->setDefaultLocale('');
|
195 |
+
$locale->setLocaleCode($locale->getDefaultLocale());
|
196 |
+
|
197 |
+
// Reset translator
|
198 |
+
$transltor = Mage::app()->getTranslator();
|
199 |
+
$transltor->setLocale($locale->getDefaultLocale());
|
200 |
+
$area = $transltor->getConfig(Mage_Core_Model_Translate::CONFIG_KEY_AREA);
|
201 |
+
$transltor->init($area, true);
|
202 |
+
}
|
203 |
+
|
204 |
+
public static function getApiTypes()
|
205 |
+
{
|
206 |
+
return self::$_apiTypes;
|
207 |
+
}
|
208 |
+
|
209 |
+
public function getRestDispatchModel()
|
210 |
+
{
|
211 |
+
return $this->_model;
|
212 |
+
}
|
213 |
+
|
214 |
+
public function setRestDispatchModel($model)
|
215 |
+
{
|
216 |
+
$this->_model = $model;
|
217 |
+
return $this;
|
218 |
+
}
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Process thrown exception
|
222 |
+
* Generate and set HTTP response code, error message to Response object
|
223 |
+
*
|
224 |
+
* @param Exception $exception
|
225 |
+
* @param Mage_Api2_Model_Renderer_Interface $renderer
|
226 |
+
* @param Mage_Api2_Model_Response $response
|
227 |
+
* @return Mage_Api2_Model_Server
|
228 |
+
*/
|
229 |
+
protected function _renderException(Exception $exception, Mage_Api2_Model_Renderer_Interface $renderer, Mage_Api2_Model_Response $response)
|
230 |
+
{
|
231 |
+
if ($exception instanceof Jmango360_Japi_Exception && $exception->getCode()) {
|
232 |
+
$httpCode = $exception->getCode();
|
233 |
+
} else {
|
234 |
+
$httpCode = self::HTTP_INTERNAL_ERROR;
|
235 |
+
}
|
236 |
+
try {
|
237 |
+
//add last error to stack
|
238 |
+
$response->setException($exception);
|
239 |
+
|
240 |
+
$messages = array();
|
241 |
+
|
242 |
+
/** @var Exception $exception */
|
243 |
+
foreach ($response->getException() as $exception) {
|
244 |
+
$message = array(
|
245 |
+
'code' => $exception->getCode(),
|
246 |
+
'message' => strip_tags(implode("\n", array_unique(explode("\n", $exception->getMessage()))))
|
247 |
+
);
|
248 |
+
|
249 |
+
if (Mage::getIsDeveloperMode()) {
|
250 |
+
$message['trace'] = $exception->getTraceAsString();
|
251 |
+
}
|
252 |
+
|
253 |
+
$messages['messages']['error'][] = $message;
|
254 |
+
}
|
255 |
+
//set HTTP Code of last error, Content-Type and Body
|
256 |
+
$response->setBody($renderer->render($messages));
|
257 |
+
$response->setHeader('Content-Type', sprintf(
|
258 |
+
'%s; charset=%s', $renderer->getMimeType(), Jmango360_Japi_Model_Response::RESPONSE_CHARSET
|
259 |
+
));
|
260 |
+
} catch (Exception $e) {
|
261 |
+
//tunnelling of 406(Not acceptable) error
|
262 |
+
$httpCode = $e->getCode() == self::HTTP_NOT_ACCEPTABLE //$e->getCode() can result in one more loop
|
263 |
+
? self::HTTP_NOT_ACCEPTABLE // of try..catch
|
264 |
+
: self::HTTP_INTERNAL_ERROR;
|
265 |
+
|
266 |
+
//if error appeared in "error rendering" process then show it in plain text
|
267 |
+
$response->setBody($e->getMessage());
|
268 |
+
$response->setHeader('Content-Type', 'text/plain; charset=' . Mage_Api2_Model_Response::RESPONSE_CHARSET);
|
269 |
+
}
|
270 |
+
|
271 |
+
/*
|
272 |
+
* In the REST not registred HTTP codes are used. because this make reactions of netwerk devices and software unpredictable the error contains the REST status
|
273 |
+
* -- but the real HTTP code is set to 500 (internal error)
|
274 |
+
*/
|
275 |
+
if ($httpCode > 505) {
|
276 |
+
$httpCode = 500;
|
277 |
+
}
|
278 |
+
|
279 |
+
$response->setHttpResponseCode($httpCode);
|
280 |
+
|
281 |
+
return $this;
|
282 |
+
}
|
283 |
+
|
284 |
+
public function getToken()
|
285 |
+
{
|
286 |
+
return $this->_renewFormKey();
|
287 |
+
}
|
288 |
+
|
289 |
+
private function _validateToken()
|
290 |
+
{
|
291 |
+
if (!Mage::getStoreConfig(self::USETOKENPATH)) {
|
292 |
+
return true;
|
293 |
+
}
|
294 |
+
|
295 |
+
$action = Mage::app()->getRequest()->getActionName();
|
296 |
+
if (in_array($action, $this->_excludeActionFromTokenValidation)) {
|
297 |
+
return true;
|
298 |
+
}
|
299 |
+
|
300 |
+
$controller = Mage::app()->getRequest()->getControllerName();
|
301 |
+
if (in_array($controller, $this->_excludeControllerFromTokenValidation)) {
|
302 |
+
return true;
|
303 |
+
}
|
304 |
+
|
305 |
+
if (Mage::getSingleton('core/session')->getIgnoreTokenCheck()) {
|
306 |
+
Mage::getSingleton('core/session')->unsIgnoreTokenCheck();
|
307 |
+
return true;
|
308 |
+
}
|
309 |
+
|
310 |
+
return $this->_validateFormKey();
|
311 |
+
}
|
312 |
+
|
313 |
+
private function _validateFormKey()
|
314 |
+
{
|
315 |
+
$test = Mage::getSingleton('core/session')->getFormKey();
|
316 |
+
if (!($formKey = Mage::app()->getRequest()->getParam('token', null))
|
317 |
+
|| $formKey != Mage::getSingleton('core/session')->getFormKey()
|
318 |
+
) {
|
319 |
+
return false;
|
320 |
+
}
|
321 |
+
return true;
|
322 |
+
}
|
323 |
+
|
324 |
+
private function _renewFormKey()
|
325 |
+
{
|
326 |
+
Mage::getSingleton('core/session')->setData('_form_key', '');
|
327 |
+
return Mage::getSingleton('core/session')->getFormKey();
|
328 |
+
}
|
329 |
+
|
330 |
+
private function _validateSessionId()
|
331 |
+
{
|
332 |
+
if (!Mage::getStoreConfigFlag(Jmango360_Japi_Model_Rest_Mage::USEFRONTENDSIDPATH)) {
|
333 |
+
return true;
|
334 |
+
}
|
335 |
+
|
336 |
+
$requestSessionId = Mage::app()->getRequest()->getParam('SID');
|
337 |
+
$sessionSessionId = Mage::getSingleton('core/session')->getSessionId();
|
338 |
+
if ($requestSessionId == $sessionSessionId) {
|
339 |
+
return true;
|
340 |
+
}
|
341 |
+
|
342 |
+
/*
|
343 |
+
* Action getSession renews the session ID and returns the new session ID
|
344 |
+
* -- excluded from the check
|
345 |
+
*/
|
346 |
+
$action = Mage::app()->getRequest()->getActionName();
|
347 |
+
if (in_array($action, $this->_excludeActionFromTokenValidation)) {
|
348 |
+
return true;
|
349 |
+
}
|
350 |
+
|
351 |
+
if (Mage::getSingleton('core/session')->getIgnoreSessionIdCheck()) {
|
352 |
+
Mage::getSingleton('core/session')->unsIgnoreSessionIdCheck();
|
353 |
+
return true;
|
354 |
+
}
|
355 |
+
|
356 |
+
return false;
|
357 |
+
}
|
358 |
+
|
359 |
+
private function _setRequest($request)
|
360 |
+
{
|
361 |
+
Mage::getModel('core/session')->setServerRequest($request);
|
362 |
+
}
|
363 |
+
|
364 |
+
private function _setResponse($response)
|
365 |
+
{
|
366 |
+
Mage::getModel('core/session')->setServerResponse($response);
|
367 |
+
}
|
368 |
+
|
369 |
+
/**
|
370 |
+
* @return Jmango360_Japi_Model_Request
|
371 |
+
*/
|
372 |
+
public function getRequest()
|
373 |
+
{
|
374 |
+
return Mage::getModel('core/session')->getServerRequest();
|
375 |
+
}
|
376 |
+
|
377 |
+
/**
|
378 |
+
* @return Jmango360_Japi_Model_Response
|
379 |
+
*/
|
380 |
+
public function getResponse()
|
381 |
+
{
|
382 |
+
return Mage::getModel('core/session')->getServerResponse();
|
383 |
+
}
|
384 |
+
|
385 |
+
public function unsRequest()
|
386 |
+
{
|
387 |
+
Mage::getModel('core/session')->unsServerRequest();
|
388 |
+
}
|
389 |
+
|
390 |
+
public function unsResponse()
|
391 |
+
{
|
392 |
+
Mage::getModel('core/session')->unsServerResponse();
|
393 |
+
}
|
394 |
+
|
395 |
+
protected function _setIsRest()
|
396 |
+
{
|
397 |
+
Mage::getSingleton('core/session')->setIsRest(true);
|
398 |
+
|
399 |
+
return $this;
|
400 |
+
}
|
401 |
+
|
402 |
+
public function setIsRest()
|
403 |
+
{
|
404 |
+
$this->_setIsRest();
|
405 |
+
}
|
406 |
+
|
407 |
+
public function getIsRest()
|
408 |
+
{
|
409 |
+
return Mage::getSingleton('core/session')->getIsRest() || Mage::app()->getRequest()->getModuleName() == 'japi';
|
410 |
+
}
|
411 |
+
|
412 |
+
public function unsetIsRest()
|
413 |
+
{
|
414 |
+
Mage::getSingleton('core/session')->setIsRest(false);
|
415 |
+
}
|
416 |
+
|
417 |
+
public function setIsSubmit()
|
418 |
+
{
|
419 |
+
Mage::getSingleton('core/session')->setIsSubmit(true);
|
420 |
+
}
|
421 |
+
|
422 |
+
public function getIsSubmit()
|
423 |
+
{
|
424 |
+
return (bool)Mage::getSingleton('core/session')->getIsSubmit();
|
425 |
+
}
|
426 |
+
|
427 |
+
public function unsetIsSubmit()
|
428 |
+
{
|
429 |
+
Mage::getSingleton('core/session')->setIsSubmit(false);
|
430 |
+
}
|
431 |
+
|
432 |
+
public function setControllerInstance($instance)
|
433 |
+
{
|
434 |
+
$this->_controllerInstance = $instance;
|
435 |
+
}
|
436 |
+
|
437 |
+
public function getControllerInstance()
|
438 |
+
{
|
439 |
+
return $this->_controllerInstance;
|
440 |
+
}
|
441 |
+
}
|
app/code/community/Jmango360/Japi/Model/System/Config/Backend/Payment.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_System_Config_Backend_Payment extends Mage_Core_Model_Config_Data
|
4 |
+
{
|
5 |
+
protected function _beforeSave()
|
6 |
+
{
|
7 |
+
$value = $this->getValue();
|
8 |
+
$source = new Jmango360_Japi_Model_System_Config_Source_Payment();
|
9 |
+
$options = $source->toOptionArray();
|
10 |
+
$origin = array();
|
11 |
+
|
12 |
+
foreach ($options as $option) {
|
13 |
+
if (!is_array($option['value'])) {
|
14 |
+
$origin[] = $option['value'];
|
15 |
+
} else {
|
16 |
+
foreach ($option['value'] as $item) {
|
17 |
+
$origin[] = $item['value'];
|
18 |
+
}
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
if (is_array($value) && count($value) == count($origin)) {
|
23 |
+
Mage::throwException(Mage::helper('japi')->__('You must leave at least one payment method available.'));
|
24 |
+
}
|
25 |
+
|
26 |
+
return $this;
|
27 |
+
}
|
28 |
+
}
|
app/code/community/Jmango360/Japi/Model/System/Config/Backend/Shipping.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_System_Config_Backend_Shipping extends Mage_Core_Model_Config_Data
|
4 |
+
{
|
5 |
+
protected function _beforeSave()
|
6 |
+
{
|
7 |
+
$value = $this->getValue();
|
8 |
+
$source = new Jmango360_Japi_Model_System_Config_Source_Shipping();
|
9 |
+
$options = $source->toOptionArray();
|
10 |
+
$origin = array();
|
11 |
+
|
12 |
+
foreach ($options as $option) {
|
13 |
+
if (!is_array($option['value'])) {
|
14 |
+
$origin[] = $option['value'];
|
15 |
+
} else {
|
16 |
+
foreach ($option['value'] as $item) {
|
17 |
+
$origin[] = $item['value'];
|
18 |
+
}
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
if (is_array($value) && count($value) == count($origin)) {
|
23 |
+
Mage::throwException(Mage::helper('japi')->__('You must leave at least one shipping method available.'));
|
24 |
+
}
|
25 |
+
|
26 |
+
return $this;
|
27 |
+
}
|
28 |
+
}
|
app/code/community/Jmango360/Japi/Model/System/Config/Source/Address/Attributes.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_System_Config_Source_Address_Attributes
|
4 |
+
{
|
5 |
+
public function toOptionArray()
|
6 |
+
{
|
7 |
+
try {
|
8 |
+
/* @var $model Jmango360_Japi_Model_Rest_Mage */
|
9 |
+
$model = Mage::getModel('japi/rest_mage');
|
10 |
+
$attributes = $model->getAddressAttributes();
|
11 |
+
} catch (Exception $e) {
|
12 |
+
$attributes = array();
|
13 |
+
}
|
14 |
+
|
15 |
+
$options = array();
|
16 |
+
$ignore = false;
|
17 |
+
foreach ($attributes as $attribute) {
|
18 |
+
if ($attribute['key'] == 'street[]') {
|
19 |
+
if ($ignore) continue;
|
20 |
+
$ignore = true;
|
21 |
+
$options[] = array(
|
22 |
+
'value' => 'street',
|
23 |
+
'label' => sprintf('%s [%s]', $attribute['label'], 'street')
|
24 |
+
);
|
25 |
+
} else {
|
26 |
+
$options[] = array(
|
27 |
+
'value' => $attribute['key'],
|
28 |
+
'label' => sprintf('%s [%s]', $attribute['label'], $attribute['key'])
|
29 |
+
);
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
return $options;
|
34 |
+
}
|
35 |
+
}
|
app/code/community/Jmango360/Japi/Model/System/Config/Source/Address/Validatetype.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Jmango360_Japi_Model_System_Config_Source_Address_Validatetype
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Model_System_Config_Source_Address_Validatetype
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Options getter
|
10 |
+
*
|
11 |
+
* @return array
|
12 |
+
*/
|
13 |
+
public function toOptionArray()
|
14 |
+
{
|
15 |
+
return array(
|
16 |
+
array('value' => 'any', 'label'=>Mage::helper('japi')->__('Any')),
|
17 |
+
array('value' => 'number', 'label'=>Mage::helper('japi')->__('Number'))
|
18 |
+
);
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Get options in "key-value" format
|
23 |
+
*
|
24 |
+
* @return array
|
25 |
+
*/
|
26 |
+
public function toArray()
|
27 |
+
{
|
28 |
+
return array(
|
29 |
+
'any' => Mage::helper('japi')->__('Any'),
|
30 |
+
'number' => Mage::helper('japi')->__('Number')
|
31 |
+
);
|
32 |
+
}
|
33 |
+
}
|
app/code/community/Jmango360/Japi/Model/System/Config/Source/Attributes.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_System_Config_Source_Attributes
|
4 |
+
{
|
5 |
+
public function toOptionArray()
|
6 |
+
{
|
7 |
+
/* @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
|
8 |
+
$collection = Mage::getResourceModel('catalog/product_attribute_collection')
|
9 |
+
->addVisibleFilter();
|
10 |
+
|
11 |
+
$options = array(
|
12 |
+
array('value' => '', 'label' => '')
|
13 |
+
);
|
14 |
+
foreach ($collection as $attribute) {
|
15 |
+
/* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
|
16 |
+
$options[] = array(
|
17 |
+
'value' => $attribute->getAttributeCode(),
|
18 |
+
'label' => sprintf('%s [%s]', $attribute->getFrontendLabel(), $attribute->getAttributeCode())
|
19 |
+
);
|
20 |
+
}
|
21 |
+
|
22 |
+
return $options;
|
23 |
+
}
|
24 |
+
}
|
app/code/community/Jmango360/Japi/Model/System/Config/Source/Catalogimage.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Jmango360_Japi_Model_System_Config_Source_Catalogimage
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Model_System_Config_Source_Catalogimage
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Options getter
|
10 |
+
*
|
11 |
+
* @return array
|
12 |
+
*/
|
13 |
+
public function toOptionArray()
|
14 |
+
{
|
15 |
+
return array(
|
16 |
+
array('value' => 'none', 'label' => Mage::helper('japi')->__('None')),
|
17 |
+
array('value' => 'image', 'label' => Mage::helper('japi')->__('Base Image')),
|
18 |
+
array('value' => 'small_image', 'label' => Mage::helper('japi')->__('Small Image')),
|
19 |
+
array('value' => 'thumbnail', 'label' => Mage::helper('japi')->__('Thumbnail')),
|
20 |
+
);
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Get options in "key-value" format
|
25 |
+
*
|
26 |
+
* @return array
|
27 |
+
*/
|
28 |
+
public function toArray()
|
29 |
+
{
|
30 |
+
return array(
|
31 |
+
'none' => Mage::helper('japi')->__('None'),
|
32 |
+
'image' => Mage::helper('japi')->__('Base Image'),
|
33 |
+
'small_image' => Mage::helper('japi')->__('Small Image'),
|
34 |
+
'thumbnail' => Mage::helper('japi')->__('Thumbnail'),
|
35 |
+
);
|
36 |
+
}
|
37 |
+
}
|
app/code/community/Jmango360/Japi/Model/System/Config/Source/Customer/Attributes.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_System_Config_Source_Customer_Attributes
|
4 |
+
{
|
5 |
+
public function toOptionArray()
|
6 |
+
{
|
7 |
+
try {
|
8 |
+
/* @var $model Jmango360_Japi_Model_Rest_Mage */
|
9 |
+
$model = Mage::getModel('japi/rest_mage');
|
10 |
+
$attributes = $model->getCustomerAttributes();
|
11 |
+
} catch (Exception $e) {
|
12 |
+
$attributes = array();
|
13 |
+
}
|
14 |
+
|
15 |
+
$options = array();
|
16 |
+
$ignore = false;
|
17 |
+
foreach ($attributes as $attribute) {
|
18 |
+
if ($attribute['key'] == 'street[]') {
|
19 |
+
if ($ignore) continue;
|
20 |
+
$ignore = true;
|
21 |
+
$options[] = array(
|
22 |
+
'value' => 'street',
|
23 |
+
'label' => sprintf('%s [%s]', $attribute['label'], 'street')
|
24 |
+
);
|
25 |
+
} else {
|
26 |
+
$options[] = array(
|
27 |
+
'value' => $attribute['key'],
|
28 |
+
'label' => sprintf('%s [%s]', $attribute['label'], $attribute['key'])
|
29 |
+
);
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
return $options;
|
34 |
+
}
|
35 |
+
}
|
app/code/community/Jmango360/Japi/Model/System/Config/Source/Defaultimage.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Jmango360_Japi_Model_System_Config_Source_Defaultimage
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Model_System_Config_Source_Defaultimage
|
7 |
+
{
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Options getter
|
11 |
+
*
|
12 |
+
* @return array
|
13 |
+
*/
|
14 |
+
public function toOptionArray()
|
15 |
+
{
|
16 |
+
return array(
|
17 |
+
array('value' => 'image', 'label'=>Mage::helper('japi')->__('Base Image')),
|
18 |
+
array('value' => 'small_image', 'label'=>Mage::helper('japi')->__('Small Image')),
|
19 |
+
array('value' => 'thumbnail', 'label'=>Mage::helper('japi')->__('Thumbnail')),
|
20 |
+
);
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Get options in "key-value" format
|
25 |
+
*
|
26 |
+
* @return array
|
27 |
+
*/
|
28 |
+
public function toArray()
|
29 |
+
{
|
30 |
+
return array(
|
31 |
+
'image' => Mage::helper('japi')->__('Base Image'),
|
32 |
+
'small_image' => Mage::helper('japi')->__('Small Image'),
|
33 |
+
'thumbnail' => Mage::helper('japi')->__('Thumbnail'),
|
34 |
+
);
|
35 |
+
}
|
36 |
+
|
37 |
+
}
|
app/code/community/Jmango360/Japi/Model/System/Config/Source/Payment.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_System_Config_Source_Payment
|
4 |
+
{
|
5 |
+
public function toOptionArray()
|
6 |
+
{
|
7 |
+
/* @var $shippingConfig Mage_Payment_Model_Config */
|
8 |
+
$shippingConfig = Mage::getSingleton('payment/config');
|
9 |
+
$methods = $shippingConfig->getActiveMethods();
|
10 |
+
$options = array();
|
11 |
+
|
12 |
+
foreach ($methods as $code => $method) {
|
13 |
+
$title = Mage::getStoreConfig("payment/$code/title");
|
14 |
+
$options[] = array('value' => $code, 'label' => $title ? $title : $code);
|
15 |
+
}
|
16 |
+
|
17 |
+
return $options;
|
18 |
+
}
|
19 |
+
}
|
app/code/community/Jmango360/Japi/Model/System/Config/Source/Shipping.php
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Model_System_Config_Source_Shipping
|
4 |
+
{
|
5 |
+
public function toOptionArray()
|
6 |
+
{
|
7 |
+
/* @var $shippingConfig Mage_Shipping_Model_Config */
|
8 |
+
$shippingConfig = Mage::getSingleton('shipping/config');
|
9 |
+
$carriers = $shippingConfig->getActiveCarriers();
|
10 |
+
$options = array();
|
11 |
+
|
12 |
+
foreach ($carriers as $carrierCode => $carrier) {
|
13 |
+
/* @var $carrier Mage_Shipping_Model_Carrier_Abstract */
|
14 |
+
$title = Mage::getStoreConfig("carriers/$carrierCode/title");
|
15 |
+
$group = array();
|
16 |
+
$methods = $carrier->getAllowedMethods();
|
17 |
+
if (is_array($methods)) {
|
18 |
+
foreach ($carrier->getAllowedMethods() as $methodCode => $method) {
|
19 |
+
$group[] = array('value' => $carrierCode . '_' . $methodCode, 'label' => $method);
|
20 |
+
}
|
21 |
+
}
|
22 |
+
$options[] = array('value' => !empty($group) ? $group : $carrierCode, 'label' => $title ? $title : $carrierCode);
|
23 |
+
}
|
24 |
+
|
25 |
+
return $options;
|
26 |
+
}
|
27 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Adminhtml/Japi/LogController.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
class Jmango360_Japi_Adminhtml_Japi_LogController extends Mage_Adminhtml_Controller_Action
|
7 |
+
{
|
8 |
+
protected function _isAllowed()
|
9 |
+
{
|
10 |
+
return Mage::getSingleton('admin/session')->isAllowed('japi/log');
|
11 |
+
}
|
12 |
+
|
13 |
+
public function downloadAction()
|
14 |
+
{
|
15 |
+
$logFile = $this->getRequest()->getParam('file', 'japi.log');
|
16 |
+
/* @var $helper Jmango360_Japi_Helper_Debug */
|
17 |
+
$helper = Mage::helper('japi/debug');
|
18 |
+
$logFilePath = $helper->getLogFile($logFile, true);
|
19 |
+
if (!file_exists($logFilePath)) {
|
20 |
+
return $this->_redirectUrl($_SERVER['HTTP_REFERER']);
|
21 |
+
}
|
22 |
+
$logSize = filesize($logFilePath);
|
23 |
+
|
24 |
+
$this->getResponse()
|
25 |
+
->setHeader('Content-Type', 'application/force-download', true)
|
26 |
+
->setHeader('Content-Length', $logSize)
|
27 |
+
->setHeader('Content-Disposition', 'attachment;filename=' . $logFile)
|
28 |
+
->setBody(file_get_contents($logFilePath));
|
29 |
+
}
|
30 |
+
|
31 |
+
public function clearAction()
|
32 |
+
{
|
33 |
+
$logFile = $this->getRequest()->getParam('file');
|
34 |
+
/* @var $helper Jmango360_Japi_Helper_Debug */
|
35 |
+
$helper = Mage::helper('japi/debug');
|
36 |
+
$logFilePath = $helper->getLogFile($logFile, true);
|
37 |
+
if (file_exists($logFilePath)) {
|
38 |
+
@unlink($logFilePath);
|
39 |
+
}
|
40 |
+
return $this->_redirectUrl($_SERVER['HTTP_REFERER']);
|
41 |
+
}
|
42 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Adminhtml/Japi/OrderController.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Copyright 2016 JMango360
|
5 |
+
*/
|
6 |
+
|
7 |
+
class Jmango360_Japi_Adminhtml_Japi_OrderController extends Mage_Adminhtml_Controller_Action
|
8 |
+
{
|
9 |
+
/**
|
10 |
+
* Init layout, menu and breadcrumb
|
11 |
+
*
|
12 |
+
* @return Jmango360_Japi_Adminhtml_Japi_OrderController
|
13 |
+
*/
|
14 |
+
protected function _initAction()
|
15 |
+
{
|
16 |
+
$this->loadLayout()
|
17 |
+
->_setActiveMenu('japi/report/japi_order')
|
18 |
+
->_addBreadcrumb($this->__('Jmango360'), $this->__('Jmango360'))
|
19 |
+
->_addBreadcrumb($this->__('Reports'), $this->__('Reports'))
|
20 |
+
->_addBreadcrumb($this->__('Order Details'), $this->__('Order Details'));
|
21 |
+
return $this;
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Japi Order grid
|
26 |
+
*/
|
27 |
+
public function indexAction()
|
28 |
+
{
|
29 |
+
$this->_title($this->__('Japi Reports'))->_title($this->__('Order Details'));
|
30 |
+
|
31 |
+
$this->_initAction()
|
32 |
+
->renderLayout();
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Japi Order grid
|
37 |
+
*/
|
38 |
+
public function gridAction()
|
39 |
+
{
|
40 |
+
$this->loadLayout();
|
41 |
+
$this->getResponse()->setBody(
|
42 |
+
$this->getLayout()->getBlock('japi_order.grid')->toHtml()
|
43 |
+
);
|
44 |
+
}
|
45 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Adminhtml/Japi/ReportController.php
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2015 JMango360
|
4 |
+
*/
|
5 |
+
|
6 |
+
require_once 'Mage/Adminhtml/controllers/Report/SalesController.php';
|
7 |
+
|
8 |
+
class Jmango360_Japi_Adminhtml_Japi_ReportController extends Mage_Adminhtml_Report_SalesController
|
9 |
+
{
|
10 |
+
protected function _init()
|
11 |
+
{
|
12 |
+
$this->loadLayout();
|
13 |
+
$this->_setActiveMenu('japi');
|
14 |
+
$this->_title(Mage::helper('japi')->__('JMango360'));
|
15 |
+
}
|
16 |
+
|
17 |
+
public function indexAction()
|
18 |
+
{
|
19 |
+
$type = $this->getRequest()->getParam('type');
|
20 |
+
$dateFrom = Mage::app()->getLocale()->date();
|
21 |
+
$dateTo = Mage::app()->getLocale()->date();
|
22 |
+
$dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
|
23 |
+
$dateFrom->subMonth(2);
|
24 |
+
$dateFrom->setDay(1);
|
25 |
+
|
26 |
+
switch ($type) {
|
27 |
+
case 'orders':
|
28 |
+
$params = array(
|
29 |
+
'report_type' => 'created_at_order',
|
30 |
+
'period_type' => 'month',
|
31 |
+
'from' => $dateFrom->toString($dateFormat),
|
32 |
+
'to' => $dateTo->toString($dateFormat),
|
33 |
+
'show_order_statuses' => 0,
|
34 |
+
'show_empty_rows' => 0,
|
35 |
+
'show_actual_columns' => 0
|
36 |
+
);
|
37 |
+
$this->_redirect('*/*/orders', array(
|
38 |
+
'filter' => urlencode(base64_encode(http_build_query($params))))
|
39 |
+
);
|
40 |
+
break;
|
41 |
+
case 'sales':
|
42 |
+
$params = array(
|
43 |
+
'report_type' => 'created_at_order',
|
44 |
+
'period_type' => 'month',
|
45 |
+
'from' => $dateFrom->toString($dateFormat),
|
46 |
+
'to' => $dateTo->toString($dateFormat),
|
47 |
+
'show_order_statuses' => 0,
|
48 |
+
'show_empty_rows' => 0,
|
49 |
+
'show_actual_columns' => 0
|
50 |
+
);
|
51 |
+
$this->_redirect('*/*/sales', array(
|
52 |
+
'filter' => urlencode(base64_encode(http_build_query($params))))
|
53 |
+
);
|
54 |
+
break;
|
55 |
+
case 'customers':
|
56 |
+
$params = array(
|
57 |
+
'report_type' => 'created_at_order',
|
58 |
+
'period_type' => 'month',
|
59 |
+
'from' => $dateFrom->toString($dateFormat),
|
60 |
+
'to' => $dateTo->toString($dateFormat),
|
61 |
+
'show_order_statuses' => 0,
|
62 |
+
'show_empty_rows' => 0,
|
63 |
+
'show_actual_columns' => 0
|
64 |
+
);
|
65 |
+
$this->_redirect('*/*/customers', array(
|
66 |
+
'filter' => urlencode(base64_encode(http_build_query($params))))
|
67 |
+
);
|
68 |
+
break;
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
public function salesAction()
|
73 |
+
{
|
74 |
+
$this->_showLastExecutionTime(Mage_Reports_Model_Flag::REPORT_ORDER_FLAG_CODE, 'sales');
|
75 |
+
|
76 |
+
$this->_init();
|
77 |
+
$this->_title(Mage::helper('japi')->__('Sales Reports'));
|
78 |
+
|
79 |
+
$gridBlock = $this->getLayout()->getBlock('adminhtml_report_sales.grid');
|
80 |
+
$filterFormBlock = $this->getLayout()->getBlock('grid.filter.form');
|
81 |
+
$chartBlock = $this->getLayout()->getBlock('report.chart');
|
82 |
+
|
83 |
+
$this->_initReportAction(array(
|
84 |
+
$gridBlock,
|
85 |
+
$filterFormBlock,
|
86 |
+
$chartBlock
|
87 |
+
));
|
88 |
+
|
89 |
+
$this->renderLayout();
|
90 |
+
}
|
91 |
+
|
92 |
+
public function ordersAction()
|
93 |
+
{
|
94 |
+
$this->_showLastExecutionTime(Mage_Reports_Model_Flag::REPORT_ORDER_FLAG_CODE, 'sales');
|
95 |
+
|
96 |
+
$this->_init();
|
97 |
+
$this->_title(Mage::helper('japi')->__('Orders Reports'));
|
98 |
+
|
99 |
+
$gridBlock = $this->getLayout()->getBlock('adminhtml_report_orders.grid');
|
100 |
+
$filterFormBlock = $this->getLayout()->getBlock('grid.filter.form');
|
101 |
+
$chartBlock = $this->getLayout()->getBlock('report.chart');
|
102 |
+
|
103 |
+
$this->_initReportAction(array(
|
104 |
+
$gridBlock,
|
105 |
+
$filterFormBlock,
|
106 |
+
$chartBlock
|
107 |
+
));
|
108 |
+
|
109 |
+
$this->renderLayout();
|
110 |
+
}
|
111 |
+
|
112 |
+
public function customersAction()
|
113 |
+
{
|
114 |
+
$this->_init();
|
115 |
+
$this->_title(Mage::helper('japi')->__('Customers Reports'));
|
116 |
+
|
117 |
+
$gridBlock = $this->getLayout()->getBlock('adminhtml_report_customers.grid');
|
118 |
+
$filterFormBlock = $this->getLayout()->getBlock('grid.filter.form');
|
119 |
+
$chartBlock = $this->getLayout()->getBlock('report.chart');
|
120 |
+
|
121 |
+
$this->_initReportAction(array(
|
122 |
+
$gridBlock,
|
123 |
+
$filterFormBlock,
|
124 |
+
$chartBlock
|
125 |
+
));
|
126 |
+
|
127 |
+
$this->renderLayout();
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Export sales report grid to CSV format
|
132 |
+
*/
|
133 |
+
public function exportSalesCsvAction()
|
134 |
+
{
|
135 |
+
$fileName = 'sales_jmango360.csv';
|
136 |
+
/* @var $grid Jmango360_Japi_Block_Adminhtml_Report_Sales_Grid */
|
137 |
+
$grid = $this->getLayout()->createBlock('japi/adminhtml_report_sales_grid');
|
138 |
+
$this->_initReportAction($grid);
|
139 |
+
$this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Export sales report grid to Excel XML format
|
144 |
+
*/
|
145 |
+
public function exportSalesExcelAction()
|
146 |
+
{
|
147 |
+
$fileName = 'sales_jmango360.xml';
|
148 |
+
/* @var $grid Jmango360_Japi_Block_Adminhtml_Report_Sales_Grid */
|
149 |
+
$grid = $this->getLayout()->createBlock('japi/adminhtml_report_sales_grid');
|
150 |
+
$this->_initReportAction($grid);
|
151 |
+
$this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
|
152 |
+
}
|
153 |
+
|
154 |
+
public function tunnelAction()
|
155 |
+
{
|
156 |
+
$httpClient = new Varien_Http_Client();
|
157 |
+
$gaData = $this->getRequest()->getParam('ga');
|
158 |
+
$gaHash = $this->getRequest()->getParam('h');
|
159 |
+
if ($gaData && $gaHash) {
|
160 |
+
$newHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
|
161 |
+
if ($newHash == $gaHash) {
|
162 |
+
$params = json_decode(base64_decode(urldecode($gaData)), true);
|
163 |
+
if ($params) {
|
164 |
+
$response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)
|
165 |
+
->setParameterGet($params)
|
166 |
+
->setConfig(array('timeout' => 5))
|
167 |
+
->request('GET');
|
168 |
+
|
169 |
+
$headers = $response->getHeaders();
|
170 |
+
|
171 |
+
$this->getResponse()
|
172 |
+
->setHeader('Content-type', $headers['Content-type'], true)
|
173 |
+
->setBody($response->getBody());
|
174 |
+
}
|
175 |
+
}
|
176 |
+
}
|
177 |
+
}
|
178 |
+
}
|
app/code/community/Jmango360/Japi/controllers/CheckoutController.php
ADDED
@@ -0,0 +1,465 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2015 JMango360
|
4 |
+
*/
|
5 |
+
include_once('Mage/Checkout/controllers/OnepageController.php');
|
6 |
+
|
7 |
+
class Jmango360_Japi_CheckoutController extends Mage_Checkout_OnepageController
|
8 |
+
{
|
9 |
+
/**
|
10 |
+
* Make sure customer is valid, if logged in
|
11 |
+
* By default will add error messages and redirect to customer edit form
|
12 |
+
*
|
13 |
+
* @param bool $redirect - stop dispatch and redirect?
|
14 |
+
* @param bool $addErrors - add error messages?
|
15 |
+
* @return bool
|
16 |
+
*/
|
17 |
+
protected function _preDispatchValidateCustomer($redirect = true, $addErrors = true)
|
18 |
+
{
|
19 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
20 |
+
if ($customer && $customer->getId()) {
|
21 |
+
$validationResult = $customer->validate();
|
22 |
+
if ((true !== $validationResult) && is_array($validationResult)) {
|
23 |
+
Mage::getSingleton('customer/session')->setCheckoutReferer(true);
|
24 |
+
if ($addErrors) {
|
25 |
+
foreach ($validationResult as $error) {
|
26 |
+
Mage::getSingleton('customer/session')->addError($error);
|
27 |
+
}
|
28 |
+
}
|
29 |
+
if ($redirect) {
|
30 |
+
$this->_redirect('japi/customer/edit', array('_secure' => true));
|
31 |
+
$this->setFlag('', self::FLAG_NO_DISPATCH, true);
|
32 |
+
}
|
33 |
+
return false;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
return true;
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Send Ajax redirect response
|
41 |
+
*
|
42 |
+
* @return Mage_Checkout_OnepageController
|
43 |
+
*/
|
44 |
+
protected function _ajaxRedirectResponse()
|
45 |
+
{
|
46 |
+
$this->getResponse()
|
47 |
+
->setHeader('Content-Type', 'application/json')
|
48 |
+
->setBody(Mage::helper('core')->jsonEncode(array(
|
49 |
+
'error' => true,
|
50 |
+
'message' => $this->__('Session exprired.')
|
51 |
+
)));
|
52 |
+
return $this;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Validate ajax request and redirect on failure
|
57 |
+
*/
|
58 |
+
protected function _expireAjax()
|
59 |
+
{
|
60 |
+
if (!$this->getOnepage()->getQuote()->hasItems()
|
61 |
+
|| $this->getOnepage()->getQuote()->getHasError()
|
62 |
+
|| $this->getOnepage()->getQuote()->getIsMultiShipping()
|
63 |
+
) {
|
64 |
+
$this->_ajaxRedirectResponse();
|
65 |
+
return true;
|
66 |
+
}
|
67 |
+
|
68 |
+
return false;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* @return Mage_Checkout_Model_Session
|
73 |
+
*/
|
74 |
+
protected function _getSesstion()
|
75 |
+
{
|
76 |
+
return Mage::getSingleton('checkout/session');
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Check can page show for unregistered users
|
81 |
+
*
|
82 |
+
* @return boolean
|
83 |
+
*/
|
84 |
+
protected function _allowGuestCheckout()
|
85 |
+
{
|
86 |
+
return Mage::getSingleton('customer/session')->isLoggedIn()
|
87 |
+
|| Mage::helper('checkout')->isAllowedGuestCheckout($this->getOnepage()->getQuote());
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Redirect to native web checkout url
|
92 |
+
*/
|
93 |
+
public function redirectAction()
|
94 |
+
{
|
95 |
+
/* @var $helper Jmango360_Japi_Helper_Data */
|
96 |
+
$helper = Mage::helper('japi');
|
97 |
+
$checkoutUrl = $helper->getCheckoutUrl();
|
98 |
+
if ($checkoutUrl) $this->_redirectUrl($checkoutUrl);
|
99 |
+
else $this->_redirect('checkout/onepage', array('_secure' => true));
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* New onepage checkout page
|
104 |
+
*/
|
105 |
+
public function onepageAction()
|
106 |
+
{
|
107 |
+
/* @var $server Jmango360_Japi_Model_Server */
|
108 |
+
$server = Mage::getSingleton('japi/server');
|
109 |
+
$server->setIsRest();
|
110 |
+
|
111 |
+
$quote = $this->getOnepage()->getQuote();
|
112 |
+
$quote->collectTotals();
|
113 |
+
if ($quote->getHasError()) {
|
114 |
+
foreach ($quote->getMessages() as $message) {
|
115 |
+
$this->_getSesstion()->addError($message->getCode());
|
116 |
+
}
|
117 |
+
}
|
118 |
+
if (!$quote->hasItems()) {
|
119 |
+
$this->_getSesstion()->addError(Mage::helper('checkout')->__('You have no items in your shopping cart.'));
|
120 |
+
$quote->setHasError(true);
|
121 |
+
}
|
122 |
+
if (!$quote->validateMinimumAmount()) {
|
123 |
+
$error = Mage::getStoreConfig('sales/minimum_order/error_message') ?
|
124 |
+
Mage::getStoreConfig('sales/minimum_order/error_message') :
|
125 |
+
Mage::helper('checkout')->__('Subtotal must exceed minimum order amount');
|
126 |
+
|
127 |
+
$this->_getSesstion()->addError($error);
|
128 |
+
$quote->setHasError(true);
|
129 |
+
}
|
130 |
+
if (!$this->_allowGuestCheckout()) {
|
131 |
+
$this->_getSesstion()->addError(
|
132 |
+
Mage::helper('checkout')->__('Sorry, guest checkout is not enabled. Please try again or contact store owner.')
|
133 |
+
);
|
134 |
+
$quote->setHasError(true);
|
135 |
+
}
|
136 |
+
if ($quote->getIsMultiShipping()) {
|
137 |
+
$this->_getSesstion()->addError(
|
138 |
+
Mage::helper('checkout')->__('Invalid checkout type.')
|
139 |
+
);
|
140 |
+
$quote->setHasError(true);
|
141 |
+
}
|
142 |
+
|
143 |
+
// Bypass merge js
|
144 |
+
Mage::app()->getStore()->setConfig('dev/js/merge_files', 0);
|
145 |
+
Mage::app()->getStore()->setConfig('gtspeed/cssjs/min_js', 0);
|
146 |
+
Mage::app()->getStore()->setConfig('gtspeed/cssjs/merge_js', 0);
|
147 |
+
|
148 |
+
// Freeze cart object
|
149 |
+
Mage::getSingleton('checkout/session')->setCartWasUpdated(false);
|
150 |
+
|
151 |
+
$this->getOnepage()->initCheckout();
|
152 |
+
$this->loadLayout();
|
153 |
+
$this->_updateLayout();
|
154 |
+
$this->getLayout()->getBlock('head')->setTitle($this->__('Checkout'));
|
155 |
+
$this->_initLayoutMessages(array('checkout/session'));
|
156 |
+
$this->renderLayout();
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Update Onepage layout with custom xml in Settings
|
161 |
+
*/
|
162 |
+
protected function _updateLayout()
|
163 |
+
{
|
164 |
+
/* @var $helper Mage_Core_Helper_Data */
|
165 |
+
$helper = Mage::helper('core');
|
166 |
+
$xml = '';
|
167 |
+
|
168 |
+
if ($helper->isModuleEnabled('PostcodeNl_Api')) {
|
169 |
+
$xml .= "
|
170 |
+
<reference name=\"head\">
|
171 |
+
<action method=\"addCss\" ifconfig=\"postcodenl_api/config/enabled\"><script>postcodenl/api/css/lookup.css</script></action>
|
172 |
+
<action method=\"addJs\" ifconfig=\"postcodenl_api/config/enabled\"><script>postcodenl/api/lookup.js</script></action>
|
173 |
+
</reference>
|
174 |
+
<reference name=\"content\">
|
175 |
+
<block type=\"postcodenl_api/jsinit\" name=\"postcodenl.jsinit\" template=\"postcodenl/api/jsinit.phtml\" />
|
176 |
+
</reference>";
|
177 |
+
}
|
178 |
+
|
179 |
+
if ($helper->isModuleEnabled('Adyen_Payment')) {
|
180 |
+
$xml .= "
|
181 |
+
<reference name=\"head\">
|
182 |
+
<action method=\"addJs\"><script>adyen/payment/cc.js</script></action>
|
183 |
+
<action method=\"addJs\"><script>adyen/payment/iban.js</script></action>
|
184 |
+
<action method=\"addJs\"><script>adyen/payment/elv.js</script></action>
|
185 |
+
<action method=\"addCss\"><stylesheet>css/adyenstyle.css</stylesheet></action>
|
186 |
+
</reference>
|
187 |
+
<reference name=\"after_body_start\">
|
188 |
+
<block type=\"core/text\" name=\"adyen.diners.validation\" after=\"-\">
|
189 |
+
<action method=\"setText\">
|
190 |
+
<text><![CDATA[<script type=\"text/javascript\">
|
191 |
+
Validation.creditCartTypes.set('DC', [new RegExp('^3(?:0[0-5]|[68][0-9])[0-9]{11}$'), new RegExp('^[0-9]{3}$'), true]);
|
192 |
+
Validation.creditCartTypes.set('CB', [new RegExp('^4[0-9]{12}([0-9]{3})?$'), new RegExp('^[0-9]{3}$'), true]);
|
193 |
+
Validation.creditCartTypes.set('ELO', [new RegExp(/^((((636368)|(438935)|(504175)|(451416)|(636297)|(506699))\d{0,10})|((5067)|(4576)|(4011))\d{0,12})$/), new RegExp('^[0-9]{3}$'), true]);
|
194 |
+
Validation.creditCartTypes.set('hipercard', [new RegExp(/^(606282\d{10}(\d{3})?)|(3841\d{15})$/), new RegExp('^[0-9]{3}$'), true]);
|
195 |
+
Validation.creditCartTypes.set('unionpay', [new RegExp('^62[0-5]\d{13,16}$'), new RegExp('^[0-9]{3}$'), true]);
|
196 |
+
</script>]]>
|
197 |
+
</text>
|
198 |
+
</action>
|
199 |
+
</block>
|
200 |
+
</reference>";
|
201 |
+
}
|
202 |
+
|
203 |
+
if ($helper->isModuleEnabled('TIG_PostNL')) {
|
204 |
+
$xml .= "
|
205 |
+
<reference name=\"head\">
|
206 |
+
<action method=\"addCss\"><stylesheet>css/TIG/PostNL/deliveryoptions/default.css</stylesheet></action>
|
207 |
+
<action method=\"addCss\"><stylesheet>css/TIG/PostNL/postcodecheck.css</stylesheet></action>
|
208 |
+
<action method=\"addCss\"><stylesheet>css/TIG/PostNL/mijnpakket.css</stylesheet></action>
|
209 |
+
<action method=\"addItem\"><type>skin_css</type><name>css/TIG/PostNL/deliveryoptions/ie8.css</name><params/><if>lt IE 9</if></action>
|
210 |
+
<action method=\"addItem\"><type>skin_js</type><file>js/TIG/PostNL/ajax.js</file></action>
|
211 |
+
<action method=\"addItem\"><type>skin_js</type><file>js/TIG/PostNL/postcodecheck.js</file></action>
|
212 |
+
<block type=\"postnl_deliveryoptions/theme\" name=\"postnl_deliveryoptions_theme\" template=\"TIG/PostNL/delivery_options/theme.phtml\"/>
|
213 |
+
</reference>
|
214 |
+
<reference name=\"checkout.onepage.billing\">
|
215 |
+
<block type=\"core/template\" name=\"postnl_billing_postcodecheck\" template=\"TIG/PostNL/address_validation/checkout/onepage/postcode_check.phtml\"/>
|
216 |
+
</reference>
|
217 |
+
<reference name=\"checkout.onepage.shipping\">
|
218 |
+
<block type=\"core/template\" name=\"postnl_shipping_postcodecheck\" template=\"TIG/PostNL/address_validation/checkout/onepage/postcode_check.phtml\"/>
|
219 |
+
</reference>
|
220 |
+
<reference name=\"before_body_end\">
|
221 |
+
<block type=\"core/template\" name=\"postnl_validation\" template=\"TIG/PostNL/address_validation/validate.phtml\"/>
|
222 |
+
<block type=\"postnl_deliveryoptions/js\" name=\"postnl_deliveryoptions_js\" template=\"TIG/PostNL/delivery_options/js.phtml\"/>
|
223 |
+
<block type=\"postnl_mijnpakket/js\" name=\"postnl_mijnpakket_js\" template=\"TIG/PostNL/mijnpakket/js.phtml\"/>
|
224 |
+
<block type=\"postnl_mijnpakket/loginButton\" name=\"postnl_mijnpakket_login\" template=\"TIG/PostNL/mijnpakket/onepage/login_button.phtml\"/>
|
225 |
+
<block type=\"postnl_deliveryoptions/pickupNotification\" name=\"postnl_billing_pickup_notification\" template=\"TIG/PostNL/delivery_options/onepage/pickup_notification.phtml\"/>
|
226 |
+
</reference>";
|
227 |
+
}
|
228 |
+
|
229 |
+
try {
|
230 |
+
$this->getLayout()->getUpdate()->addUpdate($xml);
|
231 |
+
$this->generateLayoutXml()->generateLayoutBlocks();
|
232 |
+
} catch (Exception $e) {
|
233 |
+
Mage::logException($e);
|
234 |
+
}
|
235 |
+
|
236 |
+
$customXml = Mage::getStoreConfig('japi/jmango_rest_checkout_settings/custom_xml');
|
237 |
+
if ($customXml) {
|
238 |
+
try {
|
239 |
+
$this->getLayout()->getUpdate()->addUpdate($customXml);
|
240 |
+
$this->generateLayoutXml()->generateLayoutBlocks();
|
241 |
+
} catch (Exception $e) {
|
242 |
+
Mage::logException($e);
|
243 |
+
}
|
244 |
+
}
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* Shipping method save action
|
249 |
+
*/
|
250 |
+
public function saveShippingMethodAction()
|
251 |
+
{
|
252 |
+
if (Mage::helper('core')->isModuleEnabled('Wvzonline_EasyCheckout') && Mage::getStoreConfigFlag('easycheckout/config/is_enabled')) {
|
253 |
+
$quote = $this->getOnepage()->getQuote();
|
254 |
+
$quote->getShippingAddress()->setShippingMethod($this->getRequest()->getPost('shipping_method', ''));
|
255 |
+
$quote->setTotalsCollectedFlag(false);
|
256 |
+
$quote->getShippingAddress()->collectTotals();
|
257 |
+
$quote->collectTotals();
|
258 |
+
$quote->save();
|
259 |
+
|
260 |
+
$result['goto_section'] = 'payment';
|
261 |
+
$result['update_section'] = array(
|
262 |
+
'name' => 'payment-method',
|
263 |
+
'html' => $this->getLayout()->createBlock('easycheckout/payment')
|
264 |
+
->setTemplate('easycheckout/payment/methods.phtml')
|
265 |
+
->toHtml()
|
266 |
+
);
|
267 |
+
|
268 |
+
return $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
|
269 |
+
} else {
|
270 |
+
return parent::saveShippingMethodAction();
|
271 |
+
}
|
272 |
+
}
|
273 |
+
|
274 |
+
/**
|
275 |
+
* Save payment ajax action
|
276 |
+
*
|
277 |
+
* Sets either redirect or a JSON response
|
278 |
+
*/
|
279 |
+
public function savePaymentAction()
|
280 |
+
{
|
281 |
+
if ($this->_expireAjax()) {
|
282 |
+
return;
|
283 |
+
}
|
284 |
+
|
285 |
+
try {
|
286 |
+
if (!$this->getRequest()->isPost()) {
|
287 |
+
$this->_ajaxRedirectResponse();
|
288 |
+
return;
|
289 |
+
}
|
290 |
+
|
291 |
+
$data = $this->getRequest()->getPost('payment', array());
|
292 |
+
$result = $this->getOnepage()->savePayment($data);
|
293 |
+
|
294 |
+
// get section and redirect data
|
295 |
+
$redirectUrl = $this->getOnepage()->getQuote()->getPayment()->getCheckoutRedirectUrl();
|
296 |
+
if (empty($result['error'])) {
|
297 |
+
$result['goto_section'] = 'review';
|
298 |
+
$result['update_section'] = array(
|
299 |
+
'name' => 'review',
|
300 |
+
'html' => $this->_getReviewHtml()
|
301 |
+
);
|
302 |
+
}
|
303 |
+
if ($redirectUrl) {
|
304 |
+
$result['redirect'] = $redirectUrl;
|
305 |
+
}
|
306 |
+
} catch (Mage_Payment_Exception $e) {
|
307 |
+
if ($e->getFields()) {
|
308 |
+
$result['fields'] = $e->getFields();
|
309 |
+
}
|
310 |
+
$result['error'] = $e->getMessage();
|
311 |
+
} catch (Mage_Core_Exception $e) {
|
312 |
+
$result['error'] = $e->getMessage();
|
313 |
+
} catch (Exception $e) {
|
314 |
+
Mage::logException($e);
|
315 |
+
$result['error'] = $this->__('Unable to set Payment Method.');
|
316 |
+
}
|
317 |
+
|
318 |
+
/* @var $helper Mage_Core_Helper_Data */
|
319 |
+
$helper = Mage::helper('core');
|
320 |
+
$this->getResponse()->setBody($helper->jsonEncode($result));
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Get review order step html
|
325 |
+
*
|
326 |
+
* @return string
|
327 |
+
*/
|
328 |
+
protected function _getReviewHtml()
|
329 |
+
{
|
330 |
+
$layout = $this->getLayout();
|
331 |
+
$update = $layout->getUpdate();
|
332 |
+
// load custom layout
|
333 |
+
$update->load('japi_checkout_review');
|
334 |
+
$layout->generateXml();
|
335 |
+
$layout->generateBlocks();
|
336 |
+
$output = $layout->getOutput();
|
337 |
+
return $output;
|
338 |
+
}
|
339 |
+
|
340 |
+
/**
|
341 |
+
* Apply coupon
|
342 |
+
*/
|
343 |
+
public function couponPostAction()
|
344 |
+
{
|
345 |
+
if ($this->_expireAjax()) {
|
346 |
+
return;
|
347 |
+
}
|
348 |
+
|
349 |
+
if ($this->getRequest()->getParam('remove') == 1) {
|
350 |
+
$couponCode = '';
|
351 |
+
} else {
|
352 |
+
$couponCode = (string)$this->getRequest()->getParam('coupon_code', '');
|
353 |
+
}
|
354 |
+
|
355 |
+
$quote = $this->getOnepage()->getQuote();
|
356 |
+
$oldCouponCode = $quote->getCouponCode();
|
357 |
+
$output = array();
|
358 |
+
|
359 |
+
if (!strlen($couponCode) && !strlen($oldCouponCode)) {
|
360 |
+
return;
|
361 |
+
}
|
362 |
+
|
363 |
+
try {
|
364 |
+
$codeLength = strlen($couponCode);
|
365 |
+
if (version_compare(Mage::getVersion(), '1.8.0', '>=')) {
|
366 |
+
$isCodeLengthValid = $codeLength && $codeLength <= Mage_Checkout_Helper_Cart::COUPON_CODE_MAX_LENGTH;
|
367 |
+
} else {
|
368 |
+
$isCodeLengthValid = $codeLength && $codeLength <= 255;
|
369 |
+
}
|
370 |
+
|
371 |
+
$quote->getShippingAddress()->setCollectShippingRates(true);
|
372 |
+
$quote->setCouponCode($isCodeLengthValid ? $couponCode : '')
|
373 |
+
->collectTotals()
|
374 |
+
->save();
|
375 |
+
|
376 |
+
if ($codeLength) {
|
377 |
+
if ($isCodeLengthValid && $couponCode == $quote->getCouponCode()) {
|
378 |
+
$output['success'] = true;
|
379 |
+
$output['message'] = $this->__('Coupon code "%s" was applied.', Mage::helper('core')->escapeHtml($couponCode));
|
380 |
+
$output['html'] = $this->_getReviewHtml();
|
381 |
+
} else {
|
382 |
+
$output['success'] = false;
|
383 |
+
$output['message'] = $this->__('Coupon code "%s" is not valid.', Mage::helper('core')->escapeHtml($couponCode));
|
384 |
+
}
|
385 |
+
} else {
|
386 |
+
$output['success'] = true;
|
387 |
+
$output['message'] = $this->__('Coupon code was canceled.');
|
388 |
+
$output['html'] = $this->_getReviewHtml();
|
389 |
+
}
|
390 |
+
} catch (Mage_Core_Exception $e) {
|
391 |
+
$output['success'] = false;
|
392 |
+
$output['message'] = $e->getMessage();
|
393 |
+
Mage::logException($e);
|
394 |
+
} catch (Exception $e) {
|
395 |
+
$output['success'] = false;
|
396 |
+
$output['message'] = $this->__('Cannot apply the coupon code.');
|
397 |
+
Mage::logException($e);
|
398 |
+
}
|
399 |
+
|
400 |
+
$this->getResponse()->setHeader('Content-Type', 'application/json');
|
401 |
+
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($output));
|
402 |
+
}
|
403 |
+
|
404 |
+
public function getShippingMethodAction()
|
405 |
+
{
|
406 |
+
$result = array(
|
407 |
+
'update_section' => array(
|
408 |
+
'name' => 'shipping-method',
|
409 |
+
'html' => $this->_getShippingMethodsHtml(),
|
410 |
+
)
|
411 |
+
);
|
412 |
+
|
413 |
+
$this->getResponse()->setHeader('Content-Type', 'application/json');
|
414 |
+
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
|
415 |
+
}
|
416 |
+
|
417 |
+
public function saveOrderAction()
|
418 |
+
{
|
419 |
+
/* @var $server Jmango360_Japi_Model_Server */
|
420 |
+
$server = Mage::getSingleton('japi/server');
|
421 |
+
$server->setIsSubmit();
|
422 |
+
|
423 |
+
if ($requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds()) {
|
424 |
+
$postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
|
425 |
+
$diff = array_diff($requiredAgreements, $postedAgreements);
|
426 |
+
if ($diff) {
|
427 |
+
$result['success'] = false;
|
428 |
+
$result['error'] = true;
|
429 |
+
$result['error_messages'] = $this->__('Please agree to all the terms and conditions before placing the order.');
|
430 |
+
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
|
431 |
+
return;
|
432 |
+
}
|
433 |
+
}
|
434 |
+
|
435 |
+
if ($redirectUrl = $this->getRequest()->getPost('redirect')) {
|
436 |
+
$result['success'] = true;
|
437 |
+
$result['error'] = false;
|
438 |
+
$result['redirect'] = $redirectUrl;
|
439 |
+
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
|
440 |
+
return;
|
441 |
+
}
|
442 |
+
|
443 |
+
parent::saveOrderAction();
|
444 |
+
}
|
445 |
+
|
446 |
+
/**
|
447 |
+
* Get shipping method step html
|
448 |
+
*
|
449 |
+
* @return string
|
450 |
+
*/
|
451 |
+
protected function _getShippingMethodsHtml()
|
452 |
+
{
|
453 |
+
if (Mage::helper('japi')->isModuleEnabled('Netzkollektiv_InStorePickupMulti')) {
|
454 |
+
$layout = $this->getLayout();
|
455 |
+
$update = $layout->getUpdate();
|
456 |
+
$update->load('japi_checkout_onepage_shippingmethod');
|
457 |
+
$layout->generateXml();
|
458 |
+
$layout->generateBlocks();
|
459 |
+
$output = $layout->getOutput();
|
460 |
+
return $output;
|
461 |
+
} else {
|
462 |
+
return parent::_getShippingMethodsHtml();
|
463 |
+
}
|
464 |
+
}
|
465 |
+
}
|
app/code/community/Jmango360/Japi/controllers/CustomerController.php
ADDED
@@ -0,0 +1,467 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once 'Mage/Customer/controllers/AccountController.php';
|
3 |
+
|
4 |
+
class Jmango360_Japi_CustomerController extends Mage_Customer_AccountController
|
5 |
+
{
|
6 |
+
public function preDispatch()
|
7 |
+
{
|
8 |
+
call_user_func(array(get_parent_class(get_parent_class($this)), 'preDispatch'));
|
9 |
+
}
|
10 |
+
|
11 |
+
public function registerAction()
|
12 |
+
{
|
13 |
+
$this->loadLayout();
|
14 |
+
$this->getLayout()->getBlock('head')->setTitle($this->__('Create New Customer Account'));
|
15 |
+
$session = $this->_getSession();
|
16 |
+
if ($session->getIsSubmit()) {
|
17 |
+
$session->setIsSubmit(false);
|
18 |
+
$this->getResponse()->setHeader('JM-Account-Id', $session->getCustomerId());
|
19 |
+
$this->getResponse()->setHeader('JM-Account-Email', $session->getCustomerEmail());
|
20 |
+
$this->getResponse()->setHeader('JM-Confirmation-Required', $session->getIsConfirmationRequired());
|
21 |
+
$this->getResponse()->setHeader('JM-Session-Id', $session->getSessionId());
|
22 |
+
}
|
23 |
+
$this->_initLayoutMessages(array('core/session', 'customer/session'));
|
24 |
+
if (Mage::getStoreConfigFlag('japi/jmango_rest_customer_settings/enable_address')) {
|
25 |
+
$form = $this->getLayout()->getBlock('customer_form_register');
|
26 |
+
if ($form) $form->setShowAddressFields(true);
|
27 |
+
}
|
28 |
+
$this->renderLayout();
|
29 |
+
}
|
30 |
+
|
31 |
+
public function createPostAction()
|
32 |
+
{
|
33 |
+
if (version_compare(Mage::getVersion(), '1.8.0', '<')) {
|
34 |
+
$session = $this->_getSession();
|
35 |
+
if ($session->isLoggedIn()) {
|
36 |
+
$this->_redirect('*/*/');
|
37 |
+
return;
|
38 |
+
}
|
39 |
+
$session->setEscapeMessages(true); // prevent XSS injection in user input
|
40 |
+
if ($this->getRequest()->isPost()) {
|
41 |
+
$errors = array();
|
42 |
+
|
43 |
+
if (!$customer = Mage::registry('current_customer')) {
|
44 |
+
$customer = Mage::getModel('customer/customer')->setId(null);
|
45 |
+
}
|
46 |
+
|
47 |
+
/* @var $customerForm Mage_Customer_Model_Form */
|
48 |
+
$customerForm = Mage::getModel('customer/form');
|
49 |
+
$customerForm->setFormCode('customer_account_create')
|
50 |
+
->setEntity($customer);
|
51 |
+
|
52 |
+
$customerData = $customerForm->extractData($this->getRequest());
|
53 |
+
|
54 |
+
if ($this->getRequest()->getParam('is_subscribed', false)) {
|
55 |
+
$customer->setIsSubscribed(1);
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Initialize customer group id
|
60 |
+
*/
|
61 |
+
$customer->getGroupId();
|
62 |
+
|
63 |
+
if ($this->getRequest()->getPost('create_address')) {
|
64 |
+
/* @var $address Mage_Customer_Model_Address */
|
65 |
+
$address = Mage::getModel('customer/address');
|
66 |
+
/* @var $addressForm Mage_Customer_Model_Form */
|
67 |
+
$addressForm = Mage::getModel('customer/form');
|
68 |
+
$addressForm->setFormCode('customer_register_address')
|
69 |
+
->setEntity($address);
|
70 |
+
|
71 |
+
$addressData = $addressForm->extractData($this->getRequest(), 'address', false);
|
72 |
+
$addressErrors = $addressForm->validateData($addressData);
|
73 |
+
if ($addressErrors === true) {
|
74 |
+
$address->setId(null)
|
75 |
+
->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
|
76 |
+
->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
|
77 |
+
$addressForm->compactData($addressData);
|
78 |
+
$customer->addAddress($address);
|
79 |
+
|
80 |
+
$addressErrors = $address->validate();
|
81 |
+
if (is_array($addressErrors)) {
|
82 |
+
$errors = array_merge($errors, $addressErrors);
|
83 |
+
}
|
84 |
+
} else {
|
85 |
+
$errors = array_merge($errors, $addressErrors);
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
try {
|
90 |
+
$customerErrors = $customerForm->validateData($customerData);
|
91 |
+
if ($customerErrors !== true) {
|
92 |
+
$errors = array_merge($customerErrors, $errors);
|
93 |
+
} else {
|
94 |
+
$customerForm->compactData($customerData);
|
95 |
+
$customer->setPassword($this->getRequest()->getPost('password'));
|
96 |
+
$customer->setConfirmation($this->getRequest()->getPost('confirmation'));
|
97 |
+
$customerErrors = $customer->validate();
|
98 |
+
if (is_array($customerErrors)) {
|
99 |
+
$errors = array_merge($customerErrors, $errors);
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
$validationResult = count($errors) == 0;
|
104 |
+
|
105 |
+
if (true === $validationResult) {
|
106 |
+
$customer->save();
|
107 |
+
|
108 |
+
Mage::dispatchEvent('customer_register_success',
|
109 |
+
array('account_controller' => $this, 'customer' => $customer)
|
110 |
+
);
|
111 |
+
|
112 |
+
if ($customer->isConfirmationRequired()) {
|
113 |
+
$customer->sendNewAccountEmail(
|
114 |
+
'confirmation',
|
115 |
+
$session->getBeforeAuthUrl(),
|
116 |
+
Mage::app()->getStore()->getId()
|
117 |
+
);
|
118 |
+
$session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
|
119 |
+
$this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure' => true)));
|
120 |
+
return;
|
121 |
+
} else {
|
122 |
+
//$session->setCustomerAsLoggedIn($customer);
|
123 |
+
$url = $this->_welcomeCustomer($customer);
|
124 |
+
$this->_redirectSuccess($url);
|
125 |
+
return;
|
126 |
+
}
|
127 |
+
} else {
|
128 |
+
$session->setCustomerFormData($this->getRequest()->getPost());
|
129 |
+
if (is_array($errors)) {
|
130 |
+
foreach ($errors as $errorMessage) {
|
131 |
+
$session->addError($errorMessage);
|
132 |
+
}
|
133 |
+
} else {
|
134 |
+
$session->addError($this->__('Invalid customer data'));
|
135 |
+
}
|
136 |
+
}
|
137 |
+
} catch (Mage_Core_Exception $e) {
|
138 |
+
$session->setCustomerFormData($this->getRequest()->getPost());
|
139 |
+
if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
|
140 |
+
$url = Mage::getUrl('customer/account/forgotpassword');
|
141 |
+
$message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
|
142 |
+
$session->setEscapeMessages(false);
|
143 |
+
} else {
|
144 |
+
$message = $e->getMessage();
|
145 |
+
}
|
146 |
+
$session->addError($message);
|
147 |
+
} catch (Exception $e) {
|
148 |
+
$session->setCustomerFormData($this->getRequest()->getPost())
|
149 |
+
->addException($e, $this->__('Cannot save the customer.'));
|
150 |
+
}
|
151 |
+
}
|
152 |
+
|
153 |
+
$this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true)));
|
154 |
+
} else {
|
155 |
+
parent::createPostAction();
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
protected function _getCustomer()
|
160 |
+
{
|
161 |
+
$customer = $this->_getFromRegistry('current_customer');
|
162 |
+
if (!$customer) {
|
163 |
+
$customer = $this->_getModel('customer/customer')->setId(null);
|
164 |
+
}
|
165 |
+
if ($this->getRequest()->getParam('is_subscribed', false)) {
|
166 |
+
$customer->setIsSubscribed(1);
|
167 |
+
}
|
168 |
+
/**
|
169 |
+
* Initialize customer group id
|
170 |
+
*/
|
171 |
+
$customer->getGroupId();
|
172 |
+
|
173 |
+
// Flag as JMango360 user
|
174 |
+
$customer->setData('japi', 1);
|
175 |
+
|
176 |
+
return $customer;
|
177 |
+
}
|
178 |
+
|
179 |
+
protected function _successProcessRegistration(Mage_Customer_Model_Customer $customer)
|
180 |
+
{
|
181 |
+
$session = $this->_getSession();
|
182 |
+
if ($customer->isConfirmationRequired()) {
|
183 |
+
/** @var $app Mage_Core_Model_App */
|
184 |
+
$app = $this->_getApp();
|
185 |
+
/** @var $store Mage_Core_Model_Store */
|
186 |
+
$store = $app->getStore();
|
187 |
+
$customer->sendNewAccountEmail(
|
188 |
+
'confirmation',
|
189 |
+
$session->getBeforeAuthUrl(),
|
190 |
+
$store->getId()
|
191 |
+
);
|
192 |
+
$customerHelper = $this->_getHelper('customer');
|
193 |
+
$session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.',
|
194 |
+
$customerHelper->getEmailConfirmationUrl($customer->getEmail())));
|
195 |
+
$url = $this->_getUrl('*/*/index', array('_secure' => true));
|
196 |
+
} else {
|
197 |
+
//$session->setCustomerAsLoggedIn($customer);
|
198 |
+
$url = $this->_welcomeCustomer($customer);
|
199 |
+
}
|
200 |
+
$this->_redirectSuccess($url);
|
201 |
+
return $this;
|
202 |
+
}
|
203 |
+
|
204 |
+
public function editAction()
|
205 |
+
{
|
206 |
+
$this->loadLayout();
|
207 |
+
$this->getLayout()->getBlock('head')->setTitle($this->__('Account Information'));
|
208 |
+
$session = $this->_getSession();
|
209 |
+
if ($session->getIsSubmit()) {
|
210 |
+
$session->setIsSubmit(false);
|
211 |
+
$this->getResponse()->setHeader('JM-Account-Id', $session->getCustomerId());
|
212 |
+
$this->getResponse()->setHeader('JM-Account-Email', $session->getCustomer()->getEmail());
|
213 |
+
}
|
214 |
+
if (!$session->isLoggedIn()) {
|
215 |
+
$session->addError(Mage::helper('japi')->__('Customer not logged in'));
|
216 |
+
$this->getResponse()->setHeader('HTTP/1.1', '401 Unauthorized', true);
|
217 |
+
}
|
218 |
+
$this->_initLayoutMessages(array('core/session', 'customer/session'));
|
219 |
+
$this->renderLayout();
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* @return Mage_Customer_Model_Session
|
224 |
+
*/
|
225 |
+
protected function _getSession()
|
226 |
+
{
|
227 |
+
return Mage::getSingleton('customer/session');
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* @param $path
|
232 |
+
* @param array $arguments
|
233 |
+
* @return false|Mage_Core_Model_Abstract
|
234 |
+
*/
|
235 |
+
public function _getModel($path, $arguments = array())
|
236 |
+
{
|
237 |
+
return Mage::getModel($path, $arguments);
|
238 |
+
}
|
239 |
+
|
240 |
+
/**
|
241 |
+
* @param string $path
|
242 |
+
* @return Mage_Core_Helper_Abstract
|
243 |
+
*/
|
244 |
+
protected function _getHelper($path)
|
245 |
+
{
|
246 |
+
return Mage::helper($path);
|
247 |
+
}
|
248 |
+
|
249 |
+
public function editPostAction()
|
250 |
+
{
|
251 |
+
if (!$this->_validateFormKey()) {
|
252 |
+
return $this->_redirect('*/*/edit', array('_secure' => true));
|
253 |
+
}
|
254 |
+
|
255 |
+
if ($this->getRequest()->isPost()) {
|
256 |
+
$this->_getSession()->setIsSubmit(true);
|
257 |
+
|
258 |
+
/** @var $customer Mage_Customer_Model_Customer */
|
259 |
+
$customer = $this->_getSession()->getCustomer();
|
260 |
+
|
261 |
+
/** @var $customerForm Mage_Customer_Model_Form */
|
262 |
+
$customerForm = $this->_getModel('customer/form');
|
263 |
+
$customerForm->setFormCode('customer_account_edit')
|
264 |
+
->setEntity($customer);
|
265 |
+
|
266 |
+
$customerData = $customerForm->extractData($this->getRequest());
|
267 |
+
|
268 |
+
$errors = array();
|
269 |
+
$customerErrors = $customerForm->validateData($customerData);
|
270 |
+
if ($customerErrors !== true) {
|
271 |
+
$errors = array_merge($customerErrors, $errors);
|
272 |
+
} else {
|
273 |
+
$customerForm->compactData($customerData);
|
274 |
+
$errors = array();
|
275 |
+
|
276 |
+
// If password change was requested then add it to common validation scheme
|
277 |
+
if ($this->getRequest()->getParam('change_password')) {
|
278 |
+
$currPass = $this->getRequest()->getPost('current_password');
|
279 |
+
$newPass = $this->getRequest()->getPost('password');
|
280 |
+
$confPass = $this->getRequest()->getPost('confirmation');
|
281 |
+
|
282 |
+
$oldPass = $this->_getSession()->getCustomer()->getPasswordHash();
|
283 |
+
if ($this->_getHelper('core/string')->strpos($oldPass, ':')) {
|
284 |
+
list($_salt, $salt) = explode(':', $oldPass);
|
285 |
+
} else {
|
286 |
+
$salt = false;
|
287 |
+
}
|
288 |
+
|
289 |
+
if ($customer->hashPassword($currPass, $salt) == $oldPass) {
|
290 |
+
if (strlen($newPass)) {
|
291 |
+
/**
|
292 |
+
* Set entered password and its confirmation - they
|
293 |
+
* will be validated later to match each other and be of right length
|
294 |
+
*/
|
295 |
+
$customer->setPassword($newPass);
|
296 |
+
$customer->setPasswordConfirmation($confPass);
|
297 |
+
$customer->setConfirmation($confPass);
|
298 |
+
} else {
|
299 |
+
$errors[] = $this->__('New password field cannot be empty.');
|
300 |
+
}
|
301 |
+
} else {
|
302 |
+
$errors[] = $this->__('Invalid current password');
|
303 |
+
}
|
304 |
+
}
|
305 |
+
|
306 |
+
// Validate account and compose list of errors if any
|
307 |
+
$customerErrors = $customer->validate();
|
308 |
+
if (is_array($customerErrors)) {
|
309 |
+
$errors = array_merge($errors, $customerErrors);
|
310 |
+
}
|
311 |
+
}
|
312 |
+
|
313 |
+
if (!empty($errors)) {
|
314 |
+
$this->_getSession()->setCustomerFormData($this->getRequest()->getPost());
|
315 |
+
foreach ($errors as $message) {
|
316 |
+
$this->_getSession()->addError($message);
|
317 |
+
}
|
318 |
+
$this->_redirect('*/*/edit', array('_secure' => true));
|
319 |
+
return $this;
|
320 |
+
}
|
321 |
+
|
322 |
+
try {
|
323 |
+
$customer->setConfirmation(null);
|
324 |
+
$customer->save();
|
325 |
+
$this->_getSession()->setCustomer($customer)
|
326 |
+
->addSuccess($this->__('The account information has been saved.'));
|
327 |
+
|
328 |
+
if ($this->_getSession()->getCheckoutReferer()) {
|
329 |
+
$this->_getSession()->setCheckoutReferer(false);
|
330 |
+
$this->_getSession()->setIsSubmit(false);
|
331 |
+
return $this->_redirect('japi/checkout/onepage', array('_secure' => true));
|
332 |
+
} else {
|
333 |
+
return $this->_redirect('*/*/edit', array('_secure' => true));
|
334 |
+
}
|
335 |
+
} catch (Mage_Core_Exception $e) {
|
336 |
+
$this->_getSession()->setCustomerFormData($this->getRequest()->getPost())
|
337 |
+
->addError($e->getMessage());
|
338 |
+
} catch (Exception $e) {
|
339 |
+
$this->_getSession()->setCustomerFormData($this->getRequest()->getPost())
|
340 |
+
->addException($e, $this->__('Cannot save the customer.'));
|
341 |
+
}
|
342 |
+
}
|
343 |
+
|
344 |
+
$this->_redirect('*/*/edit', array('_secure' => true));
|
345 |
+
}
|
346 |
+
|
347 |
+
public function addressAction()
|
348 |
+
{
|
349 |
+
$this->loadLayout();
|
350 |
+
$this->_updateLayout();
|
351 |
+
$this->getLayout()->getBlock('head')->setTitle($this->__('Add New Address'));
|
352 |
+
$session = $this->_getSession();
|
353 |
+
if ($session->getIsSubmit()) {
|
354 |
+
$session->setIsSubmit(false);
|
355 |
+
$this->getResponse()->setHeader('JM-Account-Id', $session->getCustomerId());
|
356 |
+
$this->getResponse()->setHeader('JM-Account-Email', $session->getCustomer()->getEmail());
|
357 |
+
$this->getResponse()->setHeader('JM-Address-Id', $this->getRequest()->getParam('id'));
|
358 |
+
}
|
359 |
+
if (!$session->isLoggedIn()) {
|
360 |
+
$session->addError(Mage::helper('japi')->__('Customer not logged in'));
|
361 |
+
$this->getResponse()->setHeader('HTTP/1.1', '401 Unauthorized', true);
|
362 |
+
}
|
363 |
+
$this->_initLayoutMessages(array('core/session', 'customer/session'));
|
364 |
+
$this->renderLayout();
|
365 |
+
}
|
366 |
+
|
367 |
+
public function addressPostAction()
|
368 |
+
{
|
369 |
+
if (!$this->_validateFormKey()) {
|
370 |
+
return $this->_redirect('*/*/', array('_secure' => true));
|
371 |
+
}
|
372 |
+
// Save data
|
373 |
+
if ($this->getRequest()->isPost()) {
|
374 |
+
$this->_getSession()->setIsSubmit(true);
|
375 |
+
|
376 |
+
$customer = $this->_getSession()->getCustomer();
|
377 |
+
/* @var $address Mage_Customer_Model_Address */
|
378 |
+
$address = Mage::getModel('customer/address');
|
379 |
+
$addressId = $this->getRequest()->getParam('id');
|
380 |
+
if ($addressId) {
|
381 |
+
$existsAddress = $customer->getAddressById($addressId);
|
382 |
+
if ($existsAddress->getId() && $existsAddress->getCustomerId() == $customer->getId()) {
|
383 |
+
$address->setId($existsAddress->getId());
|
384 |
+
}
|
385 |
+
}
|
386 |
+
|
387 |
+
$errors = array();
|
388 |
+
|
389 |
+
/* @var $addressForm Mage_Customer_Model_Form */
|
390 |
+
$addressForm = Mage::getModel('customer/form');
|
391 |
+
$addressForm->setFormCode('customer_address_edit')
|
392 |
+
->setEntity($address);
|
393 |
+
$addressData = $addressForm->extractData($this->getRequest());
|
394 |
+
$addressErrors = $addressForm->validateData($addressData);
|
395 |
+
if ($addressErrors !== true) {
|
396 |
+
$errors = $addressErrors;
|
397 |
+
}
|
398 |
+
|
399 |
+
try {
|
400 |
+
$addressForm->compactData($addressData);
|
401 |
+
$address->setCustomerId($customer->getId())
|
402 |
+
->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
|
403 |
+
->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
|
404 |
+
|
405 |
+
$addressErrors = $address->validate();
|
406 |
+
if ($addressErrors !== true) {
|
407 |
+
$errors = array_merge($errors, $addressErrors);
|
408 |
+
}
|
409 |
+
|
410 |
+
if (count($errors) === 0) {
|
411 |
+
$address->save();
|
412 |
+
$this->_getSession()->addSuccess($this->__('The address has been saved.'));
|
413 |
+
return $this->_redirect('*/*/address', array('_secure' => true, 'id' => $address->getId()));
|
414 |
+
} else {
|
415 |
+
$this->_getSession()->setAddressFormData($this->getRequest()->getPost());
|
416 |
+
foreach ($errors as $errorMessage) {
|
417 |
+
$this->_getSession()->addError($errorMessage);
|
418 |
+
}
|
419 |
+
}
|
420 |
+
} catch (Mage_Core_Exception $e) {
|
421 |
+
$this->_getSession()->setAddressFormData($this->getRequest()->getPost())
|
422 |
+
->addException($e, $e->getMessage());
|
423 |
+
} catch (Exception $e) {
|
424 |
+
$this->_getSession()->setAddressFormData($this->getRequest()->getPost())
|
425 |
+
->addException($e, $this->__('Cannot save address.'));
|
426 |
+
}
|
427 |
+
}
|
428 |
+
|
429 |
+
return $this->_redirect('*/*/edit', array('_secure' => true, '_current' => true));
|
430 |
+
}
|
431 |
+
|
432 |
+
protected function _updateLayout()
|
433 |
+
{
|
434 |
+
$xml = '';
|
435 |
+
|
436 |
+
if (Mage::helper('core')->isModuleEnabled('PostcodeNl_Api')) {
|
437 |
+
$xml .= "
|
438 |
+
<reference name=\"head\">
|
439 |
+
<action method=\"addCss\" ifconfig=\"postcodenl_api/config/enabled\"><script>postcodenl/api/css/lookup.css</script></action>
|
440 |
+
<action method=\"addJs\" ifconfig=\"postcodenl_api/config/enabled\"><script>postcodenl/api/lookup.js</script></action>
|
441 |
+
</reference>
|
442 |
+
<reference name=\"content\">
|
443 |
+
<block type=\"postcodenl_api/jsinit\" name=\"postcodenl.jsinit\" template=\"postcodenl/api/jsinit.phtml\" />
|
444 |
+
</reference>";
|
445 |
+
}
|
446 |
+
|
447 |
+
if (Mage::helper('core')->isModuleEnabled('TIG_PostNL')) {
|
448 |
+
$xml .= "
|
449 |
+
<reference name=\"head\">
|
450 |
+
<action method=\"addItem\"><type>skin_js</type><file>js/TIG/PostNL/ajax.js</file></action>
|
451 |
+
<action method=\"addItem\"><type>skin_js</type><file>js/TIG/PostNL/postcodecheck.js</file></action>
|
452 |
+
<action method=\"addItem\"><type>skin_css</type><file>css/TIG/PostNL/postcodecheck.css</file></action>
|
453 |
+
<block type=\"core/template\" name=\"postnl_validation\" template=\"TIG/PostNL/address_validation/validate.phtml\"/>
|
454 |
+
</reference>
|
455 |
+
<reference name=\"customer_address_edit\">
|
456 |
+
<block type=\"core/template\" name=\"postnl_postcodecheck\" template=\"japi/TIG/PostNL/address_validation/customer/address/postcode_check.phtml\"/>
|
457 |
+
</reference>";
|
458 |
+
}
|
459 |
+
|
460 |
+
try {
|
461 |
+
$this->getLayout()->getUpdate()->addUpdate($xml);
|
462 |
+
$this->generateLayoutXml()->generateLayoutBlocks();
|
463 |
+
} catch (Exception $e) {
|
464 |
+
Mage::logException($e);
|
465 |
+
}
|
466 |
+
}
|
467 |
+
}
|
app/code/community/Jmango360/Japi/controllers/ImageController.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_ImageController extends Mage_Core_Controller_Front_Action
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Controller entry point
|
7 |
+
*/
|
8 |
+
public function indexAction()
|
9 |
+
{
|
10 |
+
|
11 |
+
$storeId = $this->getRequest()->getParam('store');
|
12 |
+
$productId = $this->getRequest()->getParam('id');
|
13 |
+
$fileName = $this->getRequest()->getParam('file');
|
14 |
+
$height = $this->getRequest()->getParam('h');
|
15 |
+
$width = $this->getRequest()->getParam('w');
|
16 |
+
$size = $this->getRequest()->getParam('size');
|
17 |
+
|
18 |
+
$product = Mage::helper('japi/product')->getProduct($productId, $storeId);
|
19 |
+
|
20 |
+
// Check if width is numeric
|
21 |
+
if($this->_isInteger($width) == false) {
|
22 |
+
$width = null;
|
23 |
+
}
|
24 |
+
|
25 |
+
if($this->_isInteger($height) == false) {
|
26 |
+
$height = null;
|
27 |
+
}
|
28 |
+
|
29 |
+
if($this->_isInteger($size) == false) {
|
30 |
+
$size = null;
|
31 |
+
}
|
32 |
+
|
33 |
+
// Size will has more priority and height is not required
|
34 |
+
if (!is_null($size) && isset($size)) {
|
35 |
+
$width = $size;
|
36 |
+
$height = null;
|
37 |
+
}
|
38 |
+
|
39 |
+
// For Android client, it might append '?size=xxx' at the end of URL
|
40 |
+
$appendValue = '?size=';
|
41 |
+
$sizePos = strpos($fileName, $appendValue);
|
42 |
+
if ($sizePos !== false) {
|
43 |
+
|
44 |
+
// get length value '?size='
|
45 |
+
$sizeLength = strlen($appendValue);
|
46 |
+
|
47 |
+
// Get size actual xxx value
|
48 |
+
$sizeVal = substr($fileName, $sizePos + $sizeLength);
|
49 |
+
|
50 |
+
// Check and use it as width if it is correct value
|
51 |
+
if($this->_isInteger($sizeVal) == true) {
|
52 |
+
$width = $sizeVal;
|
53 |
+
$height = null;
|
54 |
+
}
|
55 |
+
|
56 |
+
// Need to remove the append value
|
57 |
+
$fileName = substr($fileName, 0, $sizePos);
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
// Get image cached
|
62 |
+
$imageUrl = $this->_getCachedImage($product, $fileName, $width, $height);
|
63 |
+
|
64 |
+
|
65 |
+
// Redirect image
|
66 |
+
Mage::app()->getFrontController()->getResponse()->setRedirect($imageUrl);
|
67 |
+
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Get cached image
|
72 |
+
*
|
73 |
+
* @param Mage_Catalog_Model_Product $product
|
74 |
+
* @param $imageFile
|
75 |
+
* @param int $width
|
76 |
+
* @param int $height
|
77 |
+
*
|
78 |
+
* @return mixed
|
79 |
+
*/
|
80 |
+
protected function _getCachedImage(Mage_Catalog_Model_Product $product, $imageFile, $width = null, $height = null) {
|
81 |
+
|
82 |
+
$imageHelper = Mage::helper('catalog/image')->init($product, 'image', $imageFile)
|
83 |
+
->setQuality(100)
|
84 |
+
->constrainOnly(true)
|
85 |
+
->keepAspectRatio(true)
|
86 |
+
->keepFrame(false)
|
87 |
+
->setWatermarkImageOpacity(0);
|
88 |
+
|
89 |
+
|
90 |
+
$cachedImageUrl = null;
|
91 |
+
|
92 |
+
|
93 |
+
// get image path & create image object
|
94 |
+
$imagePath = Mage::getModel('catalog/product_media_config')->getMediaPath($imageFile);
|
95 |
+
$image = new Varien_Image($imagePath);
|
96 |
+
|
97 |
+
// Resize image and only support scale down
|
98 |
+
if ($width != null && $width < $image->getOriginalWidth()) {
|
99 |
+
$imageHelper->resize($width, $height);
|
100 |
+
}
|
101 |
+
|
102 |
+
$cachedImageUrl = $imageHelper->__toString();
|
103 |
+
|
104 |
+
return $cachedImageUrl;
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Check numeric value
|
109 |
+
* @param $input
|
110 |
+
* @return bool
|
111 |
+
*/
|
112 |
+
protected function _isInteger($input){
|
113 |
+
return(ctype_digit(strval($input)));
|
114 |
+
}
|
115 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Rest/CartController.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Rest_CartController extends Jmango360_Japi_Controller_Abstract
|
4 |
+
{
|
5 |
+
public function updateCartAction()
|
6 |
+
{
|
7 |
+
$server = $this->getServer();
|
8 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_cart'));
|
9 |
+
$server->run();
|
10 |
+
}
|
11 |
+
|
12 |
+
public function updateCartItemAction()
|
13 |
+
{
|
14 |
+
$server = $this->getServer();
|
15 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_cart'));
|
16 |
+
$server->run();
|
17 |
+
}
|
18 |
+
|
19 |
+
public function updateCouponAction()
|
20 |
+
{
|
21 |
+
$server = $this->getServer();
|
22 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_cart'));
|
23 |
+
$server->run();
|
24 |
+
}
|
25 |
+
|
26 |
+
public function emptyCartAction()
|
27 |
+
{
|
28 |
+
$server = $this->getServer();
|
29 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_cart'));
|
30 |
+
$server->run();
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getCartAction()
|
34 |
+
{
|
35 |
+
$server = $this->getServer();
|
36 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_cart'));
|
37 |
+
$server->run();
|
38 |
+
}
|
39 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Rest/CatalogController.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Rest_CatalogController extends Jmango360_Japi_Controller_Abstract
|
4 |
+
{
|
5 |
+
/*
|
6 |
+
* @DEPRICATED is going to be replaced by the getCatalogProductList
|
7 |
+
*/
|
8 |
+
public function getAssignedProductsAction()
|
9 |
+
{
|
10 |
+
$server = $this->getServer();
|
11 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_catalog'));
|
12 |
+
$server->run();
|
13 |
+
}
|
14 |
+
|
15 |
+
/*
|
16 |
+
* @TODO is going to replace the getAssigned products service call
|
17 |
+
*/
|
18 |
+
public function getCatalogProductListAction()
|
19 |
+
{
|
20 |
+
$server = $this->getServer();
|
21 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_catalog'));
|
22 |
+
$server->run();
|
23 |
+
}
|
24 |
+
|
25 |
+
public function getLayerFiltersAction()
|
26 |
+
{
|
27 |
+
$server = $this->getServer();
|
28 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_catalog'));
|
29 |
+
$server->run();
|
30 |
+
}
|
31 |
+
|
32 |
+
public function getCategoryTreeAction()
|
33 |
+
{
|
34 |
+
$server = $this->getServer();
|
35 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_catalog'));
|
36 |
+
$server->run();
|
37 |
+
}
|
38 |
+
|
39 |
+
public function getStockItemListAction()
|
40 |
+
{
|
41 |
+
$server = $this->getServer();
|
42 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_catalog'));
|
43 |
+
$server->run();
|
44 |
+
}
|
45 |
+
|
46 |
+
public function searchProductsAction()
|
47 |
+
{
|
48 |
+
$server = $this->getServer();
|
49 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_catalog'));
|
50 |
+
$server->run();
|
51 |
+
}
|
52 |
+
|
53 |
+
public function getProductAction()
|
54 |
+
{
|
55 |
+
$server = $this->getServer();
|
56 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_catalog'));
|
57 |
+
$server->run();
|
58 |
+
}
|
59 |
+
|
60 |
+
public function getCategoryAction()
|
61 |
+
{
|
62 |
+
$server = $this->getServer();
|
63 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_catalog'));
|
64 |
+
$server->run();
|
65 |
+
}
|
66 |
+
|
67 |
+
public function searchTermsAction()
|
68 |
+
{
|
69 |
+
$server = $this->getServer();
|
70 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_catalog'));
|
71 |
+
$server->run();
|
72 |
+
}
|
73 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Rest/CheckoutController.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Rest_CheckoutController extends Jmango360_Japi_Controller_Abstract
|
4 |
+
{
|
5 |
+
public function getCheckoutMethodsAction()
|
6 |
+
{
|
7 |
+
$server = $this->getServer();
|
8 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_checkout'));
|
9 |
+
$server->run();
|
10 |
+
}
|
11 |
+
|
12 |
+
public function updateCartAddressesAction()
|
13 |
+
{
|
14 |
+
$server = $this->getServer();
|
15 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_checkout'));
|
16 |
+
$server->run();
|
17 |
+
}
|
18 |
+
|
19 |
+
public function collectTotalsAction()
|
20 |
+
{
|
21 |
+
$server = $this->getServer();
|
22 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_checkout'));
|
23 |
+
$server->run();
|
24 |
+
}
|
25 |
+
|
26 |
+
public function SubmitOrderAction()
|
27 |
+
{
|
28 |
+
$server = $this->getServer();
|
29 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_checkout'));
|
30 |
+
$server->run();
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getPaymentRedirectAction()
|
34 |
+
{
|
35 |
+
$server = $this->getServer();
|
36 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_checkout'));
|
37 |
+
$server->run();
|
38 |
+
}
|
39 |
+
|
40 |
+
public function updateShippingMethodAction()
|
41 |
+
{
|
42 |
+
$server = $this->getServer();
|
43 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_checkout'));
|
44 |
+
$server->run();
|
45 |
+
}
|
46 |
+
|
47 |
+
public function updatePaymentMethodAction()
|
48 |
+
{
|
49 |
+
$server = $this->getServer();
|
50 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_checkout'));
|
51 |
+
$server->run();
|
52 |
+
}
|
53 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Rest/CmsController.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Rest_CmsController extends Jmango360_Japi_Controller_Abstract
|
4 |
+
{
|
5 |
+
public function getCmsPageListAction()
|
6 |
+
{
|
7 |
+
$this->loadLayout();
|
8 |
+
$server = $this->getServer();
|
9 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_cms'));
|
10 |
+
$server->run();
|
11 |
+
}
|
12 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Rest/CustomerController.php
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Rest_CustomerController extends Jmango360_Japi_Controller_Abstract
|
4 |
+
{
|
5 |
+
public function getCustomerAction()
|
6 |
+
{
|
7 |
+
$server = $this->getServer();
|
8 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
9 |
+
$server->run();
|
10 |
+
}
|
11 |
+
|
12 |
+
public function loginAction()
|
13 |
+
{
|
14 |
+
$server = $this->getServer();
|
15 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
16 |
+
$server->run();
|
17 |
+
}
|
18 |
+
|
19 |
+
public function logoutAction()
|
20 |
+
{
|
21 |
+
$server = $this->getServer();
|
22 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
23 |
+
$server->run();
|
24 |
+
}
|
25 |
+
|
26 |
+
public function registerAction()
|
27 |
+
{
|
28 |
+
$server = $this->getServer();
|
29 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
30 |
+
$server->run();
|
31 |
+
}
|
32 |
+
|
33 |
+
public function editAction()
|
34 |
+
{
|
35 |
+
$server = $this->getServer();
|
36 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
37 |
+
$server->run();
|
38 |
+
}
|
39 |
+
|
40 |
+
public function passwordresetAction()
|
41 |
+
{
|
42 |
+
$server = $this->getServer();
|
43 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
44 |
+
$server->run();
|
45 |
+
}
|
46 |
+
|
47 |
+
public function addressAction()
|
48 |
+
{
|
49 |
+
$server = $this->getServer();
|
50 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
51 |
+
$server->run();
|
52 |
+
}
|
53 |
+
|
54 |
+
public function getCustomerOrderListAction()
|
55 |
+
{
|
56 |
+
$server = $this->getServer();
|
57 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
58 |
+
$server->run();
|
59 |
+
}
|
60 |
+
|
61 |
+
public function getCustomerOrderDetailsAction()
|
62 |
+
{
|
63 |
+
$server = $this->getServer();
|
64 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
65 |
+
$server->run();
|
66 |
+
}
|
67 |
+
|
68 |
+
public function ordersAction()
|
69 |
+
{
|
70 |
+
$server = $this->getServer();
|
71 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
72 |
+
$server->run();
|
73 |
+
}
|
74 |
+
|
75 |
+
public function orderDetailsAction()
|
76 |
+
{
|
77 |
+
$server = $this->getServer();
|
78 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
79 |
+
$server->run();
|
80 |
+
}
|
81 |
+
|
82 |
+
public function groupsAction()
|
83 |
+
{
|
84 |
+
$server = $this->getServer();
|
85 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
86 |
+
$server->run();
|
87 |
+
}
|
88 |
+
|
89 |
+
public function groupAction()
|
90 |
+
{
|
91 |
+
$server = $this->getServer();
|
92 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
93 |
+
$server->run();
|
94 |
+
}
|
95 |
+
|
96 |
+
public function searchAction()
|
97 |
+
{
|
98 |
+
$server = $this->getServer();
|
99 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_customer'));
|
100 |
+
$server->run();
|
101 |
+
}
|
102 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Rest/MageController.php
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Rest_MageController extends Jmango360_Japi_Controller_Abstract
|
4 |
+
{
|
5 |
+
public function storeAction()
|
6 |
+
{
|
7 |
+
$server = $this->getServer();
|
8 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
9 |
+
$server->run();
|
10 |
+
}
|
11 |
+
|
12 |
+
public function getSessionAction()
|
13 |
+
{
|
14 |
+
$server = $this->getServer();
|
15 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
16 |
+
$server->run();
|
17 |
+
}
|
18 |
+
|
19 |
+
public function getTokenAction()
|
20 |
+
{
|
21 |
+
$server = $this->getServer();
|
22 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
23 |
+
$server->run();
|
24 |
+
}
|
25 |
+
|
26 |
+
public function getMagentoInfoAction()
|
27 |
+
{
|
28 |
+
$server = $this->getServer();
|
29 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
30 |
+
$server->run();
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getPluginVersionAction()
|
34 |
+
{
|
35 |
+
$server = $this->getServer();
|
36 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
37 |
+
$server->run();
|
38 |
+
}
|
39 |
+
|
40 |
+
public function getConfigInfoAction()
|
41 |
+
{
|
42 |
+
$server = $this->getServer();
|
43 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
44 |
+
$server->run();
|
45 |
+
}
|
46 |
+
|
47 |
+
public function getDirectoryCountryListAction()
|
48 |
+
{
|
49 |
+
$server = $this->getServer();
|
50 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
51 |
+
$server->run();
|
52 |
+
}
|
53 |
+
|
54 |
+
public function getDirectoryRegionListAction()
|
55 |
+
{
|
56 |
+
$server = $this->getServer();
|
57 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
58 |
+
$server->run();
|
59 |
+
}
|
60 |
+
|
61 |
+
public function getMagentoModulesAction()
|
62 |
+
{
|
63 |
+
$server = $this->getServer();
|
64 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
65 |
+
$server->run();
|
66 |
+
}
|
67 |
+
|
68 |
+
public function getModuleRewritesAction()
|
69 |
+
{
|
70 |
+
$server = $this->getServer();
|
71 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
72 |
+
$server->run();
|
73 |
+
}
|
74 |
+
|
75 |
+
public function updateThemeAction()
|
76 |
+
{
|
77 |
+
$server = $this->getServer();
|
78 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
79 |
+
$server->run();
|
80 |
+
}
|
81 |
+
|
82 |
+
public function getThemeAction()
|
83 |
+
{
|
84 |
+
$server = $this->getServer();
|
85 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
86 |
+
$server->run();
|
87 |
+
}
|
88 |
+
|
89 |
+
public function redirectAction()
|
90 |
+
{
|
91 |
+
/**
|
92 |
+
* MPLUGIN-1126: by pass check user's IP adress to auto redirect when website installed "Experius_Geoipredirect"
|
93 |
+
*/
|
94 |
+
$helper = Mage::helper('japi');
|
95 |
+
if ($helper->isModuleEnabled('Experius_Geoipredirect')) {
|
96 |
+
Mage::getSingleton('core/session')->setData('ipcheck_redirected', Mage::app()->getStore()->getId());
|
97 |
+
}
|
98 |
+
$url = $this->getRequest()->getParam('url');
|
99 |
+
if (strpos($url, 'http') === 0) {
|
100 |
+
$this->_redirectUrl($url);
|
101 |
+
} else {
|
102 |
+
$this->_redirect($url);
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
public function ordersAction()
|
107 |
+
{
|
108 |
+
$server = $this->getServer();
|
109 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_mage'));
|
110 |
+
$server->run();
|
111 |
+
}
|
112 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Rest/ProductController.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Rest_ProductController extends Jmango360_Japi_Controller_Abstract
|
4 |
+
{
|
5 |
+
public function listAction()
|
6 |
+
{
|
7 |
+
$server = $this->getServer();
|
8 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_product'));
|
9 |
+
$server->run();
|
10 |
+
}
|
11 |
+
|
12 |
+
public function detailAction()
|
13 |
+
{
|
14 |
+
$server = $this->getServer();
|
15 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_product'));
|
16 |
+
$server->run();
|
17 |
+
}
|
18 |
+
|
19 |
+
public function searchAction()
|
20 |
+
{
|
21 |
+
$server = $this->getServer();
|
22 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_product'));
|
23 |
+
$server->run();
|
24 |
+
}
|
25 |
+
|
26 |
+
public function getRecentlyViewedAction()
|
27 |
+
{
|
28 |
+
$server = $this->getServer();
|
29 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_product'));
|
30 |
+
$server->run();
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getRecentlyPurchasedAction()
|
34 |
+
{
|
35 |
+
$server = $this->getServer();
|
36 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_product'));
|
37 |
+
$server->run();
|
38 |
+
}
|
39 |
+
|
40 |
+
public function suggestAction()
|
41 |
+
{
|
42 |
+
$server = $this->getServer();
|
43 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_product'));
|
44 |
+
$server->run();
|
45 |
+
}
|
46 |
+
}
|
app/code/community/Jmango360/Japi/controllers/Rest/WishlistController.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Jmango360_Japi_Rest_WishlistController extends Jmango360_Japi_Controller_Abstract
|
4 |
+
{
|
5 |
+
public function getItemsAction()
|
6 |
+
{
|
7 |
+
$server = $this->getServer();
|
8 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_wishlist'));
|
9 |
+
$server->run();
|
10 |
+
}
|
11 |
+
|
12 |
+
public function addAction()
|
13 |
+
{
|
14 |
+
$server = $this->getServer();
|
15 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_wishlist'));
|
16 |
+
$server->run();
|
17 |
+
}
|
18 |
+
|
19 |
+
public function updateAction()
|
20 |
+
{
|
21 |
+
$server = $this->getServer();
|
22 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_wishlist'));
|
23 |
+
$server->run();
|
24 |
+
}
|
25 |
+
|
26 |
+
public function removeAction()
|
27 |
+
{
|
28 |
+
$server = $this->getServer();
|
29 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_wishlist'));
|
30 |
+
$server->run();
|
31 |
+
}
|
32 |
+
|
33 |
+
public function cartAction()
|
34 |
+
{
|
35 |
+
$server = $this->getServer();
|
36 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_wishlist'));
|
37 |
+
$server->run();
|
38 |
+
}
|
39 |
+
|
40 |
+
public function allcartAction()
|
41 |
+
{
|
42 |
+
$server = $this->getServer();
|
43 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_wishlist'));
|
44 |
+
$server->run();
|
45 |
+
}
|
46 |
+
|
47 |
+
public function updateItemOptionsAction()
|
48 |
+
{
|
49 |
+
$server = $this->getServer();
|
50 |
+
$server->setRestDispatchModel(Mage::getModel('japi/rest_wishlist'));
|
51 |
+
$server->run();
|
52 |
+
}
|
53 |
+
}
|
app/code/community/Jmango360/Japi/controllers/TestController.php
ADDED
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* Oauth 1.0 3-way token test controller
|
5 |
+
*
|
6 |
+
*
|
7 |
+
*
|
8 |
+
*/
|
9 |
+
class Jmango360_Japi_TestController extends Mage_Core_Controller_Front_Action
|
10 |
+
{
|
11 |
+
//Find consumer key in admin: system/webservices/Rest OAuth consumers
|
12 |
+
const CONSUMERKEY = '17353f0dbb5153e1318dfede8e97ce6c';
|
13 |
+
const CONSUMERSECRET = '7a5ab5fa9d41055b375f4cccca811109';
|
14 |
+
|
15 |
+
private $_requestTokenParams = array(
|
16 |
+
'siteUrl' => ':baseurl/oauth',
|
17 |
+
'requestTokenUrl' => ':baseurl/oauth/initiate',
|
18 |
+
'consumerKey' => self::CONSUMERKEY,//Consumer key registered in server administration
|
19 |
+
'consumerSecret' => self::CONSUMERSECRET,//Consumer secret registered in server administration
|
20 |
+
);
|
21 |
+
|
22 |
+
public function translationsTestAction()
|
23 |
+
{
|
24 |
+
$strings = Mage::app()->getRequest()->getParam('strings');
|
25 |
+
$countryId = Mage::app()->getRequest()->getParam('country_id');
|
26 |
+
|
27 |
+
if ($countryId) {
|
28 |
+
$locale = $countryId;
|
29 |
+
Mage::app()->getLocale()->setLocaleCode($locale);
|
30 |
+
Mage::getSingleton('core/translate')->setLocale($locale)->init('frontend', true);
|
31 |
+
}
|
32 |
+
|
33 |
+
foreach((array)$strings as $text) {
|
34 |
+
$trans[] = Mage::helper('japi')->__($text);
|
35 |
+
}
|
36 |
+
print Mage::helper('core')->jsonEncode($trans);
|
37 |
+
|
38 |
+
exit();
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
// public function indexAction()
|
43 |
+
// {
|
44 |
+
// // Get session
|
45 |
+
// $session = Mage::getSingleton('core/session');
|
46 |
+
|
47 |
+
// $baseurl = Mage::getUrl();
|
48 |
+
// $currentUrl = Mage::getModel('core/url')->getUrl('*/*/*', array('_current' => true));
|
49 |
+
// $session->setLastUsedRestUrl($currentUrl);
|
50 |
+
|
51 |
+
// $restOperationName = $this->getRequest()->getParam('path');
|
52 |
+
// if (! $restOperationName) {
|
53 |
+
// exit('No Path found. Specify path with operation name. Example: ' . $baseurl . 'japi/test?path=api/rest/products/1/categories&method=get. See also <a target="blank" href="http://www.magentocommerce.com/api/rest/Resources/resources.html">http://www.magentocommerce.com/api/rest/Resources/resources.html</a>');
|
54 |
+
// }
|
55 |
+
// $session->setLastRestOperationName($restOperationName);
|
56 |
+
|
57 |
+
// $method = $this->getRequest()->getParam('method');
|
58 |
+
// if (empty($method)) {
|
59 |
+
// $method = 'GET';
|
60 |
+
// }
|
61 |
+
// $session->setLastUsedMethod($method);
|
62 |
+
|
63 |
+
// //Basic parameters that need to be provided for oAuth authentication
|
64 |
+
// //on Magento
|
65 |
+
// $params = array(
|
66 |
+
// 'siteUrl' => $baseurl . 'oauth',
|
67 |
+
// 'requestTokenUrl' => $baseurl . 'oauth/initiate',
|
68 |
+
// 'accessTokenUrl' => $baseurl . 'oauth/token',
|
69 |
+
// 'authorizeUrl' => $baseurl . 'admin/oAuth_authorize',//This URL is used only if we authenticate as Admin user type
|
70 |
+
// 'consumerKey' => self::CONSUMERKEY,//Consumer key registered in server administration
|
71 |
+
// 'consumerSecret' => self::CONSUMERSECRET,//Consumer secret registered in server administration
|
72 |
+
// 'callbackUrl' => $baseurl . 'japi/test/callback',//Url of callback action below
|
73 |
+
// );
|
74 |
+
|
75 |
+
// // Initiate oAuth consumer with above parameters
|
76 |
+
// $consumer = new Zend_Oauth_Consumer($params);
|
77 |
+
// // Get request token
|
78 |
+
// $requestToken = $consumer->getRequestToken();
|
79 |
+
// // Save serialized request token object in session for later use
|
80 |
+
// $session->setRequestToken(serialize($requestToken));
|
81 |
+
// // Redirect to authorize URL
|
82 |
+
// $consumer->redirect();
|
83 |
+
|
84 |
+
// return;
|
85 |
+
// }
|
86 |
+
|
87 |
+
public function requestTokenAction()
|
88 |
+
{
|
89 |
+
$session = Mage::getSingleton('core/session');
|
90 |
+
$consumer = new Zend_Oauth_Consumer($this->_getTestParams());
|
91 |
+
$requestToken = $consumer->getRequestToken();
|
92 |
+
$session->setRequestToken(serialize($requestToken));
|
93 |
+
|
94 |
+
print '<a target="blank" href="' . Mage::getUrl() . "japi/test/verifierConfirm?oauth_token=" . $requestToken->getToken() . '">confirm</a><br /><br />' . "\n\n";
|
95 |
+
|
96 |
+
/**TEST OUTPUT**/
|
97 |
+
print "===================Tokens==============";
|
98 |
+
$requestInSession = unserialize($session->getRequestToken());
|
99 |
+
$token = $requestInSession->getToken();
|
100 |
+
$secret = $requestInSession->getTokenSecret();
|
101 |
+
|
102 |
+
Zend_Debug::dump(array('secret'=>$secret, 'token'=>$token));
|
103 |
+
|
104 |
+
print '=================DEBUG===============';
|
105 |
+
Zend_Debug::dump(array('secret'=>$secret, 'token'=>$token, 'request token in session'=>$requestInSession, 'requestToken' => $requestToken, 'session' => $session));
|
106 |
+
exit;
|
107 |
+
}
|
108 |
+
|
109 |
+
public function verifierConfirmAction()
|
110 |
+
{
|
111 |
+
$helper = Mage::helper('oauth');
|
112 |
+
$server = Mage::getModel('oauth/server');
|
113 |
+
|
114 |
+
/*TEST*/
|
115 |
+
$userId = 1; //$user->getId()
|
116 |
+
$userType = Mage_Oauth_Model_Token::USER_TYPE_ADMIN;
|
117 |
+
|
118 |
+
$token = $server->authorizeToken($userId, Mage_Oauth_Model_Token::USER_TYPE_ADMIN);
|
119 |
+
$tokenString = $token->getToken();
|
120 |
+
$verifierString = $token->getVerifier();
|
121 |
+
|
122 |
+
print '<a target="blank" href="' . Mage::getUrl() . "japi/test/callback?oauth_token={$tokenString}&oauth_verifier={$verifierString}" . '">callBack</a><br /><br />' . "\n\n";
|
123 |
+
|
124 |
+
/*TEST*/
|
125 |
+
print '==================TEST Token==============';
|
126 |
+
Zend_Debug::dump($token);
|
127 |
+
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Basic parameters that need to be provided for oAuth authentication on Magento
|
132 |
+
* @return $params
|
133 |
+
*/
|
134 |
+
private function _getTestParams()
|
135 |
+
{
|
136 |
+
$baseurl = Mage::getUrl();
|
137 |
+
foreach ($this->_requestTokenParams as $key => $value) {
|
138 |
+
$params[$key] = str_replace(':baseurl/', $baseurl, $value);
|
139 |
+
}
|
140 |
+
return $params;
|
141 |
+
}
|
142 |
+
|
143 |
+
public function callbackAction() {
|
144 |
+
|
145 |
+
//oAuth parameters
|
146 |
+
$method = 'GET';
|
147 |
+
$baseurl = Mage::getUrl();
|
148 |
+
$params = array(
|
149 |
+
'siteUrl' => $baseurl . 'oauth',
|
150 |
+
'requestTokenUrl' => $baseurl . 'oauth/initiate',
|
151 |
+
'accessTokenUrl' => $baseurl . 'oauth/token',
|
152 |
+
'consumerKey' => self::CONSUMERKEY,
|
153 |
+
'consumerSecret' => self::CONSUMERSECRET
|
154 |
+
);
|
155 |
+
|
156 |
+
// Get session
|
157 |
+
$session = Mage::getSingleton('core/session');
|
158 |
+
// Read and unserialize request token from session
|
159 |
+
$requestToken = unserialize($session->getRequestToken());
|
160 |
+
// Initiate oAuth consumer
|
161 |
+
$consumer = new Zend_Oauth_Consumer($params);
|
162 |
+
// Using oAuth parameters and request Token we got, get access token
|
163 |
+
$acessToken = $consumer->getAccessToken($_GET, $requestToken);
|
164 |
+
// Get HTTP client from access token object
|
165 |
+
$restClient = $acessToken->getHttpClient($params);
|
166 |
+
|
167 |
+
// Set REST resource URL, example: api/rest/products/1/categories
|
168 |
+
//$restOperationName = $session->getLastRestOperationName();
|
169 |
+
//if (empty($restOperationName)) {
|
170 |
+
$restOperationName = 'api/rest/products';
|
171 |
+
//}
|
172 |
+
|
173 |
+
|
174 |
+
|
175 |
+
|
176 |
+
$restClient->setUri($baseurl . $restOperationName);
|
177 |
+
// In Magento it is neccesary to set json or xml headers in order to work
|
178 |
+
$restClient->setHeaders('Accept', 'application/json');
|
179 |
+
// Get method
|
180 |
+
//$method = strtoupper($session->getLastUsedMethod());
|
181 |
+
//$restClient->setMethod(constant('Zend_Http_Client::'.$method));
|
182 |
+
$restClient->setMethod($method);
|
183 |
+
//Make REST request
|
184 |
+
$response = $restClient->request();
|
185 |
+
// Here we can see that response body contains json list of products
|
186 |
+
print "<pre>";
|
187 |
+
print "JSON: " . $response->getBody();
|
188 |
+
print "JSON_DECODE: "; print_r((array)json_decode((string)$response->getBody()));
|
189 |
+
print "</pre><br /><br />\n\n";
|
190 |
+
print '<a href="' . $session->getLastUsedRestUrl() . '" target="blank">' . $session->getLastUsedRestUrl() . '</a>';
|
191 |
+
|
192 |
+
return;
|
193 |
+
}
|
194 |
+
|
195 |
+
public function addJapiColumnAction()
|
196 |
+
{
|
197 |
+
$_coreResource = Mage::getSingleton('core/resource');
|
198 |
+
$adapter = $_coreResource->getConnection('core_read');
|
199 |
+
|
200 |
+
$_gridTableName = $_coreResource->getTableName('sales/order_grid');
|
201 |
+
$_orderTableName = $_coreResource->getTableName('sales/order');
|
202 |
+
|
203 |
+
if ($adapter->isTableExists($_gridTableName)){
|
204 |
+
if ($adapter->tableColumnExists($_gridTableName, 'japi')) {
|
205 |
+
echo 'Column japi exits. Not need to update! <br/><br/><br/>';
|
206 |
+
$selectOrder = $adapter->select()
|
207 |
+
->from($_gridTableName)
|
208 |
+
->where('japi = ?', 1);
|
209 |
+
$dataOrder = $adapter->fetchAll($selectOrder);
|
210 |
+
foreach ($dataOrder as $data) {
|
211 |
+
echo($data['entity_id'] . ' =====> ' . $data['japi']); echo '<br/>';
|
212 |
+
}
|
213 |
+
} else {
|
214 |
+
$write = $_coreResource->getConnection('core_write');
|
215 |
+
$write->addColumn($_gridTableName, 'japi', 'int');
|
216 |
+
|
217 |
+
$select = $adapter->select();
|
218 |
+
$select->join(
|
219 |
+
array('order_table' => $_orderTableName),
|
220 |
+
'order_table.entity_id = grid_table.entity_id',
|
221 |
+
array('japi')
|
222 |
+
);
|
223 |
+
$write->query($select->crossUpdateFromSelect(array(
|
224 |
+
'grid_table' => $_gridTableName
|
225 |
+
)));
|
226 |
+
echo 'Column japi has been added';
|
227 |
+
}
|
228 |
+
} else {
|
229 |
+
echo "Table " . $_gridTableName . " not exist";
|
230 |
+
}
|
231 |
+
|
232 |
+
}
|
233 |
+
|
234 |
+
}
|
app/code/community/Jmango360/Japi/data/japi_setup/data-install-2.0.0.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$config = Mage::getConfig();
|
3 |
+
/* @var $helper Mage_Core_Helper_Data */
|
4 |
+
$helper = Mage::helper('core');
|
5 |
+
$apiKey = strtoupper(substr($helper->uniqHash(), 0, 16));
|
6 |
+
$config->saveConfig('japi/jmango_rest_api/apikey', $apiKey);
|
7 |
+
$config->saveConfig('japi/jmango_rest_api/apiuser', 'jmango360');
|
app/code/community/Jmango360/Japi/etc/adminhtml.xml
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
-->
|
7 |
+
<config>
|
8 |
+
<menu>
|
9 |
+
<japi>
|
10 |
+
<title>JMango360</title>
|
11 |
+
<sort_order>70</sort_order>
|
12 |
+
<children>
|
13 |
+
<report translate="title" module="japi">
|
14 |
+
<title>Reports</title>
|
15 |
+
<sort_order>0</sort_order>
|
16 |
+
<children>
|
17 |
+
<orders translate="title" module="japi">
|
18 |
+
<title>Orders</title>
|
19 |
+
<action>adminhtml/japi_report/index/type/orders</action>
|
20 |
+
<sort_order>0</sort_order>
|
21 |
+
</orders>
|
22 |
+
<sales translate="title" module="japi">
|
23 |
+
<title>Sales</title>
|
24 |
+
<action>adminhtml/japi_report/index/type/sales</action>
|
25 |
+
<sort_order>10</sort_order>
|
26 |
+
</sales>
|
27 |
+
<customer translate="title" module="japi">
|
28 |
+
<title>Customers</title>
|
29 |
+
<action>adminhtml/japi_report/index/type/customers</action>
|
30 |
+
<sort_order>20</sort_order>
|
31 |
+
</customer>
|
32 |
+
<japi_order translate="title" module="japi">
|
33 |
+
<title>Order Details</title>
|
34 |
+
<action>adminhtml/japi_order/index/</action>
|
35 |
+
<sort_order>30</sort_order>
|
36 |
+
</japi_order>
|
37 |
+
</children>
|
38 |
+
</report>
|
39 |
+
<setting translate="title" module="japi">
|
40 |
+
<title>Settings</title>
|
41 |
+
<action>adminhtml/system_config/edit/section/japi</action>
|
42 |
+
<sort_order>10</sort_order>
|
43 |
+
</setting>
|
44 |
+
</children>
|
45 |
+
</japi>
|
46 |
+
</menu>
|
47 |
+
<acl>
|
48 |
+
<resources>
|
49 |
+
<all>
|
50 |
+
<title>Allow everything</title>
|
51 |
+
</all>
|
52 |
+
<admin>
|
53 |
+
<children>
|
54 |
+
<japi>
|
55 |
+
<title>JMango360</title>
|
56 |
+
<children>
|
57 |
+
<report translate="title" module="japi">
|
58 |
+
<title>Reports</title>
|
59 |
+
<children>
|
60 |
+
<orders translate="title" module="japi">
|
61 |
+
<title>Orders</title>
|
62 |
+
</orders>
|
63 |
+
<sales translate="title" module="japi">
|
64 |
+
<title>Sales</title>
|
65 |
+
</sales>
|
66 |
+
<customer translate="title" module="japi">
|
67 |
+
<title>Customers</title>
|
68 |
+
</customer>
|
69 |
+
<japi_order translate="title" module="japi">
|
70 |
+
<title>Order Details</title>
|
71 |
+
</japi_order>
|
72 |
+
</children>
|
73 |
+
</report>
|
74 |
+
<setting translate="title" module="japi">
|
75 |
+
<title>Settings</title>
|
76 |
+
</setting>
|
77 |
+
<log translate="title" module="japi">
|
78 |
+
<title>Download log files</title>
|
79 |
+
</log>
|
80 |
+
</children>
|
81 |
+
</japi>
|
82 |
+
<system>
|
83 |
+
<children>
|
84 |
+
<config>
|
85 |
+
<children>
|
86 |
+
<japi translate="title" module="japi">
|
87 |
+
<title>JMango360 Mobile</title>
|
88 |
+
</japi>
|
89 |
+
</children>
|
90 |
+
</config>
|
91 |
+
</children>
|
92 |
+
</system>
|
93 |
+
</children>
|
94 |
+
</admin>
|
95 |
+
</resources>
|
96 |
+
</acl>
|
97 |
+
</config>
|
app/code/community/Jmango360/Japi/etc/config.xml
ADDED
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
-->
|
7 |
+
<config>
|
8 |
+
<modules>
|
9 |
+
<Jmango360_Japi>
|
10 |
+
<version>2.8.1</version>
|
11 |
+
</Jmango360_Japi>
|
12 |
+
</modules>
|
13 |
+
|
14 |
+
<global>
|
15 |
+
<models>
|
16 |
+
<japi>
|
17 |
+
<class>Jmango360_Japi_Model</class>
|
18 |
+
<resourceModel>japi_resource</resourceModel>
|
19 |
+
</japi>
|
20 |
+
<japi_resource>
|
21 |
+
<class>Jmango360_Japi_Model_Resource</class>
|
22 |
+
<entities>
|
23 |
+
<sales_order_aggregated>
|
24 |
+
<table>japi_sales_order_aggregated</table>
|
25 |
+
</sales_order_aggregated>
|
26 |
+
</entities>
|
27 |
+
</japi_resource>
|
28 |
+
<tierprices>
|
29 |
+
<rewrite>
|
30 |
+
<price>Jmango360_Japi_Model_Magpleasure_Tierprices_Price</price>
|
31 |
+
</rewrite>
|
32 |
+
</tierprices>
|
33 |
+
</models>
|
34 |
+
<resources>
|
35 |
+
<japi_setup>
|
36 |
+
<setup>
|
37 |
+
<module>Jmango360_Japi</module>
|
38 |
+
<class>Jmango360_Japi_Model_Resource_Setup</class>
|
39 |
+
</setup>
|
40 |
+
</japi_setup>
|
41 |
+
</resources>
|
42 |
+
<fieldsets>
|
43 |
+
<sales_convert_quote>
|
44 |
+
<japi>
|
45 |
+
<to_order>*</to_order>
|
46 |
+
</japi>
|
47 |
+
</sales_convert_quote>
|
48 |
+
<sales_convert_order>
|
49 |
+
<japi>
|
50 |
+
<to_quote>*</to_quote>
|
51 |
+
</japi>
|
52 |
+
</sales_convert_order>
|
53 |
+
</fieldsets>
|
54 |
+
<blocks>
|
55 |
+
<japi>
|
56 |
+
<class>Jmango360_Japi_Block</class>
|
57 |
+
</japi>
|
58 |
+
<checkout>
|
59 |
+
<rewrite>
|
60 |
+
<onepage_billing>Jmango360_Japi_Block_Checkout_Onepage_Billing</onepage_billing>
|
61 |
+
<onepage_shipping>Jmango360_Japi_Block_Checkout_Onepage_Shipping</onepage_shipping>
|
62 |
+
</rewrite>
|
63 |
+
</checkout>
|
64 |
+
</blocks>
|
65 |
+
<helpers>
|
66 |
+
<japi>
|
67 |
+
<class>Jmango360_Japi_Helper</class>
|
68 |
+
</japi>
|
69 |
+
</helpers>
|
70 |
+
<events>
|
71 |
+
<controller_front_init_before>
|
72 |
+
<observers>
|
73 |
+
<rest_init_before>
|
74 |
+
<class>japi/observer</class>
|
75 |
+
<method>controllerFrontInitBefore</method>
|
76 |
+
</rest_init_before>
|
77 |
+
</observers>
|
78 |
+
</controller_front_init_before>
|
79 |
+
</events>
|
80 |
+
</global>
|
81 |
+
|
82 |
+
<frontend>
|
83 |
+
<events>
|
84 |
+
<controller_action_postdispatch_checkout_onepage_success>
|
85 |
+
<observers>
|
86 |
+
<rest_checkout_success>
|
87 |
+
<class>japi/observer</class>
|
88 |
+
<method>setOrderIdToHeader</method>
|
89 |
+
</rest_checkout_success>
|
90 |
+
</observers>
|
91 |
+
</controller_action_postdispatch_checkout_onepage_success>
|
92 |
+
<controller_action_predispatch_checkout_onepage_index>
|
93 |
+
<observers>
|
94 |
+
<rest_checkout_success>
|
95 |
+
<class>japi/observer</class>
|
96 |
+
<method>handleErrorCheckout</method>
|
97 |
+
</rest_checkout_success>
|
98 |
+
</observers>
|
99 |
+
</controller_action_predispatch_checkout_onepage_index>
|
100 |
+
<controller_action_predispatch_checkout_cart_index>
|
101 |
+
<observers>
|
102 |
+
<rest_checkout_success>
|
103 |
+
<class>japi/observer</class>
|
104 |
+
<method>handleErrorCheckout</method>
|
105 |
+
</rest_checkout_success>
|
106 |
+
</observers>
|
107 |
+
</controller_action_predispatch_checkout_cart_index>
|
108 |
+
<controller_action_predispatch_paypal_express_return>
|
109 |
+
<observers>
|
110 |
+
<rest_checkout_success>
|
111 |
+
<class>japi/observer</class>
|
112 |
+
<method>skipPaypalExpressReview</method>
|
113 |
+
</rest_checkout_success>
|
114 |
+
</observers>
|
115 |
+
</controller_action_predispatch_paypal_express_return>
|
116 |
+
<controller_action_predispatch_paypal_express_placeOrder>
|
117 |
+
<observers>
|
118 |
+
<rest_checkout_success>
|
119 |
+
<class>japi/observer</class>
|
120 |
+
<method>skipPaypalExpressReview</method>
|
121 |
+
</rest_checkout_success>
|
122 |
+
</observers>
|
123 |
+
</controller_action_predispatch_paypal_express_placeOrder>
|
124 |
+
<controller_action_layout_generate_blocks_after>
|
125 |
+
<observers>
|
126 |
+
<rest_checkout_success>
|
127 |
+
<class>japi/observer</class>
|
128 |
+
<method>setOrderIdToHead</method>
|
129 |
+
</rest_checkout_success>
|
130 |
+
</observers>
|
131 |
+
</controller_action_layout_generate_blocks_after>
|
132 |
+
<core_block_abstract_to_html_before>
|
133 |
+
<observers>
|
134 |
+
<tig_postnl_customer_address_edit_postcodecheck>
|
135 |
+
<type>singleton</type>
|
136 |
+
<class>japi/observer</class>
|
137 |
+
<method>addressBookPostcodeCheck</method>
|
138 |
+
</tig_postnl_customer_address_edit_postcodecheck>
|
139 |
+
<tig_postnl_checkout_onepage_shipping_postcodecheck>
|
140 |
+
<type>singleton</type>
|
141 |
+
<class>japi/observer</class>
|
142 |
+
<method>shippingAddressPostcodeCheck</method>
|
143 |
+
</tig_postnl_checkout_onepage_shipping_postcodecheck>
|
144 |
+
<tig_postnl_checkout_onepage_billing_postcodecheck>
|
145 |
+
<type>singleton</type>
|
146 |
+
<class>japi/observer</class>
|
147 |
+
<method>billingAddressPostcodeCheck</method>
|
148 |
+
</tig_postnl_checkout_onepage_billing_postcodecheck>
|
149 |
+
</observers>
|
150 |
+
</core_block_abstract_to_html_before>
|
151 |
+
<customer_register_success>
|
152 |
+
<observers>
|
153 |
+
<japi_customer_register_success>
|
154 |
+
<type>singleton</type>
|
155 |
+
<class>japi/observer</class>
|
156 |
+
<method>customerRegisterSuccess</method>
|
157 |
+
</japi_customer_register_success>
|
158 |
+
</observers>
|
159 |
+
</customer_register_success>
|
160 |
+
</events>
|
161 |
+
<routers>
|
162 |
+
<japi>
|
163 |
+
<use>standard</use>
|
164 |
+
<args>
|
165 |
+
<module>Jmango360_Japi</module>
|
166 |
+
<frontName>japi</frontName>
|
167 |
+
</args>
|
168 |
+
</japi>
|
169 |
+
</routers>
|
170 |
+
<translate>
|
171 |
+
<modules>
|
172 |
+
<Jmango360_Japi>
|
173 |
+
<files>
|
174 |
+
<default>Jmango360_Japi.csv</default>
|
175 |
+
</files>
|
176 |
+
</Jmango360_Japi>
|
177 |
+
</modules>
|
178 |
+
</translate>
|
179 |
+
<layout>
|
180 |
+
<updates>
|
181 |
+
<japi>
|
182 |
+
<file>jmango360_japi.xml</file>
|
183 |
+
</japi>
|
184 |
+
</updates>
|
185 |
+
</layout>
|
186 |
+
</frontend>
|
187 |
+
|
188 |
+
<admin>
|
189 |
+
<routers>
|
190 |
+
<adminhtml>
|
191 |
+
<args>
|
192 |
+
<modules>
|
193 |
+
<japi before="Mage_Adminhtml">Jmango360_Japi_Adminhtml</japi>
|
194 |
+
</modules>
|
195 |
+
</args>
|
196 |
+
</adminhtml>
|
197 |
+
</routers>
|
198 |
+
</admin>
|
199 |
+
|
200 |
+
<adminhtml>
|
201 |
+
<layout>
|
202 |
+
<updates>
|
203 |
+
<japi>
|
204 |
+
<file>jmango360_japi.xml</file>
|
205 |
+
</japi>
|
206 |
+
</updates>
|
207 |
+
</layout>
|
208 |
+
<translate>
|
209 |
+
<modules>
|
210 |
+
<Jmango360_Japi>
|
211 |
+
<files>
|
212 |
+
<default>Jmango360_Japi.csv</default>
|
213 |
+
</files>
|
214 |
+
</Jmango360_Japi>
|
215 |
+
</modules>
|
216 |
+
</translate>
|
217 |
+
<events>
|
218 |
+
<controller_action_predispatch>
|
219 |
+
<observers>
|
220 |
+
<rest_action_predispatch>
|
221 |
+
<class>japi/observer</class>
|
222 |
+
<method>restAdminActionPreDispatch</method>
|
223 |
+
</rest_action_predispatch>
|
224 |
+
</observers>
|
225 |
+
</controller_action_predispatch>
|
226 |
+
<core_block_abstract_to_html_before>
|
227 |
+
<observers>
|
228 |
+
<japi_core_block_abstract_to_html_before>
|
229 |
+
<class>japi/observer</class>
|
230 |
+
<method>coreBlockAbstractToHtmlBefore</method>
|
231 |
+
</japi_core_block_abstract_to_html_before>
|
232 |
+
</observers>
|
233 |
+
</core_block_abstract_to_html_before>
|
234 |
+
<eav_collection_abstract_load_before>
|
235 |
+
<observers>
|
236 |
+
<eav_collection_abstract_load_before>
|
237 |
+
<class>japi/observer</class>
|
238 |
+
<method>eavCollectionAbstractLoadBefore</method>
|
239 |
+
</eav_collection_abstract_load_before>
|
240 |
+
</observers>
|
241 |
+
</eav_collection_abstract_load_before>
|
242 |
+
</events>
|
243 |
+
</adminhtml>
|
244 |
+
|
245 |
+
<crontab>
|
246 |
+
<jobs>
|
247 |
+
<japi_aggregate_sales_report_order_data>
|
248 |
+
<schedule>
|
249 |
+
<cron_expr>0 0 * * *</cron_expr>
|
250 |
+
</schedule>
|
251 |
+
<run>
|
252 |
+
<model>japi/observer::aggregateSalesReportOrderData</model>
|
253 |
+
</run>
|
254 |
+
</japi_aggregate_sales_report_order_data>
|
255 |
+
</jobs>
|
256 |
+
</crontab>
|
257 |
+
|
258 |
+
<default>
|
259 |
+
<japi>
|
260 |
+
<jmango_rest_api>
|
261 |
+
<apiuser>jmango360</apiuser>
|
262 |
+
<use_token>0</use_token>
|
263 |
+
</jmango_rest_api>
|
264 |
+
<jmango_rest_catalog_settings>
|
265 |
+
<include_all_active>1</include_all_active>
|
266 |
+
<hide_null_value>0</hide_null_value>
|
267 |
+
</jmango_rest_catalog_settings>
|
268 |
+
<jmango_rest_checkout_settings>
|
269 |
+
<onepage>1</onepage>
|
270 |
+
</jmango_rest_checkout_settings>
|
271 |
+
<jmango_rest_gallery_settings>
|
272 |
+
<image_width>1200</image_width>
|
273 |
+
<image_height>1200</image_height>
|
274 |
+
<small_image_width>800</small_image_width>
|
275 |
+
<small_image_height>800</small_image_height>
|
276 |
+
<thumbnail_width>400</thumbnail_width>
|
277 |
+
<thumbnail_height>400</thumbnail_height>
|
278 |
+
<image_default_listing>thumbnail</image_default_listing>
|
279 |
+
<catalog_image_default>thumbnail</catalog_image_default>
|
280 |
+
<show_grouped_item_image>0</show_grouped_item_image>
|
281 |
+
</jmango_rest_gallery_settings>
|
282 |
+
<jmango_rest_developer_settings>
|
283 |
+
<enable>0</enable>
|
284 |
+
</jmango_rest_developer_settings>
|
285 |
+
<jmango_rest_sales_settings>
|
286 |
+
<display_order_from>1</display_order_from>
|
287 |
+
</jmango_rest_sales_settings>
|
288 |
+
<jmango_rest_customer_settings>
|
289 |
+
<display_customer_from>1</display_customer_from>
|
290 |
+
<enable_address>0</enable_address>
|
291 |
+
<street2_require>1</street2_require>
|
292 |
+
<street2_type>number</street2_type>
|
293 |
+
<street3_require>0</street3_require>
|
294 |
+
<street4_require>0</street4_require>
|
295 |
+
</jmango_rest_customer_settings>
|
296 |
+
<jmango_app_login_settings>
|
297 |
+
<require_login>0</require_login>
|
298 |
+
</jmango_app_login_settings>
|
299 |
+
</japi>
|
300 |
+
</default>
|
301 |
+
</config>
|
app/code/community/Jmango360/Japi/etc/system.xml
ADDED
@@ -0,0 +1,517 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<japi translate="label" module="japi">
|
5 |
+
<class>separator-top</class>
|
6 |
+
<label>JMango360 Mobile</label>
|
7 |
+
<tab>service</tab>
|
8 |
+
<frontend_type>text</frontend_type>
|
9 |
+
<sort_order>400</sort_order>
|
10 |
+
<show_in_default>1</show_in_default>
|
11 |
+
<show_in_website>0</show_in_website>
|
12 |
+
<show_in_store>0</show_in_store>
|
13 |
+
<groups>
|
14 |
+
<jmango_rest_api translate="label" module="japi">
|
15 |
+
<label>Connection credentials</label>
|
16 |
+
<show_in_default>1</show_in_default>
|
17 |
+
<show_in_website>0</show_in_website>
|
18 |
+
<show_in_store>0</show_in_store>
|
19 |
+
<sort_order>10</sort_order>
|
20 |
+
<fields>
|
21 |
+
<version translate="label comment" module="japi">
|
22 |
+
<label>Version</label>
|
23 |
+
<frontend_type>text</frontend_type>
|
24 |
+
<frontend_model>japi/adminhtml_system_config_form_version</frontend_model>
|
25 |
+
<sort_order>0</sort_order>
|
26 |
+
<show_in_default>1</show_in_default>
|
27 |
+
<show_in_website>1</show_in_website>
|
28 |
+
<show_in_store>1</show_in_store>
|
29 |
+
<comment>The plugin version</comment>
|
30 |
+
</version>
|
31 |
+
<apiuser translate="label comment" module="japi">
|
32 |
+
<label>User Name</label>
|
33 |
+
<frontend_type>text</frontend_type>
|
34 |
+
<frontend_model>japi/adminhtml_system_config_form_user</frontend_model>
|
35 |
+
<sort_order>10</sort_order>
|
36 |
+
<show_in_default>1</show_in_default>
|
37 |
+
<show_in_website>1</show_in_website>
|
38 |
+
<show_in_store>1</show_in_store>
|
39 |
+
<comment>This username will be checked from every App while a session is set up between the
|
40 |
+
App and the Magento store.
|
41 |
+
</comment>
|
42 |
+
</apiuser>
|
43 |
+
<apikey translate="label comment" module="japi">
|
44 |
+
<label>Api Key</label>
|
45 |
+
<frontend_type>text</frontend_type>
|
46 |
+
<sort_order>20</sort_order>
|
47 |
+
<show_in_default>1</show_in_default>
|
48 |
+
<show_in_website>1</show_in_website>
|
49 |
+
<show_in_store>1</show_in_store>
|
50 |
+
<comment>This key will be checked from every App while a session is set up between the App
|
51 |
+
and the Magento store.
|
52 |
+
</comment>
|
53 |
+
</apikey>
|
54 |
+
<use_token translate="label comment" module="japi">
|
55 |
+
<label>Use token for Api communications</label>
|
56 |
+
<frontend_type>select</frontend_type>
|
57 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
58 |
+
<sort_order>30</sort_order>
|
59 |
+
<show_in_default>1</show_in_default>
|
60 |
+
<show_in_website>1</show_in_website>
|
61 |
+
<show_in_store>1</show_in_store>
|
62 |
+
<comment>Use token will add check and refresh the token with every request.</comment>
|
63 |
+
</use_token>
|
64 |
+
</fields>
|
65 |
+
</jmango_rest_api>
|
66 |
+
<jmango_rest_catalog_settings translate="label" module="japi">
|
67 |
+
<label>Catalogue Settings</label>
|
68 |
+
<show_in_default>1</show_in_default>
|
69 |
+
<show_in_website>0</show_in_website>
|
70 |
+
<show_in_store>0</show_in_store>
|
71 |
+
<sort_order>20</sort_order>
|
72 |
+
<fields>
|
73 |
+
<include_all_active translate="label comment" module="japi">
|
74 |
+
<label>Include all active categories</label>
|
75 |
+
<frontend_type>select</frontend_type>
|
76 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
77 |
+
<sort_order>10</sort_order>
|
78 |
+
<show_in_default>1</show_in_default>
|
79 |
+
<show_in_website>1</show_in_website>
|
80 |
+
<show_in_store>1</show_in_store>
|
81 |
+
<comment>Include all "Active" categories regardless of whether or not they are included in
|
82 |
+
navigation
|
83 |
+
</comment>
|
84 |
+
</include_all_active>
|
85 |
+
<attribute_on_listing translate="label comment" module="japi">
|
86 |
+
<label>Display attribute on Product Listing</label>
|
87 |
+
<frontend_type>select</frontend_type>
|
88 |
+
<source_model>japi/system_config_source_attributes</source_model>
|
89 |
+
<sort_order>20</sort_order>
|
90 |
+
<show_in_default>1</show_in_default>
|
91 |
+
<show_in_website>1</show_in_website>
|
92 |
+
<show_in_store>1</show_in_store>
|
93 |
+
<comment>This attribute will be displayed in product listing</comment>
|
94 |
+
</attribute_on_listing>
|
95 |
+
<attribute_on_details translate="label comment" module="japi">
|
96 |
+
<label>Display attribute on Product Details</label>
|
97 |
+
<frontend_type>select</frontend_type>
|
98 |
+
<source_model>japi/system_config_source_attributes</source_model>
|
99 |
+
<sort_order>30</sort_order>
|
100 |
+
<show_in_default>1</show_in_default>
|
101 |
+
<show_in_website>1</show_in_website>
|
102 |
+
<show_in_store>1</show_in_store>
|
103 |
+
<comment>This attribute will be displayed in product details</comment>
|
104 |
+
</attribute_on_details>
|
105 |
+
<hide_null_value translate="label comment" module="japi">
|
106 |
+
<label>Hide non value additional attributes</label>
|
107 |
+
<frontend_type>select</frontend_type>
|
108 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
109 |
+
<sort_order>40</sort_order>
|
110 |
+
<show_in_default>1</show_in_default>
|
111 |
+
<show_in_website>1</show_in_website>
|
112 |
+
<show_in_store>1</show_in_store>
|
113 |
+
<comment>Attribute whose value is N/A or blank will not be displayed on Additional
|
114 |
+
Information on product detail page
|
115 |
+
</comment>
|
116 |
+
</hide_null_value>
|
117 |
+
<show_grouped_item_image translate="label comment" module="japi">
|
118 |
+
<label>Show image of child product in Grouped Product Detail on mobile</label>
|
119 |
+
<frontend_type>select</frontend_type>
|
120 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
121 |
+
<sort_order>100</sort_order>
|
122 |
+
<show_in_default>1</show_in_default>
|
123 |
+
<show_in_website>1</show_in_website>
|
124 |
+
<show_in_store>1</show_in_store>
|
125 |
+
</show_grouped_item_image>
|
126 |
+
</fields>
|
127 |
+
</jmango_rest_catalog_settings>
|
128 |
+
<jmango_app_login_settings translate="label" module="japi">
|
129 |
+
<label>Mobile App Login Settings</label>
|
130 |
+
<show_in_default>1</show_in_default>
|
131 |
+
<show_in_website>0</show_in_website>
|
132 |
+
<show_in_store>0</show_in_store>
|
133 |
+
<sort_order>21</sort_order>
|
134 |
+
<fields>
|
135 |
+
<require_login translate="label" module="japi">
|
136 |
+
<label>App users must login to see product prices</label>
|
137 |
+
<frontend_type>select</frontend_type>
|
138 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
139 |
+
<sort_order>10</sort_order>
|
140 |
+
<show_in_default>1</show_in_default>
|
141 |
+
<show_in_website>1</show_in_website>
|
142 |
+
<show_in_store>1</show_in_store>
|
143 |
+
<comment>This will prevent mobile app user using app without an account.</comment>
|
144 |
+
</require_login>
|
145 |
+
</fields>
|
146 |
+
</jmango_app_login_settings>
|
147 |
+
<jmango_rest_checkout_settings translate="label" module="japi">
|
148 |
+
<label>Mobile App Checkout Settings</label>
|
149 |
+
<show_in_default>1</show_in_default>
|
150 |
+
<show_in_website>0</show_in_website>
|
151 |
+
<show_in_store>0</show_in_store>
|
152 |
+
<sort_order>25</sort_order>
|
153 |
+
<fields>
|
154 |
+
<shipping_excluded translate="label" module="japi">
|
155 |
+
<label>Excluded shipping methods</label>
|
156 |
+
<frontend_type>multiselect</frontend_type>
|
157 |
+
<source_model>japi/system_config_source_shipping</source_model>
|
158 |
+
<backend_model>japi/system_config_backend_shipping</backend_model>
|
159 |
+
<sort_order>10</sort_order>
|
160 |
+
<show_in_default>1</show_in_default>
|
161 |
+
<show_in_website>1</show_in_website>
|
162 |
+
<show_in_store>1</show_in_store>
|
163 |
+
<can_be_empty>1</can_be_empty>
|
164 |
+
<comment>Select one or more, but not all shipping methods that are not suitable/compatible
|
165 |
+
to be used in mobile app environment. This can be set anytime during or after creation
|
166 |
+
of JMango360 application.
|
167 |
+
</comment>
|
168 |
+
</shipping_excluded>
|
169 |
+
<payment_excluded translate="label" module="japi">
|
170 |
+
<label>Excluded payment methods</label>
|
171 |
+
<frontend_type>multiselect</frontend_type>
|
172 |
+
<source_model>japi/system_config_source_payment</source_model>
|
173 |
+
<backend_model>japi/system_config_backend_payment</backend_model>
|
174 |
+
<sort_order>20</sort_order>
|
175 |
+
<show_in_default>1</show_in_default>
|
176 |
+
<show_in_website>1</show_in_website>
|
177 |
+
<show_in_store>1</show_in_store>
|
178 |
+
<can_be_empty>1</can_be_empty>
|
179 |
+
<comment>Select one or more, but not all payment methods that are not suitable/compatible to
|
180 |
+
be used in mobile app environment. This can be set anytime during or after creation of
|
181 |
+
JMango360 application.
|
182 |
+
</comment>
|
183 |
+
</payment_excluded>
|
184 |
+
<onepage translate="label" module="japi">
|
185 |
+
<label>Use Onepage checkout for mobile app</label>
|
186 |
+
<frontend_type>select</frontend_type>
|
187 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
188 |
+
<sort_order>25</sort_order>
|
189 |
+
<show_in_default>1</show_in_default>
|
190 |
+
<show_in_website>1</show_in_website>
|
191 |
+
<show_in_store>1</show_in_store>
|
192 |
+
<can_be_empty>1</can_be_empty>
|
193 |
+
<comment>Select to use JMango360 Onepage responsive web checkout for mobile app instead of
|
194 |
+
default Magento checkout
|
195 |
+
</comment>
|
196 |
+
</onepage>
|
197 |
+
<custom_xml translate="label" module="japi">
|
198 |
+
<label>Custom Layout Update</label>
|
199 |
+
<frontend_type>textarea</frontend_type>
|
200 |
+
<sort_order>26</sort_order>
|
201 |
+
<show_in_default>1</show_in_default>
|
202 |
+
<show_in_website>1</show_in_website>
|
203 |
+
<show_in_store>1</show_in_store>
|
204 |
+
<comment>Enter xml layout update code here, it will only affect JMango360 Onepage checkout
|
205 |
+
page
|
206 |
+
</comment>
|
207 |
+
<depends>
|
208 |
+
<onepage>1</onepage>
|
209 |
+
</depends>
|
210 |
+
</custom_xml>
|
211 |
+
<custom_css translate="label" module="japi">
|
212 |
+
<label>Custom CSS</label>
|
213 |
+
<frontend_type>textarea</frontend_type>
|
214 |
+
<sort_order>27</sort_order>
|
215 |
+
<show_in_default>1</show_in_default>
|
216 |
+
<show_in_website>1</show_in_website>
|
217 |
+
<show_in_store>1</show_in_store>
|
218 |
+
<comment>Enter css code here, it will only append to JMango360 Onepage checkout page
|
219 |
+
</comment>
|
220 |
+
<depends>
|
221 |
+
<onepage>1</onepage>
|
222 |
+
</depends>
|
223 |
+
</custom_css>
|
224 |
+
<checkout_url translate="label" module="japi">
|
225 |
+
<label>Web checkout URL</label>
|
226 |
+
<frontend_type>text</frontend_type>
|
227 |
+
<sort_order>30</sort_order>
|
228 |
+
<show_in_default>1</show_in_default>
|
229 |
+
<show_in_website>1</show_in_website>
|
230 |
+
<show_in_store>1</show_in_store>
|
231 |
+
<can_be_empty>1</can_be_empty>
|
232 |
+
<comment>Enter custom checkout url of website if Jmango360 plugin could not detect. Ex:
|
233 |
+
checkout/onepage.
|
234 |
+
</comment>
|
235 |
+
<depends>
|
236 |
+
<onepage>0</onepage>
|
237 |
+
</depends>
|
238 |
+
</checkout_url>
|
239 |
+
</fields>
|
240 |
+
</jmango_rest_checkout_settings>
|
241 |
+
<jmango_rest_gallery_settings translate="label" module="japi">
|
242 |
+
<label>Product image gallery settings</label>
|
243 |
+
<show_in_default>1</show_in_default>
|
244 |
+
<show_in_website>0</show_in_website>
|
245 |
+
<show_in_store>0</show_in_store>
|
246 |
+
<sort_order>30</sort_order>
|
247 |
+
<fields>
|
248 |
+
<image_width translate="label comment" module="japi">
|
249 |
+
<label>Detail page image cache-width</label>
|
250 |
+
<frontend_type>text</frontend_type>
|
251 |
+
<sort_order>10</sort_order>
|
252 |
+
<show_in_default>1</show_in_default>
|
253 |
+
<show_in_website>1</show_in_website>
|
254 |
+
<show_in_store>1</show_in_store>
|
255 |
+
<comment>Set the default "cached" size for "big" images on the detail pages.</comment>
|
256 |
+
</image_width>
|
257 |
+
<image_height translate="label comment" module="japi">
|
258 |
+
<label>Detail page image cache-height</label>
|
259 |
+
<frontend_type>text</frontend_type>
|
260 |
+
<sort_order>20</sort_order>
|
261 |
+
<show_in_default>1</show_in_default>
|
262 |
+
<show_in_website>1</show_in_website>
|
263 |
+
<show_in_store>1</show_in_store>
|
264 |
+
<comment>Set the default "cached" size for "big" images on the detail pages.</comment>
|
265 |
+
</image_height>
|
266 |
+
<small_image_width translate="label comment" module="japi">
|
267 |
+
<label>Catalogue image cache-width</label>
|
268 |
+
<frontend_type>text</frontend_type>
|
269 |
+
<sort_order>30</sort_order>
|
270 |
+
<show_in_default>1</show_in_default>
|
271 |
+
<show_in_website>1</show_in_website>
|
272 |
+
<show_in_store>1</show_in_store>
|
273 |
+
<comment>Set the default "cached" size for images on the catalogue pages.</comment>
|
274 |
+
</small_image_width>
|
275 |
+
<small_image_height translate="label comment" module="japi">
|
276 |
+
<label>Catalogue image cache-height</label>
|
277 |
+
<frontend_type>text</frontend_type>
|
278 |
+
<sort_order>40</sort_order>
|
279 |
+
<show_in_default>1</show_in_default>
|
280 |
+
<show_in_website>1</show_in_website>
|
281 |
+
<show_in_store>1</show_in_store>
|
282 |
+
<comment>Set the default "cached" size for images on the catalogue pages.</comment>
|
283 |
+
</small_image_height>
|
284 |
+
<thumbnail_width translate="label comment" module="japi">
|
285 |
+
<label>Thumbnail image cache-width</label>
|
286 |
+
<frontend_type>text</frontend_type>
|
287 |
+
<sort_order>50</sort_order>
|
288 |
+
<show_in_default>1</show_in_default>
|
289 |
+
<show_in_website>1</show_in_website>
|
290 |
+
<show_in_store>1</show_in_store>
|
291 |
+
<comment>Set the default "cached" size for thumbnails on the detail pages.</comment>
|
292 |
+
</thumbnail_width>
|
293 |
+
<thumbnail_height translate="label comment" module="japi">
|
294 |
+
<label>Thumbnail image cache-height</label>
|
295 |
+
<frontend_type>text</frontend_type>
|
296 |
+
<sort_order>60</sort_order>
|
297 |
+
<show_in_default>1</show_in_default>
|
298 |
+
<show_in_website>1</show_in_website>
|
299 |
+
<show_in_store>1</show_in_store>
|
300 |
+
<comment>Set the default "cached" size for thumbnails on the detail pages.</comment>
|
301 |
+
</thumbnail_height>
|
302 |
+
<catalog_image_default translate="label comment" module="japi">
|
303 |
+
<label>Choose image type to be displayed if catalogue thumbnail is not available</label>
|
304 |
+
<frontend_type>select</frontend_type>
|
305 |
+
<source_model>japi/system_config_source_catalogimage</source_model>
|
306 |
+
<sort_order>80</sort_order>
|
307 |
+
<show_in_default>1</show_in_default>
|
308 |
+
<show_in_website>1</show_in_website>
|
309 |
+
<show_in_store>1</show_in_store>
|
310 |
+
<comment>Choose what kind of image of product that I would like to show in catalogue listing
|
311 |
+
in mobile app.
|
312 |
+
</comment>
|
313 |
+
</catalog_image_default>
|
314 |
+
<image_default_listing translate="label comment" module="japi">
|
315 |
+
<label>Choose image type to be displayed on catalogue page</label>
|
316 |
+
<frontend_type>select</frontend_type>
|
317 |
+
<source_model>japi/system_config_source_defaultimage</source_model>
|
318 |
+
<sort_order>90</sort_order>
|
319 |
+
<show_in_default>1</show_in_default>
|
320 |
+
<show_in_website>1</show_in_website>
|
321 |
+
<show_in_store>1</show_in_store>
|
322 |
+
<comment>Choose what kind of image of product that I would like to show in product listing
|
323 |
+
in mobile app.
|
324 |
+
</comment>
|
325 |
+
</image_default_listing>
|
326 |
+
</fields>
|
327 |
+
</jmango_rest_gallery_settings>
|
328 |
+
<jmango_rest_stock_settings translate="label" module="japi">
|
329 |
+
<label>Stock Settings</label>
|
330 |
+
<show_in_default>1</show_in_default>
|
331 |
+
<show_in_website>0</show_in_website>
|
332 |
+
<show_in_store>0</show_in_store>
|
333 |
+
<sort_order>35</sort_order>
|
334 |
+
<fields>
|
335 |
+
<display_product_stock_status translate="label" module="japi">
|
336 |
+
<label>Display products availability in stock in mobile app</label>
|
337 |
+
<frontend_type>select</frontend_type>
|
338 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
339 |
+
<sort_order>0</sort_order>
|
340 |
+
<show_in_default>1</show_in_default>
|
341 |
+
<show_in_website>1</show_in_website>
|
342 |
+
<show_in_store>1</show_in_store>
|
343 |
+
</display_product_stock_status>
|
344 |
+
</fields>
|
345 |
+
</jmango_rest_stock_settings>
|
346 |
+
<jmango_rest_sales_settings translate="label" module="japi">
|
347 |
+
<label>Sales Settings</label>
|
348 |
+
<show_in_default>1</show_in_default>
|
349 |
+
<show_in_website>0</show_in_website>
|
350 |
+
<show_in_store>0</show_in_store>
|
351 |
+
<sort_order>36</sort_order>
|
352 |
+
<fields>
|
353 |
+
<display_order_from translate="label" module="japi">
|
354 |
+
<label>Enable Order From in orders list</label>
|
355 |
+
<frontend_type>select</frontend_type>
|
356 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
357 |
+
<sort_order>0</sort_order>
|
358 |
+
<show_in_default>1</show_in_default>
|
359 |
+
<show_in_website>1</show_in_website>
|
360 |
+
<show_in_store>1</show_in_store>
|
361 |
+
<comment>Select to view which orders are from JMango360</comment>
|
362 |
+
</display_order_from>
|
363 |
+
</fields>
|
364 |
+
</jmango_rest_sales_settings>
|
365 |
+
<jmango_rest_customer_settings translate="label" module="japi">
|
366 |
+
<label>Customer Settings</label>
|
367 |
+
<show_in_default>1</show_in_default>
|
368 |
+
<show_in_website>0</show_in_website>
|
369 |
+
<show_in_store>0</show_in_store>
|
370 |
+
<sort_order>37</sort_order>
|
371 |
+
<fields>
|
372 |
+
<display_customer_from translate="label" module="japi">
|
373 |
+
<label>Enable JMango360 User in Customers list</label>
|
374 |
+
<frontend_type>select</frontend_type>
|
375 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
376 |
+
<sort_order>0</sort_order>
|
377 |
+
<show_in_default>1</show_in_default>
|
378 |
+
<show_in_website>1</show_in_website>
|
379 |
+
<show_in_store>1</show_in_store>
|
380 |
+
<comment>Select to view which customers are from JMango360</comment>
|
381 |
+
</display_customer_from>
|
382 |
+
<!--attributes translate="label" module="japi">
|
383 |
+
<label>Select customer attributes</label>
|
384 |
+
<frontend_type>multiselect</frontend_type>
|
385 |
+
<source_model>japi/system_config_source_customer_attributes</source_model>
|
386 |
+
<sort_order>10</sort_order>
|
387 |
+
<show_in_default>1</show_in_default>
|
388 |
+
<show_in_website>1</show_in_website>
|
389 |
+
<show_in_store>1</show_in_store>
|
390 |
+
<can_be_empty>1</can_be_empty>
|
391 |
+
<comment>Select one or more attributes to include to customer registration form in mobile app</comment>
|
392 |
+
</attributes!-->
|
393 |
+
<enable_address translate="label" module="japi">
|
394 |
+
<label>Enable additional fields on sign up form</label>
|
395 |
+
<frontend_type>select</frontend_type>
|
396 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
397 |
+
<sort_order>20</sort_order>
|
398 |
+
<show_in_default>1</show_in_default>
|
399 |
+
<show_in_website>1</show_in_website>
|
400 |
+
<show_in_store>1</show_in_store>
|
401 |
+
<comment>Enable additional fields on sign up form</comment>
|
402 |
+
</enable_address>
|
403 |
+
<!--address_attributes translate="label" module="japi">
|
404 |
+
<label>Select address attributes</label>
|
405 |
+
<frontend_type>multiselect</frontend_type>
|
406 |
+
<source_model>japi/system_config_source_address_attributes</source_model>
|
407 |
+
<sort_order>30</sort_order>
|
408 |
+
<show_in_default>1</show_in_default>
|
409 |
+
<show_in_website>1</show_in_website>
|
410 |
+
<show_in_store>1</show_in_store>
|
411 |
+
<can_be_empty>1</can_be_empty>
|
412 |
+
<comment>Select one or more attributes to include to customer registration form in mobile app</comment>
|
413 |
+
</address_attributes-->
|
414 |
+
<street2_label translate="label" module="japi">
|
415 |
+
<label>Street Address #2 Label</label>
|
416 |
+
<frontend_type>text</frontend_type>
|
417 |
+
<sort_order>40</sort_order>
|
418 |
+
<show_in_default>1</show_in_default>
|
419 |
+
<show_in_website>1</show_in_website>
|
420 |
+
<show_in_store>1</show_in_store>
|
421 |
+
<comment>Set the label for 2nd street address.</comment>
|
422 |
+
</street2_label>
|
423 |
+
<street2_require translate="label" module="japi">
|
424 |
+
<label>Street Address #2 as Required</label>
|
425 |
+
<frontend_type>select</frontend_type>
|
426 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
427 |
+
<sort_order>50</sort_order>
|
428 |
+
<show_in_default>1</show_in_default>
|
429 |
+
<show_in_website>1</show_in_website>
|
430 |
+
<show_in_store>1</show_in_store>
|
431 |
+
<comment>Set if the street address field is required input.</comment>
|
432 |
+
</street2_require>
|
433 |
+
<street2_type translate="label" module="japi">
|
434 |
+
<label>Street Address #2 Validation</label>
|
435 |
+
<frontend_type>select</frontend_type>
|
436 |
+
<source_model>japi/system_config_source_address_validatetype</source_model>
|
437 |
+
<sort_order>60</sort_order>
|
438 |
+
<show_in_default>1</show_in_default>
|
439 |
+
<show_in_website>1</show_in_website>
|
440 |
+
<show_in_store>1</show_in_store>
|
441 |
+
<comment>Set type of input for the street address field.</comment>
|
442 |
+
</street2_type>
|
443 |
+
<street3_label translate="label" module="japi">
|
444 |
+
<label>Street Address #3 Label</label>
|
445 |
+
<frontend_type>text</frontend_type>
|
446 |
+
<sort_order>70</sort_order>
|
447 |
+
<show_in_default>1</show_in_default>
|
448 |
+
<show_in_website>1</show_in_website>
|
449 |
+
<show_in_store>1</show_in_store>
|
450 |
+
<comment>Set the label for 3rd street address.</comment>
|
451 |
+
</street3_label>
|
452 |
+
<street3_require translate="label" module="japi">
|
453 |
+
<label>Street Address #3 as Required</label>
|
454 |
+
<frontend_type>select</frontend_type>
|
455 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
456 |
+
<sort_order>80</sort_order>
|
457 |
+
<show_in_default>1</show_in_default>
|
458 |
+
<show_in_website>1</show_in_website>
|
459 |
+
<show_in_store>1</show_in_store>
|
460 |
+
<comment>Set if the street address field is required input.</comment>
|
461 |
+
</street3_require>
|
462 |
+
<street4_label translate="label" module="japi">
|
463 |
+
<label>Street Address #4 Label</label>
|
464 |
+
<frontend_type>text</frontend_type>
|
465 |
+
<sort_order>90</sort_order>
|
466 |
+
<show_in_default>1</show_in_default>
|
467 |
+
<show_in_website>1</show_in_website>
|
468 |
+
<show_in_store>1</show_in_store>
|
469 |
+
<comment>Set the label for 4th street address.</comment>
|
470 |
+
</street4_label>
|
471 |
+
<street4_require translate="label" module="japi">
|
472 |
+
<label>Street Address #4 as Required</label>
|
473 |
+
<frontend_type>select</frontend_type>
|
474 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
475 |
+
<sort_order>100</sort_order>
|
476 |
+
<show_in_default>1</show_in_default>
|
477 |
+
<show_in_website>1</show_in_website>
|
478 |
+
<show_in_store>1</show_in_store>
|
479 |
+
<comment>Set if the street address field is required input.</comment>
|
480 |
+
</street4_require>
|
481 |
+
</fields>
|
482 |
+
</jmango_rest_customer_settings>
|
483 |
+
<jmango_rest_developer_settings translate="label" module="japi">
|
484 |
+
<label>Developer</label>
|
485 |
+
<show_in_default>1</show_in_default>
|
486 |
+
<show_in_website>0</show_in_website>
|
487 |
+
<show_in_store>0</show_in_store>
|
488 |
+
<sort_order>40</sort_order>
|
489 |
+
<fields>
|
490 |
+
<enable translate="label comment" module="japi">
|
491 |
+
<label>Enable debug logging</label>
|
492 |
+
<frontend_type>select</frontend_type>
|
493 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
494 |
+
<sort_order>10</sort_order>
|
495 |
+
<show_in_default>1</show_in_default>
|
496 |
+
<show_in_website>1</show_in_website>
|
497 |
+
<show_in_store>1</show_in_store>
|
498 |
+
<comment>Log requests to japi.log. Disable in production.</comment>
|
499 |
+
</enable>
|
500 |
+
<log_file translate="label">
|
501 |
+
<label></label>
|
502 |
+
<frontend_type>button</frontend_type>
|
503 |
+
<frontend_model>japi/adminhtml_system_config_form_log</frontend_model>
|
504 |
+
<sort_order>20</sort_order>
|
505 |
+
<show_in_default>1</show_in_default>
|
506 |
+
<show_in_website>1</show_in_website>
|
507 |
+
<show_in_store>1</show_in_store>
|
508 |
+
<depends>
|
509 |
+
<enable>1</enable>
|
510 |
+
</depends>
|
511 |
+
</log_file>
|
512 |
+
</fields>
|
513 |
+
</jmango_rest_developer_settings>
|
514 |
+
</groups>
|
515 |
+
</japi>
|
516 |
+
</sections>
|
517 |
+
</config>
|
app/code/community/Jmango360/Japi/sql/japi_setup/install-1.0.0.php
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?php
|
app/code/community/Jmango360/Japi/sql/japi_setup/upgrade-2.0.1.2-2.0.2.php
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2015 JMango360
|
4 |
+
*/
|
5 |
+
|
6 |
+
/* @var $this Mage_Catalog_Model_Resource_Setup */
|
7 |
+
$this->startSetup();
|
8 |
+
|
9 |
+
$installer = new Mage_Sales_Model_Resource_Setup('core_setup');
|
10 |
+
$installer->addAttribute('order', 'japi', array('type' => 'int'));
|
11 |
+
$installer->addAttribute('quote', 'japi', array('type' => 'int'));
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Create table 'japi/sales_order_aggregated'
|
15 |
+
*/
|
16 |
+
$tableName = $installer->getTable('japi/sales_order_aggregated');
|
17 |
+
if (!$installer->getConnection()->isTableExists($tableName)) {
|
18 |
+
$table = $installer->getConnection()
|
19 |
+
->newTable($tableName)
|
20 |
+
->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
21 |
+
'identity' => true,
|
22 |
+
'unsigned' => true,
|
23 |
+
'nullable' => false,
|
24 |
+
'primary' => true,
|
25 |
+
), 'Id')
|
26 |
+
->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array(), 'Period')
|
27 |
+
->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
|
28 |
+
'unsigned' => true,
|
29 |
+
), 'Store Id')
|
30 |
+
->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array(
|
31 |
+
'nullable' => false,
|
32 |
+
'default' => '',
|
33 |
+
), 'Order Status')
|
34 |
+
->addColumn('orders_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
35 |
+
'nullable' => false,
|
36 |
+
'default' => '0',
|
37 |
+
), 'Orders Count')
|
38 |
+
->addColumn('total_qty_ordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
39 |
+
'nullable' => false,
|
40 |
+
'default' => '0.0000',
|
41 |
+
), 'Total Qty Ordered')
|
42 |
+
->addColumn('total_qty_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
43 |
+
'nullable' => false,
|
44 |
+
'default' => '0.0000',
|
45 |
+
), 'Total Qty Invoiced')
|
46 |
+
->addColumn('total_income_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
47 |
+
'nullable' => false,
|
48 |
+
'default' => '0.0000',
|
49 |
+
), 'Total Income Amount')
|
50 |
+
->addColumn('total_revenue_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
51 |
+
'nullable' => false,
|
52 |
+
'default' => '0.0000',
|
53 |
+
), 'Total Revenue Amount')
|
54 |
+
->addColumn('total_profit_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
55 |
+
'nullable' => false,
|
56 |
+
'default' => '0.0000',
|
57 |
+
), 'Total Profit Amount')
|
58 |
+
->addColumn('total_invoiced_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
59 |
+
'nullable' => false,
|
60 |
+
'default' => '0.0000',
|
61 |
+
), 'Total Invoiced Amount')
|
62 |
+
->addColumn('total_canceled_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
63 |
+
'nullable' => false,
|
64 |
+
'default' => '0.0000',
|
65 |
+
), 'Total Canceled Amount')
|
66 |
+
->addColumn('total_paid_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
67 |
+
'nullable' => false,
|
68 |
+
'default' => '0.0000',
|
69 |
+
), 'Total Paid Amount')
|
70 |
+
->addColumn('total_refunded_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
71 |
+
'nullable' => false,
|
72 |
+
'default' => '0.0000',
|
73 |
+
), 'Total Refunded Amount')
|
74 |
+
->addColumn('total_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
75 |
+
'nullable' => false,
|
76 |
+
'default' => '0.0000',
|
77 |
+
), 'Total Tax Amount')
|
78 |
+
->addColumn('total_tax_amount_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
79 |
+
'nullable' => false,
|
80 |
+
'default' => '0.0000',
|
81 |
+
), 'Total Tax Amount Actual')
|
82 |
+
->addColumn('total_shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
83 |
+
'nullable' => false,
|
84 |
+
'default' => '0.0000',
|
85 |
+
), 'Total Shipping Amount')
|
86 |
+
->addColumn('total_shipping_amount_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
87 |
+
'nullable' => false,
|
88 |
+
'default' => '0.0000',
|
89 |
+
), 'Total Shipping Amount Actual')
|
90 |
+
->addColumn('total_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
91 |
+
'nullable' => false,
|
92 |
+
'default' => '0.0000',
|
93 |
+
), 'Total Discount Amount')
|
94 |
+
->addColumn('total_discount_amount_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
|
95 |
+
'nullable' => false,
|
96 |
+
'default' => '0.0000',
|
97 |
+
), 'Total Discount Amount Actual')
|
98 |
+
->addIndex(
|
99 |
+
$installer->getIdxName(
|
100 |
+
'japi/sales_order_aggregated',
|
101 |
+
array('period', 'store_id', 'order_status'),
|
102 |
+
Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
|
103 |
+
),
|
104 |
+
array('period', 'store_id', 'order_status'),
|
105 |
+
array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
|
106 |
+
)
|
107 |
+
->addIndex(
|
108 |
+
$installer->getIdxName('japi/sales_order_aggregated', array('store_id')),
|
109 |
+
array('store_id')
|
110 |
+
)
|
111 |
+
->addForeignKey(
|
112 |
+
$installer->getFkName('japi/sales_order_aggregated', 'store_id', 'core/store', 'store_id'),
|
113 |
+
'store_id',
|
114 |
+
$installer->getTable('core/store'),
|
115 |
+
'store_id',
|
116 |
+
Varien_Db_Ddl_Table::ACTION_SET_NULL,
|
117 |
+
Varien_Db_Ddl_Table::ACTION_CASCADE
|
118 |
+
)
|
119 |
+
->setComment('Sales Order Aggregated From JMango360');
|
120 |
+
$installer->getConnection()->createTable($table);
|
121 |
+
}
|
122 |
+
|
123 |
+
$this->endSetup();
|
app/code/community/Jmango360/Japi/sql/japi_setup/upgrade-2.1.6-2.2.0.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2015 JMango360
|
4 |
+
*/
|
5 |
+
|
6 |
+
/* @var $this Mage_Catalog_Model_Resource_Setup */
|
7 |
+
$this->startSetup();
|
8 |
+
|
9 |
+
$customerEntityTypeId = $this->getEntityType('customer');
|
10 |
+
|
11 |
+
$this->addAttribute('customer', 'japi', array(
|
12 |
+
'type' => 'varchar',
|
13 |
+
'input' => 'text',
|
14 |
+
'label' => 'JMango360',
|
15 |
+
'visible' => false,
|
16 |
+
'required' => false,
|
17 |
+
'user_defined' => true,
|
18 |
+
'visible_on_front' => false,
|
19 |
+
'note' => 'User used Jmango360 mobile app'
|
20 |
+
));
|
21 |
+
|
22 |
+
$this->endSetup();
|
app/code/community/Jmango360/Japi/sql/japi_setup/upgrade-2.2.0-2.2.1.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2016 JMango360
|
4 |
+
*/
|
5 |
+
|
6 |
+
/* @var $this Mage_Catalog_Model_Resource_Setup */
|
7 |
+
$this->startSetup();
|
8 |
+
|
9 |
+
// Add new column japi to grid table
|
10 |
+
$this->getConnection()->addColumn($this->getTable('sales/order_grid'), 'japi', 'int');
|
11 |
+
|
12 |
+
// Fill data
|
13 |
+
$select = $this->getConnection()->select();
|
14 |
+
$select->join(
|
15 |
+
array('order_table' => $this->getTable('sales/order')),
|
16 |
+
'order_table.entity_id = grid_table.entity_id',
|
17 |
+
array('japi')
|
18 |
+
);
|
19 |
+
$this->getConnection()->query($select->crossUpdateFromSelect(array(
|
20 |
+
'grid_table' => $this->getTable('sales/order_grid')
|
21 |
+
)));
|
22 |
+
|
23 |
+
$this->endSetup();
|
app/design/adminhtml/default/default/layout/jmango360_japi.xml
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
-->
|
7 |
+
<layout>
|
8 |
+
<adminhtml_japi_report_orders>
|
9 |
+
<update handle="report_sales"/>
|
10 |
+
<reference name="content">
|
11 |
+
<block type="japi/adminhtml_report_orders" template="japi/report/grid/container.phtml"
|
12 |
+
name="sales.report.grid.container">
|
13 |
+
<block type="adminhtml/store_switcher" template="report/store/switcher/enhanced.phtml"
|
14 |
+
name="store.switcher">
|
15 |
+
<action method="setStoreVarName">
|
16 |
+
<var_name>store_ids</var_name>
|
17 |
+
</action>
|
18 |
+
</block>
|
19 |
+
<block type="japi/adminhtml_report_orders_chart" name="report.chart"/>
|
20 |
+
<block type="japi/adminhtml_report_filter_form_orders" name="grid.filter.form"/>
|
21 |
+
</block>
|
22 |
+
</reference>
|
23 |
+
</adminhtml_japi_report_orders>
|
24 |
+
|
25 |
+
<adminhtml_japi_report_sales>
|
26 |
+
<update handle="report_sales"/>
|
27 |
+
<reference name="content">
|
28 |
+
<block type="japi/adminhtml_report_sales" template="japi/report/grid/container.phtml"
|
29 |
+
name="sales.report.grid.container">
|
30 |
+
<block type="adminhtml/store_switcher" template="report/store/switcher/enhanced.phtml"
|
31 |
+
name="store.switcher">
|
32 |
+
<action method="setStoreVarName">
|
33 |
+
<var_name>store_ids</var_name>
|
34 |
+
</action>
|
35 |
+
</block>
|
36 |
+
<block type="japi/adminhtml_report_sales_chart" name="report.chart"/>
|
37 |
+
<block type="japi/adminhtml_report_filter_form" name="grid.filter.form"/>
|
38 |
+
</block>
|
39 |
+
</reference>
|
40 |
+
</adminhtml_japi_report_sales>
|
41 |
+
|
42 |
+
<adminhtml_japi_report_customers>
|
43 |
+
<reference name="content">
|
44 |
+
<block type="japi/adminhtml_report_customers" template="japi/report/grid/container.phtml"
|
45 |
+
name="sales.report.grid.container">
|
46 |
+
<block type="adminhtml/store_switcher" template="report/store/switcher/enhanced.phtml"
|
47 |
+
name="store.switcher">
|
48 |
+
<action method="setStoreVarName">
|
49 |
+
<var_name>store_ids</var_name>
|
50 |
+
</action>
|
51 |
+
</block>
|
52 |
+
<block type="japi/adminhtml_report_customers_chart" name="report.chart"/>
|
53 |
+
<block type="japi/adminhtml_report_filter_form_orders" name="grid.filter.form"/>
|
54 |
+
</block>
|
55 |
+
</reference>
|
56 |
+
</adminhtml_japi_report_customers>
|
57 |
+
|
58 |
+
<adminhtml_japi_order_grid>
|
59 |
+
<update handle="formkey"/>
|
60 |
+
<block type="japi/adminhtml_order_grid" name="japi_order.grid" output="toHtml" />
|
61 |
+
</adminhtml_japi_order_grid>
|
62 |
+
|
63 |
+
<adminhtml_japi_order_index>
|
64 |
+
<reference name="content">
|
65 |
+
<block type="japi/adminhtml_order" name="japi_order.grid.container" />
|
66 |
+
</reference>
|
67 |
+
</adminhtml_japi_order_index>
|
68 |
+
</layout>
|
app/design/adminhtml/default/default/template/japi/report/chart.phtml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2015 JMango360
|
4 |
+
*/
|
5 |
+
?>
|
6 |
+
<?php /* @var $this Jmango360_Japi_Block_Adminhtml_Report_Chart_Sales */ ?>
|
7 |
+
<?php if ($this->getCount()): ?>
|
8 |
+
<img src="<?php echo $this->getChartUrl(false) ?>" alt="chart" title="chart"/>
|
9 |
+
<?php else: ?>
|
10 |
+
<p class="a-center"><?php echo $this->__('No Data Found') ?></p>
|
11 |
+
<?php endif ?>
|
app/design/adminhtml/default/default/template/japi/report/grid/container.phtml
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package default_default
|
23 |
+
* @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<style type="text/css">
|
28 |
+
.form-table {
|
29 |
+
display: table;
|
30 |
+
}
|
31 |
+
|
32 |
+
.form-cell {
|
33 |
+
display: table-cell;
|
34 |
+
width: 100%;
|
35 |
+
padding-right: 10px;
|
36 |
+
}
|
37 |
+
|
38 |
+
.form-cell:last-child {
|
39 |
+
padding-right: 0;
|
40 |
+
}
|
41 |
+
|
42 |
+
#chart_fieldset table {
|
43 |
+
width: 100%;
|
44 |
+
}
|
45 |
+
</style>
|
46 |
+
<div class="content-header">
|
47 |
+
<table cellspacing="0">
|
48 |
+
<tr>
|
49 |
+
<td style="<?php echo $this->getHeaderWidth() ?>"><?php echo $this->getHeaderHtml() ?></td>
|
50 |
+
<td class="form-buttons"><?php echo $this->getButtonsHtml() ?></td>
|
51 |
+
</tr>
|
52 |
+
</table>
|
53 |
+
</div>
|
54 |
+
<div>
|
55 |
+
<?php echo $this->getChildHtml('store.switcher') ?>
|
56 |
+
</div>
|
57 |
+
<div class="form-table">
|
58 |
+
<div class="form-cell" id="sales-report-filter" style="width: 540px;">
|
59 |
+
<?php echo $this->getChildHtml('grid.filter.form') ?>
|
60 |
+
</div>
|
61 |
+
<div class="form-cell" id="sales-report-chart">
|
62 |
+
<?php echo $this->getChildHtml('report.chart') ?>
|
63 |
+
</div>
|
64 |
+
</div>
|
65 |
+
<div>
|
66 |
+
<?php echo $this->getGridHtml() ?>
|
67 |
+
</div>
|
68 |
+
<script type="text/javascript">
|
69 |
+
//<![CDATA[
|
70 |
+
function filterFormSubmit() {
|
71 |
+
var filters = $$('#filter_form input', '#filter_form select');
|
72 |
+
var elements = [];
|
73 |
+
for (var i in filters) {
|
74 |
+
if (filters[i].value && filters[i].value.length && !filters[i].disabled) {
|
75 |
+
elements.push(filters[i]);
|
76 |
+
}
|
77 |
+
}
|
78 |
+
var validator = new Validation('filter_form');
|
79 |
+
if (validator.validate()) {
|
80 |
+
setLocation('<?php echo $this->getFilterUrl(); ?>filter/' + encode_base64(Form.serializeElements(elements)) + '/');
|
81 |
+
}
|
82 |
+
}
|
83 |
+
//]]>
|
84 |
+
</script>
|
app/design/adminhtml/default/default/template/japi/widget/form/renderer/element/chart.phtml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2015 JMango360
|
4 |
+
*/
|
5 |
+
?>
|
6 |
+
<?php /* @var $this Jmango360_Japi_Block_Adminhtml_Widget_Form_Renderer_Element_Chart */ ?>
|
7 |
+
<tr>
|
8 |
+
<td style="text-align: center;">
|
9 |
+
<?php echo $this->getGraphHtml() ?>
|
10 |
+
</td>
|
11 |
+
</tr>
|
app/design/frontend/base/default/layout/jmango360_japi.xml
ADDED
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Copyright 2015 JMango360
|
5 |
+
*/
|
6 |
+
-->
|
7 |
+
<layout version="0.1.0">
|
8 |
+
<japi_checkout_default translate="label">
|
9 |
+
<label>JMango360 Onepage Checkout Page</label>
|
10 |
+
<block type="page/html" name="root" output="toHtml" template="japi/page/rwd.phtml">
|
11 |
+
<block type="page/html_head" name="head" as="head" template="japi/page/html/head.phtml">
|
12 |
+
<action method="addItem"><type>skin_css</type><file>japi/lib/bootstrap/css/bootstrap.min.css</file></action>
|
13 |
+
<action method="addItem"><type>skin_css</type><file>japi/lib/ladda/ladda.min.css</file></action>
|
14 |
+
<action method="addItem"><type>skin_css</type><file>japi/css/icomoon/style.css</file></action>
|
15 |
+
|
16 |
+
<action method="addJs"><script>prototype/prototype.js</script></action>
|
17 |
+
<action method="addJs"><script>lib/ccard.js</script></action>
|
18 |
+
<action method="addJs"><script>prototype/validation.js</script></action>
|
19 |
+
<action method="addJs"><script>scriptaculous/builder.js</script></action>
|
20 |
+
<action method="addJs"><script>scriptaculous/effects.js</script></action>
|
21 |
+
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
|
22 |
+
<action method="addJs"><script>scriptaculous/controls.js</script></action>
|
23 |
+
<action method="addJs"><script>scriptaculous/slider.js</script></action>
|
24 |
+
<action method="addJs"><script>varien/js.js</script></action>
|
25 |
+
<action method="addJs"><script>varien/form.js</script></action>
|
26 |
+
<action method="addJs"><script>varien/menu.js</script></action>
|
27 |
+
<action method="addJs"><script>mage/translate.js</script></action>
|
28 |
+
<action method="addJs"><script>mage/cookies.js</script></action>
|
29 |
+
|
30 |
+
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
|
31 |
+
|
32 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/spin/spin.min.js</file></action>
|
33 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/ladda/ladda.min.js</file></action>
|
34 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/jquery/jquery-1.11.2.min.js</file></action>
|
35 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/jquery/jquery-noconflict.js</file></action>
|
36 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/bootstrap/js/transition.js</file></action>
|
37 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/bootstrap/js/collapse.js</file></action>
|
38 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/bootstrap/js/modal.js</file></action>
|
39 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/scrollto/scrollTo.js</file></action>
|
40 |
+
<action method="addItem"><type>skin_js</type><file>js/opcheckout.js</file></action>
|
41 |
+
<action method="addItem"><type>skin_js</type><file>japi/js/checkout.js?v=2.7.0</file></action>
|
42 |
+
</block>
|
43 |
+
<block type="core/text_list" name="after_body_start" as="after_body_start" translate="label">
|
44 |
+
<label>Page Top</label>
|
45 |
+
</block>
|
46 |
+
<block type="core/messages" name="global_messages" as="global_messages"/>
|
47 |
+
<block type="core/messages" name="messages" as="messages"/>
|
48 |
+
<block type="core/text_list" name="content" as="content" translate="label">
|
49 |
+
<label>Main Content Area</label>
|
50 |
+
</block>
|
51 |
+
<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
|
52 |
+
<label>Page Bottom</label>
|
53 |
+
</block>
|
54 |
+
</block>
|
55 |
+
</japi_checkout_default>
|
56 |
+
|
57 |
+
<japi_checkout_onepage>
|
58 |
+
<update handle="japi_checkout_default"/>
|
59 |
+
<reference name="content">
|
60 |
+
<block type="core/template" name="checkout.onepage.style" as="checkout.onepage.style" template="japi/checkout/onepage/style.phtml"/>
|
61 |
+
<block type="checkout/onepage" name="checkout.onepage" template="japi/checkout/onepage.phtml">
|
62 |
+
<block type="checkout/onepage_billing" name="checkout.onepage.billing" as="billing" template="japi/checkout/onepage/billing.phtml">
|
63 |
+
<block type="japi/form" name="form.additional.info">
|
64 |
+
<action method="setPrefix"><value>billing</value></action>
|
65 |
+
<action method="setForm"><value>billing</value></action>
|
66 |
+
</block>
|
67 |
+
</block>
|
68 |
+
<block type="checkout/onepage_shipping" name="checkout.onepage.shipping" as="shipping" template="japi/checkout/onepage/shipping.phtml"/>
|
69 |
+
<block type="checkout/onepage_shipping_method" name="checkout.onepage.shipping_method" as="shipping_method" template="japi/checkout/onepage/shipping_method.phtml">
|
70 |
+
<block type="checkout/onepage_shipping_method_available" name="checkout.onepage.shipping_method.available" as="available" template="japi/checkout/onepage/shipping_method/available.phtml"/>
|
71 |
+
<block type="checkout/onepage_shipping_method_additional" name="checkout.onepage.shipping_method.additional" as="additional" template="japi/checkout/onepage/shipping_method/additional.phtml"/>
|
72 |
+
</block>
|
73 |
+
<block type="checkout/onepage_payment" name="checkout.onepage.payment" as="payment" template="japi/checkout/onepage/payment.phtml">
|
74 |
+
<block type="checkout/onepage_payment_methods" name="checkout.onepage.payment.methods" as="methods" template="japi/checkout/onepage/payment/info.phtml"/>
|
75 |
+
</block>
|
76 |
+
<block type="checkout/onepage_review" name="checkout.onepage.review" as="review" template="japi/checkout/onepage/review.phtml"/>
|
77 |
+
</block>
|
78 |
+
</reference>
|
79 |
+
</japi_checkout_onepage>
|
80 |
+
|
81 |
+
<japi_checkout_review>
|
82 |
+
<remove name="right"/>
|
83 |
+
<remove name="left"/>
|
84 |
+
<block type="checkout/onepage_review_info" name="root" output="toHtml" template="japi/checkout/onepage/review/info.phtml">
|
85 |
+
<action method="addItemRender">
|
86 |
+
<type>default</type>
|
87 |
+
<block>checkout/cart_item_renderer</block>
|
88 |
+
<template>japi/checkout/onepage/review/item.phtml</template>
|
89 |
+
</action>
|
90 |
+
<action method="addItemRender">
|
91 |
+
<type>grouped</type>
|
92 |
+
<block>checkout/cart_item_renderer_grouped</block>
|
93 |
+
<template>japi/checkout/onepage/review/item.phtml</template>
|
94 |
+
</action>
|
95 |
+
<action method="addItemRender">
|
96 |
+
<type>configurable</type>
|
97 |
+
<block>checkout/cart_item_renderer_configurable</block>
|
98 |
+
<template>japi/checkout/onepage/review/item.phtml</template>
|
99 |
+
</action>
|
100 |
+
<action method="addItemRender">
|
101 |
+
<type>bundle</type>
|
102 |
+
<block>bundle/checkout_cart_item_renderer</block>
|
103 |
+
<template>japi/checkout/onepage/review/item.phtml</template>
|
104 |
+
</action>
|
105 |
+
<block type="checkout/cart_totals" name="checkout.onepage.review.info.totals" as="totals" template="japi/checkout/onepage/review/totals.phtml"/>
|
106 |
+
<block type="core/text_list" name="checkout.onepage.review.info.items.before" as="items_before" output="toHtml" translate="label">
|
107 |
+
<label>Items Before</label>
|
108 |
+
</block>
|
109 |
+
<block type="core/text_list" name="checkout.onepage.review.info.items.after" as="items_after" output="toHtml" translate="label">
|
110 |
+
<label>Items After</label>
|
111 |
+
</block>
|
112 |
+
<block type="checkout/agreements" name="checkout.onepage.agreements" as="agreements" template="japi/checkout/onepage/agreements.phtml"/>
|
113 |
+
<block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="japi/checkout/onepage/coupon.phtml"/>
|
114 |
+
<block type="core/template" name="checkout.onepage.review.button" as="button" template="japi/checkout/onepage/review/button.phtml"/>
|
115 |
+
</block>
|
116 |
+
</japi_checkout_review>
|
117 |
+
|
118 |
+
<japi_customer_default translate="label">
|
119 |
+
<label>JMango360 Customer Forms</label>
|
120 |
+
<block type="page/html" name="root" output="toHtml" template="japi/page/rwd.phtml">
|
121 |
+
<block type="page/html_head" name="head" as="head" template="japi/page/html/head.phtml">
|
122 |
+
<action method="addItem"><type>skin_css</type><file>japi/lib/bootstrap/css/bootstrap.min.css</file></action>
|
123 |
+
<action method="addItem"><type>skin_css</type><file>japi/lib/ladda/ladda.min.css</file></action>
|
124 |
+
<action method="addItem"><type>skin_css</type><file>japi/css/icomoon/style.css</file></action>
|
125 |
+
|
126 |
+
<action method="addJs"><script>prototype/prototype.js</script></action>
|
127 |
+
<action method="addJs"><script>lib/ccard.js</script></action>
|
128 |
+
<action method="addJs"><script>prototype/validation.js</script></action>
|
129 |
+
<action method="addJs"><script>scriptaculous/builder.js</script></action>
|
130 |
+
<action method="addJs"><script>scriptaculous/effects.js</script></action>
|
131 |
+
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
|
132 |
+
<action method="addJs"><script>scriptaculous/controls.js</script></action>
|
133 |
+
<action method="addJs"><script>scriptaculous/slider.js</script></action>
|
134 |
+
<action method="addJs"><script>varien/js.js</script></action>
|
135 |
+
<action method="addJs"><script>varien/form.js</script></action>
|
136 |
+
<action method="addJs"><script>varien/menu.js</script></action>
|
137 |
+
<action method="addJs"><script>mage/translate.js</script></action>
|
138 |
+
<action method="addJs"><script>mage/cookies.js</script></action>
|
139 |
+
|
140 |
+
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
|
141 |
+
|
142 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/spin/spin.min.js</file></action>
|
143 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/ladda/ladda.min.js</file></action>
|
144 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/jquery/jquery-1.11.2.min.js</file></action>
|
145 |
+
<action method="addItem"><type>skin_js</type><file>japi/lib/jquery/jquery-noconflict.js</file></action>
|
146 |
+
<action method="addItem"><type>skin_js</type><file>japi/js/varien/form.js</file></action>
|
147 |
+
</block>
|
148 |
+
<block type="core/text_list" name="after_body_start" as="after_body_start" translate="label">
|
149 |
+
<label>Page Top</label>
|
150 |
+
</block>
|
151 |
+
<block type="core/messages" name="global_messages" as="global_messages"/>
|
152 |
+
<block type="core/messages" name="messages" as="messages"/>
|
153 |
+
<block type="core/text_list" name="content" as="content" translate="label">
|
154 |
+
<label>Main Content Area</label>
|
155 |
+
</block>
|
156 |
+
<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
|
157 |
+
<label>Page Bottom</label>
|
158 |
+
</block>
|
159 |
+
</block>
|
160 |
+
</japi_customer_default>
|
161 |
+
|
162 |
+
<japi_customer_register>
|
163 |
+
<update handle="japi_customer_default"/>
|
164 |
+
<reference name="content">
|
165 |
+
<block type="core/template" name="checkout.onepage.style" as="checkout.onepage.style" template="japi/checkout/onepage/style.phtml"/>
|
166 |
+
<block type="customer/form_register" name="customer_form_register" template="japi/customer/form/register.phtml">
|
167 |
+
<block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label">
|
168 |
+
<label>Form Fields Before</label>
|
169 |
+
</block>
|
170 |
+
</block>
|
171 |
+
</reference>
|
172 |
+
</japi_customer_register>
|
173 |
+
|
174 |
+
<japi_customer_edit>
|
175 |
+
<update handle="japi_customer_default"/>
|
176 |
+
<reference name="content">
|
177 |
+
<block type="core/template" name="checkout.onepage.style" as="checkout.onepage.style" template="japi/checkout/onepage/style.phtml"/>
|
178 |
+
<block type="customer/form_edit" name="customer_edit" template="japi/customer/form/edit.phtml"/>
|
179 |
+
</reference>
|
180 |
+
</japi_customer_edit>
|
181 |
+
|
182 |
+
<japi_customer_address>
|
183 |
+
<update handle="japi_customer_default"/>
|
184 |
+
<reference name="content">
|
185 |
+
<block type="core/template" name="checkout.onepage.style" as="checkout.onepage.style" template="japi/checkout/onepage/style.phtml"/>
|
186 |
+
<block type="customer/address_edit" name="customer_address_edit" template="japi/customer/address/edit.phtml"/>
|
187 |
+
</reference>
|
188 |
+
</japi_customer_address>
|
189 |
+
|
190 |
+
<japi_checkout_onepage_shippingmethod>
|
191 |
+
<remove name="right"/>
|
192 |
+
<remove name="left"/>
|
193 |
+
|
194 |
+
<block type="checkout/onepage_shipping_method_available" name="root" output="toHtml" template="japi/checkout/onepage/shipping_method/available.phtml"/>
|
195 |
+
</japi_checkout_onepage_shippingmethod>
|
196 |
+
</layout>
|
app/design/frontend/base/default/template/japi/TIG/PostNL/address_validation/checkout/onepage/billing.phtml
ADDED
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* ___________ __ __
|
4 |
+
* \__ ___/____ _/ |_ _____ | |
|
5 |
+
* | | / _ \\ __\\__ \ | |
|
6 |
+
* | | | |_| || | / __ \_| |__
|
7 |
+
* |____| \____/ |__| (____ /|____/
|
8 |
+
* \/
|
9 |
+
* ___ __ __
|
10 |
+
* | | ____ _/ |_ ____ _______ ____ ____ _/ |_
|
11 |
+
* | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
|
12 |
+
* | || | \| | \ ___/ | | \/| | \\ ___/ | |
|
13 |
+
* |___||___| /|__| \_____>|__| |___| / \_____>|__|
|
14 |
+
* \/ \/
|
15 |
+
* ________
|
16 |
+
* / _____/_______ ____ __ __ ______
|
17 |
+
* / \ ___\_ __ \ / _ \ | | \\____ \
|
18 |
+
* \ \_\ \| | \/| |_| || | /| |_| |
|
19 |
+
* \______ /|__| \____/ |____/ | __/
|
20 |
+
* \/ |__|
|
21 |
+
*
|
22 |
+
* NOTICE OF LICENSE
|
23 |
+
*
|
24 |
+
* This source file is subject to the Creative Commons License.
|
25 |
+
* It is available through the world-wide-web at this URL:
|
26 |
+
* http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
|
27 |
+
* If you are unable to obtain it through the world-wide-web, please send an email
|
28 |
+
* to servicedesk@tig.nl so we can send you a copy immediately.
|
29 |
+
*
|
30 |
+
* DISCLAIMER
|
31 |
+
*
|
32 |
+
* Do not edit or add to this file if you wish to upgrade this module to newer
|
33 |
+
* versions in the future. If you wish to customize this module for your
|
34 |
+
* needs please contact servicedesk@tig.nl for more information.
|
35 |
+
*
|
36 |
+
* @copyright Copyright (c) 2015 Total Internet Group B.V. (http://www.tig.nl)
|
37 |
+
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
|
38 |
+
*/
|
39 |
+
?>
|
40 |
+
<form id="co-billing-form" action="">
|
41 |
+
<fieldset>
|
42 |
+
<ul class="form-list">
|
43 |
+
<?php if ($this->customerHasAddresses()): ?>
|
44 |
+
<li class="wide">
|
45 |
+
<label for="billing-address-select"><?php echo $this->__('Select a billing address from your address book or enter a new address.') ?></label>
|
46 |
+
<div class="input-box">
|
47 |
+
<?php echo $this->getAddressesHtmlSelect('billing') ?>
|
48 |
+
</div>
|
49 |
+
</li>
|
50 |
+
<?php endif; ?>
|
51 |
+
<li id="billing-new-address-form"<?php if ($this->customerHasAddresses()): ?> style="display:none;"<?php endif; ?>>
|
52 |
+
<fieldset>
|
53 |
+
<input type="hidden" name="billing[address_id]" value="<?php echo $this->getAddress()->getId() ?>" id="billing:address_id" />
|
54 |
+
<ul>
|
55 |
+
<li class="fields"><?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getAddress()->getFirstname() ? $this->getAddress() : $this->getQuote()->getCustomer())->setForceUseCustomerRequiredAttributes(!$this->isCustomerLoggedIn())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?></li>
|
56 |
+
<li class="fields">
|
57 |
+
<div class="field">
|
58 |
+
<label for="billing:company"><?php echo $this->__('Company') ?></label>
|
59 |
+
<div class="input-box">
|
60 |
+
<input type="text" id="billing:company" name="billing[company]" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="input-text <?php echo $this->helper('postnl/addressValidation')->getAttributeValidationClass('company') ?>" />
|
61 |
+
</div>
|
62 |
+
</div>
|
63 |
+
<?php if(!$this->isCustomerLoggedIn()): ?>
|
64 |
+
<div class="field">
|
65 |
+
<label for="billing:email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
|
66 |
+
<div class="input-box">
|
67 |
+
<input type="text" name="billing[email]" id="billing:email" value="<?php echo $this->escapeHtml($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
<?php endif; ?>
|
71 |
+
</li>
|
72 |
+
<?php echo $this->getChild('postnl_billing_postcodecheck')
|
73 |
+
->setAddressType('billing')
|
74 |
+
->setAddress($this->getAddress())
|
75 |
+
->setCountryHtmlSelect($this->getCountryHtmlSelect('billing'))
|
76 |
+
->toHtml(); ?>
|
77 |
+
<?php if (is_callable(array($this->helper('customer/address'), 'isVatAttributeVisible')) && $this->helper('customer/address')->isVatAttributeVisible()) : ?>
|
78 |
+
<li class="wide">
|
79 |
+
<label for="billing:vat_id"><?php echo $this->__('VAT Number'); ?></label>
|
80 |
+
<div class="input-box">
|
81 |
+
<input type="text" id="billing:vat_id" name="billing[vat_id]" value="<?php echo $this->escapeHtml($this->getAddress()->getVatId()); ?>" title="<?php echo $this->__('VAT Number'); ?>" class="input-text <?php echo $this->helper('postnl/addressValidation')->getAttributeValidationClass('vat_id') ?>" />
|
82 |
+
</div>
|
83 |
+
</li>
|
84 |
+
<?php endif; ?>
|
85 |
+
<li class="fields">
|
86 |
+
<div class="field">
|
87 |
+
<label for="billing:region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
|
88 |
+
<div class="input-box">
|
89 |
+
<select id="billing:region_id" name="billing[region_id]" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
|
90 |
+
<option value=""><?php echo $this->__('Please select region, state or province') ?></option>
|
91 |
+
</select>
|
92 |
+
<script type="text/javascript">
|
93 |
+
//<![CDATA[
|
94 |
+
$('billing:region_id').setAttribute('defaultValue', "<?php echo $this->getAddress()->getRegionId() ?>");
|
95 |
+
//]]>
|
96 |
+
</script>
|
97 |
+
<input type="text" id="billing:region" name="billing[region]" value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('postnl/addressValidation')->getAttributeValidationClass('region') ?>" style="display:none;" />
|
98 |
+
</div>
|
99 |
+
</div>
|
100 |
+
</li>
|
101 |
+
<li class="fields">
|
102 |
+
<div class="field">
|
103 |
+
<label for="billing:telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
|
104 |
+
<div class="input-box">
|
105 |
+
<input type="text" name="billing[telephone]" value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text <?php echo $this->helper('postnl/addressValidation')->getAttributeValidationClass('telephone') ?>" id="billing:telephone" />
|
106 |
+
</div>
|
107 |
+
</div>
|
108 |
+
<div class="field">
|
109 |
+
<label for="billing:fax"><?php echo $this->__('Fax') ?></label>
|
110 |
+
<div class="input-box">
|
111 |
+
<input type="text" name="billing[fax]" value="<?php echo $this->escapeHtml($this->getAddress()->getFax()) ?>" title="<?php echo $this->__('Fax') ?>" class="input-text <?php echo $this->helper('postnl/addressValidation')->getAttributeValidationClass('fax') ?>" id="billing:fax" />
|
112 |
+
</div>
|
113 |
+
</div>
|
114 |
+
</li>
|
115 |
+
<?php if(!$this->isCustomerLoggedIn()): ?>
|
116 |
+
|
117 |
+
<?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
|
118 |
+
<?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
|
119 |
+
<?php if ($_dob->isEnabled() || $_gender->isEnabled()): ?>
|
120 |
+
<li class="fields">
|
121 |
+
<?php if ($_dob->isEnabled()): ?>
|
122 |
+
<div class="field">
|
123 |
+
<?php echo $_dob->setDate($this->getQuote()->getCustomerDob())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?>
|
124 |
+
</div>
|
125 |
+
<?php endif; ?>
|
126 |
+
<?php if ($_gender->isEnabled()): ?>
|
127 |
+
<div class="field">
|
128 |
+
<?php echo $_gender->setGender($this->getQuote()->getCustomerGender())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?>
|
129 |
+
</div>
|
130 |
+
<?php endif ?>
|
131 |
+
</li>
|
132 |
+
<?php endif ?>
|
133 |
+
|
134 |
+
<?php if ($this->isTaxvatEnabled()):?>
|
135 |
+
<li><?php echo $this->getTaxvatHtml() ?></li>
|
136 |
+
<?php endif; ?>
|
137 |
+
|
138 |
+
<li class="fields" id="register-customer-password">
|
139 |
+
<div class="field">
|
140 |
+
<label for="billing:customer_password" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
|
141 |
+
<div class="input-box">
|
142 |
+
<input type="password" name="billing[customer_password]" id="billing:customer_password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
|
143 |
+
</div>
|
144 |
+
</div>
|
145 |
+
<div class="field">
|
146 |
+
<label for="billing:confirm_password" class="required"><em>*</em><?php echo $this->__('Confirm Password') ?></label>
|
147 |
+
<div class="input-box">
|
148 |
+
<input type="password" name="billing[confirm_password]" title="<?php echo $this->__('Confirm Password') ?>" id="billing:confirm_password" class="input-text required-entry validate-cpassword" />
|
149 |
+
</div>
|
150 |
+
</div>
|
151 |
+
</li>
|
152 |
+
<?php echo $this->getChildHtml('persistent.remember.me'); ?>
|
153 |
+
<?php endif; ?>
|
154 |
+
<?php if ($this->isCustomerLoggedIn() && $this->customerHasAddresses()):?>
|
155 |
+
<li class="control">
|
156 |
+
<input type="checkbox" name="billing[save_in_address_book]" value="1" title="<?php echo $this->__('Save in address book') ?>" id="billing:save_in_address_book" onchange="if(window.shipping) shipping.setSameAsBilling(false);"<?php if ($this->getAddress()->getSaveInAddressBook()):?> checked="checked"<?php endif;?> class="checkbox" /><label for="billing:save_in_address_book"><?php echo $this->__('Save in address book') ?></label>
|
157 |
+
</li>
|
158 |
+
<?php else:?>
|
159 |
+
<li class="no-display"><input type="hidden" name="billing[save_in_address_book]" value="1" /></li>
|
160 |
+
<?php endif; ?>
|
161 |
+
<?php echo $this->getChildHtml('form.additional.info'); ?>
|
162 |
+
</ul>
|
163 |
+
<?php echo $this->getChildHtml('persistent.remember.me.tooltip'); ?>
|
164 |
+
</fieldset>
|
165 |
+
</li>
|
166 |
+
<?php if ($this->canShip()): ?>
|
167 |
+
<li class="control">
|
168 |
+
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes" value="1"<?php if ($this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> title="<?php echo $this->__('Ship to this address') ?>" onclick="$('shipping:same_as_billing').checked = true;" class="radio" /><label for="billing:use_for_shipping_yes"><?php echo $this->__('Ship to this address') ?></label></li>
|
169 |
+
<li class="control">
|
170 |
+
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_no" value="0"<?php if (!$this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> title="<?php echo $this->__('Ship to different address') ?>" onclick="$('shipping:same_as_billing').checked = false;" class="radio" /><label for="billing:use_for_shipping_no"><?php echo $this->__('Ship to different address') ?></label>
|
171 |
+
</li>
|
172 |
+
<?php endif; ?>
|
173 |
+
</ul>
|
174 |
+
<?php if (!$this->canShip()): ?>
|
175 |
+
<input type="hidden" name="billing[use_for_shipping]" value="1" />
|
176 |
+
<?php endif; ?>
|
177 |
+
<div class="buttons-set" id="billing-buttons-container">
|
178 |
+
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
|
179 |
+
<button type="button" title="<?php echo $this->__('Continue') ?>" class="button" onclick="billing.save()"><span><span><?php echo $this->__('Continue') ?></span></span></button>
|
180 |
+
<span class="please-wait" id="billing-please-wait" style="display:none;">
|
181 |
+
<img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Loading next step...') ?>" title="<?php echo $this->__('Loading next step...') ?>" class="v-middle" /> <?php echo $this->__('Loading next step...') ?>
|
182 |
+
</span>
|
183 |
+
</div>
|
184 |
+
</fieldset>
|
185 |
+
</form>
|
186 |
+
<script type="text/javascript">
|
187 |
+
//<![CDATA[
|
188 |
+
var billing = new Billing('co-billing-form', '<?php echo $this->getUrl('checkout/onepage/getAddress') ?>address/', '<?php echo $this->getUrl('checkout/onepage/saveBilling') ?>');
|
189 |
+
var billingForm = new VarienForm('co-billing-form');
|
190 |
+
|
191 |
+
//billingForm.setElementsRelation('billing:country_id', 'billing:region', '<?php echo $this->getUrl('directory/json/childRegion') ?>', '<?php echo $this->__('Select State/Province...') ?>');
|
192 |
+
$('billing-address-select') && billing.newAddress(!$('billing-address-select').value);
|
193 |
+
|
194 |
+
var billingRegionUpdater = new RegionUpdater('billing:country_id', 'billing:region', 'billing:region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'billing:postcode');
|
195 |
+
if ($('onepage-guest-register-button')) {
|
196 |
+
Event.observe($('onepage-guest-register-button'), 'click', function(event) {
|
197 |
+
var billingRememberMe = $('co-billing-form').select('#remember-me-box');
|
198 |
+
if (billingRememberMe.length > 0) {
|
199 |
+
if ($('login:guest') && $('login:guest').checked) {
|
200 |
+
billingRememberMe[0].hide();
|
201 |
+
} else if ($('login:register') && ($('login:register').checked || $('login:register').type == 'hidden')) {
|
202 |
+
billingRememberMe[0].show();
|
203 |
+
}
|
204 |
+
}
|
205 |
+
});
|
206 |
+
}
|
207 |
+
//]]>
|
208 |
+
</script>
|
app/design/frontend/base/default/template/japi/TIG/PostNL/address_validation/checkout/onepage/shipping.phtml
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* ___________ __ __
|
4 |
+
* \__ ___/____ _/ |_ _____ | |
|
5 |
+
* | | / _ \\ __\\__ \ | |
|
6 |
+
* | | | |_| || | / __ \_| |__
|
7 |
+
* |____| \____/ |__| (____ /|____/
|
8 |
+
* \/
|
9 |
+
* ___ __ __
|
10 |
+
* | | ____ _/ |_ ____ _______ ____ ____ _/ |_
|
11 |
+
* | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
|
12 |
+
* | || | \| | \ ___/ | | \/| | \\ ___/ | |
|
13 |
+
* |___||___| /|__| \_____>|__| |___| / \_____>|__|
|
14 |
+
* \/ \/
|
15 |
+
* ________
|
16 |
+
* / _____/_______ ____ __ __ ______
|
17 |
+
* / \ ___\_ __ \ / _ \ | | \\____ \
|
18 |
+
* \ \_\ \| | \/| |_| || | /| |_| |
|
19 |
+
* \______ /|__| \____/ |____/ | __/
|
20 |
+
* \/ |__|
|
21 |
+
*
|
22 |
+
* NOTICE OF LICENSE
|
23 |
+
*
|
24 |
+
* This source file is subject to the Creative Commons License.
|
25 |
+
* It is available through the world-wide-web at this URL:
|
26 |
+
* http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
|
27 |
+
* If you are unable to obtain it through the world-wide-web, please send an email
|
28 |
+
* to servicedesk@tig.nl so we can send you a copy immediately.
|
29 |
+
*
|
30 |
+
* DISCLAIMER
|
31 |
+
*
|
32 |
+
* Do not edit or add to this file if you wish to upgrade this module to newer
|
33 |
+
* versions in the future. If you wish to customize this module for your
|
34 |
+
* needs please contact servicedesk@tig.nl for more information.
|
35 |
+
*
|
36 |
+
* @copyright Copyright (c) 2015 Total Internet Group B.V. (http://www.tig.nl)
|
37 |
+
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
|
38 |
+
*/
|
39 |
+
?>
|
40 |
+
<form action="" id="co-shipping-form">
|
41 |
+
<ul class="form-list">
|
42 |
+
<?php if ($this->customerHasAddresses()): ?>
|
43 |
+
<li class="wide">
|
44 |
+
<label
|
45 |
+
for="shipping-address-select"><?php echo $this->__('Select a shipping address from your address book or enter a new address.') ?></label>
|
46 |
+
<div class="input-box">
|
47 |
+
<?php echo $this->getAddressesHtmlSelect('shipping') ?>
|
48 |
+
</div>
|
49 |
+
</li>
|
50 |
+
<?php endif ?>
|
51 |
+
<li id="shipping-new-address-form"<?php if ($this->customerHasAddresses()): ?> style="display:none;"<?php endif ?>>
|
52 |
+
<fieldset>
|
53 |
+
<input type="hidden" name="shipping[address_id]" value="<?php echo $this->getAddress()->getId() ?>"
|
54 |
+
id="shipping:address_id"/>
|
55 |
+
<ul>
|
56 |
+
<li class="fields"><?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getAddress())->setFieldIdFormat('shipping:%s')->setFieldNameFormat('shipping[%s]')->setFieldParams('onchange="shipping.setSameAsBilling(false)"')->toHtml() ?></li>
|
57 |
+
<li class="fields">
|
58 |
+
<div class="fields">
|
59 |
+
<label for="shipping:company"><?php echo $this->__('Company') ?></label>
|
60 |
+
<div class="input-box">
|
61 |
+
<input type="text" id="shipping:company" name="shipping[company]"
|
62 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>"
|
63 |
+
title="<?php echo $this->__('Company') ?>"
|
64 |
+
class="input-text <?php echo $this->helper('postnl/addressValidation')->getAttributeValidationClass('company') ?>"
|
65 |
+
onchange="shipping.setSameAsBilling(false);"/>
|
66 |
+
</div>
|
67 |
+
</div>
|
68 |
+
</li>
|
69 |
+
<?php echo $this->getChild('postnl_shipping_postcodecheck')
|
70 |
+
->setAddressType('shipping')
|
71 |
+
->setAddress($this->getAddress())
|
72 |
+
->setCountryHtmlSelect($this->getCountryHtmlSelect('shipping'))
|
73 |
+
->toHtml(); ?>
|
74 |
+
<?php if (is_callable(array($this->helper('customer/address'), 'isVatAttributeVisible')) && $this->helper('customer/address')->isVatAttributeVisible()) : ?>
|
75 |
+
<li class="wide">
|
76 |
+
<label for="billing:vat_id"><?php echo $this->__('VAT Number'); ?></label>
|
77 |
+
<div class="input-box">
|
78 |
+
<input type="text" id="shipping:vat_id" name="shipping[vat_id]"
|
79 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getVatId()); ?>"
|
80 |
+
title="<?php echo $this->__('VAT Number'); ?>"
|
81 |
+
class="input-text <?php echo $this->helper('postnl/addressValidation')->getAttributeValidationClass('vat_id') ?>"/>
|
82 |
+
</div>
|
83 |
+
</li>
|
84 |
+
<?php endif; ?>
|
85 |
+
<li class="fields">
|
86 |
+
<div class="field">
|
87 |
+
<label for="shipping:region"
|
88 |
+
class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
|
89 |
+
<div class="input-box">
|
90 |
+
<select id="shipping:region_id" name="shipping[region_id]"
|
91 |
+
title="<?php echo $this->__('State/Province') ?>" class="validate-select"
|
92 |
+
style="display:none;">
|
93 |
+
<option
|
94 |
+
value=""><?php echo $this->__('Please select region, state or province') ?></option>
|
95 |
+
</select>
|
96 |
+
<script type="text/javascript">
|
97 |
+
//<![CDATA[
|
98 |
+
$('shipping:region_id').setAttribute('defaultValue', "<?php echo $this->getAddress()->getRegionId() ?>");
|
99 |
+
//]]>
|
100 |
+
</script>
|
101 |
+
<input type="text" id="shipping:region" name="shipping[region]"
|
102 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>"
|
103 |
+
title="<?php echo $this->__('State/Province') ?>"
|
104 |
+
class="input-text <?php echo $this->helper('postnl/addressValidation')->getAttributeValidationClass('region') ?>"
|
105 |
+
style="display:none;"/>
|
106 |
+
</div>
|
107 |
+
</div>
|
108 |
+
</li>
|
109 |
+
<li class="fields">
|
110 |
+
<div class="field">
|
111 |
+
<label for="shipping:telephone"
|
112 |
+
class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
|
113 |
+
<div class="input-box">
|
114 |
+
<input type="text" name="shipping[telephone]"
|
115 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>"
|
116 |
+
title="<?php echo $this->__('Telephone') ?>"
|
117 |
+
class="input-text <?php echo $this->helper('postnl/addressValidation')->getAttributeValidationClass('telephone') ?>"
|
118 |
+
id="shipping:telephone" onchange="shipping.setSameAsBilling(false);"/>
|
119 |
+
</div>
|
120 |
+
</div>
|
121 |
+
<div class="field">
|
122 |
+
<label for="shipping:fax"><?php echo $this->__('Fax') ?></label>
|
123 |
+
<div class="input-box">
|
124 |
+
<input type="text" name="shipping[fax]"
|
125 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getFax()) ?>"
|
126 |
+
title="<?php echo $this->__('Fax') ?>"
|
127 |
+
class="input-text <?php echo $this->helper('postnl/addressValidation')->getAttributeValidationClass('fax') ?>"
|
128 |
+
id="shipping:fax" onchange="shipping.setSameAsBilling(false);"/>
|
129 |
+
</div>
|
130 |
+
</div>
|
131 |
+
</li>
|
132 |
+
|
133 |
+
<!-- Additional customer address fields -->
|
134 |
+
<?php echo $this->getLayout()->createBlock('japi/form')->setFields(Mage::helper('japi')->getCustomerAddressFormFields())->setPrefix('shipping')->toHtml() ?>
|
135 |
+
|
136 |
+
<?php if ($this->isCustomerLoggedIn() && $this->customerHasAddresses()): ?>
|
137 |
+
<li class="control">
|
138 |
+
<input type="checkbox" name="shipping[save_in_address_book]" value="1"
|
139 |
+
title="<?php echo $this->__('Save in address book') ?>"
|
140 |
+
id="shipping:save_in_address_book"
|
141 |
+
onchange="shipping.setSameAsBilling(false);"<?php if ($this->getAddress()->getSaveInAddressBook()): ?> checked="checked"<?php endif; ?>
|
142 |
+
class="checkbox"/>
|
143 |
+
<label
|
144 |
+
for="shipping:save_in_address_book"><?php echo $this->__('Save in address book') ?></label>
|
145 |
+
</li>
|
146 |
+
<?php else: ?>
|
147 |
+
<li class="no-display"><input type="hidden" name="shipping[save_in_address_book]" value="1"/>
|
148 |
+
</li>
|
149 |
+
<?php endif; ?>
|
150 |
+
</ul>
|
151 |
+
</fieldset>
|
152 |
+
</li>
|
153 |
+
<li class="control">
|
154 |
+
<input type="checkbox" name="shipping[same_as_billing]" id="shipping:same_as_billing"
|
155 |
+
value="1"<?php if ($this->getAddress()->getSameAsBilling()): ?> checked="checked"<?php endif; ?>
|
156 |
+
title="<?php echo $this->__('Use Billing Address') ?>"
|
157 |
+
onclick="shipping.setSameAsBilling(this.checked)" class="checkbox"/>
|
158 |
+
<label for="shipping:same_as_billing"><?php echo $this->__('Use Billing Address') ?></label>
|
159 |
+
</li>
|
160 |
+
</ul>
|
161 |
+
<div class="buttons-set" id="shipping-buttons-container">
|
162 |
+
<button type="button" class="button" title="<?php echo $this->__('Continue') ?>" onclick="shipping.save()">
|
163 |
+
<span><span><?php echo $this->__('Continue') ?></span></span>
|
164 |
+
</button>
|
165 |
+
</div>
|
166 |
+
</form>
|
167 |
+
<script type="text/javascript">
|
168 |
+
//<![CDATA[
|
169 |
+
var shipping = new Shipping('co-shipping-form', '<?php echo $this->getUrl('checkout/onepage/getAddress') ?>address/', '<?php echo $this->getUrl('checkout/onepage/saveShipping') ?>', '<?php echo $this->getUrl('checkout/onepage/shippingMethod') ?>');
|
170 |
+
var shippingForm = new VarienForm('co-shipping-form');
|
171 |
+
shippingForm.extraChildParams = ' onchange="shipping.setSameAsBilling(false);"';
|
172 |
+
//shippingForm.setElementsRelation('shipping:country_id', 'shipping:region', '<?php echo $this->getUrl('directory/json/childRegion') ?>', '<?php echo $this->__('Select State/Province...') ?>');
|
173 |
+
$('shipping-address-select') && shipping.newAddress(!$('shipping-address-select').value);
|
174 |
+
var shippingRegionUpdater = new RegionUpdater('shipping:country_id', 'shipping:region', 'shipping:region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'shipping:postcode');
|
175 |
+
//]]>
|
176 |
+
</script>
|
app/design/frontend/base/default/template/japi/TIG/PostNL/address_validation/customer/address/edit.phtml
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* ___________ __ __
|
4 |
+
* \__ ___/____ _/ |_ _____ | |
|
5 |
+
* | | / _ \\ __\\__ \ | |
|
6 |
+
* | | | |_| || | / __ \_| |__
|
7 |
+
* |____| \____/ |__| (____ /|____/
|
8 |
+
* \/
|
9 |
+
* ___ __ __
|
10 |
+
* | | ____ _/ |_ ____ _______ ____ ____ _/ |_
|
11 |
+
* | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
|
12 |
+
* | || | \| | \ ___/ | | \/| | \\ ___/ | |
|
13 |
+
* |___||___| /|__| \_____>|__| |___| / \_____>|__|
|
14 |
+
* \/ \/
|
15 |
+
* ________
|
16 |
+
* / _____/_______ ____ __ __ ______
|
17 |
+
* / \ ___\_ __ \ / _ \ | | \\____ \
|
18 |
+
* \ \_\ \| | \/| |_| || | /| |_| |
|
19 |
+
* \______ /|__| \____/ |____/ | __/
|
20 |
+
* \/ |__|
|
21 |
+
*
|
22 |
+
* NOTICE OF LICENSE
|
23 |
+
*
|
24 |
+
* This source file is subject to the Creative Commons License.
|
25 |
+
* It is available through the world-wide-web at this URL:
|
26 |
+
* http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
|
27 |
+
* If you are unable to obtain it through the world-wide-web, please send an email
|
28 |
+
* to servicedesk@tig.nl so we can send you a copy immediately.
|
29 |
+
*
|
30 |
+
* DISCLAIMER
|
31 |
+
*
|
32 |
+
* Do not edit or add to this file if you wish to upgrade this module to newer
|
33 |
+
* versions in the future. If you wish to customize this module for your
|
34 |
+
* needs please contact servicedesk@tig.nl for more information.
|
35 |
+
*
|
36 |
+
* @copyright Copyright (c) 2015 Total Internet Group B.V. (http://www.tig.nl)
|
37 |
+
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
|
38 |
+
*/
|
39 |
+
?>
|
40 |
+
<div class="account-address">
|
41 |
+
<?php if ($this->getTitle()): ?>
|
42 |
+
<div class="page-title">
|
43 |
+
<h1><?php echo $this->getTitle() ?></h1>
|
44 |
+
</div>
|
45 |
+
<?php endif; ?>
|
46 |
+
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
|
47 |
+
<form action="<?php echo $this->getSaveUrl() ?>" method="post" id="form-validate">
|
48 |
+
<div class="fieldset">
|
49 |
+
<?php echo $this->getBlockHtml('formkey') ?>
|
50 |
+
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>"/>
|
51 |
+
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>"/>
|
52 |
+
<h2 class="legend"><?php echo $this->__('Contact Information') ?></h2>
|
53 |
+
<ul class="form-list">
|
54 |
+
<li class="fields">
|
55 |
+
<?php echo $this->getNameBlockHtml() ?>
|
56 |
+
</li>
|
57 |
+
<li class="wide">
|
58 |
+
<label for="company"><?php echo $this->__('Company') ?></label>
|
59 |
+
<div class="input-box">
|
60 |
+
<input type="text" name="company" id="company" title="<?php echo $this->__('Company') ?>"
|
61 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>"
|
62 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>"/>
|
63 |
+
</div>
|
64 |
+
</li>
|
65 |
+
<li class="fields">
|
66 |
+
<div class="field">
|
67 |
+
<label for="telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
|
68 |
+
<div class="input-box">
|
69 |
+
<input type="text" name="telephone"
|
70 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>"
|
71 |
+
title="<?php echo $this->__('Telephone') ?>"
|
72 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>"
|
73 |
+
id="telephone"/>
|
74 |
+
</div>
|
75 |
+
</div>
|
76 |
+
<div class="field">
|
77 |
+
<label for="fax"><?php echo $this->__('Fax') ?></label>
|
78 |
+
<div class="input-box">
|
79 |
+
<input type="text" name="fax" id="fax" title="<?php echo $this->__('Fax') ?>"
|
80 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getFax()) ?>"
|
81 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('fax') ?>"/>
|
82 |
+
</div>
|
83 |
+
</div>
|
84 |
+
</li>
|
85 |
+
</ul>
|
86 |
+
</div>
|
87 |
+
<div class="fieldset">
|
88 |
+
<h2 class="legend"><?php echo $this->__('Address') ?></h2>
|
89 |
+
<ul class="form-list">
|
90 |
+
<?php echo $this->getChild('postnl_postcodecheck')
|
91 |
+
->setAddress($this->getAddress())
|
92 |
+
->setCountryHtmlSelect($this->getCountryHtmlSelect())
|
93 |
+
->toHtml(); ?>
|
94 |
+
<?php if ($this->helper('customer/address')->isVatAttributeVisible()) : ?>
|
95 |
+
<li class="wide">
|
96 |
+
<label for="vat_id"><?php echo $this->__('VAT Number') ?></label>
|
97 |
+
<div class="input-box">
|
98 |
+
<input type="text" name="vat_id"
|
99 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getVatId()) ?>"
|
100 |
+
title="<?php echo $this->__('VAT Number') ?>" id="vat_id"
|
101 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('vat_id') ?>"/>
|
102 |
+
</div>
|
103 |
+
</li>
|
104 |
+
<?php endif; ?>
|
105 |
+
<li class="fields">
|
106 |
+
<div class="field">
|
107 |
+
<label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?>
|
108 |
+
</label>
|
109 |
+
<div class="input-box">
|
110 |
+
<select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>"
|
111 |
+
class="validate-select" style="display:none;">
|
112 |
+
<option
|
113 |
+
value=""><?php echo $this->__('Please select region, state or province') ?></option>
|
114 |
+
</select>
|
115 |
+
<script type="text/javascript">
|
116 |
+
//<![CDATA[
|
117 |
+
$('region_id').setAttribute('defaultValue', "<?php echo $this->getAddress()->getRegionId() ?>");
|
118 |
+
//]]>
|
119 |
+
</script>
|
120 |
+
<input type="text" id="region" name="region"
|
121 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>"
|
122 |
+
title="<?php echo $this->__('State/Province') ?>"
|
123 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>"/>
|
124 |
+
</div>
|
125 |
+
</div>
|
126 |
+
</li>
|
127 |
+
<li<?php if ($this->canSetAsDefaultBilling()) echo ' class="control"' ?>>
|
128 |
+
<?php if ($this->isDefaultBilling()): ?>
|
129 |
+
<strong><?php echo $this->__('Default Billing Address') ?></strong>
|
130 |
+
<?php elseif ($this->canSetAsDefaultBilling()): ?>
|
131 |
+
<input type="checkbox" id="primary_billing" name="default_billing" value="1"
|
132 |
+
title="<?php echo $this->__('Use as My Default Billing Address') ?>" class="checkbox"/>
|
133 |
+
<label
|
134 |
+
for="primary_billing"><?php echo $this->__('Use as my default billing address') ?></label>
|
135 |
+
<?php else: ?>
|
136 |
+
<input type="hidden" name="default_billing" value="1"/>
|
137 |
+
<?php endif; ?>
|
138 |
+
</li>
|
139 |
+
<li<?php if ($this->canSetAsDefaultShipping()) echo ' class="control"' ?>>
|
140 |
+
<?php if ($this->isDefaultShipping()): ?>
|
141 |
+
<strong><?php echo $this->__('Default Shipping Address') ?></strong>
|
142 |
+
<?php elseif ($this->canSetAsDefaultShipping()): ?>
|
143 |
+
<input type="checkbox" id="primary_shipping" name="default_shipping" value="1"
|
144 |
+
title="<?php echo $this->__('Use as My Default Shipping Address') ?>" class="checkbox"/>
|
145 |
+
<label
|
146 |
+
for="primary_shipping"><?php echo $this->__('Use as my default shipping address') ?></label>
|
147 |
+
<?php else: ?>
|
148 |
+
<input type="hidden" name="default_shipping" value="1"/>
|
149 |
+
<?php endif; ?>
|
150 |
+
</li>
|
151 |
+
</ul>
|
152 |
+
</div>
|
153 |
+
<div class="buttons-set">
|
154 |
+
<button type="submit" title="<?php echo $this->__('Save Address') ?>" class="button">
|
155 |
+
<span><span><?php echo $this->__('Save Address') ?></span></span>
|
156 |
+
</button>
|
157 |
+
</div>
|
158 |
+
</form>
|
159 |
+
<script type="text/javascript">
|
160 |
+
//<![CDATA[
|
161 |
+
var dataForm = new VarienForm('form-validate', true);
|
162 |
+
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
|
163 |
+
//]]>
|
164 |
+
</script>
|
165 |
+
</div>
|
app/design/frontend/base/default/template/japi/TIG/PostNL/address_validation/customer/address/postcode_check.phtml
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* ___________ __ __
|
4 |
+
* \__ ___/____ _/ |_ _____ | |
|
5 |
+
* | | / _ \\ __\\__ \ | |
|
6 |
+
* | | | |_| || | / __ \_| |__
|
7 |
+
* |____| \____/ |__| (____ /|____/
|
8 |
+
* \/
|
9 |
+
* ___ __ __
|
10 |
+
* | | ____ _/ |_ ____ _______ ____ ____ _/ |_
|
11 |
+
* | | / \\ __\_/ __ \\_ __ \ / \ _/ __ \\ __\
|
12 |
+
* | || | \| | \ ___/ | | \/| | \\ ___/ | |
|
13 |
+
* |___||___| /|__| \_____>|__| |___| / \_____>|__|
|
14 |
+
* \/ \/
|
15 |
+
* ________
|
16 |
+
* / _____/_______ ____ __ __ ______
|
17 |
+
* / \ ___\_ __ \ / _ \ | | \\____ \
|
18 |
+
* \ \_\ \| | \/| |_| || | /| |_| |
|
19 |
+
* \______ /|__| \____/ |____/ | __/
|
20 |
+
* \/ |__|
|
21 |
+
*
|
22 |
+
* NOTICE OF LICENSE
|
23 |
+
*
|
24 |
+
* This source file is subject to the Creative Commons License.
|
25 |
+
* It is available through the world-wide-web at this URL:
|
26 |
+
* http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
|
27 |
+
* If you are unable to obtain it through the world-wide-web, please send an email
|
28 |
+
* to servicedesk@tig.nl so we can send you a copy immediately.
|
29 |
+
*
|
30 |
+
* DISCLAIMER
|
31 |
+
*
|
32 |
+
* Do not edit or add to this file if you wish to upgrade this module to newer
|
33 |
+
* versions in the future. If you wish to customize this module for your
|
34 |
+
* needs please contact servicedesk@tig.nl for more information.
|
35 |
+
*
|
36 |
+
* @copyright Copyright (c) 2015 Total Internet Group B.V. (http://www.tig.nl)
|
37 |
+
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
|
38 |
+
*/
|
39 |
+
?>
|
40 |
+
<?php $_readOnly = ''; ?>
|
41 |
+
<?php $_readOnlyClass = ''; ?>
|
42 |
+
<?php if ($this->getAddress()->getCountryId() == 'NL'): ?>
|
43 |
+
<?php $_readOnly = 'readonly=""'; ?>
|
44 |
+
<?php $_readOnlyClass = 'postnl-readonly'; ?>
|
45 |
+
<?php endif; ?>
|
46 |
+
|
47 |
+
<?php $_addressType = $this->hasAddressType() ? $this->getAddressType() : 'billing'; ?>
|
48 |
+
<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
|
49 |
+
<?php $_streetValidationClassNotRequired = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
|
50 |
+
|
51 |
+
<?php $_postnlHelper = Mage::helper('postnl/addressValidation'); ?>
|
52 |
+
|
53 |
+
<?php $_timeoutDelay = $_postnlHelper->getPostcodeCheckTimeoutDelay(); ?>
|
54 |
+
<?php $_maxAttempts = $_postnlHelper->getPostcodeCheckMaxAttempts(); ?>
|
55 |
+
<li>
|
56 |
+
<label for=":country_id" class="required"><em>*</em><?php echo $_postnlHelper->__('Country') ?></label>
|
57 |
+
<div class="input-box">
|
58 |
+
<?php echo $this->getCountryHtmlSelect() ?>
|
59 |
+
</div>
|
60 |
+
</li>
|
61 |
+
<li class="fields" id="ca_postnl_ce">
|
62 |
+
<div class="field field-postcode">
|
63 |
+
<label for="postcode" class="required"><em>*</em><?php echo $_postnlHelper->__('Zip/Postal Code') ?></label>
|
64 |
+
<div class="input-box">
|
65 |
+
<input type="text" title="<?php echo $_postnlHelper->__('Zip/Postal Code') ?>" name="postcode" id="postcode" value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>" class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
|
66 |
+
</div>
|
67 |
+
</div>
|
68 |
+
<div class="field field-housenumber">
|
69 |
+
<label for="virtual_street2" class="required"><em>*</em><?php echo $_postnlHelper->__('Housenumber') ?></label>
|
70 |
+
<div class="input-box">
|
71 |
+
<input type="text" title="<?php echo $_postnlHelper->__('Housenumber') ?>" name="virtual_street[]" id="virtual_street2" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet(2)) ?>" class="input-text <?php echo $_streetValidationClass ?>" />
|
72 |
+
</div>
|
73 |
+
</div>
|
74 |
+
<div class="field field-extension">
|
75 |
+
<label for="virtual_street3"><?php echo $_postnlHelper->__('Extension') ?></label>
|
76 |
+
<div class="input-box">
|
77 |
+
<input type="text" title="<?php echo $_postnlHelper->__('Extension') ?>" name="virtual_street[]" id="virtual_street3" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet(3)) ?>" class="input-text <?php echo $_streetValidationClassNotRequired ?>" />
|
78 |
+
</div>
|
79 |
+
</div>
|
80 |
+
<div id="postnl_postcodecheck_spinner_" class="postnl-loading" style="display:none;">
|
81 |
+
<img src="<?php echo $this->getSkinUrl('images/TIG/PostNL/opc-ajax-loader.gif'); ?>"/>
|
82 |
+
</div>
|
83 |
+
<div class="postnl validation-advice" style="display:none;" id="postnl_address_error_">
|
84 |
+
<?php echo $_postnlHelper->__('Your postcode/housenumber combination could not be found. Please enter your streetname and city manually.'); ?>
|
85 |
+
</div>
|
86 |
+
<div class="postnl validation-advice" style="display:none;" id="postnl_address_missing_">
|
87 |
+
<?php echo $_postnlHelper->__('Please enter a postcode and housenumber.'); ?>
|
88 |
+
</div>
|
89 |
+
<div class="postnl validation-advice" style="display:none;" id="postnl_address_invalid_">
|
90 |
+
<?php echo $_postnlHelper->__('Your postcode/housenumber combination could not be found. Please make sure you have entered a valid postcode and housenumber and try again.'); ?>
|
91 |
+
</div>
|
92 |
+
</li>
|
93 |
+
<li>
|
94 |
+
<label for="virtual_street1" class="required"><em>*</em><?php echo $_postnlHelper->__('Street name') ?></label>
|
95 |
+
<div class="input-box">
|
96 |
+
<input type="text" title="<?php echo $_postnlHelper->__('Street name') ?>" name="virtual_street[]" id="virtual_street1" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet(1)) ?>" class="input-text <?php echo $_streetValidationClass ?> <?php echo $_readOnlyClass; ?>" <?php echo $_readOnly; ?>/>
|
97 |
+
</div>
|
98 |
+
</li>
|
99 |
+
<?php /* Only street lines 4+ will be used as expected. Street lines 1, 2 and 3 are used for the postcode check. */ ?>
|
100 |
+
<?php for ($_i = 4, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
|
101 |
+
<li class="add-field">
|
102 |
+
<div class="input-box">
|
103 |
+
<input type="text" title="<?php echo $_postnlHelper->__('Street Address %s', $_i) ?>" name="virtual_street[]" id="virtual_street<?php echo $_i ?>" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet($_i)) ?>" class="input-text <?php echo $_streetValidationClassNotRequired ?>" />
|
104 |
+
</div>
|
105 |
+
</li>
|
106 |
+
<?php endfor; ?>
|
107 |
+
<li class="fields">
|
108 |
+
<div class="field">
|
109 |
+
<label for="city" class="required"><em>*</em><?php echo $_postnlHelper->__('City') ?></label>
|
110 |
+
<div class="input-box">
|
111 |
+
<input type="text" title="<?php echo $_postnlHelper->__('City') ?>" name="city" id="city" value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?> <?php echo $_readOnlyClass; ?>" <?php echo $_readOnly; ?>/>
|
112 |
+
</div>
|
113 |
+
</div>
|
114 |
+
</li>
|
115 |
+
|
116 |
+
<!-- Hidden fields for all the street lines to force them in the proper order regardless of the order in which they are displayed. -->
|
117 |
+
<div style="display:none;">
|
118 |
+
<input type="hidden" name="street[]" id="street1"/>
|
119 |
+
<input type="hidden" name="street[]" id="street2"/>
|
120 |
+
<input type="hidden" name="street[]" id="street3"/>
|
121 |
+
<?php for ($_i = 4, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
|
122 |
+
<input type="hidden" name="street[]" id="street<?php echo $_i ?>"/>
|
123 |
+
<?php endfor; ?>
|
124 |
+
</div>
|
125 |
+
|
126 |
+
<script type="text/javascript">
|
127 |
+
//<![CDATA[
|
128 |
+
<?php for ($_i = 4, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
|
129 |
+
$('virtual_street<?php echo $_i; ?>').observe('change', function(event) {
|
130 |
+
var element = Event.element(event);
|
131 |
+
var value = element.getValue();
|
132 |
+
|
133 |
+
$('street<?php echo $_i; ?>').setValue(value);
|
134 |
+
});
|
135 |
+
$('virtual_street<?php echo $_i; ?>').observe('change', function(event) {
|
136 |
+
var element = Event.element(event);
|
137 |
+
var value = element.getValue();
|
138 |
+
|
139 |
+
$('street<?php echo $_i; ?>').setValue(value);
|
140 |
+
});
|
141 |
+
<?php endfor; ?>
|
142 |
+
|
143 |
+
document.observe('dom:loaded', function() {
|
144 |
+
var postcodeCheck = new PostnlPostcodecheck(
|
145 |
+
'<?php echo $this->getUrl('postnl/addressValidation/postcodeCheck', array('_secure' => true)); ?>',
|
146 |
+
'',
|
147 |
+
'country',
|
148 |
+
'postcode',
|
149 |
+
'street1',
|
150 |
+
'street2',
|
151 |
+
'street3',
|
152 |
+
'city',
|
153 |
+
'virtual_'
|
154 |
+
);
|
155 |
+
postcodeCheck.errorMax = <?php echo $_maxAttempts; ?>;
|
156 |
+
postcodeCheck.timeoutDelay = '<?php echo $_timeoutDelay; ?>';
|
157 |
+
postcodeCheck.init();
|
158 |
+
});
|
159 |
+
//]]>
|
160 |
+
</script>
|
app/design/frontend/base/default/template/japi/checkout/onepage.phtml
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php /* @var $this Mage_Checkout_Block_Onepage */ ?>
|
28 |
+
<div class="page-title">
|
29 |
+
<h1><?php echo $this->__('Checkout') ?></h1>
|
30 |
+
</div>
|
31 |
+
<?php $error = $this->getMessagesBlock()->getGroupedHtml() ?>
|
32 |
+
<?php echo $error ?>
|
33 |
+
<?php if ($this->getQuote()->getHasError()) return ?>
|
34 |
+
<ol class="opc quote-<?php echo $this->getQuote()->getId() ?>" id="checkoutSteps">
|
35 |
+
<?php $i = 0 ?>
|
36 |
+
<?php foreach ($this->getSteps() as $_stepId => $_stepInfo): ?>
|
37 |
+
<?php if (!$this->getChild($_stepId) || !$this->getChild($_stepId)->isShow()): continue; endif; ?>
|
38 |
+
<?php $i++ ?>
|
39 |
+
<li id="opc-<?php echo $_stepId ?>"
|
40 |
+
class="panel section<?php echo $i == 1 || !empty($_stepInfo['allow']) ? ' allow' : '' ?>">
|
41 |
+
<div class="step-title" role="tab">
|
42 |
+
<div class="step-number-wrapper">
|
43 |
+
<span class="step-number"><?php echo $i ?></span>
|
44 |
+
</div>
|
45 |
+
<h2><?php echo $_stepInfo['label'] ?></h2>
|
46 |
+
<a href="#checkout-step-<?php echo $_stepId ?>" data-toggle="collapse" role="button"
|
47 |
+
data-parent="#checkoutSteps" <?php if ($i == 1): ?>aria-expanded="true" <?php endif; ?>
|
48 |
+
aria-controls="checkout-step-<?php echo $_stepId ?>" class="section-control">
|
49 |
+
<i class="icomoon-pencil"></i>
|
50 |
+
</a>
|
51 |
+
</div>
|
52 |
+
<div id="checkout-step-<?php echo $_stepId ?>" role="tabpanel"
|
53 |
+
class="step a-item collapse<?php echo $i == 1 ? ' in' : '' ?>"
|
54 |
+
style="<?php echo $i > 1 ? 'display:none;' : '' ?>">
|
55 |
+
<?php echo $this->getChildHtml($_stepId) ?>
|
56 |
+
</div>
|
57 |
+
</li>
|
58 |
+
<?php endforeach ?>
|
59 |
+
</ol>
|
60 |
+
<script type="text/javascript">
|
61 |
+
//<![CDATA[
|
62 |
+
var accordion = JMango('#checkoutSteps');
|
63 |
+
var checkout = new JMCheckout(accordion, {
|
64 |
+
progress: '<?php echo $this->getUrl('japi/checkout/progress', array('_secure' => true)) ?>',
|
65 |
+
review: '<?php echo $this->getUrl('japi/checkout/review', array('_secure' => true)) ?>',
|
66 |
+
saveMethod: '<?php echo $this->getUrl('japi/checkout/saveMethod', array('_secure' => true)) ?>',
|
67 |
+
failure: '<?php echo $this->getUrl('japi/checkout/onepage', array('_secure' => true)) ?>'
|
68 |
+
});
|
69 |
+
<?php if (!$error && Mage::getSingleton('core/session')->getData('is_address_update') && $this->getQuote()->getBillingAddress()->getCountryId()): ?>
|
70 |
+
<?php Mage::getSingleton('core/session')->setData('is_address_update', false) ?>
|
71 |
+
document.observe("dom:loaded", function () {
|
72 |
+
checkout.gotoSection('shipping_method');
|
73 |
+
shippingMethod.load('<?php echo $this->getUrl('japi/checkout/getShippingMethod', array('_secure' => true)) ?>');
|
74 |
+
});
|
75 |
+
<?php endif ?>
|
76 |
+
//]]>
|
77 |
+
</script>
|
app/design/frontend/base/default/template/japi/checkout/onepage/address.phtml
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2016 JMango360
|
4 |
+
*/
|
5 |
+
?>
|
6 |
+
<?php /* @var $this Jmango360_Japi_Block_Checkout_Onepage_Address */ ?>
|
7 |
+
<?php foreach ($this->getFields() as $field): ?>
|
8 |
+
<li class="wide">
|
9 |
+
<label class="<?php echo $field['required'] ? 'required' : '' ?>" for="">
|
10 |
+
<?php if ($field['required']): ?><em>*</em><?php endif ?>
|
11 |
+
<?php echo $this->__($field['label']) ?>
|
12 |
+
</label>
|
13 |
+
<div class="input-box">
|
14 |
+
<?php switch ($field['display_type']):
|
15 |
+
case 'drop_down':
|
16 |
+
case 'multi_select': ?>
|
17 |
+
<select <?php echo $field['display_type'] == 'multi_select' ? 'multiple' : '' ?>
|
18 |
+
name="<?php echo $this->getFieldName($field['key']) ?>"
|
19 |
+
id="<?php echo $this->getFieldId($field['key']) ?>"
|
20 |
+
class="<?php echo $field['required'] ? 'required-entry' : '' ?>">
|
21 |
+
<?php if (isset($field['options'])): ?>
|
22 |
+
<?php foreach ($field['options'] as $value => $label): ?>
|
23 |
+
<option
|
24 |
+
value="<?php echo $value ?>"
|
25 |
+
selected="<?php echo $this->getFieldValue($field['key']) == $value ? 'selected' : '' ?>"
|
26 |
+
><?php echo $label ?></option>
|
27 |
+
<?php endforeach ?>
|
28 |
+
<?php endif; ?>
|
29 |
+
</select>
|
30 |
+
<?php break; ?>
|
31 |
+
<?php case 'checkbox': ?>
|
32 |
+
<input type="checkbox"
|
33 |
+
name="<?php echo $this->getFieldName($field['key']) ?>"
|
34 |
+
id="<?php echo $this->getFieldId($field['key']) ?>"
|
35 |
+
value="1"
|
36 |
+
checked="<?php echo $this->getFieldValue($field['key']) ? 'checked' : '' ?>"
|
37 |
+
class="input-text<?php echo $field['required'] ? ' required-entry' : '' ?>"/>
|
38 |
+
<?php break; ?>
|
39 |
+
<?php default: ?>
|
40 |
+
<input type="text"
|
41 |
+
name="<?php echo $this->getFieldName($field['key']) ?>"
|
42 |
+
id="<?php echo $this->getFieldId($field['key']) ?>"
|
43 |
+
value="<?php echo $this->escapeHtml($this->getFieldValue($field['key'])) ?>"
|
44 |
+
class="input-text<?php echo $field['required'] ? ' required-entry' : '' ?>"/>
|
45 |
+
<?php endswitch; ?>
|
46 |
+
</div>
|
47 |
+
</li>
|
48 |
+
<?php endforeach; ?>
|
app/design/frontend/base/default/template/japi/checkout/onepage/agreements.phtml
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php
|
28 |
+
/**
|
29 |
+
* @see Mage_Checkout_Block_Agreements
|
30 |
+
*/
|
31 |
+
?>
|
32 |
+
<?php if (!$this->getAgreements()) return; ?>
|
33 |
+
<form action="" id="checkout-agreements" onsubmit="return false;">
|
34 |
+
<dl class="sp-methods">
|
35 |
+
<?php foreach ($this->getAgreements() as $_a): ?>
|
36 |
+
<dt>
|
37 |
+
<input type="checkbox" id="agreement-<?php echo $_a->getId() ?>"
|
38 |
+
name="agreement[<?php echo $_a->getId() ?>]" value="1"
|
39 |
+
title="<?php echo $this->escapeHtml($_a->getCheckboxText()) ?>" class="checkbox"/>
|
40 |
+
|
41 |
+
<label for="agreement-<?php echo $_a->getId() ?>">
|
42 |
+
<a href="#agreementModal<?php echo $_a->getId() ?>" data-toggle="modal" class="agreement-label">
|
43 |
+
<?php echo $_a->getIsHtml() ? $_a->getCheckboxText() : $this->escapeHtml($_a->getCheckboxText()) ?>
|
44 |
+
</a>
|
45 |
+
</label>
|
46 |
+
|
47 |
+
<div id="agreementModal<?php echo $_a->getId() ?>" class="modal modal-agreement" tabindex="-1"
|
48 |
+
role="modal" aria-labelledby="agreementModalLabel<?php echo $_a->getId() ?>">
|
49 |
+
<div class="modal-dialog" role="document">
|
50 |
+
<div class="modal-content">
|
51 |
+
<div class="modal-header">
|
52 |
+
<button type="button" class="close" data-dismiss="modal"
|
53 |
+
aria-label="<?php echo $this->__('Close') ?>">
|
54 |
+
<span aria-hidden="true">×</span>
|
55 |
+
</button>
|
56 |
+
<h1 class="modal-title" id="agreementModalLabel<?php echo $_a->getId() ?>">
|
57 |
+
<?php echo $this->escapeHtml($_a->getName()) ?>
|
58 |
+
</h1>
|
59 |
+
</div>
|
60 |
+
<div class="modal-body">
|
61 |
+
<?php if ($_a->getIsHtml()): ?>
|
62 |
+
<?php echo $_a->getContent() ?>
|
63 |
+
<?php else: ?>
|
64 |
+
<?php echo nl2br($this->escapeHtml($_a->getContent())) ?>
|
65 |
+
<?php endif; ?>
|
66 |
+
</div>
|
67 |
+
</div>
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
</dt>
|
71 |
+
<?php endforeach; ?>
|
72 |
+
</dl>
|
73 |
+
</form>
|
74 |
+
<script type="text/javascript">
|
75 |
+
//<![CDATA[
|
76 |
+
new JMAgreement($('checkout-agreements'));
|
77 |
+
//]]>
|
78 |
+
</script>
|
app/design/frontend/base/default/template/japi/checkout/onepage/billing.phtml
ADDED
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<form id="co-billing-form" action="">
|
28 |
+
<fieldset>
|
29 |
+
<ul class="form-list">
|
30 |
+
<?php if ($this->customerHasAddresses()): ?>
|
31 |
+
<li class="wide">
|
32 |
+
<label
|
33 |
+
for="billing-address-select"><?php echo $this->__('Select a billing address from your address book or enter a new address.') ?></label>
|
34 |
+
<div class="input-box">
|
35 |
+
<?php echo $this->getAddressesHtmlSelect('billing') ?>
|
36 |
+
</div>
|
37 |
+
</li>
|
38 |
+
<?php endif; ?>
|
39 |
+
<li id="billing-new-address-form"<?php if ($this->customerHasAddresses()): ?> style="display:none;"<?php endif; ?>>
|
40 |
+
<fieldset>
|
41 |
+
<input type="hidden" name="billing[address_id]" value="<?php echo $this->getAddress()->getId() ?>"
|
42 |
+
id="billing:address_id"/>
|
43 |
+
<ul>
|
44 |
+
<li class="fields"><?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getAddress()->getFirstname() ? $this->getAddress() : $this->getQuote()->getCustomer())->setForceUseCustomerRequiredAttributes(!$this->isCustomerLoggedIn())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?></li>
|
45 |
+
<li class="fields">
|
46 |
+
<div class="field">
|
47 |
+
<label for="billing:company"><?php echo $this->__('Company') ?></label>
|
48 |
+
<div class="input-box">
|
49 |
+
<input type="text" id="billing:company" name="billing[company]"
|
50 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>"
|
51 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Company')) ?>"
|
52 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>"/>
|
53 |
+
</div>
|
54 |
+
</div>
|
55 |
+
<?php if (!$this->isCustomerLoggedIn()): ?>
|
56 |
+
<div class="field">
|
57 |
+
<label for="billing:email"
|
58 |
+
class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
|
59 |
+
<div class="input-box">
|
60 |
+
<input type="text" name="billing[email]" id="billing:email"
|
61 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getEmail()) ?>"
|
62 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Email Address')) ?>"
|
63 |
+
class="input-text validate-email required-entry"/>
|
64 |
+
</div>
|
65 |
+
</div>
|
66 |
+
<?php endif; ?>
|
67 |
+
</li>
|
68 |
+
<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
|
69 |
+
<li class="wide">
|
70 |
+
<label for="billing:street1" class="required"><em>*</em><?php echo $this->__('Address') ?>
|
71 |
+
</label>
|
72 |
+
<div class="input-box">
|
73 |
+
<input type="text"
|
74 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Street Address')) ?>"
|
75 |
+
name="billing[street][]" id="billing:street1"
|
76 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getStreet(1)) ?>"
|
77 |
+
class="input-text <?php echo $_streetValidationClass ?>"/>
|
78 |
+
</div>
|
79 |
+
</li>
|
80 |
+
<?php
|
81 |
+
$_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass));
|
82 |
+
$_streetConfig = Mage::getStoreConfig('japi/jmango_rest_customer_settings');
|
83 |
+
?>
|
84 |
+
<?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
|
85 |
+
<li class="wide">
|
86 |
+
<?php if (!empty($_streetConfig['street'.$_i.'_label'])): ?>
|
87 |
+
<label for="billing:street<?php echo $_i ?>" class="<?php echo !$_streetConfig['street'.$_i.'_require'] ? '' : 'required' ?>">
|
88 |
+
<?php if ($_streetConfig['street'.$_i.'_require']): ?><em>*</em><?php endif; ?>
|
89 |
+
<?php echo Mage::helper('core')->quoteEscape($this->__($_streetConfig['street'.$_i.'_label'])) ?>
|
90 |
+
</label>
|
91 |
+
<?php endif; //End if (!empty($_streetConfig['street'.$_i.'_label'])) ?>
|
92 |
+
<?php
|
93 |
+
$additionValidate = '';
|
94 |
+
if ($_streetConfig['street'.$_i.'_require']) {
|
95 |
+
$additionValidate .= ' required-entry';
|
96 |
+
}
|
97 |
+
if (!empty($_streetConfig['street'.$_i.'_type'])
|
98 |
+
&& $_streetConfig['street'.$_i.'_type'] == 'number') {
|
99 |
+
$additionValidate .= ' validate-number';
|
100 |
+
}
|
101 |
+
|
102 |
+
if (!empty($_streetConfig['street'.$_i.'_label'])) {
|
103 |
+
$_title = Mage::helper('core')->quoteEscape($this->__($_streetConfig['street'.$_i.'_label']));
|
104 |
+
} else {
|
105 |
+
$_title = Mage::helper('core')->quoteEscape($this->__('Street Address %s', $_i));
|
106 |
+
}
|
107 |
+
?>
|
108 |
+
<div class="input-box">
|
109 |
+
<input type="text" name="billing[street][]"
|
110 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getStreet($_i)) ?>"
|
111 |
+
title="<?php echo $_title ?>"
|
112 |
+
id="billing:street<?php echo $_i ?>"
|
113 |
+
class="input-text <?php echo $_streetValidationClass . $additionValidate ?>"/>
|
114 |
+
</div>
|
115 |
+
</li>
|
116 |
+
<?php endfor; ?>
|
117 |
+
<?php if ($this->helper('customer/address')->isVatAttributeVisible()) : ?>
|
118 |
+
<li class="wide">
|
119 |
+
<label for="billing:vat_id"><?php echo $this->__('VAT Number') ?></label>
|
120 |
+
<div class="input-box">
|
121 |
+
<input type="text" id="billing:vat_id" name="billing[vat_id]"
|
122 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getVatId()) ?>"
|
123 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('VAT Number')) ?>"
|
124 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('vat_id') ?>"/>
|
125 |
+
</div>
|
126 |
+
</li>
|
127 |
+
<?php endif; ?>
|
128 |
+
<li class="fields">
|
129 |
+
<div class="field">
|
130 |
+
<label for="billing:city" class="required"><em>*</em><?php echo $this->__('City') ?>
|
131 |
+
</label>
|
132 |
+
<div class="input-box">
|
133 |
+
<input type="text"
|
134 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('City')) ?>"
|
135 |
+
name="billing[city]"
|
136 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>"
|
137 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>"
|
138 |
+
id="billing:city"/>
|
139 |
+
</div>
|
140 |
+
</div>
|
141 |
+
<div class="field">
|
142 |
+
<label for="billing:region_id"
|
143 |
+
class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
|
144 |
+
<div class="input-box">
|
145 |
+
<select id="billing:region_id" name="billing[region_id]"
|
146 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>"
|
147 |
+
class="validate-select" style="display:none;">
|
148 |
+
<option
|
149 |
+
value=""><?php echo $this->__('Please select region, state or province') ?></option>
|
150 |
+
</select>
|
151 |
+
<script type="text/javascript">
|
152 |
+
//<![CDATA[
|
153 |
+
$('billing:region_id').setAttribute('defaultValue', "<?php echo $this->getAddress()->getRegionId() ?>");
|
154 |
+
//]]>
|
155 |
+
</script>
|
156 |
+
<input type="text" id="billing:region" name="billing[region]"
|
157 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>"
|
158 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>"
|
159 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>"
|
160 |
+
style="display:none;"/>
|
161 |
+
</div>
|
162 |
+
</div>
|
163 |
+
</li>
|
164 |
+
<li class="fields">
|
165 |
+
<div class="field">
|
166 |
+
<label for="billing:postcode"
|
167 |
+
class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
|
168 |
+
<div class="input-box">
|
169 |
+
<input type="text"
|
170 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Zip/Postal Code')) ?>"
|
171 |
+
name="billing[postcode]" id="billing:postcode"
|
172 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>"
|
173 |
+
class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>"/>
|
174 |
+
</div>
|
175 |
+
</div>
|
176 |
+
<div class="field">
|
177 |
+
<label for="billing:country_id"
|
178 |
+
class="required"><em>*</em><?php echo $this->__('Country') ?></label>
|
179 |
+
<div class="input-box">
|
180 |
+
<?php echo $this->getCountryHtmlSelect('billing') ?>
|
181 |
+
</div>
|
182 |
+
</div>
|
183 |
+
</li>
|
184 |
+
<li class="fields">
|
185 |
+
<div class="field">
|
186 |
+
<label for="billing:telephone"
|
187 |
+
class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
|
188 |
+
<div class="input-box">
|
189 |
+
<input type="text" name="billing[telephone]"
|
190 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>"
|
191 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Telephone')) ?>"
|
192 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>"
|
193 |
+
id="billing:telephone"/>
|
194 |
+
</div>
|
195 |
+
</div>
|
196 |
+
<div class="field">
|
197 |
+
<label for="billing:fax"><?php echo $this->__('Fax') ?></label>
|
198 |
+
<div class="input-box">
|
199 |
+
<input type="text" name="billing[fax]"
|
200 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getFax()) ?>"
|
201 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Fax')) ?>"
|
202 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('fax') ?>"
|
203 |
+
id="billing:fax"/>
|
204 |
+
</div>
|
205 |
+
</div>
|
206 |
+
</li>
|
207 |
+
<?php if (!$this->isCustomerLoggedIn()): ?>
|
208 |
+
|
209 |
+
<?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
|
210 |
+
<?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
|
211 |
+
<?php if ($_dob->isEnabled() || $_gender->isEnabled()): ?>
|
212 |
+
<li class="fields">
|
213 |
+
<?php if ($_dob->isEnabled()): ?>
|
214 |
+
<div class="field">
|
215 |
+
<?php echo $_dob->setDate($this->getQuote()->getCustomerDob())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?>
|
216 |
+
</div>
|
217 |
+
<?php endif; ?>
|
218 |
+
<?php if ($_gender->isEnabled()): ?>
|
219 |
+
<div class="field">
|
220 |
+
<?php echo $_gender->setGender($this->getQuote()->getCustomerGender())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?>
|
221 |
+
</div>
|
222 |
+
<?php endif ?>
|
223 |
+
</li>
|
224 |
+
<?php endif ?>
|
225 |
+
|
226 |
+
<?php $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat') ?>
|
227 |
+
<?php if ($_taxvat->isEnabled()): ?>
|
228 |
+
<li>
|
229 |
+
<?php echo $_taxvat->setTaxvat($this->getQuote()->getCustomerTaxvat())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?>
|
230 |
+
</li>
|
231 |
+
<?php endif ?>
|
232 |
+
<?php endif ?>
|
233 |
+
|
234 |
+
<?php if (!$this->isCustomerLoggedIn()): ?>
|
235 |
+
<li class="fields" id="register-customer-password">
|
236 |
+
<div class="field">
|
237 |
+
<label for="billing:customer_password"
|
238 |
+
class="required"><em>*</em><?php echo $this->__('Password') ?></label>
|
239 |
+
<div class="input-box">
|
240 |
+
<input type="password" name="billing[customer_password]"
|
241 |
+
id="billing:customer_password"
|
242 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Password')) ?>"
|
243 |
+
class="input-text required-entry validate-password"/>
|
244 |
+
</div>
|
245 |
+
</div>
|
246 |
+
<div class="field">
|
247 |
+
<label for="billing:confirm_password"
|
248 |
+
class="required"><em>*</em><?php echo $this->__('Confirm Password') ?>
|
249 |
+
</label>
|
250 |
+
<div class="input-box">
|
251 |
+
<input type="password" name="billing[confirm_password]"
|
252 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Confirm Password')) ?>"
|
253 |
+
id="billing:confirm_password"
|
254 |
+
class="input-text required-entry validate-cpassword"/>
|
255 |
+
</div>
|
256 |
+
</div>
|
257 |
+
</li>
|
258 |
+
<?php endif; ?>
|
259 |
+
<?php if ($this->isCustomerLoggedIn() && $this->customerHasAddresses()): ?>
|
260 |
+
<li class="control">
|
261 |
+
<input type="checkbox" name="billing[save_in_address_book]" value="1"
|
262 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Save in address book')) ?>"
|
263 |
+
id="billing:save_in_address_book"
|
264 |
+
onchange="if(window.shipping) shipping.setSameAsBilling(false);"<?php if ($this->getAddress()->getSaveInAddressBook()): ?> checked="checked"<?php endif; ?>
|
265 |
+
class="checkbox"/>
|
266 |
+
<label
|
267 |
+
for="billing:save_in_address_book"><?php echo $this->__('Save in address book') ?></label>
|
268 |
+
</li>
|
269 |
+
<?php else: ?>
|
270 |
+
<li class="no-display"><input type="hidden" name="billing[save_in_address_book]" value="1"/>
|
271 |
+
</li>
|
272 |
+
<?php endif; ?>
|
273 |
+
<?php echo $this->getChildHtml('form.additional.info'); ?>
|
274 |
+
</ul>
|
275 |
+
</fieldset>
|
276 |
+
</li>
|
277 |
+
<?php /* Extensions placeholder */ ?>
|
278 |
+
<?php echo $this->getChildHtml('checkout.onepage.billing.extra') ?>
|
279 |
+
<?php if ($this->canShip()): ?>
|
280 |
+
<li class="control">
|
281 |
+
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes"
|
282 |
+
value="1"<?php if ($this->isUseBillingAddressForShipping()) { ?> checked="checked"<?php } ?>
|
283 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Ship to this address')) ?>"
|
284 |
+
onclick="$('shipping:same_as_billing').checked = true;" class="radio"/>
|
285 |
+
<label for="billing:use_for_shipping_yes"><?php echo $this->__('Ship to this address') ?></label>
|
286 |
+
</li>
|
287 |
+
<li class="control">
|
288 |
+
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_no"
|
289 |
+
value="0"<?php if (!$this->isUseBillingAddressForShipping()) { ?> checked="checked"<?php } ?>
|
290 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Ship to different address')) ?>"
|
291 |
+
onclick="$('shipping:same_as_billing').checked = false;" class="radio"/>
|
292 |
+
<label
|
293 |
+
for="billing:use_for_shipping_no"><?php echo $this->__('Ship to different address') ?></label>
|
294 |
+
</li>
|
295 |
+
<?php endif; ?>
|
296 |
+
</ul>
|
297 |
+
<?php if (!$this->canShip()): ?>
|
298 |
+
<input type="hidden" name="billing[use_for_shipping]" value="1"/>
|
299 |
+
<?php endif; ?>
|
300 |
+
<div class="buttons-set" id="billing-buttons-container">
|
301 |
+
<button id="billing-button" type="button"
|
302 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Continue')) ?>"
|
303 |
+
class="ladda-button" onclick="billing.save()" data-color="jmango" data-style="slide-up"
|
304 |
+
data-size="s">
|
305 |
+
<span class="ladda-label"><?php echo $this->__('Continue') ?></span>
|
306 |
+
</button>
|
307 |
+
</div>
|
308 |
+
</fieldset>
|
309 |
+
</form>
|
310 |
+
<script type="text/javascript">
|
311 |
+
//<![CDATA[
|
312 |
+
var billing = new Billing(
|
313 |
+
'co-billing-form',
|
314 |
+
'<?php echo $this->getUrl('japi/checkout/getAddress', array('_secure' => true)) ?>address/',
|
315 |
+
'<?php echo $this->getUrl('japi/checkout/saveBilling', array('_secure' => true)) ?>'
|
316 |
+
);
|
317 |
+
var billingForm = new VarienForm('co-billing-form');
|
318 |
+
$('billing-address-select') && billing.newAddress(!$('billing-address-select').value);
|
319 |
+
var billingRegionUpdater = new RegionUpdater(
|
320 |
+
'billing:country_id', 'billing:region', 'billing:region_id',
|
321 |
+
<?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'billing:postcode'
|
322 |
+
);
|
323 |
+
//]]>
|
324 |
+
</script>
|
app/design/frontend/base/default/template/japi/checkout/onepage/coupon.phtml
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<form id="discount-coupon-form" action="" method="post">
|
28 |
+
<dl class="sp-methods">
|
29 |
+
<dt><?php echo $this->__('Discount Codes') ?>
|
30 |
+
<a href="#coupon-content" data-toggle="collapse" role="button" aria-expanded="false"
|
31 |
+
aria-controls="coupon-content" class="section-control">
|
32 |
+
<i class="icomoon-pencil"></i>
|
33 |
+
</a>
|
34 |
+
</dt>
|
35 |
+
<dd>
|
36 |
+
<ul class="form-list collapse<?php echo strlen($this->getCouponCode()) ? ' in' : '' ?>" id="coupon-content">
|
37 |
+
<li>
|
38 |
+
<label for="coupon_code"><?php echo $this->__('Enter your coupon code if you have one.') ?></label>
|
39 |
+
<input type="hidden" name="remove" id="remove-coupone" value="0"/>
|
40 |
+
<div class="input-box">
|
41 |
+
<input class="input-text" id="coupon_code" name="coupon_code" type="text"
|
42 |
+
value="<?php echo $this->escapeHtml($this->getCouponCode()) ?>"/>
|
43 |
+
</div>
|
44 |
+
<div class="buttons-set">
|
45 |
+
<?php if (!strlen($this->getCouponCode())): ?>
|
46 |
+
<button type="button" class="ladda-button" data-color="jmango" data-size="xs"
|
47 |
+
data-style="slide-up" onclick="discountForm.submit(false)"
|
48 |
+
style="width:auto;" id="coupon-button"
|
49 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Apply Coupon')) ?>"
|
50 |
+
value="<?php echo Mage::helper('core')->quoteEscape($this->__('Apply Coupon')) ?>">
|
51 |
+
<span class="ladda-label"><?php echo $this->__('Apply Coupon') ?></span></button>
|
52 |
+
<?php else: ?>
|
53 |
+
<button type="button" class="ladda-button" data-color="jmango" data-size="xs"
|
54 |
+
data-style="slide-up" onclick="discountForm.submit(true)"
|
55 |
+
style="width:auto;" id="coupon-button"
|
56 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Cancel Coupon')) ?>"
|
57 |
+
value="<?php echo Mage::helper('core')->quoteEscape($this->__('Cancel Coupon')) ?>">
|
58 |
+
<span class="ladda-label"><?php echo $this->__('Cancel Coupon') ?></span></button>
|
59 |
+
<?php endif ?>
|
60 |
+
</div>
|
61 |
+
</li>
|
62 |
+
</ul>
|
63 |
+
</dd>
|
64 |
+
</dl>
|
65 |
+
</form>
|
66 |
+
<script type="text/javascript">
|
67 |
+
//<![CDATA[
|
68 |
+
discountForm = new JMDiscount('discount-coupon-form', '<?php echo $this->getUrl('japi/checkout/couponPost', array('_secure' => true)) ?>');
|
69 |
+
//]]>
|
70 |
+
</script>
|
app/design/frontend/base/default/template/japi/checkout/onepage/js.phtml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* @var $this Jmango360_Japi_Block_Checkout_Onepage_Addjs */
|
3 |
+
?>
|
4 |
+
<style type="text/css">
|
5 |
+
<?php echo $this->getCustomCss() ?>
|
6 |
+
</style>
|
app/design/frontend/base/default/template/japi/checkout/onepage/payment.phtml
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php
|
28 |
+
$_edition = Mage::getEdition();
|
29 |
+
$_version = Mage::getVersion();
|
30 |
+
?>
|
31 |
+
<script type="text/javascript">
|
32 |
+
//<![CDATA[
|
33 |
+
var quoteBaseGrandTotal = <?php echo (float)$this->getQuoteBaseGrandTotal(); ?>;
|
34 |
+
var checkQuoteBaseGrandTotal = quoteBaseGrandTotal;
|
35 |
+
payment = new Payment('co-payment-form', '<?php echo $this->getUrl('japi/checkout/savePayment', array('_secure'=>true)) ?>');
|
36 |
+
var lastPrice;
|
37 |
+
//]]>
|
38 |
+
</script>
|
39 |
+
<form action="" id="co-payment-form">
|
40 |
+
<fieldset>
|
41 |
+
<?php if ($_edition == Mage::EDITION_COMMUNITY && version_compare($_version, '1.8', '<')===true): ?>
|
42 |
+
<dl class="sp-methods" id="checkout-payment-method-load">
|
43 |
+
<?php endif; ?>
|
44 |
+
<?php echo $this->getChildHtml('methods') ?>
|
45 |
+
<?php if ($_edition == Mage::EDITION_COMMUNITY && version_compare($_version, '1.8', '<')===true): ?>
|
46 |
+
</dl>
|
47 |
+
<?php endif; ?>
|
48 |
+
</fieldset>
|
49 |
+
</form>
|
50 |
+
<div class="buttons-set" id="payment-buttons-container">
|
51 |
+
<button id="payment-button" type="button" class="ladda-button" onclick="payment.save()"
|
52 |
+
data-style="slide-up" data-color="jmango" data-size="s">
|
53 |
+
<span class="ladda-label"><?php echo $this->__('Continue') ?></span>
|
54 |
+
</button>
|
55 |
+
</div>
|
56 |
+
<script type="text/javascript">
|
57 |
+
//<![CDATA[
|
58 |
+
payment.currentMethod = "<?php echo $this->getChild('methods')->getSelectedMethodCode() ?>";
|
59 |
+
//]]>
|
60 |
+
</script>
|
app/design/frontend/base/default/template/japi/checkout/onepage/payment/info.phtml
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<dl class="sp-methods" id="checkout-payment-method-load">
|
28 |
+
<!-- Content dynamically loaded. Content from the methods.phtml is loaded during the ajax call -->
|
29 |
+
</dl>
|
app/design/frontend/base/default/template/japi/checkout/onepage/review.phtml
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<div class="order-review" id="checkout-review-load">
|
28 |
+
<!-- Content loaded dynamically -->
|
29 |
+
</div>
|
app/design/frontend/base/default/template/japi/checkout/onepage/review/button.phtml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<button type="button" id="review-button" class="ladda-button" data-color="jmango" data-style="slide-up"
|
28 |
+
onclick="review.save()" data-size="s">
|
29 |
+
<span class="ladda-label"><?php echo $this->__('Place Order') ?></span>
|
30 |
+
</button>
|
app/design/frontend/base/default/template/japi/checkout/onepage/review/info.phtml
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php echo $this->getChildHtml('items_before'); ?>
|
28 |
+
<div id="checkout-review-table-wrapper">
|
29 |
+
<table class="data-table" id="checkout-review-table">
|
30 |
+
<tbody>
|
31 |
+
<?php foreach ($this->getItems() as $_item): ?>
|
32 |
+
<?php echo $this->getItemHtml($_item) ?>
|
33 |
+
<?php endforeach ?>
|
34 |
+
</tbody>
|
35 |
+
<?php echo $this->getChildHtml('totals'); ?>
|
36 |
+
</table>
|
37 |
+
</div>
|
38 |
+
<?php echo $this->getChildHtml('items_after'); ?>
|
39 |
+
<div id="checkout-review-submit">
|
40 |
+
<?php echo $this->getChildHtml('agreements') ?>
|
41 |
+
<?php echo $this->getChildHtml('coupon') ?>
|
42 |
+
<div class="buttons-set" id="review-buttons-container">
|
43 |
+
<?php echo $this->getChildHtml('button') ?>
|
44 |
+
</div>
|
45 |
+
</div>
|
46 |
+
<script type="text/javascript">
|
47 |
+
//<![CDATA[
|
48 |
+
review = new Review(
|
49 |
+
'<?php echo $this->getUrl('japi/checkout/saveOrder', array(
|
50 |
+
'form_key' => Mage::getSingleton('core/session')->getFormKey(),
|
51 |
+
'_secure' => true
|
52 |
+
)) ?>',
|
53 |
+
'<?php echo $this->getUrl('checkout/onepage/success', array('_secure' => true)) ?>',
|
54 |
+
$('checkout-agreements')
|
55 |
+
);
|
56 |
+
//]]>
|
57 |
+
</script>
|
app/design/frontend/base/default/template/japi/checkout/onepage/review/item.phtml
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php $_item = $this->getItem() ?>
|
28 |
+
<tr class="jm-item">
|
29 |
+
<td class="jm-item-img">
|
30 |
+
<div class="jm-item-img-inner">
|
31 |
+
<span class="jm-item-qty"><?php echo $_item->getQty() ?></span>
|
32 |
+
<img src="<?php echo $this->helper('catalog/image')->init($_item->getProduct(), 'small_image')->resize(135) ?>"
|
33 |
+
alt="<?php echo $this->escapeHtml($this->getProductName()) ?>"/>
|
34 |
+
</div>
|
35 |
+
</td>
|
36 |
+
|
37 |
+
<td class="jm-item-detail">
|
38 |
+
<span class="jm-item-name"><?php echo $this->escapeHtml($this->getProductName()) ?></span>
|
39 |
+
<span class="jm-item-desc">
|
40 |
+
<?php if ($_options = $this->getOptionList()): ?>
|
41 |
+
<?php foreach ($_options as $_option) : ?>
|
42 |
+
<span class="jm-item-desc-item">
|
43 |
+
<?php $_formatedOptionValue = $this->getFormatedOptionValue($_option) ?>
|
44 |
+
<?php echo $this->escapeHtml($_option['label']) ?>: <?php echo $_formatedOptionValue['value'] ?>
|
45 |
+
</span>
|
46 |
+
<?php endforeach; ?>
|
47 |
+
<?php endif;?>
|
48 |
+
|
49 |
+
<?php if ($addtInfoBlock = $this->getProductAdditionalInformationBlock()):?>
|
50 |
+
<?php echo $addtInfoBlock->setItem($_item)->toHtml() ?>
|
51 |
+
<?php endif;?>
|
52 |
+
|
53 |
+
<?php if ($links = $this->getLinks()): ?>
|
54 |
+
<span class="jm-item-desc-item">
|
55 |
+
<?php echo $this->getLinksTitle() ?>:
|
56 |
+
</span>
|
57 |
+
<?php foreach ($links as $link): ?>
|
58 |
+
<span class="jm-item-desc-item">
|
59 |
+
<strong><?php echo $this->escapeHtml($link->getTitle()); ?></strong>
|
60 |
+
</span>
|
61 |
+
<?php endforeach; ?>
|
62 |
+
<?php endif; ?>
|
63 |
+
</span>
|
64 |
+
</td>
|
65 |
+
|
66 |
+
<td class="jm-item-price">
|
67 |
+
<?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
|
68 |
+
<div class="a-right">
|
69 |
+
<?php if (Mage::helper('weee')->typeOfDisplay($_item, array(1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
70 |
+
<span class="cart-tax-total" onclick="taxToggle('esubtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
|
71 |
+
<?php else: ?>
|
72 |
+
<span class="cart-price">
|
73 |
+
<?php endif; ?>
|
74 |
+
|
75 |
+
<?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
76 |
+
<?php echo $this->helper('checkout')->formatPrice($_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()); ?>
|
77 |
+
<?php else: ?>
|
78 |
+
<?php echo $this->helper('checkout')->formatPrice($_item->getRowTotal()) ?>
|
79 |
+
<?php endif; ?>
|
80 |
+
</span>
|
81 |
+
|
82 |
+
<?php if (Mage::helper('weee')->getApplied($_item)): ?>
|
83 |
+
<div class="cart-tax-info" id="esubtotal-item-tax-details<?php echo $_item->getId(); ?>" style="display:none;">
|
84 |
+
<?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
85 |
+
<small>
|
86 |
+
<?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
|
87 |
+
<span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount'],true,true); ?></span><br />
|
88 |
+
<?php endforeach; ?>
|
89 |
+
</small>
|
90 |
+
<?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
91 |
+
<?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
|
92 |
+
<span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount'],true,true); ?></small></span><br />
|
93 |
+
<?php endforeach; ?>
|
94 |
+
<?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
95 |
+
<small>
|
96 |
+
<?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
|
97 |
+
<span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount'],true,true); ?></span><br />
|
98 |
+
<?php endforeach; ?>
|
99 |
+
</small>
|
100 |
+
<?php endif; ?>
|
101 |
+
</div>
|
102 |
+
|
103 |
+
<?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
104 |
+
<div class="cart-tax-total" onclick="taxToggle('esubtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
|
105 |
+
<span class="nobr"><?php echo Mage::helper('weee')->__('Total'); ?>:<br /> <?php echo $this->helper('checkout')->formatPrice($_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()); ?></span>
|
106 |
+
</div>
|
107 |
+
<?php endif; ?>
|
108 |
+
<?php endif; ?>
|
109 |
+
</div>
|
110 |
+
<?php endif; ?>
|
111 |
+
|
112 |
+
<?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
|
113 |
+
<div>
|
114 |
+
<?php $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); ?>
|
115 |
+
|
116 |
+
<?php if (Mage::helper('weee')->typeOfDisplay($_item, array(1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
117 |
+
<span class="cart-tax-total" onclick="taxToggle('subtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
|
118 |
+
<?php else: ?>
|
119 |
+
<span class="cart-price">
|
120 |
+
<?php endif; ?>
|
121 |
+
|
122 |
+
<?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
123 |
+
<?php echo $this->helper('checkout')->formatPrice($_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)); ?>
|
124 |
+
<?php else: ?>
|
125 |
+
<?php echo $this->helper('checkout')->formatPrice($_incl-$_item->getWeeeTaxRowDisposition()) ?>
|
126 |
+
<?php endif; ?>
|
127 |
+
</span>
|
128 |
+
|
129 |
+
<?php if (Mage::helper('weee')->getApplied($_item)): ?>
|
130 |
+
<div class="cart-tax-info" id="subtotal-item-tax-details<?php echo $_item->getId(); ?>" style="display:none;">
|
131 |
+
<?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
132 |
+
<small>
|
133 |
+
<?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
|
134 |
+
<span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span><br />
|
135 |
+
<?php endforeach; ?>
|
136 |
+
</small>
|
137 |
+
<?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
138 |
+
<?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
|
139 |
+
<span class="nobr"><small><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></small></span><br />
|
140 |
+
<?php endforeach; ?>
|
141 |
+
<?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
142 |
+
<small>
|
143 |
+
<?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
|
144 |
+
<span class="nobr"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span><br />
|
145 |
+
<?php endforeach; ?>
|
146 |
+
</small>
|
147 |
+
<?php endif; ?>
|
148 |
+
</div>
|
149 |
+
|
150 |
+
<?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
|
151 |
+
<div class="cart-tax-total" onclick="taxToggle('subtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
|
152 |
+
<span class="nobr"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>:<br /> <?php echo $this->helper('checkout')->formatPrice($_incl + Mage::helper('weee')->getRowWeeeTaxInclTax($_item)); ?></span>
|
153 |
+
</div>
|
154 |
+
<?php endif; ?>
|
155 |
+
<?php endif; ?>
|
156 |
+
</div>
|
157 |
+
<?php endif; ?>
|
158 |
+
</td>
|
159 |
+
</tr>
|
app/design/frontend/base/default/template/japi/checkout/onepage/review/totals.phtml
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var $this Mage_Checkout_Block_Cart_Totals
|
29 |
+
*/
|
30 |
+
?>
|
31 |
+
<?php if ($this->getTotals()): ?>
|
32 |
+
<tfoot>
|
33 |
+
<?php $_colspan = 2 ?>
|
34 |
+
<?php echo $this->renderTotals(null, $_colspan); ?>
|
35 |
+
<?php echo $this->renderTotals('footer', $_colspan); ?>
|
36 |
+
<?php if ($this->needDisplayBaseGrandtotal()): ?>
|
37 |
+
<tr>
|
38 |
+
<td class="a-right" colspan="<?php echo $_colspan; ?>">
|
39 |
+
<small><?php echo $this->helper('sales')->__('Your credit card will be charged for') ?></small>
|
40 |
+
</td>
|
41 |
+
<td class="a-right">
|
42 |
+
<small><?php echo $this->displayBaseGrandtotal() ?></small>
|
43 |
+
</td>
|
44 |
+
</tr>
|
45 |
+
<?php endif ?>
|
46 |
+
</tfoot>
|
47 |
+
<?php endif; ?>
|
app/design/frontend/base/default/template/japi/checkout/onepage/shipping.phtml
ADDED
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<form action="" id="co-shipping-form">
|
28 |
+
<ul class="form-list">
|
29 |
+
<?php if ($this->customerHasAddresses()): ?>
|
30 |
+
<li class="wide">
|
31 |
+
<label
|
32 |
+
for="shipping-address-select"><?php echo $this->__('Select a shipping address from your address book or enter a new address.') ?></label>
|
33 |
+
<div class="input-box">
|
34 |
+
<?php echo $this->getAddressesHtmlSelect('shipping') ?>
|
35 |
+
</div>
|
36 |
+
</li>
|
37 |
+
<?php endif ?>
|
38 |
+
<li id="shipping-new-address-form"<?php if ($this->customerHasAddresses()): ?> style="display:none;"<?php endif ?>>
|
39 |
+
<fieldset>
|
40 |
+
<input type="hidden" name="shipping[address_id]" value="<?php echo $this->getAddress()->getId() ?>"
|
41 |
+
id="shipping:address_id"/>
|
42 |
+
<ul>
|
43 |
+
<li class="fields"><?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getAddress())->setFieldIdFormat('shipping:%s')->setFieldNameFormat('shipping[%s]')->setFieldParams('onchange="shipping.setSameAsBilling(false)"')->toHtml() ?></li>
|
44 |
+
<li class="fields">
|
45 |
+
<div class="fields">
|
46 |
+
<label for="shipping:company"><?php echo $this->__('Company') ?></label>
|
47 |
+
<div class="input-box">
|
48 |
+
<input type="text" id="shipping:company" name="shipping[company]"
|
49 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>"
|
50 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Company')) ?>"
|
51 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>"
|
52 |
+
onchange="shipping.setSameAsBilling(false);"/>
|
53 |
+
</div>
|
54 |
+
</div>
|
55 |
+
</li>
|
56 |
+
<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
|
57 |
+
<li class="wide">
|
58 |
+
<label for="shipping:street1" class="required"><em>*</em><?php echo $this->__('Address') ?>
|
59 |
+
</label>
|
60 |
+
<div class="input-box">
|
61 |
+
<input type="text"
|
62 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Street Address')) ?>"
|
63 |
+
name="shipping[street][]" id="shipping:street1"
|
64 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getStreet(1)) ?>"
|
65 |
+
class="input-text <?php echo $_streetValidationClass ?>"
|
66 |
+
onchange="shipping.setSameAsBilling(false);"/>
|
67 |
+
</div>
|
68 |
+
</li>
|
69 |
+
<?php
|
70 |
+
$_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass));
|
71 |
+
$_streetConfig = Mage::getStoreConfig('japi/jmango_rest_customer_settings');
|
72 |
+
?>
|
73 |
+
<?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
|
74 |
+
<li class="wide">
|
75 |
+
<?php if (!empty($_streetConfig['street'.$_i.'_label'])): ?>
|
76 |
+
<label for="shipping:street<?php echo $_i ?>" class="<?php echo !$_streetConfig['street'.$_i.'_require'] ? '' : 'required' ?>">
|
77 |
+
<?php if ($_streetConfig['street'.$_i.'_require']): ?><em>*</em><?php endif; ?>
|
78 |
+
<?php echo Mage::helper('core')->quoteEscape($this->__($_streetConfig['street'.$_i.'_label'])) ?>
|
79 |
+
</label>
|
80 |
+
<?php endif; //End if (!empty($_streetConfig['street'.$_i.'_label'])) ?>
|
81 |
+
<?php
|
82 |
+
$additionValidate = '';
|
83 |
+
if ($_streetConfig['street'.$_i.'_require']) {
|
84 |
+
$additionValidate .= ' required-entry';
|
85 |
+
}
|
86 |
+
if (!empty($_streetConfig['street'.$_i.'_type'])
|
87 |
+
&& $_streetConfig['street'.$_i.'_type'] == 'number') {
|
88 |
+
$additionValidate .= ' validate-number';
|
89 |
+
}
|
90 |
+
|
91 |
+
if (!empty($_streetConfig['street'.$_i.'_label'])) {
|
92 |
+
$_title = Mage::helper('core')->quoteEscape($this->__($_streetConfig['street'.$_i.'_label']));
|
93 |
+
} else {
|
94 |
+
$_title = Mage::helper('core')->quoteEscape($this->__('Street Address %s', $_i));
|
95 |
+
}
|
96 |
+
?>
|
97 |
+
<div class="input-box">
|
98 |
+
<input type="text" name="shipping[street][]"
|
99 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getStreet($_i)) ?>"
|
100 |
+
title="<?php echo $_title ?>"
|
101 |
+
id="shipping:street<?php echo $_i ?>"
|
102 |
+
class="input-text <?php echo $_streetValidationClass . $additionValidate ?>"/>
|
103 |
+
</div>
|
104 |
+
</li>
|
105 |
+
<?php endfor; ?>
|
106 |
+
<?php if ($this->helper('customer/address')->isVatAttributeVisible()) : ?>
|
107 |
+
<li class="wide">
|
108 |
+
<label for="billing:vat_id"><?php echo $this->__('VAT Number'); ?></label>
|
109 |
+
<div class="input-box">
|
110 |
+
<input type="text" id="shipping:vat_id" name="shipping[vat_id]"
|
111 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getVatId()); ?>"
|
112 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('VAT Number')); ?>"
|
113 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('vat_id') ?>"/>
|
114 |
+
</div>
|
115 |
+
</li>
|
116 |
+
<?php endif; ?>
|
117 |
+
<li class="fields">
|
118 |
+
<div class="field">
|
119 |
+
<label for="shipping:city" class="required"><em>*</em><?php echo $this->__('City') ?>
|
120 |
+
</label>
|
121 |
+
<div class="input-box">
|
122 |
+
<input type="text"
|
123 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('City')) ?>"
|
124 |
+
name="shipping[city]"
|
125 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>"
|
126 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>"
|
127 |
+
id="shipping:city" onchange="shipping.setSameAsBilling(false);"/>
|
128 |
+
</div>
|
129 |
+
</div>
|
130 |
+
<div class="field">
|
131 |
+
<label for="shipping:region"
|
132 |
+
class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
|
133 |
+
<div class="input-box">
|
134 |
+
<select id="shipping:region_id" name="shipping[region_id]"
|
135 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>"
|
136 |
+
class="validate-select" style="display:none;">
|
137 |
+
<option
|
138 |
+
value=""><?php echo $this->__('Please select region, state or province') ?></option>
|
139 |
+
</select>
|
140 |
+
<script type="text/javascript">
|
141 |
+
//<![CDATA[
|
142 |
+
$('shipping:region_id').setAttribute('defaultValue', "<?php echo $this->getAddress()->getRegionId() ?>");
|
143 |
+
//]]>
|
144 |
+
</script>
|
145 |
+
<input type="text" id="shipping:region" name="shipping[region]"
|
146 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>"
|
147 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>"
|
148 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>"
|
149 |
+
style="display:none;"/>
|
150 |
+
</div>
|
151 |
+
</div>
|
152 |
+
</li>
|
153 |
+
<li class="fields">
|
154 |
+
<div class="field">
|
155 |
+
<label for="shipping:postcode"
|
156 |
+
class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
|
157 |
+
<div class="input-box">
|
158 |
+
<input type="text"
|
159 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Zip/Postal Code')) ?>"
|
160 |
+
name="shipping[postcode]" id="shipping:postcode"
|
161 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>"
|
162 |
+
class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>"
|
163 |
+
onchange="shipping.setSameAsBilling(false);"/>
|
164 |
+
</div>
|
165 |
+
</div>
|
166 |
+
<div class="field">
|
167 |
+
<label for="shipping:country_id"
|
168 |
+
class="required"><em>*</em><?php echo $this->__('Country') ?></label>
|
169 |
+
<div class="input-box">
|
170 |
+
<?php echo $this->getCountryHtmlSelect('shipping') ?>
|
171 |
+
</div>
|
172 |
+
</div>
|
173 |
+
</li>
|
174 |
+
<li class="fields">
|
175 |
+
<div class="field">
|
176 |
+
<label for="shipping:telephone"
|
177 |
+
class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
|
178 |
+
<div class="input-box">
|
179 |
+
<input type="text" name="shipping[telephone]"
|
180 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>"
|
181 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Telephone')) ?>"
|
182 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>"
|
183 |
+
id="shipping:telephone" onchange="shipping.setSameAsBilling(false);"/>
|
184 |
+
</div>
|
185 |
+
</div>
|
186 |
+
<div class="field">
|
187 |
+
<label for="shipping:fax"><?php echo $this->__('Fax') ?></label>
|
188 |
+
<div class="input-box">
|
189 |
+
<input type="text" name="shipping[fax]"
|
190 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getFax()) ?>"
|
191 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Fax')) ?>"
|
192 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('fax') ?>"
|
193 |
+
id="shipping:fax" onchange="shipping.setSameAsBilling(false);"/>
|
194 |
+
</div>
|
195 |
+
</div>
|
196 |
+
</li>
|
197 |
+
|
198 |
+
<!-- Additional customer address fields -->
|
199 |
+
<?php echo $this->getLayout()->createBlock('japi/form')->setFields(Mage::helper('japi')->getCustomerAddressFormFields())->setPrefix('shipping')->toHtml() ?>
|
200 |
+
|
201 |
+
<?php if ($this->isCustomerLoggedIn() && $this->customerHasAddresses()): ?>
|
202 |
+
<li class="control">
|
203 |
+
<input type="checkbox" name="shipping[save_in_address_book]" value="1"
|
204 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Save in address book')) ?>"
|
205 |
+
id="shipping:save_in_address_book"
|
206 |
+
onchange="shipping.setSameAsBilling(false);"<?php if ($this->getAddress()->getSaveInAddressBook()): ?> checked="checked"<?php endif; ?>
|
207 |
+
class="checkbox"/>
|
208 |
+
<label
|
209 |
+
for="shipping:save_in_address_book"><?php echo $this->__('Save in address book') ?></label>
|
210 |
+
</li>
|
211 |
+
<?php else: ?>
|
212 |
+
<li class="no-display"><input type="hidden" name="shipping[save_in_address_book]" value="1"/>
|
213 |
+
</li>
|
214 |
+
<?php endif; ?>
|
215 |
+
</ul>
|
216 |
+
</fieldset>
|
217 |
+
</li>
|
218 |
+
<li class="control">
|
219 |
+
<input type="checkbox" name="shipping[same_as_billing]" id="shipping:same_as_billing"
|
220 |
+
value="1"<?php if ($this->getAddress()->getSameAsBilling()): ?> checked="checked"<?php endif; ?>
|
221 |
+
title="<?php echo $this->__('Use Billing Address') ?>"
|
222 |
+
onclick="shipping.setSameAsBilling(this.checked)" class="checkbox"/>
|
223 |
+
<label for="shipping:same_as_billing"><?php echo $this->__('Use Billing Address') ?></label>
|
224 |
+
</li>
|
225 |
+
</ul>
|
226 |
+
<div class="buttons-set" id="shipping-buttons-container">
|
227 |
+
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
|
228 |
+
<p class="back-link"><a href="#" onclick="checkout.back(); return false;">
|
229 |
+
<small>« </small><?php echo $this->__('Back') ?></a></p>
|
230 |
+
<button id="shipping-button" type="button" class="ladda-button" data-color="jmango" data-style="slide-up"
|
231 |
+
data-size="s"
|
232 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Continue')) ?>"
|
233 |
+
onclick="shipping.save()">
|
234 |
+
<span class="ladda-label"><?php echo $this->__('Continue') ?></span>
|
235 |
+
</button>
|
236 |
+
<span id="shipping-please-wait" class="please-wait" style="display:none;">
|
237 |
+
<img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>"
|
238 |
+
alt="<?php echo Mage::helper('core')->quoteEscape($this->__('Loading next step...')) ?>"
|
239 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Loading next step...')) ?>"
|
240 |
+
class="v-middle"/> <?php echo $this->__('Loading next step...') ?>
|
241 |
+
</span>
|
242 |
+
</div>
|
243 |
+
</form>
|
244 |
+
<script type="text/javascript">
|
245 |
+
//<![CDATA[
|
246 |
+
var shipping = new Shipping(
|
247 |
+
'co-shipping-form',
|
248 |
+
'<?php echo $this->getUrl('japi/checkout/getAddress', array('_secure' => true)) ?>address/',
|
249 |
+
'<?php echo $this->getUrl('japi/checkout/saveShipping', array('_secure' => true)) ?>',
|
250 |
+
'<?php echo $this->getUrl('japi/checkout/shippingMethod', array('_secure' => true)) ?>'
|
251 |
+
);
|
252 |
+
var shippingForm = new VarienForm('co-shipping-form');
|
253 |
+
shippingForm.extraChildParams = ' onchange="shipping.setSameAsBilling(false);"';
|
254 |
+
$('shipping-address-select') && shipping.newAddress(!$('shipping-address-select').value);
|
255 |
+
var shippingRegionUpdater = new RegionUpdater('shipping:country_id', 'shipping:region', 'shipping:region_id',
|
256 |
+
<?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'shipping:postcode'
|
257 |
+
);
|
258 |
+
//]]>
|
259 |
+
</script>
|
app/design/frontend/base/default/template/japi/checkout/onepage/shipping_method.phtml
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<form id="co-shipping-method-form" action="">
|
28 |
+
<div id="checkout-shipping-method-load"><?php echo Mage::helper('japi')->__('Please wait') ?>...</div>
|
29 |
+
<script type="text/javascript">
|
30 |
+
//<![CDATA[
|
31 |
+
var shippingMethod = new ShippingMethod(
|
32 |
+
'co-shipping-method-form',
|
33 |
+
"<?php echo $this->getUrl('japi/checkout/saveShippingMethod', array('_secure' => true)) ?>"
|
34 |
+
);
|
35 |
+
//]]>
|
36 |
+
</script>
|
37 |
+
<div id="onepage-checkout-shipping-method-additional-load">
|
38 |
+
<?php echo $this->getChildHtml('additional') ?>
|
39 |
+
</div>
|
40 |
+
<div class="buttons-set" id="shipping-method-buttons-container">
|
41 |
+
<button id="shipping-method-button" type="button" class="ladda-button" onclick="shippingMethod.save()"
|
42 |
+
data-style="slide-up" data-color="jmango" data-size="s">
|
43 |
+
<span class="ladda-label"><?php echo $this->__('Continue') ?></span>
|
44 |
+
</button>
|
45 |
+
</div>
|
46 |
+
</form>
|
app/design/frontend/base/default/template/japi/checkout/onepage/shipping_method/additional.phtml
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php if (!$this->getQuote()->isVirtual() && $this->helper('core')->isModuleOutputEnabled('Mage_GiftMessage')): ?>
|
28 |
+
<?php echo $this->helper('japi/giftMessage_message')->getInline('onepage_checkout', $this->getQuote(), $this->getDontDisplayContainer()) ?>
|
29 |
+
<?php endif; ?>
|
app/design/frontend/base/default/template/japi/checkout/onepage/shipping_method/available.phtml
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php /** @var $this Mage_Checkout_Block_Onepage_Shipping_Method_Available */ ?>
|
28 |
+
<?php $_shippingRateGroups = $this->getShippingRates(); ?>
|
29 |
+
<?php if (!$_shippingRateGroups): ?>
|
30 |
+
<p><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></p>
|
31 |
+
<?php else: ?>
|
32 |
+
<dl class="sp-methods">
|
33 |
+
<?php $shippingCodePrice = array(); ?>
|
34 |
+
<?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
|
35 |
+
<dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
|
36 |
+
<dd>
|
37 |
+
<ul>
|
38 |
+
<?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?>
|
39 |
+
<?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
|
40 |
+
<li>
|
41 |
+
<?php if ($_rate->getErrorMessage()): ?>
|
42 |
+
<ul class="messages"><li class="error-msg"><ul><li><?php echo $this->escapeHtml($_rate->getErrorMessage()) ?></li></ul></li></ul>
|
43 |
+
<?php else: ?>
|
44 |
+
<?php if ($_sole) : ?>
|
45 |
+
<span class="no-display"><input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" /></span>
|
46 |
+
<?php else: ?>
|
47 |
+
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
|
48 |
+
|
49 |
+
<?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
|
50 |
+
<script type="text/javascript">
|
51 |
+
//<![CDATA[
|
52 |
+
lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
|
53 |
+
//]]>
|
54 |
+
</script>
|
55 |
+
<?php endif; ?>
|
56 |
+
|
57 |
+
<?php endif; ?>
|
58 |
+
<label for="s_method_<?php echo $_rate->getCode() ?>">
|
59 |
+
<?php
|
60 |
+
/**
|
61 |
+
* MPLUGIN-1203: don't use escape HTML when display method title for "Netzkollektiv_InStorePickupMulti"
|
62 |
+
*/
|
63 |
+
if (Mage::helper('japi')->isModuleEnabled('Netzkollektiv_InStorePickupMulti')
|
64 |
+
&& $_rate->getCarrier() == 'instorepickupmulti') {
|
65 |
+
echo $_rate->getMethodTitle();
|
66 |
+
} else {
|
67 |
+
echo $this->escapeHtml($_rate->getMethodTitle());
|
68 |
+
}
|
69 |
+
?>
|
70 |
+
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
|
71 |
+
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
|
72 |
+
<?php echo $_excl; ?>
|
73 |
+
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
|
74 |
+
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
|
75 |
+
<?php endif; ?>
|
76 |
+
</label>
|
77 |
+
<?php endif ?>
|
78 |
+
</li>
|
79 |
+
<?php endforeach; ?>
|
80 |
+
</ul>
|
81 |
+
</dd>
|
82 |
+
<?php endforeach; ?>
|
83 |
+
</dl>
|
84 |
+
<script type="text/javascript">
|
85 |
+
//<![CDATA[
|
86 |
+
<?php if (!empty($shippingCodePrice)): ?>
|
87 |
+
var shippingCodePrice = {<?php echo implode(',',$shippingCodePrice); ?>};
|
88 |
+
<?php endif; ?>
|
89 |
+
|
90 |
+
$$('input[type="radio"][name="shipping_method"]').each(function(el){
|
91 |
+
Event.observe(el, 'click', function(){
|
92 |
+
if (el.checked == true) {
|
93 |
+
var getShippingCode = el.getValue();
|
94 |
+
<?php if (!empty($shippingCodePrice)): ?>
|
95 |
+
var newPrice = shippingCodePrice[getShippingCode];
|
96 |
+
if (!lastPrice) {
|
97 |
+
lastPrice = newPrice;
|
98 |
+
quoteBaseGrandTotal += newPrice;
|
99 |
+
}
|
100 |
+
if (newPrice != lastPrice) {
|
101 |
+
quoteBaseGrandTotal += (newPrice-lastPrice);
|
102 |
+
lastPrice = newPrice;
|
103 |
+
}
|
104 |
+
<?php endif; ?>
|
105 |
+
checkQuoteBaseGrandTotal = quoteBaseGrandTotal;
|
106 |
+
return false;
|
107 |
+
}
|
108 |
+
});
|
109 |
+
});
|
110 |
+
//]]>
|
111 |
+
</script>
|
112 |
+
<?php endif; ?>
|
app/design/frontend/base/default/template/japi/checkout/onepage/style.phtml
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* @var $model Jmango360_Japi_Model_Rest_Mage */
|
3 |
+
$model = Mage::getModel('japi/rest_mage');
|
4 |
+
$data = $model->getThemeData();
|
5 |
+
$barBgColor = '#f9f9f9';
|
6 |
+
$barFgColor = '#000000';
|
7 |
+
$buttonBgColor = '#d3d3d3';
|
8 |
+
$buttonFgColor = '#000000';
|
9 |
+
try {
|
10 |
+
$data = Mage::helper('core')->jsonDecode($data);
|
11 |
+
$barStyle = isset($data['titleBar']) ? $data['titleBar'] : array();
|
12 |
+
$buttonStyle = isset($data['actionbutton']) ? $data['actionbutton'] : array();
|
13 |
+
$buttonBgColor = isset($buttonStyle['bgColor']) ? $buttonStyle['bgColor'] : $buttonBgColor;
|
14 |
+
$buttonFgColor = isset($buttonStyle['fgColor']) ? $buttonStyle['fgColor'] : $buttonFgColor;
|
15 |
+
} catch (Exception $e) {
|
16 |
+
Mage::logException($e);
|
17 |
+
}
|
18 |
+
$customCss = Mage::getStoreConfig('japi/jmango_rest_checkout_settings/custom_css');
|
19 |
+
$TIGPostNLVersion = Mage::helper('japi')->getExtensionVersion('TIG_PostNL');
|
20 |
+
?>
|
21 |
+
<link type="text/css" rel="stylesheet" media="all"
|
22 |
+
href="<?php echo $this->getSkinUrl('japi/css/style.css?v=2.7.0-0') ?>"/>
|
23 |
+
<style type="text/css">
|
24 |
+
.ladda-button[data-color=jmango] {
|
25 |
+
background: <?php echo $buttonBgColor ?>;
|
26 |
+
}
|
27 |
+
|
28 |
+
.ladda-button[data-color=jmango]:hover {
|
29 |
+
background: <?php echo $buttonBgColor ?>;
|
30 |
+
}
|
31 |
+
|
32 |
+
.ladda-button[disabled],
|
33 |
+
.ladda-button[disabled]:hover,
|
34 |
+
.ladda-button[data-loading],
|
35 |
+
.ladda-button[data-loading]:hover {
|
36 |
+
background: #999;
|
37 |
+
}
|
38 |
+
|
39 |
+
.ladda-button .ladda-label {
|
40 |
+
color: <?php echo $buttonFgColor ?>;
|
41 |
+
}
|
42 |
+
|
43 |
+
#progressbar {
|
44 |
+
background: <?php echo $barBgColor ?>;
|
45 |
+
}
|
46 |
+
|
47 |
+
#progressbar li:before {
|
48 |
+
background: <?php echo $barFgColor ?>;
|
49 |
+
color: <?php echo $barBgColor ?>;
|
50 |
+
}
|
51 |
+
|
52 |
+
#progressbar li:after {
|
53 |
+
background: <?php echo $barFgColor ?>;
|
54 |
+
opacity: 0.1;
|
55 |
+
}
|
56 |
+
|
57 |
+
#progressbar li.active:before {
|
58 |
+
background: <?php echo $barFgColor ?>;
|
59 |
+
color: <?php echo $barBgColor ?>;
|
60 |
+
}
|
61 |
+
|
62 |
+
#progressbar li.active:after {
|
63 |
+
background: <?php echo $barFgColor ?>;
|
64 |
+
opacity: 1;
|
65 |
+
}
|
66 |
+
|
67 |
+
<?php if ($TIGPostNLVersion && version_compare($TIGPostNLVersion, '1.7.2', '<=')): ?>
|
68 |
+
#postnl_add_location .popup-window {
|
69 |
+
width: 100%;
|
70 |
+
margin: 0;
|
71 |
+
top: 0;
|
72 |
+
left: 0;
|
73 |
+
}
|
74 |
+
|
75 |
+
#postnl_add_location .popup-window .popup-content .button-set {
|
76 |
+
padding: 0;
|
77 |
+
margin: 1em;
|
78 |
+
position: absolute;
|
79 |
+
bottom: 0;
|
80 |
+
right: 0;
|
81 |
+
}
|
82 |
+
|
83 |
+
.location-options > li {
|
84 |
+
margin: 0;
|
85 |
+
}
|
86 |
+
|
87 |
+
.col2-set .col-1, .col2-set .col-2 {
|
88 |
+
padding: 0;
|
89 |
+
min-width: 100%;
|
90 |
+
}
|
91 |
+
|
92 |
+
.tooltip-container .tooltip {
|
93 |
+
opacity: 1;
|
94 |
+
z-index: 999;
|
95 |
+
}
|
96 |
+
|
97 |
+
.postnl-container .location .tooltip-container {
|
98 |
+
display: inline-block;
|
99 |
+
float: right;
|
100 |
+
}
|
101 |
+
|
102 |
+
.postnl-container .location .show-map {
|
103 |
+
display: inline-block;
|
104 |
+
}
|
105 |
+
|
106 |
+
.option-list > .option {
|
107 |
+
height: auto;
|
108 |
+
padding: 0;
|
109 |
+
}
|
110 |
+
|
111 |
+
<?php endif; ?>
|
112 |
+
|
113 |
+
<?php echo $customCss ?>
|
114 |
+
</style>
|
app/design/frontend/base/default/template/japi/customer/address/edit.phtml
ADDED
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php
|
28 |
+
/**
|
29 |
+
* Edit customer address template
|
30 |
+
*
|
31 |
+
* @var $this Mage_Customer_Block_Address_Edit
|
32 |
+
*/
|
33 |
+
?>
|
34 |
+
<div class="account-address">
|
35 |
+
<?php if ($this->getTitle()): ?>
|
36 |
+
<div class="page-title">
|
37 |
+
<h1><?php echo $this->getTitle() ?></h1>
|
38 |
+
</div>
|
39 |
+
<?php endif; ?>
|
40 |
+
<?php echo $this->getMessagesBlock()->toHtml() ?>
|
41 |
+
<?php if (!$this->getCustomer()->getId()) return; ?>
|
42 |
+
<form action="<?php echo $this->getUrl('*/*/addressPost', array('_current' => true)) ?>" method="post"
|
43 |
+
id="form-validate">
|
44 |
+
<div class="fieldset">
|
45 |
+
<?php echo $this->getBlockHtml('formkey') ?>
|
46 |
+
<input type="hidden" name="success_url"
|
47 |
+
value="<?php echo $this->getUrl('*/*/*', array('_current' => true)) ?>"/>
|
48 |
+
<input type="hidden" name="error_url"
|
49 |
+
value="<?php echo $this->getUrl('*/*/*', array('_current' => true)) ?>"/>
|
50 |
+
<h2 class="legend"><?php echo $this->__('Contact Information') ?></h2>
|
51 |
+
<ul class="form-list">
|
52 |
+
<li class="fields">
|
53 |
+
<?php echo $this->getNameBlockHtml() ?>
|
54 |
+
</li>
|
55 |
+
<li class="wide">
|
56 |
+
<label for="company"><?php echo $this->__('Company') ?></label>
|
57 |
+
<div class="input-box">
|
58 |
+
<input type="text" name="company" id="company"
|
59 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Company')) ?>"
|
60 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>"
|
61 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>"/>
|
62 |
+
</div>
|
63 |
+
</li>
|
64 |
+
<li class="fields">
|
65 |
+
<div class="field">
|
66 |
+
<label for="telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
|
67 |
+
<div class="input-box">
|
68 |
+
<input type="text" name="telephone"
|
69 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>"
|
70 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Telephone')) ?>"
|
71 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>"
|
72 |
+
id="telephone"/>
|
73 |
+
</div>
|
74 |
+
</div>
|
75 |
+
<div class="field">
|
76 |
+
<label for="fax"><?php echo $this->__('Fax') ?></label>
|
77 |
+
<div class="input-box">
|
78 |
+
<input type="text" name="fax" id="fax"
|
79 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Fax')) ?>"
|
80 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getFax()) ?>"
|
81 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('fax') ?>"/>
|
82 |
+
</div>
|
83 |
+
</div>
|
84 |
+
</li>
|
85 |
+
</ul>
|
86 |
+
</div>
|
87 |
+
<div class="fieldset">
|
88 |
+
<h2 class="legend"><?php echo $this->__('Address') ?></h2>
|
89 |
+
<ul class="form-list">
|
90 |
+
<!-- Additional customer address fields -->
|
91 |
+
<?php echo $this->getLayout()->createBlock('japi/form')->setFields(Mage::helper('japi')->getCustomerAddressFormFields())->toHtml() ?>
|
92 |
+
|
93 |
+
<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
|
94 |
+
<li class="wide">
|
95 |
+
<label for="street_1" class="required"><em>*</em><?php echo $this->__('Street Address') ?></label>
|
96 |
+
<div class="input-box">
|
97 |
+
<input type="text" name="street[]"
|
98 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getStreet(1)) ?>"
|
99 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Street Address')) ?>"
|
100 |
+
id="street_1" class="input-text <?php echo $_streetValidationClass ?>"/>
|
101 |
+
</div>
|
102 |
+
</li>
|
103 |
+
<?php
|
104 |
+
$_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass));
|
105 |
+
$_streetConfig = Mage::getStoreConfig('japi/jmango_rest_customer_settings');
|
106 |
+
?>
|
107 |
+
<?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
|
108 |
+
<li class="wide">
|
109 |
+
<?php if (!empty($_streetConfig['street'.$_i.'_label'])): ?>
|
110 |
+
<label for="street_<?php echo $_i ?>" class="<?php echo !$_streetConfig['street'.$_i.'_require'] ? '' : 'required' ?>">
|
111 |
+
<?php if ($_streetConfig['street'.$_i.'_require']): ?><em>*</em><?php endif; ?>
|
112 |
+
<?php echo Mage::helper('core')->quoteEscape($this->__($_streetConfig['street'.$_i.'_label'])) ?>
|
113 |
+
</label>
|
114 |
+
<?php endif; //End if (!empty($_streetConfig['street'.$_i.'_label'])) ?>
|
115 |
+
<?php
|
116 |
+
$additionValidate = '';
|
117 |
+
if ($_streetConfig['street'.$_i.'_require']) {
|
118 |
+
$additionValidate .= ' required-entry';
|
119 |
+
}
|
120 |
+
if (!empty($_streetConfig['street'.$_i.'_type'])
|
121 |
+
&& $_streetConfig['street'.$_i.'_type'] == 'number') {
|
122 |
+
$additionValidate .= ' validate-number';
|
123 |
+
}
|
124 |
+
|
125 |
+
if (!empty($_streetConfig['street'.$_i.'_label'])) {
|
126 |
+
$_title = Mage::helper('core')->quoteEscape($this->__($_streetConfig['street'.$_i.'_label']));
|
127 |
+
} else {
|
128 |
+
$_title = Mage::helper('core')->quoteEscape($this->__('Street Address %s', $_i));
|
129 |
+
}
|
130 |
+
?>
|
131 |
+
<div class="input-box">
|
132 |
+
<input type="text" name="street[]"
|
133 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getStreet($_i)) ?>"
|
134 |
+
title="<?php echo $_title ?>"
|
135 |
+
id="street_<?php echo $_i ?>"
|
136 |
+
class="input-text <?php echo $_streetValidationClass . $additionValidate ?>"/>
|
137 |
+
</div>
|
138 |
+
</li>
|
139 |
+
<?php endfor; ?>
|
140 |
+
<?php if ($this->helper('customer/address')->isVatAttributeVisible()) : ?>
|
141 |
+
<li class="wide">
|
142 |
+
<label for="vat_id"><?php echo $this->__('VAT Number') ?></label>
|
143 |
+
<div class="input-box">
|
144 |
+
<input type="text" name="vat_id"
|
145 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getVatId()) ?>"
|
146 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('VAT Number')) ?>"
|
147 |
+
id="vat_id"
|
148 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('vat_id') ?>"/>
|
149 |
+
</div>
|
150 |
+
</li>
|
151 |
+
<?php endif; ?>
|
152 |
+
<li class="fields">
|
153 |
+
<div class="field">
|
154 |
+
<label for="city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
|
155 |
+
<div class="input-box">
|
156 |
+
<input type="text" name="city"
|
157 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>"
|
158 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('City')) ?>"
|
159 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>"
|
160 |
+
id="city"/>
|
161 |
+
</div>
|
162 |
+
</div>
|
163 |
+
<div class="field">
|
164 |
+
<label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?>
|
165 |
+
</label>
|
166 |
+
<div class="input-box">
|
167 |
+
<select id="region_id" name="region_id"
|
168 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>"
|
169 |
+
class="validate-select" style="display:none;">
|
170 |
+
<option
|
171 |
+
value=""><?php echo $this->__('Please select region, state or province') ?></option>
|
172 |
+
</select>
|
173 |
+
<script type="text/javascript">
|
174 |
+
//<![CDATA[
|
175 |
+
$('region_id').setAttribute('defaultValue', "<?php echo $this->getAddress()->getRegionId() ?>");
|
176 |
+
//]]>
|
177 |
+
</script>
|
178 |
+
<input type="text" id="region" name="region"
|
179 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>"
|
180 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>"
|
181 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>"/>
|
182 |
+
</div>
|
183 |
+
</div>
|
184 |
+
</li>
|
185 |
+
<li class="fields">
|
186 |
+
<div class="field">
|
187 |
+
<label for="zip" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
|
188 |
+
<div class="input-box">
|
189 |
+
<input type="text" name="postcode"
|
190 |
+
value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>"
|
191 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Zip/Postal Code')) ?>"
|
192 |
+
id="zip"
|
193 |
+
class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>"/>
|
194 |
+
</div>
|
195 |
+
</div>
|
196 |
+
<div class="field">
|
197 |
+
<label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
|
198 |
+
<div class="input-box">
|
199 |
+
<?php echo $this->getCountryHtmlSelect() ?>
|
200 |
+
</div>
|
201 |
+
</div>
|
202 |
+
</li>
|
203 |
+
<li<?php if ($this->canSetAsDefaultBilling()) echo ' class="control"' ?>>
|
204 |
+
<?php if ($this->isDefaultBilling()): ?>
|
205 |
+
<strong><?php echo $this->__('Default Billing Address') ?></strong>
|
206 |
+
<?php elseif ($this->canSetAsDefaultBilling()): ?>
|
207 |
+
<input type="checkbox" id="primary_billing" name="default_billing" value="1"
|
208 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Use as My Default Billing Address')) ?>"
|
209 |
+
class="checkbox"/><label
|
210 |
+
for="primary_billing"><?php echo $this->__('Use as my default billing address') ?></label>
|
211 |
+
<?php else: ?>
|
212 |
+
<input type="hidden" name="default_billing" value="1"/>
|
213 |
+
<?php endif; ?>
|
214 |
+
</li>
|
215 |
+
<li<?php if ($this->canSetAsDefaultShipping()) echo ' class="control"' ?>>
|
216 |
+
<?php if ($this->isDefaultShipping()): ?>
|
217 |
+
<strong><?php echo $this->__('Default Shipping Address') ?></strong>
|
218 |
+
<?php elseif ($this->canSetAsDefaultShipping()): ?>
|
219 |
+
<input type="checkbox" id="primary_shipping" name="default_shipping" value="1"
|
220 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Use as My Default Shipping Address')) ?>"
|
221 |
+
class="checkbox"/><label
|
222 |
+
for="primary_shipping"><?php echo $this->__('Use as my default shipping address') ?></label>
|
223 |
+
<?php else: ?>
|
224 |
+
<input type="hidden" name="default_shipping" value="1"/>
|
225 |
+
<?php endif; ?>
|
226 |
+
</li>
|
227 |
+
</ul>
|
228 |
+
</div>
|
229 |
+
<div class="buttons-set">
|
230 |
+
<button data-action="save-customer-address" type="submit"
|
231 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Save Address')) ?>" class="button">
|
232 |
+
<span><span><?php echo $this->__('Save Address') ?></span></span>
|
233 |
+
</button>
|
234 |
+
</div>
|
235 |
+
</form>
|
236 |
+
<script type="text/javascript">
|
237 |
+
//<![CDATA[
|
238 |
+
var dataForm = new VarienForm('form-validate', true);
|
239 |
+
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
|
240 |
+
//]]>
|
241 |
+
</script>
|
242 |
+
</div>
|
app/design/frontend/base/default/template/japi/customer/form/edit.phtml
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<div class="account-edit">
|
28 |
+
<div class="page-title">
|
29 |
+
<h1><?php echo $this->__('Edit Account Information') ?></h1>
|
30 |
+
</div>
|
31 |
+
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
|
32 |
+
<?php if (!$this->getCustomer()->getId()) return; ?>
|
33 |
+
<form action="<?php echo $this->getUrl('*/*/editPost') ?>" method="post" id="form-validate"
|
34 |
+
autocomplete="off" enctype="multipart/form-data">
|
35 |
+
<div class="fieldset">
|
36 |
+
<?php echo $this->getBlockHtml('formkey') ?>
|
37 |
+
<h2 class="legend"><?php echo $this->__('Account Information') ?></h2>
|
38 |
+
<ul class="form-list">
|
39 |
+
<li class="fields">
|
40 |
+
<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?>
|
41 |
+
</li>
|
42 |
+
<li>
|
43 |
+
<label for="email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
|
44 |
+
<div class="input-box">
|
45 |
+
<input type="text" name="email" id="email"
|
46 |
+
value="<?php echo $this->escapeHtml($this->getCustomer()->getEmail()) ?>"
|
47 |
+
title="<?php echo $this->__('Email Address') ?>"
|
48 |
+
class="input-text required-entry validate-email"/>
|
49 |
+
</div>
|
50 |
+
</li>
|
51 |
+
<?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
|
52 |
+
<?php if ($_dob->isEnabled()): ?>
|
53 |
+
<li><?php echo $_dob->setDate($this->getCustomer()->getDob())->toHtml() ?></li>
|
54 |
+
<?php endif ?>
|
55 |
+
<?php $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat') ?>
|
56 |
+
<?php if ($_taxvat->isEnabled()): ?>
|
57 |
+
<li><?php echo $_taxvat->setTaxvat($this->getCustomer()->getTaxvat())->toHtml() ?></li>
|
58 |
+
<?php endif ?>
|
59 |
+
<?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
|
60 |
+
<?php if ($_gender->isEnabled()): ?>
|
61 |
+
<li><?php echo $_gender->setGender($this->getCustomer()->getGender())->toHtml() ?></li>
|
62 |
+
<?php endif ?>
|
63 |
+
|
64 |
+
<!-- Additional customer fields -->
|
65 |
+
<?php echo $this->getLayout()->createBlock('japi/form')->setFields(Mage::helper('japi')->getSignupFormFields())->toHtml() ?>
|
66 |
+
|
67 |
+
<li class="control">
|
68 |
+
<input type="checkbox" name="change_password" id="change_password" value="1"
|
69 |
+
onclick="setPasswordForm(this.checked)"
|
70 |
+
title="<?php echo $this->__('Change Password') ?>"<?php if ($this->getCustomer()->getChangePassword() == 1): ?> checked="checked"<?php endif; ?>
|
71 |
+
class="checkbox"/><label
|
72 |
+
for="change_password"><?php echo $this->__('Change Password') ?></label>
|
73 |
+
</li>
|
74 |
+
</ul>
|
75 |
+
</div>
|
76 |
+
<div class="fieldset" style="display:none;">
|
77 |
+
<h2 class="legend"><?php echo $this->__('Change Password') ?></h2>
|
78 |
+
<ul class="form-list">
|
79 |
+
<li>
|
80 |
+
<label for="current_password" class="required"><em>*</em><?php echo $this->__('Current Password') ?>
|
81 |
+
</label>
|
82 |
+
<div class="input-box">
|
83 |
+
<input type="password" title="<?php echo $this->__('Current Password') ?>" class="input-text"
|
84 |
+
name="current_password" id="current_password"/>
|
85 |
+
</div>
|
86 |
+
</li>
|
87 |
+
<li class="fields">
|
88 |
+
<div class="field">
|
89 |
+
<label for="password" class="required"><em>*</em><?php echo $this->__('New Password') ?></label>
|
90 |
+
<div class="input-box">
|
91 |
+
<input type="password" title="<?php echo $this->__('New Password') ?>"
|
92 |
+
class="input-text validate-password" name="password" id="password"/>
|
93 |
+
</div>
|
94 |
+
</div>
|
95 |
+
<div class="field">
|
96 |
+
<label for="confirmation"
|
97 |
+
class="required"><em>*</em><?php echo $this->__('Confirm New Password') ?></label>
|
98 |
+
<div class="input-box">
|
99 |
+
<input type="password" title="<?php echo $this->__('Confirm New Password') ?>"
|
100 |
+
class="input-text validate-cpassword" name="confirmation" id="confirmation"/>
|
101 |
+
</div>
|
102 |
+
</div>
|
103 |
+
</li>
|
104 |
+
</ul>
|
105 |
+
</div>
|
106 |
+
<div class="buttons-set">
|
107 |
+
<button type="submit" title="<?php echo $this->__('Save') ?>" class="button">
|
108 |
+
<span><span><?php echo $this->__('Save') ?></span></span>
|
109 |
+
</button>
|
110 |
+
</div>
|
111 |
+
</form>
|
112 |
+
<script type="text/javascript">
|
113 |
+
//<![CDATA[
|
114 |
+
var dataForm = new VarienForm('form-validate', true);
|
115 |
+
function setPasswordForm(arg) {
|
116 |
+
if (arg) {
|
117 |
+
$('current_password').up(3).show();
|
118 |
+
$('current_password').addClassName('required-entry');
|
119 |
+
$('password').addClassName('required-entry');
|
120 |
+
$('confirmation').addClassName('required-entry');
|
121 |
+
|
122 |
+
} else {
|
123 |
+
$('current_password').up(3).hide();
|
124 |
+
$('current_password').removeClassName('required-entry');
|
125 |
+
$('password').removeClassName('required-entry');
|
126 |
+
$('confirmation').removeClassName('required-entry');
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
<?php if($this->getCustomer()->getChangePassword()): ?>
|
131 |
+
setPasswordForm(true);
|
132 |
+
<?php endif; ?>
|
133 |
+
//]]>
|
134 |
+
</script>
|
135 |
+
</div>
|
app/design/frontend/base/default/template/japi/customer/form/register.phtml
ADDED
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php
|
28 |
+
/**
|
29 |
+
* Create account form template
|
30 |
+
*
|
31 |
+
* @var $this Mage_Customer_Block_Form_Register
|
32 |
+
*/
|
33 |
+
?>
|
34 |
+
<div class="account-create">
|
35 |
+
<div class="page-title">
|
36 |
+
<h1><?php echo $this->__('Create an Account') ?></h1>
|
37 |
+
</div>
|
38 |
+
<?php echo $this->getChildHtml('form_fields_before') ?>
|
39 |
+
<?php echo $this->getMessagesBlock()->toHtml() ?>
|
40 |
+
<?php /* Extensions placeholder */ ?>
|
41 |
+
<?php echo $this->getChildHtml('customer.form.register.extra') ?>
|
42 |
+
<form action="<?php echo $this->getUrl('*/*/createPost', array('_secure' => true)) ?>"
|
43 |
+
method="post" id="form-validate">
|
44 |
+
<div class="fieldset">
|
45 |
+
<input type="hidden" name="success_url"
|
46 |
+
value="<?php echo $this->getUrl('*/*/*', array('_secure' => true)) ?>"/>
|
47 |
+
<input type="hidden" name="error_url"
|
48 |
+
value="<?php echo $this->getUrl('*/*/*', array('_secure' => true)) ?>"/>
|
49 |
+
<input type="hidden" name="form_key"
|
50 |
+
value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>"/>
|
51 |
+
<h2 class="legend"><?php echo $this->__('Personal Information') ?></h2>
|
52 |
+
<ul class="form-list">
|
53 |
+
<li class="fields">
|
54 |
+
<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
|
55 |
+
</li>
|
56 |
+
<li>
|
57 |
+
<label for="email_address" class="required"><em>*</em><?php echo $this->__('Email Address') ?>
|
58 |
+
</label>
|
59 |
+
<div class="input-box">
|
60 |
+
<input type="text" name="email" id="email_address"
|
61 |
+
value="<?php echo $this->escapeHtml($this->getFormData()->getEmail()) ?>"
|
62 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Email Address')) ?>"
|
63 |
+
class="input-text validate-email required-entry"/>
|
64 |
+
</div>
|
65 |
+
</li>
|
66 |
+
<?php if ($this->isNewsletterEnabled()): ?>
|
67 |
+
<li class="control">
|
68 |
+
<div class="input-box">
|
69 |
+
<input type="checkbox" name="is_subscribed"
|
70 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Sign Up for Newsletter')) ?>"
|
71 |
+
value="1"
|
72 |
+
id="is_subscribed"<?php if ($this->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?>
|
73 |
+
class="checkbox"/>
|
74 |
+
</div>
|
75 |
+
<label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
|
76 |
+
<?php /* Extensions placeholder */ ?>
|
77 |
+
<?php echo $this->getChildHtml('customer.form.register.newsletter') ?>
|
78 |
+
</li>
|
79 |
+
<?php endif ?>
|
80 |
+
<?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
|
81 |
+
<?php if ($_dob->isEnabled()): ?>
|
82 |
+
<li><?php echo $_dob->setDate($this->getFormData()->getDob())->toHtml() ?></li>
|
83 |
+
<?php endif ?>
|
84 |
+
<?php $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat') ?>
|
85 |
+
<?php if ($_taxvat->isEnabled()): ?>
|
86 |
+
<li><?php echo $_taxvat->setTaxvat($this->getFormData()->getTaxvat())->toHtml() ?></li>
|
87 |
+
<?php endif ?>
|
88 |
+
<?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
|
89 |
+
<?php if ($_gender->isEnabled()): ?>
|
90 |
+
<li><?php echo $_gender->setGender($this->getFormData()->getGender())->toHtml() ?></li>
|
91 |
+
<?php endif ?>
|
92 |
+
|
93 |
+
<!-- Additional customer fields -->
|
94 |
+
<?php echo $this->getLayout()->createBlock('japi/form')->setFields(Mage::helper('japi')->getSignupFormFields())->toHtml() ?>
|
95 |
+
</ul>
|
96 |
+
</div>
|
97 |
+
<?php if ($this->getShowAddressFields()): ?>
|
98 |
+
<div class="fieldset">
|
99 |
+
<input type="hidden" name="create_address" value="1"/>
|
100 |
+
<h2 class="legend"><?php echo $this->__('Address Information') ?></h2>
|
101 |
+
<ul class="form-list">
|
102 |
+
<!-- Additional customer address fields -->
|
103 |
+
<?php echo $this->getLayout()->createBlock('japi/form')->setFields(Mage::helper('japi')->getSignupAddressFormFields())->toHtml() ?>
|
104 |
+
|
105 |
+
<li class="fields">
|
106 |
+
<div class="field">
|
107 |
+
<label for="company"><?php echo $this->__('Company') ?></label>
|
108 |
+
<div class="input-box">
|
109 |
+
<input type="text" name="company" id="company"
|
110 |
+
value="<?php echo $this->escapeHtml($this->getFormData()->getCompany()) ?>"
|
111 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Company')) ?>"
|
112 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>"/>
|
113 |
+
</div>
|
114 |
+
</div>
|
115 |
+
<div class="field">
|
116 |
+
<label for="telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?>
|
117 |
+
</label>
|
118 |
+
<div class="input-box">
|
119 |
+
<input type="text" name="telephone" id="telephone"
|
120 |
+
value="<?php echo $this->escapeHtml($this->getFormData()->getTelephone()) ?>"
|
121 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Telephone')) ?>"
|
122 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>"/>
|
123 |
+
</div>
|
124 |
+
</div>
|
125 |
+
</li>
|
126 |
+
<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
|
127 |
+
<li class="wide">
|
128 |
+
<label for="street_1" class="required"><em>*</em><?php echo $this->__('Street Address') ?>
|
129 |
+
</label>
|
130 |
+
<div class="input-box">
|
131 |
+
<input type="text" name="street[]"
|
132 |
+
value="<?php echo $this->escapeHtml($this->getFormData()->getStreet(1)) ?>"
|
133 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Street Address')) ?>"
|
134 |
+
id="street_1" class="input-text <?php echo $_streetValidationClass ?>"/>
|
135 |
+
</div>
|
136 |
+
</li>
|
137 |
+
<?php
|
138 |
+
$_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass));
|
139 |
+
$_streetConfig = Mage::getStoreConfig('japi/jmango_rest_customer_settings');
|
140 |
+
?>
|
141 |
+
<?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
|
142 |
+
<li class="wide">
|
143 |
+
<?php if (!empty($_streetConfig['street'.$_i.'_label'])): ?>
|
144 |
+
<label for="street_<?php echo $_i ?>" class="<?php echo !$_streetConfig['street'.$_i.'_require'] ? '' : 'required' ?>">
|
145 |
+
<?php if ($_streetConfig['street'.$_i.'_require']): ?><em>*</em><?php endif; ?>
|
146 |
+
<?php echo Mage::helper('core')->quoteEscape($this->__($_streetConfig['street'.$_i.'_label'])) ?>
|
147 |
+
</label>
|
148 |
+
<?php endif; //End if (!empty($_streetConfig['street'.$_i.'_label'])) ?>
|
149 |
+
<?php
|
150 |
+
$additionValidate = '';
|
151 |
+
if ($_streetConfig['street'.$_i.'_require']) {
|
152 |
+
$additionValidate .= ' required-entry';
|
153 |
+
}
|
154 |
+
if (!empty($_streetConfig['street'.$_i.'_type'])
|
155 |
+
&& $_streetConfig['street'.$_i.'_type'] == 'number') {
|
156 |
+
$additionValidate .= ' validate-number';
|
157 |
+
}
|
158 |
+
|
159 |
+
if (!empty($_streetConfig['street'.$_i.'_label'])) {
|
160 |
+
$_title = Mage::helper('core')->quoteEscape($this->__($_streetConfig['street'.$_i.'_label']));
|
161 |
+
} else {
|
162 |
+
$_title = Mage::helper('core')->quoteEscape($this->__('Street Address %s', $_i));
|
163 |
+
}
|
164 |
+
?>
|
165 |
+
<div class="input-box">
|
166 |
+
<input type="text" name="street[]"
|
167 |
+
value="<?php echo $this->escapeHtml($this->getFormData()->getStreet($_i)) ?>"
|
168 |
+
title="<?php echo $_title ?>"
|
169 |
+
id="street_<?php echo $_i ?>"
|
170 |
+
class="input-text <?php echo $_streetValidationClass . $additionValidate ?>"/>
|
171 |
+
</div>
|
172 |
+
</li>
|
173 |
+
<?php endfor; ?>
|
174 |
+
<li class="fields">
|
175 |
+
<div class="field">
|
176 |
+
<label for="city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
|
177 |
+
<div class="input-box">
|
178 |
+
<input type="text" name="city"
|
179 |
+
value="<?php echo $this->escapeHtml($this->getFormData()->getCity()) ?>"
|
180 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('City')) ?>"
|
181 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>"
|
182 |
+
id="city"/>
|
183 |
+
</div>
|
184 |
+
</div>
|
185 |
+
<div class="field">
|
186 |
+
<label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?>
|
187 |
+
</label>
|
188 |
+
<div class="input-box">
|
189 |
+
<select id="region_id" name="region_id"
|
190 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>"
|
191 |
+
class="validate-select" style="display:none;">
|
192 |
+
<option
|
193 |
+
value=""><?php echo $this->__('Please select region, state or province') ?></option>
|
194 |
+
</select>
|
195 |
+
<script type="text/javascript">
|
196 |
+
//<![CDATA[
|
197 |
+
$('region_id').setAttribute('defaultValue', "<?php echo $this->getFormData()->getRegionId() ?>");
|
198 |
+
//]]>
|
199 |
+
</script>
|
200 |
+
<input type="text" id="region" name="region"
|
201 |
+
value="<?php echo $this->escapeHtml($this->getRegion()) ?>"
|
202 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('State/Province')) ?>"
|
203 |
+
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>"
|
204 |
+
style="display:none;"/>
|
205 |
+
</div>
|
206 |
+
</div>
|
207 |
+
</li>
|
208 |
+
<li class="fields">
|
209 |
+
<div class="field">
|
210 |
+
<label for="zip" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?>
|
211 |
+
</label>
|
212 |
+
<div class="input-box">
|
213 |
+
<input type="text" name="postcode"
|
214 |
+
value="<?php echo $this->escapeHtml($this->getFormData()->getPostcode()) ?>"
|
215 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Zip/Postal Code')) ?>"
|
216 |
+
id="zip"
|
217 |
+
class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>"/>
|
218 |
+
</div>
|
219 |
+
</div>
|
220 |
+
<div class="field">
|
221 |
+
<label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
|
222 |
+
<div class="input-box">
|
223 |
+
<?php echo $this->getCountryHtmlSelect() ?>
|
224 |
+
</div>
|
225 |
+
</div>
|
226 |
+
</li>
|
227 |
+
</ul>
|
228 |
+
<input type="hidden" name="default_billing" value="1"/>
|
229 |
+
<input type="hidden" name="default_shipping" value="1"/>
|
230 |
+
</div>
|
231 |
+
<?php endif; ?>
|
232 |
+
<div class="fieldset">
|
233 |
+
<h2 class="legend"><?php echo $this->__('Login Information') ?></h2>
|
234 |
+
<ul class="form-list">
|
235 |
+
<li class="fields">
|
236 |
+
<div class="field">
|
237 |
+
<label for="password" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
|
238 |
+
<div class="input-box">
|
239 |
+
<input type="password" name="password" id="password"
|
240 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Password')) ?>"
|
241 |
+
class="input-text required-entry validate-password"/>
|
242 |
+
</div>
|
243 |
+
</div>
|
244 |
+
<div class="field">
|
245 |
+
<label for="confirmation" class="required"><em>*</em><?php echo $this->__('Confirm Password') ?>
|
246 |
+
</label>
|
247 |
+
<div class="input-box">
|
248 |
+
<input type="password" name="confirmation"
|
249 |
+
title="<?php echo Mage::helper('core')->quoteEscape($this->__('Confirm Password')) ?>"
|
250 |
+
id="confirmation" class="input-text required-entry validate-cpassword"/>
|
251 |
+
</div>
|
252 |
+
</div>
|
253 |
+
</li>
|
254 |
+
<?php echo $this->getChildHtml('form.additional.info'); ?>
|
255 |
+
</ul>
|
256 |
+
</div>
|
257 |
+
<div class="buttons-set">
|
258 |
+
<button type="submit" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Submit')) ?>"
|
259 |
+
class="button"><span><span><?php echo $this->__('Submit') ?></span></span></button>
|
260 |
+
</div>
|
261 |
+
</form>
|
262 |
+
<script type="text/javascript">
|
263 |
+
//<![CDATA[
|
264 |
+
var dataForm = new VarienForm('form-validate', true);
|
265 |
+
<?php if($this->getShowAddressFields()): ?>
|
266 |
+
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
|
267 |
+
<?php endif; ?>
|
268 |
+
//]]>
|
269 |
+
</script>
|
270 |
+
</div>
|
app/design/frontend/base/default/template/japi/form.phtml
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2016 JMango360
|
4 |
+
*/
|
5 |
+
?>
|
6 |
+
<?php /* @var $this Jmango360_Japi_Block_Form */ ?>
|
7 |
+
<?php foreach ($this->getFields() as $field): ?>
|
8 |
+
<li class="wide">
|
9 |
+
<label class="<?php echo $field['required'] ? 'required' : '' ?>" for="">
|
10 |
+
<?php if ($field['required']): ?><em>*</em><?php endif ?>
|
11 |
+
<?php echo $this->__($field['label']) ?>
|
12 |
+
</label>
|
13 |
+
<div class="input-box">
|
14 |
+
<?php switch ($field['display_type']):
|
15 |
+
case 'select':
|
16 |
+
case 'multiselect': ?>
|
17 |
+
<select <?php echo $field['display_type'] == 'multi_select' ? 'multiple' : '' ?>
|
18 |
+
name="<?php echo $this->getFieldName($field['key']) ?>"
|
19 |
+
id="<?php echo $this->getFieldId($field['key']) ?>"
|
20 |
+
class="<?php echo $field['required'] ? 'required-entry' : '' ?>">
|
21 |
+
<?php if (isset($field['options'])): ?>
|
22 |
+
<?php foreach ($field['options'] as $value => $label): ?>
|
23 |
+
<option
|
24 |
+
value="<?php echo $value ?>"
|
25 |
+
<?php if ($this->getFieldValue($field['key']) == $value): ?>selected="selected"<?php endif; ?>
|
26 |
+
><?php echo $label ?></option>
|
27 |
+
<?php endforeach ?>
|
28 |
+
<?php endif; ?>
|
29 |
+
</select>
|
30 |
+
<?php break; ?>
|
31 |
+
<?php case 'boolean': ?>
|
32 |
+
<input type="checkbox"
|
33 |
+
name="<?php echo $this->getFieldName($field['key']) ?>"
|
34 |
+
id="<?php echo $this->getFieldId($field['key']) ?>"
|
35 |
+
value="1"
|
36 |
+
checked="<?php echo $this->getFieldValue($field['key']) ? 'checked' : '' ?>"
|
37 |
+
class="input-text<?php echo $field['required'] ? ' required-entry' : '' ?>"/>
|
38 |
+
<?php break; ?>
|
39 |
+
<?php default: ?>
|
40 |
+
<input type="text"
|
41 |
+
name="<?php echo $this->getFieldName($field['key']) ?>"
|
42 |
+
id="<?php echo $this->getFieldId($field['key']) ?>"
|
43 |
+
value="<?php echo $this->escapeHtml($this->getFieldValue($field['key'])) ?>"
|
44 |
+
class="input-text<?php echo $field['required'] ? ' required-entry' : '' ?>"/>
|
45 |
+
<?php endswitch; ?>
|
46 |
+
</div>
|
47 |
+
</li>
|
48 |
+
<?php endforeach; ?>
|
app/design/frontend/base/default/template/japi/giftmessage/inline.phtml
ADDED
@@ -0,0 +1,334 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<?php if(!$this->getDontDisplayContainer()): ?>
|
28 |
+
<script type="text/javascript">
|
29 |
+
//<![CDATA[
|
30 |
+
if(!window.toogleVisibilityOnObjects) {
|
31 |
+
var toogleVisibilityOnObjects = function(source, objects) {
|
32 |
+
if($(source) && $(source).checked) {
|
33 |
+
objects.each(function(item){
|
34 |
+
$(item).show();
|
35 |
+
$$('#' + item + ' .input-text').each(function(item) {
|
36 |
+
item.removeClassName('validation-passed');
|
37 |
+
});
|
38 |
+
});
|
39 |
+
} else {
|
40 |
+
objects.each(function(item){
|
41 |
+
if ($(item)) {
|
42 |
+
$(item).hide();
|
43 |
+
$$('#' + item + ' .input-text').each(function(sitem) {
|
44 |
+
sitem.addClassName('validation-passed');
|
45 |
+
});
|
46 |
+
$$('#' + item + ' .giftmessage-area').each(function(sitem) {
|
47 |
+
sitem.value = '';
|
48 |
+
});
|
49 |
+
$$('#' + item + ' .checkbox').each(function(sitem) {
|
50 |
+
sitem.checked = false;
|
51 |
+
});
|
52 |
+
$$('#' + item + ' .select').each(function(sitem) {
|
53 |
+
sitem.value = '';
|
54 |
+
});
|
55 |
+
$$('#' + item + ' .price-box').each(function(sitem) {
|
56 |
+
sitem.addClassName('no-display');
|
57 |
+
});
|
58 |
+
}
|
59 |
+
});
|
60 |
+
}
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
if(!window.toogleRequired) {
|
65 |
+
var toogleRequired = function (source, objects)
|
66 |
+
{
|
67 |
+
if(!$(source).value.blank()) {
|
68 |
+
objects.each(function(item) {
|
69 |
+
$(item).addClassName('required-entry');
|
70 |
+
});
|
71 |
+
} else {
|
72 |
+
objects.each(function(item) {
|
73 |
+
if (typeof shippingMethod != 'undefined' && shippingMethod.validator) {
|
74 |
+
shippingMethod.validator.reset(item);
|
75 |
+
}
|
76 |
+
$(item).removeClassName('required-entry');
|
77 |
+
});
|
78 |
+
|
79 |
+
}
|
80 |
+
}
|
81 |
+
}
|
82 |
+
if(window.shipping) {
|
83 |
+
|
84 |
+
shipping.onSave = function(evt){
|
85 |
+
new Ajax.Updater('onepage-checkout-shipping-method-additional-load', '<?php echo $this->getAdditionalUrl(); ?>', {onSuccess: function() {
|
86 |
+
this.nextStep(evt);
|
87 |
+
}.bind(this), evalScripts:true});
|
88 |
+
}.bindAsEventListener(shipping);
|
89 |
+
|
90 |
+
billing.onSave = function(evt){
|
91 |
+
new Ajax.Updater('onepage-checkout-shipping-method-additional-load', '<?php echo $this->getAdditionalUrl(); ?>', {onSuccess: function() {
|
92 |
+
this.nextStep(evt);
|
93 |
+
}.bind(this), evalScripts:true});
|
94 |
+
}.bindAsEventListener(billing);
|
95 |
+
|
96 |
+
}
|
97 |
+
//]]>
|
98 |
+
</script>
|
99 |
+
<?php endif ?>
|
100 |
+
<?php if ($this->isMessagesAvailable() || $this->isItemsAvailable()): ?>
|
101 |
+
<?php switch ($this->getType()): ?>
|
102 |
+
<?php case 'onepage_checkout': ?>
|
103 |
+
<div class="gift-messages">
|
104 |
+
<h3><?php echo $this->__('Do you have any gift items in your order?'); ?></h3>
|
105 |
+
<p class="control">
|
106 |
+
<input type="checkbox" name="allow_gift_messages" id="allow_gift_messages" value="1" onclick="toogleVisibilityOnObjects(this, ['allow-gift-message-container']);"<?php if($this->getItemsHasMesssages() || $this->getEntityHasMessage()): ?> checked="checked"<?php endif; ?> class="checkbox" />
|
107 |
+
<label for="allow_gift_messages"><?php echo $this->__('Add gift options.') ?></label>
|
108 |
+
</p>
|
109 |
+
</div>
|
110 |
+
<div class="gift-messages-form" id="allow-gift-message-container">
|
111 |
+
<div class="inner-box">
|
112 |
+
<?php if ($this->isMessagesAvailable()): ?>
|
113 |
+
<h4><?php echo $this->__('Gift Options for the Entire Order.'); ?></h4>
|
114 |
+
<p>
|
115 |
+
<input type="checkbox" name="allow_gift_messages_for_order" id="allow_gift_messages_for_order" value="1" onclick="toogleVisibilityOnObjects(this, ['allow-gift-messages-for-order-container']);"<?php if($this->getEntityHasMessage()): ?> checked="checked"<?php endif; ?> class="checkbox" />
|
116 |
+
<label for="allow_gift_messages_for_order"><?php echo $this->__('Add gift options for the Entire Order') ?></label>
|
117 |
+
</p>
|
118 |
+
<div class="allow-gift-messages-for-order-container" id="allow-gift-messages-for-order-container" style="display:none">
|
119 |
+
<p><?php echo $this->__('You can leave this box blank if you do not wish to add a gift message for whole order.') ?></p>
|
120 |
+
<input type="hidden" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][type]" value="quote" />
|
121 |
+
<ul class="form-list">
|
122 |
+
<li class="fields">
|
123 |
+
<div class="field">
|
124 |
+
<label for="gift-message-whole-from"><?php echo $this->__('From') ?></label>
|
125 |
+
<div class="input-box">
|
126 |
+
<input type="text" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][from]" id="gift-message-whole-from" title="<?php echo Mage::helper('core')->quoteEscape($this->__('From')) ?>" value="<?php echo $this->getEscaped($this->getMessage()->getSender(), $this->getDefaultFrom()) ?>" class="input-text validation-passed" />
|
127 |
+
</div>
|
128 |
+
</div>
|
129 |
+
<div class="field">
|
130 |
+
<label for="gift-message-whole-to"><?php echo $this->__('To') ?></label>
|
131 |
+
<div class="input-box">
|
132 |
+
<input type="text" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][to]" id="gift-message-whole-to" title="<?php echo Mage::helper('core')->quoteEscape($this->__('To')) ?>" value="<?php echo $this->getEscaped($this->getMessage()->getRecipient(), $this->getDefaultTo()) ?>" class="input-text validation-passed" />
|
133 |
+
</div>
|
134 |
+
</div>
|
135 |
+
</li>
|
136 |
+
<li class="wide">
|
137 |
+
<label for="gift-message-whole-message"><?php echo $this->__('Message') ?></label>
|
138 |
+
<div class="input-box">
|
139 |
+
<textarea id="gift-message-whole-message" onchange="toogleRequired('gift-message-whole-message', ['gift-message-whole-from','gift-message-whole-to'])" class="input-text validation-passed giftmessage-area" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][message]" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Message')) ?>" rows="5" cols="10"><?php echo $this->getEscaped($this->getMessage()->getMessage()) ?></textarea>
|
140 |
+
</div>
|
141 |
+
</li>
|
142 |
+
</ul>
|
143 |
+
<script type="text/javascript">
|
144 |
+
//<![CDATA[
|
145 |
+
toogleRequired('gift-message-whole-message', ['gift-message-whole-from','gift-message-whole-to']);
|
146 |
+
//]]>
|
147 |
+
</script>
|
148 |
+
</div>
|
149 |
+
<?php endif; ?>
|
150 |
+
<?php if($this->isItemsAvailable()): ?>
|
151 |
+
<h4><?php echo $this->__('Gift Options for Individual Items'); ?></h4>
|
152 |
+
<p>
|
153 |
+
<input type="checkbox" name="allow_gift_messages_for_items" id="allow_gift_messages_for_items" value="1" onclick="toogleVisibilityOnObjects(this, ['allow-gift-messages-for-items-container']);"<?php if($this->getItemsHasMesssages()): ?> checked="checked"<?php endif; ?> class="checkbox" />
|
154 |
+
<label for="allow_gift_messages_for_items"><?php echo $this->__('Add gift options for Individual Items') ?></label>
|
155 |
+
</p>
|
156 |
+
<div id="allow-gift-messages-for-items-container">
|
157 |
+
<p><?php echo $this->__('You can leave this box blank if you do not wish to add a gift message for the item.') ?></p>
|
158 |
+
<ol>
|
159 |
+
<?php foreach($this->getItems() as $_index=>$_item): ?>
|
160 |
+
<?php $_product=$_item->getProduct() ?>
|
161 |
+
<li class="item">
|
162 |
+
<div class="product-img-box">
|
163 |
+
<p class="product-image">
|
164 |
+
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(75); ?>" width="75" height="75" alt="<?php echo $this->escapeHtml($_product->getName()) ?>" title="<?php echo $this->escapeHtml($_product->getName()) ?>" />
|
165 |
+
</p>
|
166 |
+
<p class="number"><?php echo $this->__('Item %d of %d', $_index+1, $this->countItems()) ?></p>
|
167 |
+
</div>
|
168 |
+
<div class="details">
|
169 |
+
<div class="f-fix">
|
170 |
+
<h5 class="product-name"><?php echo $this->escapeHtml($_product->getName()) ?></h5>
|
171 |
+
<input type="hidden" name="giftmessage[<?php echo $_item->getId() ?>][type]" value="quote_item" />
|
172 |
+
<ul class="form-list">
|
173 |
+
<li class="fields">
|
174 |
+
<div class="field">
|
175 |
+
<label for="gift-message-<?php echo $_item->getId() ?>-from"><?php echo $this->__('From') ?></label>
|
176 |
+
<div class="input-box">
|
177 |
+
<input type="text" name="giftmessage[<?php echo $_item->getId() ?>][from]" id="gift-message-<?php echo $_item->getId() ?>-from" title="<?php echo Mage::helper('core')->quoteEscape($this->__('From')) ?>" value="<?php echo $this->getEscaped($this->getMessage($_item)->getSender(), $this->getDefaultFrom()) ?>" class="input-text validation-passed" />
|
178 |
+
</div>
|
179 |
+
</div>
|
180 |
+
<div class="field">
|
181 |
+
<label for="gift-message-<?php echo $_item->getId() ?>-to"><?php echo $this->__('To') ?></label>
|
182 |
+
<div class="input-box">
|
183 |
+
<input type="text" name="giftmessage[<?php echo $_item->getId() ?>][to]" id="gift-message-<?php echo $_item->getId() ?>-to" title="<?php echo Mage::helper('core')->quoteEscape($this->__('To')) ?>" value="<?php echo $this->getEscaped($this->getMessage($_item)->getRecipient(), $this->getDefaultTo()) ?>" class="input-text validation-passed" />
|
184 |
+
</div>
|
185 |
+
</div>
|
186 |
+
</li>
|
187 |
+
<li class="wide">
|
188 |
+
<label for="gift-message-<?php echo $_item->getId() ?>-message"><?php echo $this->__('Message') ?></label>
|
189 |
+
<div class="input-box">
|
190 |
+
<textarea id="gift-message-<?php echo $_item->getId() ?>-message" onchange="toogleRequired('gift-message-<?php echo $_item->getId() ?>-message', ['gift-message-<?php echo $_item->getId() ?>-from','gift-message-<?php echo $_item->getId() ?>-to'])" class="input-text validation-passed giftmessage-area" name="giftmessage[<?php echo $_item->getId() ?>][message]" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Message')) ?>" rows="5" cols="40"><?php echo $this->getEscaped($this->getMessage($_item)->getMessage()) ?></textarea>
|
191 |
+
</div>
|
192 |
+
</li>
|
193 |
+
</ul>
|
194 |
+
<script type="text/javascript">
|
195 |
+
//<![CDATA[
|
196 |
+
toogleRequired('gift-message-<?php echo $_item->getId() ?>-message', ['gift-message-<?php echo $_item->getId() ?>-from','gift-message-<?php echo $_item->getId() ?>-to']);
|
197 |
+
//]]>
|
198 |
+
</script>
|
199 |
+
</div>
|
200 |
+
</div>
|
201 |
+
</li>
|
202 |
+
<?php endforeach; ?>
|
203 |
+
</ol>
|
204 |
+
</div>
|
205 |
+
<?php endif; ?>
|
206 |
+
</div>
|
207 |
+
</div>
|
208 |
+
<script type="text/javascript">
|
209 |
+
//<![CDATA[
|
210 |
+
toogleVisibilityOnObjects('allow_gift_messages', ['allow-gift-message-container']);
|
211 |
+
toogleVisibilityOnObjects('allow_gift_messages_for_order', ['allow-gift-messages-for-order-container']);
|
212 |
+
toogleVisibilityOnObjects('allow_gift_messages_for_items', ['allow-gift-messages-for-items-container']);
|
213 |
+
//]]>
|
214 |
+
</script>
|
215 |
+
<?php break; ?>
|
216 |
+
<?php case 'multishipping_adress_checkbox': ?>
|
217 |
+
|
218 |
+
<?php break; ?>
|
219 |
+
<?php case 'multishipping_adress': ?>
|
220 |
+
<div class="gift-messages">
|
221 |
+
<h3><?php echo $this->__('Do you have any gift items in your order?'); ?></h3>
|
222 |
+
<p class="control">
|
223 |
+
<input type="checkbox" name="allow_gift_messages_<?php echo $this->getEntity()->getId() ?>" id="allow_gift_messages_<?php echo $this->getEntity()->getId() ?>" value="1" onclick="toogleVisibilityOnObjects(this, ['allow-gift-message-container-<?php echo $this->getEntity()->getId() ?>']);"<?php if($this->getItemsHasMesssages() || $this->getEntityHasMessage()): ?> checked="checked"<?php endif ?> class="checkbox" />
|
224 |
+
<label for="allow_gift_messages_<?php echo $this->getEntity()->getId() ?>"><?php echo $this->__('Add gift options') ?></label>
|
225 |
+
</p>
|
226 |
+
</div>
|
227 |
+
<div class="gift-messages-form" id="allow-gift-message-container-<?php echo $this->getEntity()->getId() ?>">
|
228 |
+
<div class="inner-box">
|
229 |
+
<?php if ($this->isMessagesAvailable()): ?>
|
230 |
+
<h4><?php echo $this->__('Gift Options for this address.'); ?></h4>
|
231 |
+
<p>
|
232 |
+
<input type="checkbox" name="allow_gift_messages_for_order_<?php echo $this->getEntity()->getId() ?>" id="allow_gift_messages_for_order_<?php echo $this->getEntity()->getId() ?>" value="1" onclick="toogleVisibilityOnObjects(this, ['allow-gift-messages-for-order-container-<?php echo $this->getEntity()->getId() ?>']);"<?php if($this->getEntityHasMessage()): ?> checked="checked"<?php endif; ?> class="checkbox" />
|
233 |
+
<label for="allow_gift_messages_for_order"><?php echo $this->__('Add gift options for the Entire Order') ?></label>
|
234 |
+
</p>
|
235 |
+
<div id="allow-gift-messages-for-order-container-<?php echo $this->getEntity()->getId() ?>">
|
236 |
+
<p><?php echo $this->__('You can leave this box blank if you do not wish to add a gift message for this address.') ?></p>
|
237 |
+
<input type="hidden" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][type]" value="quote_address" />
|
238 |
+
<ul class="form-list">
|
239 |
+
<li class="fields">
|
240 |
+
<div class="field">
|
241 |
+
<label for="gift-message-<?php echo $this->getEntity()->getId() ?>-from"><?php echo $this->__('From') ?></label>
|
242 |
+
<div class="input-box">
|
243 |
+
<input type="text" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][from]" id="gift-message-<?php echo $this->getEntity()->getId() ?>-from" title="<?php echo Mage::helper('core')->quoteEscape($this->__('From')) ?>" value="<?php echo $this->getEscaped($this->getMessage()->getSender(), $this->getDefaultFrom()) ?>" class="input-text validation-passed" />
|
244 |
+
</div>
|
245 |
+
</div>
|
246 |
+
<div class="field">
|
247 |
+
<label for="gift-message-<?php echo $this->getEntity()->getId() ?>-to"><?php echo $this->__('To') ?></label>
|
248 |
+
<div class="input-box">
|
249 |
+
<input type="text" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][to]" id="gift-message-<?php echo $this->getEntity()->getId() ?>-to" title="<?php echo Mage::helper('core')->quoteEscape($this->__('To')) ?>" value="<?php echo $this->getEscaped($this->getMessage()->getRecipient(), $this->getDefaultTo()) ?>" class="input-text validation-passed" />
|
250 |
+
</div>
|
251 |
+
</div>
|
252 |
+
</li>
|
253 |
+
<li class="wide">
|
254 |
+
<label for="gift-message-<?php echo $this->getEntity()->getId() ?>-message"><?php echo $this->__('Message') ?></label>
|
255 |
+
<div class="input-box">
|
256 |
+
<textarea id="gift-message-<?php echo $this->getEntity()->getId() ?>-message" onchange="toogleRequired('gift-message-<?php echo $this->getEntity()->getId() ?>-message', ['gift-message-<?php echo $this->getEntity()->getId() ?>-from','gift-message-<?php echo $this->getEntity()->getId() ?>-to'])" class="input-text validation-passed giftmessage-area" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][message]" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Message')) ?>" rows="5" cols="40"><?php echo $this->getEscaped($this->getMessage()->getMessage()) ?></textarea>
|
257 |
+
</div>
|
258 |
+
</li>
|
259 |
+
</ul>
|
260 |
+
<script type="text/javascript">
|
261 |
+
//<![CDATA[
|
262 |
+
var shippingMethod = new VarienForm('shipping_method_form');
|
263 |
+
toogleRequired('gift-message-<?php echo $this->getEntity()->getId() ?>-message', ['gift-message-<?php echo $this->getEntity()->getId() ?>-from','gift-message-<?php echo $this->getEntity()->getId() ?>-to']);
|
264 |
+
//]]>
|
265 |
+
</script>
|
266 |
+
</div>
|
267 |
+
<?php endif; ?>
|
268 |
+
<?php if($this->isItemsAvailable()): ?>
|
269 |
+
<h4><?php echo $this->__('Gift Options for Individual Items'); ?></h4>
|
270 |
+
<p>
|
271 |
+
<input type="checkbox" name="allow_gift_messages_for_items_<?php echo $this->getEntity()->getId() ?>" id="allow_gift_messages_for_items_<?php echo $this->getEntity()->getId() ?>" value="1" onclick="toogleVisibilityOnObjects(this, ['allow-gift-messages-for-items-container-<?php echo $this->getEntity()->getId() ?>']);"<?php if($this->getItemsHasMesssages()): ?> checked="checked"<?php endif; ?> class="checkbox" />
|
272 |
+
<label for="allow_gift_messages_for_items_<?php echo $this->getEntity()->getId() ?>"><?php echo $this->__('Add gift options for Individual Items') ?></label>
|
273 |
+
</p>
|
274 |
+
<div id="allow-gift-messages-for-items-container-<?php echo $this->getEntity()->getId() ?>">
|
275 |
+
<p><?php echo $this->__('You can leave this box blank if you do not wish to add a gift message for the item.') ?></p>
|
276 |
+
<ol>
|
277 |
+
<?php foreach($this->getItems() as $_index=>$_item): ?>
|
278 |
+
<?php $_product=$_item->getProduct() ?>
|
279 |
+
<li class="item">
|
280 |
+
<div class="product-img-box">
|
281 |
+
<p class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(75); ?>" width="75" height="75" alt="<?php echo $this->escapeHtml($_product->getName()) ?>" title="<?php echo $this->escapeHtml($_product->getName()) ?>" /></p>
|
282 |
+
<p class="number"><?php echo $this->__('Item %d of %d', $_index+1, $this->countItems()) ?></p>
|
283 |
+
</div>
|
284 |
+
<div class="details">
|
285 |
+
<div class="f-fix">
|
286 |
+
<input type="hidden" name="giftmessage[<?php echo $_item->getId() ?>][type]" value="quote_address_item" />
|
287 |
+
<input type="hidden" name="giftmessage[<?php echo $_item->getId() ?>][address]" value="<?php echo $this->getEntity()->getId()?>" />
|
288 |
+
<h5 class="product-name"><?php echo $this->escapeHtml($_product->getName()) ?></h5>
|
289 |
+
<ul class="form-list">
|
290 |
+
<li class="fields">
|
291 |
+
<div class="field">
|
292 |
+
<label for="gift-message-<?php echo $_item->getId() ?>-from"><?php echo $this->__('From') ?></label>
|
293 |
+
<div class="input-box">
|
294 |
+
<input type="text" name="giftmessage[<?php echo $_item->getId() ?>][from]" id="gift-message-<?php echo $_item->getId() ?>-from" title="<?php echo Mage::helper('core')->quoteEscape($this->__('From')) ?>" value="<?php echo $this->getEscaped($this->getMessage($_item)->getSender(), $this->getDefaultFrom()) ?>" class="input-text validation-passed" />
|
295 |
+
</div>
|
296 |
+
</div>
|
297 |
+
<div class="field">
|
298 |
+
<label for="gift-message-<?php echo $_item->getId() ?>-to"><?php echo $this->__('To') ?></label>
|
299 |
+
<div class="input-box">
|
300 |
+
<input type="text" name="giftmessage[<?php echo $_item->getId() ?>][to]" id="gift-message-<?php echo $_item->getId() ?>-to" title="<?php echo Mage::helper('core')->quoteEscape($this->__('To')) ?>" value="<?php echo $this->getEscaped($this->getMessage($_item)->getRecipient(), $this->getDefaultTo()) ?>" class="input-text validation-passed" />
|
301 |
+
</div>
|
302 |
+
</div>
|
303 |
+
</li>
|
304 |
+
<li class="wide">
|
305 |
+
<label for="gift-message-<?php echo $_item->getId() ?>-message"><?php echo $this->__('Message') ?></label>
|
306 |
+
<div class="input-box">
|
307 |
+
<textarea id="gift-message-<?php echo $_item->getId() ?>-message" onchange="toogleRequired('gift-message-<?php echo $_item->getId() ?>-message', ['gift-message-<?php echo $_item->getId() ?>-from','gift-message-<?php echo $_item->getId() ?>-to'])" class="input-text validation-passed giftmessage-area" name="giftmessage[<?php echo $_item->getId() ?>][message]" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Message')) ?>" rows="5" cols="10"><?php echo $this->getEscaped($this->getMessage($_item)->getMessage()) ?></textarea>
|
308 |
+
</div>
|
309 |
+
</li>
|
310 |
+
</ul>
|
311 |
+
<script type="text/javascript">
|
312 |
+
//<![CDATA[
|
313 |
+
toogleRequired('gift-message-<?php echo $_item->getId() ?>-message', ['gift-message-<?php echo $_item->getId() ?>-from','gift-message-<?php echo $_item->getId() ?>-to']);
|
314 |
+
//]]>
|
315 |
+
</script>
|
316 |
+
</div>
|
317 |
+
</div>
|
318 |
+
</li>
|
319 |
+
<?php endforeach; ?>
|
320 |
+
</ol>
|
321 |
+
</div>
|
322 |
+
<?php endif; ?>
|
323 |
+
</div>
|
324 |
+
</div>
|
325 |
+
<script type="text/javascript">
|
326 |
+
//<![CDATA[
|
327 |
+
toogleVisibilityOnObjects('allow_gift_messages_<?php echo $this->getEntity()->getId() ?>', ['allow-gift-message-container-<?php echo $this->getEntity()->getId() ?>']);
|
328 |
+
toogleVisibilityOnObjects('allow_gift_messages_for_order_<?php echo $this->getEntity()->getId() ?>', ['allow-gift-messages-for-order-container-<?php echo $this->getEntity()->getId() ?>']);
|
329 |
+
toogleVisibilityOnObjects('allow_gift_messages_for_items_<?php echo $this->getEntity()->getId() ?>', ['allow-gift-messages-for-items-container-<?php echo $this->getEntity()->getId() ?>']);
|
330 |
+
//]]>
|
331 |
+
</script>
|
332 |
+
<?php break; ?>
|
333 |
+
<?php endswitch ?>
|
334 |
+
<?php endif; ?>
|
app/design/frontend/base/default/template/japi/page/html/head.phtml
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/afl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magento.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magento.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package base_default
|
23 |
+
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
|
24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
25 |
+
*/
|
26 |
+
?>
|
27 |
+
<meta http-equiv="Content-Type" content="<?php echo $this->getContentType() ?>" />
|
28 |
+
<title><?php echo $this->getTitle() ?></title>
|
29 |
+
<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
|
30 |
+
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" />
|
31 |
+
<meta name="robots" content="<?php echo htmlspecialchars($this->getRobots()) ?>" />
|
32 |
+
<link rel="icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
|
33 |
+
<link rel="shortcut icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
|
34 |
+
<!--[if lt IE 7]>
|
35 |
+
<script type="text/javascript">
|
36 |
+
//<![CDATA[
|
37 |
+
var BLANK_URL = '<?php echo $this->helper('core/js')->getJsUrl('blank.html') ?>';
|
38 |
+
var BLANK_IMG = '<?php echo $this->helper('core/js')->getJsUrl('spacer.gif') ?>';
|
39 |
+
//]]>
|
40 |
+
</script>
|
41 |
+
<![endif]-->
|
42 |
+
<?php echo $this->getCssJsHtml() ?>
|
43 |
+
<?php echo $this->getChildHtml() ?>
|
44 |
+
<?php echo $this->helper('core/js')->getTranslatorScript() ?>
|
45 |
+
<?php echo $this->getIncludes() ?>
|
app/design/frontend/base/default/template/japi/page/rwd.phtml
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright 2015 JMango360
|
4 |
+
*/
|
5 |
+
?><!DOCTYPE html>
|
6 |
+
<html lang="en">
|
7 |
+
<head>
|
8 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
|
9 |
+
<?php echo $this->getChildHtml('head') ?>
|
10 |
+
</head>
|
11 |
+
<body>
|
12 |
+
<?php echo $this->getChildHtml('after_body_start') ?>
|
13 |
+
<?php //echo $this->getChildHtml('header') ?>
|
14 |
+
<?php echo $this->getChildHtml('global_messages') ?>
|
15 |
+
<?php echo $this->getChildHtml('content') ?>
|
16 |
+
<?php //echo $this->getChildHtml('footer') ?>
|
17 |
+
<?php echo $this->getChildHtml('before_body_end') ?>
|
18 |
+
</body>
|
19 |
+
</html>
|
app/etc/modules/Jmango360_Japi.xml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<config>
|
2 |
+
<modules>
|
3 |
+
<Jmango360_Japi>
|
4 |
+
<active>true</active>
|
5 |
+
<codePool>community</codePool>
|
6 |
+
<depends>
|
7 |
+
<Mage_Core />
|
8 |
+
<Mage_Api2 />
|
9 |
+
</depends>
|
10 |
+
</Jmango360_Japi>
|
11 |
+
</modules>
|
12 |
+
</config>
|
app/locale/ar_SA/Jmango360_Japi.csv
ADDED
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"Connection credentials", "التعليمة البرمجية للاتصال"
|
2 |
+
"This account is not confirmed. <a href='%s'>Click here</a> to resend confirmation email.", "إرسال رسالة تأكيد البريد الإلكتروني. الحساب لا يتم التحقق من هذا <a href='%s'>انقر هنا لإعادة</a>"
|
3 |
+
"Customer is already logged in.", "تم الزبون بتسجيل الدخول بالفعل"
|
4 |
+
"Could not login", ""
|
5 |
+
"Login and password are required.", "تسجيل الدخول والباسورد مطلوبة."
|
6 |
+
"This account need confirmation. See in confirmation email.", "هذا الحساب يحتاج الى تأكيد الرسولي في رسالة تأكيد بالبريد الإلكتروني"
|
7 |
+
"Account is created. Please check email to confirm.", "Account is created. Please check email to confirm."
|
8 |
+
"Invalid Exception code '%d'", "رمز الاستثناء غير صالح : %d"
|
9 |
+
"Order List", "قائمة طلب"
|
10 |
+
"Order #", "# طلب"
|
11 |
+
"Order Date", "تاريخ طلب"
|
12 |
+
"Billing Country", "بلد إرسال الفواتير"
|
13 |
+
"Shipping Country", "بلد الشحن"
|
14 |
+
"Qty. Ordered", "الكمية المطلوبة"
|
15 |
+
"Subtotal", "الإجمالي الفرعي"
|
16 |
+
"Total", "الإجمالي"
|
17 |
+
"Invoiced", "المفوترة"
|
18 |
+
"Status", "الحالة"
|
19 |
+
"Action", "إجراء"
|
20 |
+
"View", "عرض"
|
21 |
+
"Total Customers from JMango360 Report", "تقرير بإجمالي الزبائن من JMango360"
|
22 |
+
"Show Report", "عرض التقرير"
|
23 |
+
"Total Ordered from JMango360 Report", "تقرير بالإجمالي المطلوبة من JMango360"
|
24 |
+
"Total Sales from JMango360 Report", "تقرير بإجمالي المبيعات من JMango360"
|
25 |
+
"Chart", "جدول"
|
26 |
+
"Period", "فترة"
|
27 |
+
"Customers", "زبائن"
|
28 |
+
"Orders", "طلبات"
|
29 |
+
"Order From", "طلبات من"
|
30 |
+
"JMango360 User", "JMango360 مستخدم"
|
31 |
+
"Download", "تحميل"
|
32 |
+
"Clear", "واضح"
|
33 |
+
"No", "لا"
|
34 |
+
"Yes", "نعم"
|
35 |
+
"Invalid token", "رمز غير صالحة"
|
36 |
+
"Session expired.", "انتهت الجلسة"
|
37 |
+
"No rest model found.", "لم يتم العثور على نموذج بقية"
|
38 |
+
"Resource method not implemented", "طريقة الموارد لم تنفذ"
|
39 |
+
"Minimum order amount is %s", "%s كمية من أجل الحد الأدنى هو"
|
40 |
+
"Guest checkout is not enabled", "لم يتم تمكين خروج الضيف"
|
41 |
+
"Product ID invalid", "معرف المنتج غير صالح"
|
42 |
+
"Something is wrong with the order.", "هناك خطأ ما مع النظام"
|
43 |
+
"Something is wrong with the quote or order.", "هناك خطأ ما مع الاقتباس أو النظام."
|
44 |
+
"Cart is empty.", "سلة التسوق فارغة."
|
45 |
+
"Multishipping not implemented yet.", "لم تنفذ متعددة الشحن بعد"
|
46 |
+
"Checkout method not implemented yet: ", "لم تنفذ طريقة الخروج بعد"
|
47 |
+
"Could not log-out customer", "لا يمكن الزبون بتسجيل الخروج"
|
48 |
+
"Please login.", "يرجي تسجيل الدخول"
|
49 |
+
"Country code cannot be empty", "لا يمكن رمز البلد أن يكون فارغ"
|
50 |
+
"Country does not exist: ", "لا يوجد بلد: "
|
51 |
+
"Country does not exist", "لا يوجد بلد"
|
52 |
+
"Store not found'", "لم يتم العثور على مخزن"
|
53 |
+
"Not allowed.", "غير مسموح"
|
54 |
+
"Set store option %s not found", "لم يتم العثور على مجموعة المخزن بخيار %s"
|
55 |
+
"Set store option cannot be empty.", "لا يمكن خيار مجموعة المخزن أن يكون فارغا"
|
56 |
+
"It's OK, I see it.", "لا بأس وأرى ذلك"
|
57 |
+
"Product ID invalid", "معرف المنتج غير صالح"
|
58 |
+
"Product not found", "لم يتم العثور على صنف "
|
59 |
+
"Please login first!", "يرجي تسجيل الدخول أولا"
|
60 |
+
"Cannot specify product.", "لا يمكن تحديد المنتج"
|
61 |
+
"Item not found", "لم يتم العثور على بند"
|
62 |
+
"%1$s has been updated in your wishlist.", "%1$s قد تم تحديث في قائمة الأمنيات لك"
|
63 |
+
"An error occurred while updating your wishlist.", "حدث خطأ أثناء تحديث قائمة الأمنيات لك"
|
64 |
+
"Cannot specify your wishlist item.", "لا يمكن تحديد بند قائمة الأمنيات لك"
|
65 |
+
"The product does not exist.", "المنتج لا يوجد"
|
66 |
+
"Wishlist item removed", "تم بند قائمة الأمنيات إزالة"
|
67 |
+
"An error occurred while deleting the item from wishlist: %s", "%s :حدث خطأ أثناء حذف االبند من قائمة الأمنيات"
|
68 |
+
"An error occurred while deleting the item from wishlist.", "حدث خطأ أثناء حذف االبند من قائمة الأمنيات"
|
69 |
+
"Can't save description %s", "%s لا يمكن حفظ وصف"
|
70 |
+
"Can't delete item from wishlist", "لا يمكن حذف االبند من قائمة الأمنيات "
|
71 |
+
"Can't save qty %s", "%s لا يمكن حفظ كمية"
|
72 |
+
"Wishlist updated successfully", "قائمة الأمنيات محدثة بنجاح"
|
73 |
+
"Can't update wishlist", "لا يمكن تحديث قائمة الأمنيات"
|
74 |
+
"No item updated", "عدم بند محدث"
|
75 |
+
"Cannot specify product", "لا يمكن تحديد منتج"
|
76 |
+
"%s has been added to your wishlist.", "%s قد أضيفت إلى قائمة الأمنيات لك"
|
77 |
+
"An error occurred while adding item to your wishlist: %s", "%s :حدث خطأ أثناء إضافة بند إلى قائمة الأمنيات لك"
|
78 |
+
"An error occurred while adding item to your wishlist", "حدث خطأ أثناء إضافة بند إلى قائمة الأمنيات لك"
|
79 |
+
"Wishlist not allowed", "قائمة الأمنيات غير مسموح"
|
80 |
+
"Wishlist doesn't exist", "قائمة الأمنيات لا توجد"
|
81 |
+
"Customer not logged in", "زبون لم يسجل دخول"
|
82 |
+
"Cart is empty.", "سلة التسوق فارغة"
|
83 |
+
"Coupon is not valid: ", "الكوبون غير صالح"
|
84 |
+
"Coupon could not be applied.", "لا يمكن تطبيق الكوبون"
|
85 |
+
"%s: Minimum quantity allowed for purchase is %s.", "%s كمية الحد الأدنى المسموح لشراء هي :%s"
|
86 |
+
"%s: Maximum quantity allowed for purchase is %s.", "%s الكمية القصوى المسموح لشراء هي :%s"
|
87 |
+
"%s was added to your shopping cart.", "تم إضافتها إلى سلة التسوق الخاصة بك %s"
|
88 |
+
"No cart data found.", "عدم بيانات السلة التسوق موجودة"
|
89 |
+
"Your shopping cart has been updated.", "قد تم تحديث سلة التسوق الخاصة بك"
|
90 |
+
"No bundle-product cart item ID found.", "لحزمة - المنتج ID لاتوجد بند السلة التسوق "
|
91 |
+
"The product you are trying to delete could not be found in the cart (item id is %s not found in cart).", "لم يمكن العثور على المنتج الذي تحاول حذف في السلة التسوق id( لم يتم العثور في سلة التسو %s البند )"
|
92 |
+
"The product has been deleted from your shopping cart.", "قد تمت إزالة المنتج من سلة التسوق الخاصة بك"
|
93 |
+
"Category not found.", "لم يتم العثورعلى فئة"
|
94 |
+
"Category not available.", "فئة غير موجودة"
|
95 |
+
"No category found.", "عدم فئة معثورة"
|
96 |
+
"Your search returns no results.", "تقوم بحثك بإرجاع عدم نتائج."
|
97 |
+
"Query cannot be empty.", "لا يمكن استعلام أن يكون فارغا"
|
98 |
+
"Methods are not complete yet. Cart shipping address is not yet completed and saved.", "طرق لا تكتمل بعد. عنوان شحن السلة التسوق لا تكتمل وتحفظ بعد"
|
99 |
+
"Methods are not complete yet. Cart is empty.", "طرق لا تكتمل بعد. سلة التسوق فارغة"
|
100 |
+
"Shipping method has no shipping carrier object: %s", "%s :طريقة الشحن لديها عدم كائن ناقل الشحن"
|
101 |
+
"Carrier object has no collectRates method: %s", "%s :كائن الناقل لديه عدم طريقة تجمع المعدلات"
|
102 |
+
"Shipping method has no rates object: %s", "%s :طريقة الشحن لديها عدم كائن المعدلات"
|
103 |
+
"Shipping method has no getAllRates function: %s", "%s :طريقة الشحن لا يمتلك أي وظيفة الحصول على جميع المعدلات"
|
104 |
+
"Shipping method has no rates: %s", "%s :طريقة الشحن لديها عدم المعدلات"
|
105 |
+
"Shipping method can not be empty.", "لا يمكن طريقة الشحن أن يكون فارغا"
|
106 |
+
"This shipping method is currently not available.", "هذه الطريقة الشحن هو حاليا غير متوفرة"
|
107 |
+
"Customer shipping address not found.", "لم يتم العثور على عنوان شحن الزبون"
|
108 |
+
"Customer shipping address email not found.", "لم يتم العثور على البريد الإلكتروني لعنون الشحن الزبون"
|
109 |
+
"Customer billing address not found.", "لم يتم العثور على عنوان فواتير الزبون "
|
110 |
+
"Payment method cannot be empty.", "لا تمكن طريقة الدفع أن تكن فارغا"
|
111 |
+
"Email cannot be empty.", "لا تمكن البريد الإلكتروني أن تكن فارغا"
|
112 |
+
"This payment method is currently not available.", "هذه طريقة الدفع غير متوفرة حاليا"
|
113 |
+
"Please add ", " يرجي إضافة"
|
114 |
+
"Request info not matches the order.", "لا يتطابق مع المعلومات المطلوبة في النظام"
|
115 |
+
"No payment provider to redirect found.", "عدم موفر دفع معثور لإعادة توجيه"
|
116 |
+
"Request info does not match the quote. Probably the cart is ordered or the session is expired.", "لا يتطابق المعلومات المطلوبة مع الاقتباس. قد تم السلة التسوق طلبا بالفعل أو انتهاء الدورة."
|
117 |
+
"Cart is no longer active.", "السلة التسوق لم تعد فعال"
|
118 |
+
"Replaced by new order.", "استعاضة عن طلب جديد"
|
119 |
+
"Cannot save the address: ", "%s :لا يمكن أن يحفظ العنوان"
|
120 |
+
"The address does not belong to this customer.", "لا ينتمي عنوان لهذا الزبون"
|
121 |
+
"Default billing address can not be removed.", "عنوان الفواتير الافتراضية لا يمكن إزالته"
|
122 |
+
"Default shipping address can not be removed.", "عنوان الشحن الافتراضية لا يمكن إزالته"
|
123 |
+
"An error occurred while deleting the address.", "حدث خطأ أثناء حذف العنوان"
|
124 |
+
"Address ID can not be empty.", "ID أن يكون فارغا لا يمكن عنوان"
|
125 |
+
"New password field cannot be empty.", "New password field cannot be empty."
|
126 |
+
"Invalid current password", "الباسورد الحالي غير صالح"
|
127 |
+
"The account information has been saved.", "قد تم حفظ معلومات الحساب"
|
128 |
+
"Could not retrieve list: ", "لا يمكن استرداد القائمة"
|
129 |
+
"Order not found (no ID).", "(ID لم يتم العثور على طلب (عدم"
|
130 |
+
"Invalid email address.", "عنوان البريد الإلكتروني غير صالح"
|
131 |
+
"Please enter your email.", "يرجى إدخال البريد الإلكتروني الخاص بك"
|
132 |
+
"This account needs confirmation. See in confirmation email.", "هذا الحساب يحتاج الى تأكيد الرسولي في رسالة تأكيد بالبريد الإلكتروني"
|
133 |
+
"No products found.", "عدم منتجات معثور"
|
134 |
+
"Category not found.", "عدم فئة معثور"
|
135 |
+
"Cannot find customer ID, please try again!", "ID لا يمكن العثور على الزبون، يرجى المحاولة مرة أخرى"
|
136 |
+
"Your search returns no results.", "يجب أن تترك على الأقل طريقة دفعة واحدة متاحة"
|
137 |
+
"You must leave at least one payment method available.", "يجب أن تترك على الأقل طريقة دفعة واحدة متاحة"
|
138 |
+
"You must leave at least one shipping method available.", "يجب أن تترك على الأقل طريقة شحن واحدة متاحة"
|
139 |
+
"None", "لا شيء"
|
140 |
+
"Base Image", "الصورة الأساسية"
|
141 |
+
"Small Image", "الصورة الصغيرة"
|
142 |
+
"Thumbnail", "المصغرات"
|
143 |
+
"Shipping Excl. Tax (%s)", "(%s) الشحن باستثناء ضريبة"
|
144 |
+
"Shipping Incl. Tax (%s)", "(%s) الشحن بضمن ضريبة"
|
145 |
+
"Subtotal (Excl. Tax)", "(الإجمالي الفرعي ( باستثناء ضريبة"
|
146 |
+
"Subtotal (Incl. Tax)", "(الإجمالي الفرعي ( بضمن ضريبة"
|
147 |
+
"Grand Total Excl. Tax", "المجموع الإجمالي باستثناء ضريبة"
|
148 |
+
"Grand Total Incl. Tax", "المجموع الإجمالي بضمن ضريبة"
|
149 |
+
"Unable to set Payment Method.", "غير قادر على تعيين طريقة الدفع"
|
150 |
+
"Reports", "تقارير"
|
151 |
+
"Order Details", "تفاصيل الطلب"
|
152 |
+
"Sales Reports", "تقارير المبيعات"
|
153 |
+
"Orders Reports", "تقارير طلبات"
|
154 |
+
"Customers Reports", "تقارير الزبائن"
|
155 |
+
"Connection credentials", "التعليمة البرمجية للاتصال"
|
156 |
+
"Version", "نسخة"
|
157 |
+
"The plugin version", "نسخة المساعد"
|
158 |
+
"User Name", "اسم المستخدم"
|
159 |
+
"This username will be checked from every App while a session is set up between the App and the Magento store.", "وسيتم فحص هذا المستخدم من كل تطبيق في حين يتم إقامة جلسة عمل بين تخزين التطبيق والماجنتو"
|
160 |
+
"Api Key", " Api مفتاح"
|
161 |
+
"This key will be checked from every App while a session is set up between the App and the Magento store.", "وسيتم فحص هذا المفتاح من كل تطبيق في حين يتم إقامة جلسة عمل بين تخزين التطبيق والماجنتو"
|
162 |
+
"Use token for Api communications", "Api استخدم رمز للاتصالات"
|
163 |
+
"Use token will add check and refresh the token with every request.", "استخدام رمز سوف تضيف تحقق وتجديد من الرمز مع كل طلب"
|
164 |
+
"Catalogue Settings", "إعدادات الكاتالوج"
|
165 |
+
"Include all active categories", "تشمل جميع الفئات الفعالة"
|
166 |
+
"Include all ""Active"" categories regardless of whether or not they are included in navigation", "تشمل جميع الفئات "الفعالة" بغض النظر عن ما إذا كانت أم لم تم تضمين في الملاحة"
|
167 |
+
"Display attribute on Product Listing", "عرض سمات على قائمة المنتجات"
|
168 |
+
"This attribute will be displayed in product listing", "سيتم عرض هذه السمة في قائمة المنتجات"
|
169 |
+
"Display attribute on Product Details", "عرض سمات على تفاصيل المنتجات"
|
170 |
+
"This attribute will be displayed in product details", "سيتم عرض هذه السمة في تفاصيل المنتجات"
|
171 |
+
"Mobile App Checkout Settings", "إعدادات خروج تطبيق الجوال"
|
172 |
+
"Excluded shipping methods", "تم استثناء طرق الشحن"
|
173 |
+
"Select one or more, but not all shipping methods that are not suitable/compatible to be used in mobile app environment. This can be set anytime during or after creation of JMango360 application.", "اختيار واحد أو أكثر ولكن ليس كل طرق الشحن التي ليست مناسبة / متوافقة ليتم استخدامها في بيئة تطبيق الجوال . هذا يمكن تعيين أي وقت أثناء أو بعد إنشاء تطبيق JMango360"
|
174 |
+
"Excluded payment methods", "تم استثناء طرق الدفع"
|
175 |
+
"Select one or more, but not all payment methods that are not suitable/compatible to be used in mobile app environment. This can be set anytime during or after creation of JMango360 application.", "اختيار واحد أو أكثر ولكن ليس كل طرق الدفع التي ليست مناسبة / متوافقة ليتم استخدامها في بيئة تطبيق الجوال . هذا يمكن تعيين أي وقت أثناء أو بعد إنشاء تطبيق JMango360"
|
176 |
+
"Web checkout URL", "URL لخروج على شبكة الإنترنت "
|
177 |
+
"Enter custom checkout url of website if Jmango360 plugin could not detect. Ex: checkout/onepage.", "العرف url أدخل للموقع إذا لم يمكن مساعد كشف Jmango360 عنها. مثلا: الخروج / صفحة واحدة"
|
178 |
+
"Product image gallery settings", "إعدادات معرض صور المنتج"
|
179 |
+
"Detail page image cache-width", "تفاصيل تخزين تخزينا مؤقتا-العرض صورة الصفحة"
|
180 |
+
"Set the default ""cached"" size for ""big"" images on the detail pages.", "تعيين الافتراضي ""مخبأ"" حجم للصور ""كبيرة"" على صفحات من التفاصيل"
|
181 |
+
"Detail page image cache-height", "تفاصيل تخزين تخزينا مؤقتا-الارتفاع صورة الصفحة"
|
182 |
+
"Set the default ""cached"" size for ""big"" images on the detail pages.", "تعيين الافتراضي ""مخبأ"" حجم للصور ""كبيرة"" على صفحات من التفاصيل"
|
183 |
+
"Catalogue image cache-width", "صورة الكاتالوج تخزين تخزينا مؤقتا-العرض"
|
184 |
+
"Set the default ""cached"" size for images on the catalogue pages.", "تعيين الافتراضي ""مخبأ"" حجم للصور ""كبيرة"" على صفحات من الكاتالوج"
|
185 |
+
"Catalogue image cache-height", "صورة الكاتالوج تخزين تخزينا مؤقتا-الارتفاع"
|
186 |
+
"Set the default ""cached"" size for images on the catalog pages.", "تعيين الافتراضي ""مخبأ""حجم للصور ""كبيرة"" على صفحات من الكاتالوج"
|
187 |
+
"Thumbnail image cache-width", "تخزين تخزينا مؤقتا-العرض لمصغرة صورة"
|
188 |
+
"Set the default ""cached"" size for thumbnails on the detail pages.", "تعيين الافتراضي ""مخبأ"" حجم للصور المصغرة على صفحات من التفاصيل"
|
189 |
+
"Thumbnail image cache-height", "تخزين تخزينا مؤقتا-الارتفاع لمصغرة صورة"
|
190 |
+
"Set the default """cached"" size for thumbnails on the detail pages.", "تعيين الافتراضي ""مخبأ"" حجم للصور المصغرة على صفحات من التفاصيل"
|
191 |
+
"Choose image type to be displayed if catalogue thumbnail is not available", "اختر نوع الصورة لعرضها إذا كتالوج مصغر غير متوفرة"
|
192 |
+
" Choose what kind of image of product that I would like to show in catalogue listing in mobile app.", "اختر أي نوع من صورة المنتج التي أود أن تظهر في قائمة الكتالوج في تطبيق الجوال"
|
193 |
+
"Choose image type to be displayed on catalogue page", "اختر نوع الصورة للظهور على صفحة الكتالوج"
|
194 |
+
"Choose what kind of image of product that I would like to show in product listing in mobile app.", "اختر أي نوع من صورة المنتج التي أود أن تظهر في قائمة المنتج في تطبيق الجوال"
|
195 |
+
"Stock Settings", "إعدادات الأسهم"
|
196 |
+
"Display products availability in stock in mobile app", "عرض توفر المنتجات في الأسهم في تطبيق الجوال"
|
197 |
+
"Developer", "مطور"
|
198 |
+
"Enable debug logging", "تمكين تسجيل التصحيح"
|
199 |
+
"Log requests to japi.log. Disable in production.", "بتعطيل في الإنتاج .japi.log تسجيل يطلب إلى"
|
200 |
+
"Reports", "تقارير"
|
201 |
+
"Orders", "طلبات"
|
202 |
+
"Sales", "مبيعات"
|
203 |
+
"Customers", "زبائن"
|
204 |
+
"Order Details", "تفاصيل الطلب"
|
205 |
+
"Settings", "إعدادات"
|
206 |
+
"Use Onepage checkout for mobile app", "استخدم خروج أحد الصفحة لتطبيق الجوال"
|
207 |
+
"Select to use JMango360 Onepage responsive web checkout for mobile app instead of default Magento checkout", "اختر لاستخدام خروج شبكة الإنترنت الاستجابة JMango360 Onepage لتطبيق الجوال بدلا من خروج الماجنتو الافتراضية"
|
208 |
+
"Hide non value additional attributes", "اخفاء سمات إضافية غير ذات قيمة"
|
209 |
+
"Atrribute whose value is N/A or blank will not be displayed on Additional Infomation on product detail page", "N / A السمة التي تقدر قيمتها أو خالية ابحث لن يتم عرض على معلومات إضافية على صفحة المنتج من التفصيل"
|
210 |
+
"Mobile App Login Settings", "إعدادات دخول تطبيق الجوال"
|
211 |
+
"App users must login to see product prices", "يجب على مستخدمين التطبيق أن يدخلوا لمعرفة الأسعار وزر أضف إلى السلة التسوق"
|
212 |
+
"This will prevent mobile app user using app without an account.", "هذا سيمنع مستخدمي تطبيق الجوال من استخدام التطبيق بدون حساب"
|
213 |
+
"Discount Codes", "Discount Codes"
|
214 |
+
"Enter your coupon code if you have one.", "Enter your coupon code if you have one."
|
215 |
+
"Apply Coupon", "Apply Coupon"
|
216 |
+
"Cancel Coupon", "Cancel Coupon"
|
217 |
+
"Enable Order From in orders list", "تمكين طلب من في قائمة الطلبات"
|
218 |
+
"Select to view which orders are from JMango360", "اختر لعرض ما الطلبات من JMango360"
|
219 |
+
"Enable JMango360 User in Customers list", "تمكين مستخدم JMango360 في قائمة الزبائن"
|
220 |
+
"Select to view which customers are from JMango360", "اختر لعرض ما الزبائن من JMango360"
|
221 |
+
"Adding extra attributes to registration form", "مضيفا سمات إضافية لاستمارة التسجيل"
|
222 |
+
"Adding these attributes to customer registration form in mobile app", "مضيفا هذه السمات إلى نموذج تسجيل الزبائن في تطبيق الجوال"
|
223 |
+
"Show image of child product in Grouped Product Detail on mobile", "تظهر صورة المنتج لأطفال في تفاصيل المنتج المجمع على الجوال"
|
224 |
+
"Please wait", "يرجي الانتظار"
|
225 |
+
"Enter xml layout update code here, it will only affect JMango360 Onepage checkout page", "ادخل رمز التحديث لتخطيط هنا، وسوف تؤثر فقط xml صفحة الخروج ل JMango360 Onepage"
|
226 |
+
"Enter css code here, it will only append to JMango360 Onepage checkout page", " هنا، فإنه css ادخل رمز سيتم إلحاق فقط إلى صفحة الخروج ل JMango360 Onepage"
|
227 |
+
"A new version of the JMango360 Mobile plugin %s is available. Please update.", "يتوفر النسخة الجديدة لتليفون JMango360 المساعد%s يرجى التحديث"
|
228 |
+
"Group ID not found.", "Group ID not found."
|
229 |
+
"Group not found.", "Group not found."
|
230 |
+
"Account is created. Please check email to confirm.", "Account is created. Please check email to confirm."
|
231 |
+
"Attribute whose value is N/A or blank will not be displayed on Additional Information on product detail page", "لسمة التي تقدر قيمتها N / A أو فارغة لن يتم عرض على معلومات إضافية على صفحة المنتج من التفصيل"
|
232 |
+
"Custom Layout Update", "تحديث التخطيط العرف"
|
233 |
+
"Custom CSS", "CSS العرف"
|
app/locale/en_US/Jmango360_Japi.csv
ADDED
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
"Connection credentials","Connection credentials"
|
3 |
+
"This account is not confirmed. <a href='%s'>Click here</a> to resend confirmation email.","This account is not confirmed. <a href='%s'>Click here</a> to resend confirmation email."
|
4 |
+
"Customer is already logged in.","Customer is already logged in."
|
5 |
+
"Could not login","Could not login"
|
6 |
+
"Login and password are required.","Login and password are required."
|
7 |
+
"This account need confirmation. See in confirmation email.","This account need confirmation. See in confirmation email."
|
8 |
+
"Account is created. Please check email to confirm.","Account is created. Please check email to confirm."
|
9 |
+
"Invalid Exception code '%d'", "Invalid Exception code '%d'"
|
10 |
+
"Order List", "Order List"
|
11 |
+
"Order #", "Order #"
|
12 |
+
"Order Date", "Order Date"
|
13 |
+
"Billing Country", "Billing Country"
|
14 |
+
"Shipping Country", "Shipping Country"
|
15 |
+
"Qty. Ordered", "Qty. Ordered"
|
16 |
+
"Subtotal", "Subtotal"
|
17 |
+
"Total", "Total"
|
18 |
+
"Invoiced", "Invoiced"
|
19 |
+
"Status", "Status"
|
20 |
+
"Action", "Action"
|
21 |
+
"View", "View"
|
22 |
+
"Total Customers from JMango360 Report", "Total Customers from JMango360 Report"
|
23 |
+
"Show Report", "Show Report"
|
24 |
+
"Total Ordered from JMango360 Report", "Total Ordered from JMango360 Report"
|
25 |
+
"Total Sales from JMango360 Report", "Total Sales from JMango360 Report"
|
26 |
+
"Chart", "Chart"
|
27 |
+
"Period", "Period"
|
28 |
+
"Customers", "Customers"
|
29 |
+
"Orders", "Orders"
|
30 |
+
"Order From", "Order From"
|
31 |
+
"JMango360 User", "JMango360 User"
|
32 |
+
"Download", "Download"
|
33 |
+
"Clear", "Clear"
|
34 |
+
"No", "No"
|
35 |
+
"Yes", "Yes"
|
36 |
+
"Invalid token", "Invalid token"
|
37 |
+
"Session expired.", "Session expired."
|
38 |
+
"No rest model found.", "No rest model found."
|
39 |
+
"Resource method not implemented", "Resource method not implemented"
|
40 |
+
"Minimum order amount is %s", "Minimum order amount is %s"
|
41 |
+
"Guest checkout is not enabled", "Guest checkout is not enabled"
|
42 |
+
"Product ID invalid", "Product ID invalid"
|
43 |
+
"Something is wrong with the order.", "Something is wrong with the order."
|
44 |
+
"Something is wrong with the quote or order.", "Something is wrong with the quote or order."
|
45 |
+
"Cart is empty.", "Cart is empty."
|
46 |
+
"Multishipping not implemented yet.", "Multishipping not implemented yet."
|
47 |
+
"Checkout method not implemented yet: ", "Checkout method not implemented yet: "
|
48 |
+
"Could not log-out customer", "Could not log-out customer"
|
49 |
+
"Please login.", "Please login."
|
50 |
+
"Country code cannot be empty", "Country code cannot be empty"
|
51 |
+
"Country does not exist: ", "Country does not exist: "
|
52 |
+
"Country does not exist", "Country does not exist"
|
53 |
+
"Store not found'", "Store not found'"
|
54 |
+
"Not allowed.", "Not allowed."
|
55 |
+
"Set store option %s not found", "Set store option %s not found"
|
56 |
+
"Set store option cannot be empty.", "Set store option cannot be empty."
|
57 |
+
"It's OK, I see it.", "It's OK, I see it."
|
58 |
+
"Product ID invalid", "Product ID invalid"
|
59 |
+
"Product not found", "Product not found"
|
60 |
+
"Please login first!", "Please login first!"
|
61 |
+
"Cannot specify product.", "Cannot specify product."
|
62 |
+
"Item not found", "Item not found"
|
63 |
+
"%1$s has been updated in your wishlist.", "%1$s has been updated in your wishlist."
|
64 |
+
"An error occurred while updating your wishlist.", "An error occurred while updating your wishlist."
|
65 |
+
"Cannot specify your wishlist item.", "Cannot specify your wishlist item."
|
66 |
+
"The product does not exist.", "The product does not exist."
|
67 |
+
"Wishlist item removed", "Wishlist item removed"
|
68 |
+
"An error occurred while deleting the item from wishlist: %s", "An error occurred while deleting the item from wishlist: %s"
|
69 |
+
"An error occurred while deleting the item from wishlist.", "An error occurred while deleting the item from wishlist."
|
70 |
+
"Can't save description %s", "Can't save description %s"
|
71 |
+
"Can't delete item from wishlist", "Can't delete item from wishlist"
|
72 |
+
"Can't save qty %s", "Can't save qty %s"
|
73 |
+
"Wishlist updated successfully", "Wishlist updated successfully"
|
74 |
+
"Can't update wishlist", "Can't update wishlist"
|
75 |
+
"No item updated", "No item updated"
|
76 |
+
"Cannot specify product", "Cannot specify product"
|
77 |
+
"%s has been added to your wishlist.", "%s has been added to your wishlist."
|
78 |
+
"An error occurred while adding item to your wishlist: %s", "An error occurred while adding item to your wishlist: %s"
|
79 |
+
"An error occurred while adding item to your wishlist", "An error occurred while adding item to your wishlist"
|
80 |
+
"Wishlist not allowed", "Wishlist not allowed"
|
81 |
+
"Wishlist doesn't exist", "Wishlist doesn't exist"
|
82 |
+
"Customer not logged in", "Customer not logged in"
|
83 |
+
"Cart is empty.", "Cart is empty."
|
84 |
+
"Coupon is not valid: ", "Coupon is not valid: "
|
85 |
+
"Coupon could not be applied.", "Coupon could not be applied."
|
86 |
+
"%s: Minimum quantity allowed for purchase is %s.", "%s: Minimum quantity allowed for purchase is %s."
|
87 |
+
"%s: Maximum quantity allowed for purchase is %s.", "%s: Maximum quantity allowed for purchase is %s."
|
88 |
+
"%s was added to your shopping cart.", "%s was added to your shopping cart."
|
89 |
+
"No cart data found.", "No cart data found."
|
90 |
+
"Your shopping cart has been updated.", "Your shopping cart has been updated."
|
91 |
+
"No bundle-product cart item ID found.", "No bundle-product cart item ID found."
|
92 |
+
"The product you are trying to delete could not be found in the cart (item id is %s not found in cart).", "The product you are trying to delete could not be found in the cart (item id is %s not found in cart)."
|
93 |
+
"The product has been deleted from your shopping cart.", "The product has been deleted from your shopping cart."
|
94 |
+
"Category not found.", "Category not found."
|
95 |
+
"Category not available.", "Category not available."
|
96 |
+
"No category found.", "No category found."
|
97 |
+
"Your search returns no results.", "Your search returns no results."
|
98 |
+
"Query cannot be empty.", "Query cannot be empty."
|
99 |
+
"Methods are not complete yet. Cart shipping address is not yet completed and saved.", "Methods are not complete yet. Cart shipping address is not yet completed and saved."
|
100 |
+
"Methods are not complete yet. Cart is empty.", "Methods are not complete yet. Cart is empty."
|
101 |
+
"Shipping method has no shipping carrier object: %s", "Shipping method has no shipping carrier object: %s"
|
102 |
+
"Carrier object has no collectRates method: %s", "Carrier object has no collectRates method: %s"
|
103 |
+
"Shipping method has no rates object: %s", "Shipping method has no rates object: %s"
|
104 |
+
"Shipping method has no getAllRates function: %s", "Shipping method has no getAllRates function: %s"
|
105 |
+
"Shipping method has no rates: %s", "Shipping method has no rates: %s"
|
106 |
+
"Shipping method can not be empty.", "Shipping method can not be empty."
|
107 |
+
"This shipping method is currently not available.", "This shipping method is currently not available."
|
108 |
+
"This shipping method is currently not available.", "This shipping method is currently not available."
|
109 |
+
"Customer shipping address not found.", "Customer shipping address not found."
|
110 |
+
"Customer shipping address email not found.", "Customer shipping address email not found."
|
111 |
+
"Customer billing address not found.", "Customer billing address not found."
|
112 |
+
"Payment method cannot be empty.", "Payment method cannot be empty."
|
113 |
+
"Email cannot be empty.", "Email cannot be empty."
|
114 |
+
"This payment method is currently not available.", "This payment method is currently not available."
|
115 |
+
"Please add ", "Please add "
|
116 |
+
"Request info not matches the order.", "Request info not matches the order."
|
117 |
+
"No payment provider to redirect found.", "No payment provider to redirect found."
|
118 |
+
"Request info does not match the quote. Probably the cart is ordered or the session is expired.", "Request info does not match the quote. Probably the cart is ordered or the session is expired."
|
119 |
+
"Cart is no longer active.", "Cart is no longer active."
|
120 |
+
"Replaced by new order.", "Replaced by new order."
|
121 |
+
"Cannot save the address: ", "Cannot save the address: "
|
122 |
+
"The address does not belong to this customer.", "The address does not belong to this customer."
|
123 |
+
"Default billing address can not be removed.", "Default billing address can not be removed."
|
124 |
+
"Default shipping address can not be removed.", "Default shipping address can not be removed."
|
125 |
+
"An error occurred while deleting the address.", "An error occurred while deleting the address."
|
126 |
+
"Address ID can not be empty.", "Address ID can not be empty."
|
127 |
+
"New password field cannot be empty.", "New password field cannot be empty."
|
128 |
+
"Invalid current password", "Invalid current password"
|
129 |
+
"The account information has been saved.", "The account information has been saved."
|
130 |
+
"Could not retrieve list: ", "Could not retrieve list: "
|
131 |
+
"Order not found (no ID).", "Order not found (no ID)."
|
132 |
+
"Invalid email address.", "Invalid email address."
|
133 |
+
"Please enter your email.", "Please enter your email."
|
134 |
+
"This account needs confirmation. See in confirmation email.", "This account needs confirmation. See in confirmation email."
|
135 |
+
"No products found.", "No products found."
|
136 |
+
"Category not found.", "Category not found."
|
137 |
+
"Cannot find customer ID, please try again!", "Cannot find customer ID, please try again!"
|
138 |
+
"Your search returns no results.", "Your search returns no results."
|
139 |
+
"You must leave at least one payment method available.", "You must leave at least one payment method available."
|
140 |
+
"You must leave at least one shipping method available.", "You must leave at least one shipping method available."
|
141 |
+
"None", "None"
|
142 |
+
"Base Image", "Base Image"
|
143 |
+
"Small Image", "Small Image"
|
144 |
+
"Thumbnail", "Thumbnail"
|
145 |
+
"Shipping Excl. Tax (%s)", "Shipping Excl. Tax (%s)"
|
146 |
+
"Shipping Incl. Tax (%s)", "Shipping Incl. Tax (%s)"
|
147 |
+
"Subtotal (Excl. Tax)", "Subtotal (Excl. Tax)"
|
148 |
+
"Subtotal (Incl. Tax)", "Subtotal (Incl. Tax)"
|
149 |
+
"Grand Total Excl. Tax", "Grand Total Excl. Tax"
|
150 |
+
"Grand Total Incl. Tax", "Grand Total Incl. Tax"
|
151 |
+
"Unable to set Payment Method.", "Unable to set Payment Method."
|
152 |
+
"Reports", "Reports"
|
153 |
+
"Order Details", "Order Details"
|
154 |
+
"Sales Reports", "Sales Reports"
|
155 |
+
"Orders Reports", "Orders Reports"
|
156 |
+
"Customers Reports", "Customers Reports"
|
157 |
+
"Connection credentials", "Connection credentials"
|
158 |
+
"Version", "Version"
|
159 |
+
"The plugin version", "The plugin version"
|
160 |
+
"User Name", "User Name"
|
161 |
+
"This username will be checked from every App while a session is set up between the App and the Magento store.", "This username will be checked from every App while a session is set up between the App and the Magento store."
|
162 |
+
"Api Key", "Api Key"
|
163 |
+
"This key will be checked from every App while a session is set up between the App and the Magento store.", "This key will be checked from every App while a session is set up between the App and the Magento store."
|
164 |
+
"Use token for Api communications", "Use token for Api communications"
|
165 |
+
"Use token will add check and refresh the token with every request.", "Use token will add check and refresh the token with every request."
|
166 |
+
"Catalogue Settings", "Catalogue Settings"
|
167 |
+
"Include all active categories", "Include all active categories"
|
168 |
+
"Include all ""Active"" categories regardless of whether or not they are included in navigation", "Include all ""Active"" categories regardless of whether or not they are included in navigation"
|
169 |
+
"Display attribute on Product Listing", "Display attribute on Product Listing"
|
170 |
+
"This attribute will be displayed in product listing", "This attribute will be displayed in product listing"
|
171 |
+
"Display attribute on Product Details", "Display attribute on Product Details"
|
172 |
+
"This attribute will be displayed in product details", "This attribute will be displayed in product details"
|
173 |
+
"Mobile App Checkout Settings", "Mobile App Checkout Settings"
|
174 |
+
"Excluded shipping methods", "Excluded shipping methods"
|
175 |
+
"Select one or more, but not all shipping methods that are not suitable/compatible to be used in mobile app environment. This can be set anytime during or after creation of JMango360 application.", "Select one or more, but not all shipping methods that are not suitable/compatible to be used in mobile app environment. This can be set anytime during or after creation of JMango360 application."
|
176 |
+
"Excluded payment methods", "Excluded payment methods"
|
177 |
+
"Select one or more, but not all payment methods that are not suitable/compatible to be used in mobile app environment. This can be set anytime during or after creation of JMango360 application.", "Select one or more, but not all payment methods that are not suitable/compatible to be used in mobile app environment. This can be set anytime during or after creation of JMango360 application."
|
178 |
+
"Web checkout URL", "Web checkout URL"
|
179 |
+
"Enter custom checkout url of website if Jmango360 plugin could not detect. Ex: checkout/onepage.", "Enter custom checkout url of website if Jmango360 plugin could not detect. Ex: checkout/onepage."
|
180 |
+
"Product image gallery settings", "Product image gallery settings"
|
181 |
+
"Detail page image cache-width", "Detail page image cache-width"
|
182 |
+
"Set the default ""cached"" size for ""big"" images on the detail pages.", "Set the default """cached"" size for ""big"" images on the detail pages."
|
183 |
+
"Detail page image cache-height", "Detail page image cache-height"
|
184 |
+
"Set the default ""cached"" size for ""big"" images on the detail pages.", "Set the default ""cached"" size for ""big"" images on the detail pages."
|
185 |
+
"Catalogue image cache-width", "Catalogue image cache-width"
|
186 |
+
"Set the default ""cached"" size for images on the catalogue pages.", "Set the default ""cached"" size for images on the catalogue pages."
|
187 |
+
"Catalogue image cache-height", "Catalogue image cache-height"
|
188 |
+
"Set the default ""cached"" size for images on the catalog pages.", "Set the default ""cached"" size for images on the catalog pages."
|
189 |
+
"Thumbnail image cache-width", "Thumbnail image cache-width"
|
190 |
+
"Set the default ""cached"" size for thumbnails on the detail pages.", "Set the default ""cached"" size for thumbnails on the detail pages."
|
191 |
+
"Thumbnail image cache-height", "Thumbnail image cache-height"
|
192 |
+
"Set the default """cached"" size for thumbnails on the detail pages.", "Set the default """cached"" size for thumbnails on the detail pages."
|
193 |
+
"Choose image type to be displayed if catalogue thumbnail is not available", "Choose image type to be displayed if catalogue thumbnail is not available"
|
194 |
+
" Choose what kind of image of product that I would like to show in catalogue listing in mobile app.", " Choose what kind of image of product that I would like to show in catalogue listing in mobile app."
|
195 |
+
"Choose image type to be displayed on catalogue page", "Choose image type to be displayed on catalogue page"
|
196 |
+
"Choose what kind of image of product that I would like to show in product listing in mobile app.", "Choose what kind of image of product that I would like to show in product listing in mobile app."
|
197 |
+
"Stock Settings", "Stock Settings"
|
198 |
+
"Display products availability in stock in mobile app", "Display products availability in stock in mobile app"
|
199 |
+
"Developer", "Developer"
|
200 |
+
"Enable debug logging", "Enable debug logging"
|
201 |
+
"Log requests to japi.log. Disable in production.", "Log requests to japi.log. Disable in production."
|
202 |
+
"Reports", "Reports"
|
203 |
+
"Orders", "Orders"
|
204 |
+
"Sales", "Sales"
|
205 |
+
"Customers", "Customers"
|
206 |
+
"Order Details", "Order Details"
|
207 |
+
"Settings", "Settings"
|
208 |
+
"Use Onepage checkout for mobile app","Use Onepage checkout for mobile app"
|
209 |
+
"Select to use JMango360 Onepage responsive web checkout for mobile app instead of default Magento checkout","Select to use JMango360 Onepage responsive web checkout for mobile app instead of default Magento checkout"
|
210 |
+
"Hide non value additional attributes","Hide non value additional attributes"
|
211 |
+
"Atrribute whose value is N/A or blank will not be displayed on Additional Infomation on product detail page","Atrribute whose value is N/A or blank will not be displayed on Additional Infomation on product detail page"
|
212 |
+
"Mobile App Login Settings","Mobile App Login Settings"
|
213 |
+
"App users must login to see product prices","App users must login to see product prices"
|
214 |
+
"This will prevent mobile app user using app without an account.","This will prevent mobile app user using app without an account."
|
215 |
+
"Discount Codes","Discount Codes"
|
216 |
+
"Enter your coupon code if you have one.","Enter your coupon code if you have one."
|
217 |
+
"Apply Coupon","Apply Coupon"
|
218 |
+
"Cancel Coupon","Cancel Coupon"
|
219 |
+
"Enable Order From in orders list","Enable Order From in orders list"
|
220 |
+
"Select
|