Version Notes
Product caching added to load product more faster.
Download this release
Release Info
Developer | mss |
Extension | Mss_Connector |
Version | 1.4.5 |
Comparing to | |
See all releases |
Version 1.4.5
- app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Edit.php +29 -0
- app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Edit/Form.php +21 -0
- app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Edit/Tab/Form.php +97 -0
- app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Edit/Tabs.php +24 -0
- app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Grid.php +53 -0
- app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Helper/Image.php +14 -0
- app/code/local/Mss/Bannerslider/Block/Adminhtml/Grid.php +12 -0
- app/code/local/Mss/Bannerslider/Block/Adminhtml/Renderer/Image.php +15 -0
- app/code/local/Mss/Bannerslider/Helper/Data.php +67 -0
- app/code/local/Mss/Bannerslider/Model/Bannerslider.php +12 -0
- app/code/local/Mss/Bannerslider/Model/Mysql4/Bannerslider.php +8 -0
- app/code/local/Mss/Bannerslider/Model/Mysql4/Bannerslider/Collection.php +13 -0
- app/code/local/Mss/Bannerslider/Model/Observer.php +6 -0
- app/code/local/Mss/Bannerslider/controllers/Adminhtml/BannersliderController.php +203 -0
- app/code/local/Mss/Bannerslider/controllers/BannerController.php +61 -0
- app/code/local/Mss/Bannerslider/etc/adminhtml.xml +15 -0
- app/code/local/Mss/Bannerslider/etc/config.xml +89 -0
- app/code/local/Mss/Bannerslider/sql/bannerslider_setup/mysql4-install-0.1.0.php +21 -0
- app/code/local/Mss/Connector/Block/Adminhtml/Notifications.php +22 -0
- app/code/local/Mss/Connector/Block/System/Config/About.php +14 -0
- app/code/local/Mss/Connector/Block/System/Config/Authorizenet.php +15 -0
- app/code/local/Mss/Connector/Block/System/Config/Banktransfer.php +15 -0
- app/code/local/Mss/Connector/Block/System/Config/Checkmo.php +15 -0
- app/code/local/Mss/Connector/Block/System/Config/Cod.php +15 -0
- app/code/local/Mss/Connector/Block/System/Config/Mpaypal.php +16 -0
- app/code/local/Mss/Connector/Block/System/Config/Payu.php +19 -0
- app/code/local/Mss/Connector/Helper/Data.php +197 -0
- app/code/local/Mss/Connector/Model/Connector.php +10 -0
- app/code/local/Mss/Connector/Model/Mysql4/Connector.php +10 -0
- app/code/local/Mss/Connector/Model/Mysql4/Connector/Collection.php +10 -0
- app/code/local/Mss/Connector/Model/Observer.php +67 -0
- app/code/local/Mss/Connector/controllers/CartController.php +1394 -0
- app/code/local/Mss/Connector/controllers/CreditController.php +143 -0
- app/code/local/Mss/Connector/controllers/CustomerController.php +802 -0
- app/code/local/Mss/Connector/controllers/FeedbackController.php +37 -0
- app/code/local/Mss/Connector/controllers/IndexController.php +753 -0
- app/code/local/Mss/Connector/controllers/ItemController.php +798 -0
- app/code/local/Mss/Connector/controllers/ItemsController.php +398 -0
- app/code/local/Mss/Connector/controllers/MenuController.php +98 -0
- app/code/local/Mss/Connector/controllers/ProductsController.php +594 -0
- app/code/local/Mss/Connector/controllers/SearchController.php +200 -0
- app/code/local/Mss/Connector/controllers/StaticpagesController.php +76 -0
- app/code/local/Mss/Connector/controllers/StoreController.php +61 -0
- app/code/local/Mss/Connector/controllers/StoreinfoController.php +69 -0
- app/code/local/Mss/Connector/controllers/TokenController.php +189 -0
- app/code/local/Mss/Connector/controllers/WishlistController.php +182 -0
- app/code/local/Mss/Connector/controllers/_new_ProductsController.php +1 -0
- app/code/local/Mss/Connector/etc/adminhtml.xml +43 -0
- app/code/local/Mss/Connector/etc/config.xml +93 -0
- app/code/local/Mss/Connector/etc/system.xml +427 -0
- app/code/local/Mss/Connector/sql/connector_setup/mysql4-install-0.1.0.php +21 -0
- app/code/local/Mss/Connector/sql/connector_setup/mysql4-upgrade-0.1.0-0.1.1.php +26 -0
- app/code/local/Mss/Mpaypal/Helper/Data.php +5 -0
- app/code/local/Mss/Mpaypal/Model/Mpaypal.php +8 -0
- app/code/local/Mss/Mpaypal/Model/Observer.php +21 -0
- app/code/local/Mss/Mpaypal/controllers/IndexController.php +126 -0
- app/code/local/Mss/Mpaypal/etc/config.xml +70 -0
- app/code/local/Mss/Mpaypal/etc/system.xml +46 -0
- app/code/local/Mss/Payu/Block/Index.php +10 -0
- app/code/local/Mss/Payu/Helper/Data.php +5 -0
- app/code/local/Mss/Payu/controllers/IndexController.php +89 -0
- app/code/local/Mss/Payu/etc/config.xml +38 -0
- app/code/local/Mss/Pushnotification/Block/Adminhtml/Pushnotificationbackend.php +5 -0
- app/code/local/Mss/Pushnotification/Helper/Data.php +182 -0
- app/code/local/Mss/Pushnotification/Model/Entity/Resource.php +24 -0
- app/code/local/Mss/Pushnotification/Model/Mysql4/Pushnotification.php +10 -0
- app/code/local/Mss/Pushnotification/Model/Mysql4/Pushnotification/Collection.php +10 -0
- app/code/local/Mss/Pushnotification/Model/Pushnotification.php +10 -0
- app/code/local/Mss/Pushnotification/Model/System/Config/Backend/File.php +13 -0
- app/code/local/Mss/Pushnotification/Model/System/Config/Backend/Image.php +10 -0
- app/code/local/Mss/Pushnotification/Model/System/Config/Backend/Iosmode.php +60 -0
- app/code/local/Mss/Pushnotification/controllers/Adminhtml/PushnotificationbackendController.php +18 -0
- app/code/local/Mss/Pushnotification/etc/config.xml +133 -0
- app/code/local/Mss/Pushnotification/etc/system.xml +173 -0
- app/code/local/Mss/Pushnotification/sql/pushnotification_setup/mysql4-upgrade-0.1.5-0.1.6.php +67 -0
- app/code/local/Mss/Sociallogin/Helper/Data.php +140 -0
- app/code/local/Mss/Sociallogin/Model/Mysql4/Sociallogin.php +10 -0
- app/code/local/Mss/Sociallogin/Model/Sociallogin.php +10 -0
- app/code/local/Mss/Sociallogin/etc/config.xml +47 -0
- app/code/local/Mss/Sociallogin/sql/sociallogin_setup/mysql4-install-0.1.0.php +51 -0
- app/design/adminhtml/default/default/layout/bannerslider.xml +8 -0
- app/design/adminhtml/default/default/layout/connector.xml +8 -0
- app/design/adminhtml/default/default/layout/pushnotification.xml +8 -0
- app/design/adminhtml/default/default/template/connector/notification.phtml +3 -0
- app/design/adminhtml/default/default/template/pushnotification/pushnotificationbackend.phtml +58 -0
- app/design/frontend/base/default/layout/mpaypal.xml +13 -0
- app/design/frontend/base/default/layout/payu.xml +13 -0
- app/design/frontend/base/default/template/mpaypal/index.phtml +117 -0
- app/design/frontend/base/default/template/payu/index.phtml +265 -0
- app/design/frontend/base/default/template/payu/test.phtml +10 -0
- app/etc/modules/Mss_Bannerslider.xml +30 -0
- app/etc/modules/Mss_Connector.xml +9 -0
- app/etc/modules/Mss_Mpaypal.xml +13 -0
- app/etc/modules/Mss_Payu.xml +10 -0
- app/etc/modules/Mss_Pushnotification.xml +10 -0
- app/etc/modules/Mss_Sociallogin.xml +10 -0
- package.xml +18 -0
- skin/frontend/base/default/images/magentomobileshop/magentomobileshop_loader.gif +0 -0
app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Edit.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Bannerslider_Block_Adminhtml_Bannerslider_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
|
4 |
+
{
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
parent::__construct();
|
8 |
+
|
9 |
+
$this->_objectId = 'id';
|
10 |
+
$this->_blockGroup = 'bannerslider';
|
11 |
+
$this->_controller = 'adminhtml_bannerslider';
|
12 |
+
|
13 |
+
$this->_updateButton('save', 'label', Mage::helper('bannerslider')->__('Save Banner'));
|
14 |
+
$this->_updateButton('delete', 'label', Mage::helper('bannerslider')->__('Delete Banner'));
|
15 |
+
|
16 |
+
|
17 |
+
}
|
18 |
+
|
19 |
+
public function getHeaderText()
|
20 |
+
{
|
21 |
+
if( Mage::registry('banner_data') && Mage::registry('banner_data')->getId() ) {
|
22 |
+
return Mage::helper('bannerslider')->__("Edit Banner '%s'", $this->htmlEscape(Mage::registry('banner_data')->getName()));
|
23 |
+
} else {
|
24 |
+
return Mage::helper('bannerslider')->__('Add Banner');
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
}
|
app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Edit/Form.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Bannerslider_Block_Adminhtml_Bannerslider_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
|
4 |
+
{
|
5 |
+
protected function _prepareForm()
|
6 |
+
{
|
7 |
+
$form = new Varien_Data_Form(array(
|
8 |
+
'id' => 'edit_form',
|
9 |
+
'action' => $this->getUrl('*/*/save',
|
10 |
+
array('id' => $this->getRequest()->getParam('id')
|
11 |
+
)),
|
12 |
+
'method' => 'post',
|
13 |
+
'enctype' => 'multipart/form-data'
|
14 |
+
)
|
15 |
+
);
|
16 |
+
|
17 |
+
$form->setUseContainer(true);
|
18 |
+
$this->setForm($form);
|
19 |
+
return parent::_prepareForm();
|
20 |
+
}
|
21 |
+
}
|
app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Edit/Tab/Form.php
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Bannerslider_Block_Adminhtml_Bannerslider_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {
|
4 |
+
|
5 |
+
protected function _prepareForm() {
|
6 |
+
$form = new Varien_Data_Form();
|
7 |
+
$this->setForm($form);
|
8 |
+
$fieldset = $form->addFieldset('banner_form',
|
9 |
+
array('legend'=>'Banner Information'));
|
10 |
+
$fieldset->addField('name', 'text',
|
11 |
+
array(
|
12 |
+
'label' => Mage::helper('bannerslider')->__('Title'),
|
13 |
+
'class' => 'required-entry',
|
14 |
+
'required' => true,
|
15 |
+
'name' => 'name',
|
16 |
+
));
|
17 |
+
$fieldset->addType('thumbnail','Mss_Bannerslider_Block_Adminhtml_Bannerslider_Helper_Image');
|
18 |
+
|
19 |
+
$fieldset->addField('image', 'thumbnail', array(
|
20 |
+
'label' => Mage::helper('bannerslider')->__('Image'),
|
21 |
+
'required' => true,
|
22 |
+
'name' => 'image',
|
23 |
+
));
|
24 |
+
$fieldset->addField('image_alt', 'textarea',
|
25 |
+
array(
|
26 |
+
'label' => Mage::helper('bannerslider')->__('Description'),
|
27 |
+
|
28 |
+
|
29 |
+
'name' => 'image_alt',
|
30 |
+
));
|
31 |
+
$fieldset->addField('order_banner', 'text',
|
32 |
+
array(
|
33 |
+
'label' => Mage::helper('bannerslider')->__('Order'),
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
'name' => 'order_banner',
|
38 |
+
));
|
39 |
+
$fieldset->addField('url_type', 'select',
|
40 |
+
array(
|
41 |
+
'label' => Mage::helper('bannerslider')->__('Link With Type'),
|
42 |
+
'values' => array(
|
43 |
+
|
44 |
+
|
45 |
+
array(
|
46 |
+
'value' => 'Category',
|
47 |
+
'label' => Mage::helper('core')->__('Category'),
|
48 |
+
),
|
49 |
+
array(
|
50 |
+
'value' => 'Product',
|
51 |
+
'label' => Mage::helper('core')->__('Product'),
|
52 |
+
),
|
53 |
+
),
|
54 |
+
|
55 |
+
'name' => 'url_type',
|
56 |
+
));
|
57 |
+
|
58 |
+
$fieldset->addField('product_id', 'text',
|
59 |
+
array(
|
60 |
+
'label' => Mage::helper('bannerslider')->__('Product Id to Display'),
|
61 |
+
|
62 |
+
|
63 |
+
'name' => 'product_id',
|
64 |
+
));
|
65 |
+
$fieldset->addField('category_id', 'text',
|
66 |
+
array(
|
67 |
+
'label' => Mage::helper('bannerslider')->__('Category Id to Display'),
|
68 |
+
|
69 |
+
|
70 |
+
'name' => 'category_id',
|
71 |
+
));
|
72 |
+
$fieldset->addField('status', 'select',
|
73 |
+
array(
|
74 |
+
'label' => Mage::helper('bannerslider')->__('Status'),
|
75 |
+
|
76 |
+
'values' => array(
|
77 |
+
|
78 |
+
|
79 |
+
array(
|
80 |
+
'value' => 0,
|
81 |
+
'label' => Mage::helper('core')->__('Disable'),
|
82 |
+
),
|
83 |
+
array(
|
84 |
+
'value' => 1,
|
85 |
+
'label' => Mage::helper('core')->__('Enable'),
|
86 |
+
),
|
87 |
+
),
|
88 |
+
'name' => 'status',
|
89 |
+
));
|
90 |
+
|
91 |
+
if ( Mage::registry('banner_data') )
|
92 |
+
{
|
93 |
+
$form->setValues(Mage::registry('banner_data')->getData());
|
94 |
+
}
|
95 |
+
return parent::_prepareForm();
|
96 |
+
}
|
97 |
+
}
|
app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Edit/Tabs.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Bannerslider_Block_Adminhtml_Bannerslider_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
|
4 |
+
{
|
5 |
+
|
6 |
+
public function __construct()
|
7 |
+
{
|
8 |
+
parent::__construct();
|
9 |
+
$this->setId('banner_tabs');
|
10 |
+
$this->setDestElementId('edit_form');
|
11 |
+
$this->setTitle(Mage::helper('bannerslider')->__('Banner Manager'));
|
12 |
+
}
|
13 |
+
|
14 |
+
protected function _beforeToHtml()
|
15 |
+
{
|
16 |
+
$this->addTab('form_section', array(
|
17 |
+
'label' => Mage::helper('bannerslider')->__('Banner Information'),
|
18 |
+
'title' => Mage::helper('bannerslider')->__('Banner Information'),
|
19 |
+
'content' => $this->getLayout()->createBlock('bannerslider/adminhtml_bannerslider_edit_tab_form')->toHtml(),
|
20 |
+
));
|
21 |
+
|
22 |
+
return parent::_beforeToHtml();
|
23 |
+
}
|
24 |
+
}
|
app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Grid.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Bannerslider_Block_Adminhtml_Bannerslider_Grid extends Mage_Adminhtml_Block_Widget_Grid {
|
4 |
+
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
parent::__construct();
|
8 |
+
$this->setId('bannerGrid');
|
9 |
+
$this->setDefaultSort('banner_id');
|
10 |
+
$this->setDefaultDir('ASC');
|
11 |
+
$this->setSaveParametersInSession(true);
|
12 |
+
|
13 |
+
}
|
14 |
+
protected function _prepareCollection()
|
15 |
+
{
|
16 |
+
$collection = Mage::getModel('bannerslider/bannerslider')->getCollection();
|
17 |
+
$this->setCollection($collection);
|
18 |
+
return parent::_prepareCollection();
|
19 |
+
}
|
20 |
+
protected function _prepareColumns()
|
21 |
+
{
|
22 |
+
$this->addColumn('banner_id',
|
23 |
+
array(
|
24 |
+
'header' => 'ID',
|
25 |
+
'align' =>'right',
|
26 |
+
'width' => '50px',
|
27 |
+
'index' => 'banner_id',
|
28 |
+
));
|
29 |
+
$this->addColumn('name',
|
30 |
+
array(
|
31 |
+
'header' => 'Name',
|
32 |
+
'align' =>'left',
|
33 |
+
'index' => 'name',
|
34 |
+
));
|
35 |
+
$this->addColumn('url_type', array(
|
36 |
+
'header' => 'Link Type',
|
37 |
+
'align' =>'left',
|
38 |
+
'index' => 'url_type',
|
39 |
+
));
|
40 |
+
$this->addColumn('image', array(
|
41 |
+
'header' => 'Image',
|
42 |
+
'align' =>'left',
|
43 |
+
'index' => 'image',
|
44 |
+
'renderer' => 'Mss_Bannerslider_Block_Adminhtml_Renderer_Image',
|
45 |
+
));
|
46 |
+
return parent::_prepareColumns();
|
47 |
+
}
|
48 |
+
public function getRowUrl($row)
|
49 |
+
{
|
50 |
+
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
|
51 |
+
}
|
52 |
+
|
53 |
+
}
|
app/code/local/Mss/Bannerslider/Block/Adminhtml/Bannerslider/Helper/Image.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class Mss_Bannerslider_Block_Adminhtml_Bannerslider_Helper_Image
|
5 |
+
extends Varien_Data_Form_Element_Image {
|
6 |
+
protected function _getUrl(){
|
7 |
+
$url = false;
|
8 |
+
if ($this->getValue()) {
|
9 |
+
$path = Mage::helper('bannerslider')->reImageName($this->getValue());
|
10 |
+
$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)."media/bannerslider/".$path;
|
11 |
+
}
|
12 |
+
return $url;
|
13 |
+
}
|
14 |
+
}
|
app/code/local/Mss/Bannerslider/Block/Adminhtml/Grid.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Bannerslider_Block_Adminhtml_Grid extends Mage_Adminhtml_Block_Widget_Grid_Container
|
3 |
+
{
|
4 |
+
public function __construct()
|
5 |
+
{
|
6 |
+
$this->_controller = 'adminhtml_bannerslider';
|
7 |
+
$this->_blockGroup = 'bannerslider';
|
8 |
+
$this->_headerText = Mage::helper('bannerslider')->__('Banner Manager');
|
9 |
+
$this->_addButtonLabel = Mage::helper('bannerslider')->__('Add Banner');
|
10 |
+
parent::__construct();
|
11 |
+
}
|
12 |
+
}
|
app/code/local/Mss/Bannerslider/Block/Adminhtml/Renderer/Image.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php class Mss_Bannerslider_Block_Adminhtml_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
|
2 |
+
{
|
3 |
+
public function render(Varien_Object $row)
|
4 |
+
{
|
5 |
+
|
6 |
+
if($row->getData('image') != NULL)
|
7 |
+
{
|
8 |
+
$image=$row->getData('image');
|
9 |
+
$path = Mage::helper('bannerslider')->reImageName($image);
|
10 |
+
return '<img src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'media/bannerslider/'.$path.'" width="100px" alt="brandlogo"/>';
|
11 |
+
}
|
12 |
+
}
|
13 |
+
|
14 |
+
|
15 |
+
}
|
app/code/local/Mss/Bannerslider/Helper/Data.php
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Bannerslider_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
|
5 |
+
public function deleteImageFile($image) {
|
6 |
+
if (!$image) {
|
7 |
+
return;
|
8 |
+
}
|
9 |
+
$name = $this->reImageName($image);
|
10 |
+
$banner_image_path = Mage::getBaseDir() . '/media/bannerslider/' . $name;
|
11 |
+
if (!file_exists($banner_image_path)) {
|
12 |
+
return;
|
13 |
+
}
|
14 |
+
|
15 |
+
try {
|
16 |
+
unlink($banner_image_path);
|
17 |
+
} catch (Exception $exc) {
|
18 |
+
echo $exc->getTraceAsString();
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
public static function uploadBannerImage() {
|
23 |
+
$banner_image_path = Mage::getBaseDir() . '/media/bannerslider/';
|
24 |
+
$image = "";
|
25 |
+
$image_resolution = getimagesize($_FILES['image']['tmp_name']);
|
26 |
+
|
27 |
+
if($image_resolution['0'] != '640' && $image_resolution['1'] != '320'):
|
28 |
+
Mage::getSingleton('core/session')->addError('Banner Image resolution is incorrect, please upload image of resolution 640X320 px. ');
|
29 |
+
$image = false;
|
30 |
+
else:
|
31 |
+
if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') {
|
32 |
+
try {
|
33 |
+
/* Starting upload */
|
34 |
+
$uploader = new Varien_File_Uploader('image');
|
35 |
+
|
36 |
+
// Any extention would work
|
37 |
+
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
|
38 |
+
$uploader->setAllowRenameFiles(false);
|
39 |
+
|
40 |
+
$uploader->setFilesDispersion(true);
|
41 |
+
|
42 |
+
$uploader->save($banner_image_path, $_FILES['image']['name']);
|
43 |
+
|
44 |
+
} catch (Exception $e) {
|
45 |
+
|
46 |
+
}
|
47 |
+
|
48 |
+
$image = $_FILES['image']['name'];
|
49 |
+
}
|
50 |
+
endif;
|
51 |
+
return $image;
|
52 |
+
}
|
53 |
+
|
54 |
+
public function reImageName($imageName) {
|
55 |
+
|
56 |
+
$subname = substr($imageName, 0, 2);
|
57 |
+
$array = array();
|
58 |
+
$subDir1 = substr($subname, 0, 1);
|
59 |
+
$subDir2 = substr($subname, 1, 1);
|
60 |
+
$array[0] = $subDir1;
|
61 |
+
$array[1] = $subDir2;
|
62 |
+
$name = $array[0] . '/' . $array[1] . '/' . $imageName;
|
63 |
+
|
64 |
+
return strtolower($name);
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
app/code/local/Mss/Bannerslider/Model/Bannerslider.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Bannerslider_Model_Bannerslider extends Mage_Core_Model_Abstract
|
4 |
+
{
|
5 |
+
protected function _construct(){
|
6 |
+
|
7 |
+
$this->_init("bannerslider/bannerslider");
|
8 |
+
|
9 |
+
}
|
10 |
+
|
11 |
+
}
|
12 |
+
|
app/code/local/Mss/Bannerslider/Model/Mysql4/Bannerslider.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Bannerslider_Model_Mysql4_Bannerslider extends Mage_Core_Model_Mysql4_Abstract
|
3 |
+
{
|
4 |
+
protected function _construct()
|
5 |
+
{
|
6 |
+
$this->_init("bannerslider/bannerslider", "banner_id");
|
7 |
+
}
|
8 |
+
}
|
app/code/local/Mss/Bannerslider/Model/Mysql4/Bannerslider/Collection.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Bannerslider_Model_Mysql4_Bannerslider_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
3 |
+
{
|
4 |
+
|
5 |
+
public function _construct(){
|
6 |
+
parent::_construct();
|
7 |
+
$this->_init("bannerslider/bannerslider");
|
8 |
+
}
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
}
|
13 |
+
|
app/code/local/Mss/Bannerslider/Model/Observer.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Bannerslider_Model_Observer
|
3 |
+
{
|
4 |
+
|
5 |
+
|
6 |
+
}
|
app/code/local/Mss/Bannerslider/controllers/Adminhtml/BannersliderController.php
ADDED
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class Mss_Bannerslider_Adminhtml_BannersliderController extends Mage_Adminhtml_Controller_Action {
|
5 |
+
|
6 |
+
/**
|
7 |
+
* init layout and set active for current menu
|
8 |
+
*
|
9 |
+
* @return Mss_Bannerslider_Adminhtml_BannersliderController
|
10 |
+
*/
|
11 |
+
protected function _initAction() {
|
12 |
+
$this->loadLayout()
|
13 |
+
->_setActiveMenu('bannerslider/bannerslider')
|
14 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
15 |
+
return $this;
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* index action
|
20 |
+
*/
|
21 |
+
public function indexAction() {
|
22 |
+
$this->_initAction()
|
23 |
+
->renderLayout();
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* view and edit item action
|
28 |
+
*/
|
29 |
+
public function editAction() {
|
30 |
+
$id = $this->getRequest()->getParam('id');
|
31 |
+
$store = $this->getRequest()->getParam('store');
|
32 |
+
$model = Mage::getModel('bannerslider/bannerslider')->setStoreId($store)->load($id);
|
33 |
+
|
34 |
+
if ($model->getId() || $id == 0) {
|
35 |
+
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
|
36 |
+
if (!empty($data))
|
37 |
+
$model->setData($data);
|
38 |
+
|
39 |
+
Mage::register('banner_data', $model);
|
40 |
+
|
41 |
+
$this->loadLayout();
|
42 |
+
$this->_setActiveMenu('bannerslider/bannerslider');
|
43 |
+
|
44 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
45 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
46 |
+
|
47 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
48 |
+
$this->_addContent($this->getLayout()->createBlock('bannerslider/adminhtml_bannerslider_edit'))
|
49 |
+
->_addLeft($this->getLayout()->createBlock('bannerslider/adminhtml_bannerslider_edit_tabs'));
|
50 |
+
|
51 |
+
$this->renderLayout();
|
52 |
+
} else {
|
53 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('bannerslider')->__('Item does not exist'));
|
54 |
+
$this->_redirect('*/*/');
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
public function newAction() {
|
59 |
+
$this->_forward('edit');
|
60 |
+
}
|
61 |
+
|
62 |
+
public function addinAction() {
|
63 |
+
$this->loadLayout();
|
64 |
+
$this->_setActiveMenu('bannerslider/bannerslider');
|
65 |
+
|
66 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
67 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
68 |
+
|
69 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
70 |
+
|
71 |
+
$this->_addContent($this->getLayout()->createBlock('bannerslider/adminhtml_addbutton')->setTemplate('bannerslider/addbanner.phtml'));
|
72 |
+
|
73 |
+
$this->renderLayout();
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* save item action
|
78 |
+
*/
|
79 |
+
public function saveAction() {
|
80 |
+
if ($data = $this->getRequest()->getPost()) {
|
81 |
+
|
82 |
+
$model = Mage::getModel('bannerslider/bannerslider');
|
83 |
+
if (isset($data['image']['delete'])) {
|
84 |
+
Mage::helper('bannerslider')->deleteImageFile($data['image']['value']);
|
85 |
+
}
|
86 |
+
$image = Mage::helper('bannerslider')->uploadBannerImage();
|
87 |
+
|
88 |
+
if(!$image):
|
89 |
+
|
90 |
+
$this->_redirect('*/*/new', array('page_key' => 'collection'));
|
91 |
+
return;
|
92 |
+
endif;
|
93 |
+
|
94 |
+
if ($image || (isset($data['image']['delete']) && $data['image']['delete'])) {
|
95 |
+
$data['image'] = $image;
|
96 |
+
} else {
|
97 |
+
unset($data['image']);
|
98 |
+
}
|
99 |
+
|
100 |
+
$model->setOrderBanner("7");
|
101 |
+
$model->setData($data)
|
102 |
+
->setData('banner_id', $this->getRequest()->getParam('id'));
|
103 |
+
try {
|
104 |
+
|
105 |
+
|
106 |
+
$model->save();
|
107 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('bannerslider')->__('Banner was successfully saved'));
|
108 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
109 |
+
//Zend_debug::dump($this->getRequest()->getParam('slider'));die();
|
110 |
+
if($this->getRequest()->getParam('slider') == 'check'){
|
111 |
+
$this->_redirect('*/*/addin', array('id' => $model->getId()));
|
112 |
+
return;
|
113 |
+
}
|
114 |
+
if ($this->getRequest()->getParam('back')) {
|
115 |
+
$this->_redirect('*/*/edit', array('id' => $model->getId(), 'store' => $this->getRequest()->getParam("store")));
|
116 |
+
return;
|
117 |
+
}
|
118 |
+
$this->_redirect('*/*/');
|
119 |
+
return;
|
120 |
+
} catch (Exception $e) {
|
121 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
122 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
123 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
124 |
+
return;
|
125 |
+
}
|
126 |
+
}
|
127 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('bannerslider')->__('Unable to find banner to save'));
|
128 |
+
$this->_redirect('*/*/');
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* delete item action
|
133 |
+
*/
|
134 |
+
public function deleteAction() {
|
135 |
+
if ($this->getRequest()->getParam('id') > 0) {
|
136 |
+
try {
|
137 |
+
$model = Mage::getModel('bannerslider/bannerslider');
|
138 |
+
$model->setId($this->getRequest()->getParam('id'))
|
139 |
+
->delete();
|
140 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Banner was successfully deleted'));
|
141 |
+
$this->_redirect('*/*/');
|
142 |
+
} catch (Exception $e) {
|
143 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
144 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'), 'store' => $this->getRequest()->getParam("store")));
|
145 |
+
}
|
146 |
+
}
|
147 |
+
$this->_redirect('*/*/');
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* mass delete item(s) action
|
152 |
+
*/
|
153 |
+
public function massDeleteAction() {
|
154 |
+
$bannersliderIds = $this->getRequest()->getParam('banner');
|
155 |
+
if (!is_array($bannersliderIds)) {
|
156 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
|
157 |
+
} else {
|
158 |
+
try {
|
159 |
+
foreach ($bannersliderIds as $bannersliderId) {
|
160 |
+
$bannerslider = Mage::getModel('bannerslider/bannerslider')->load($bannersliderId);
|
161 |
+
$bannerslider->delete();
|
162 |
+
}
|
163 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Total of %d record(s) were successfully deleted', count($bannersliderIds)));
|
164 |
+
} catch (Exception $e) {
|
165 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
166 |
+
}
|
167 |
+
}
|
168 |
+
$this->_redirect('*/*/index', array('store' => $this->getRequest()->getParam("store")));
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* mass change status for item(s) action
|
173 |
+
*/
|
174 |
+
public function massStatusAction() {
|
175 |
+
$bannerIds = $this->getRequest()->getParam('banner');
|
176 |
+
if (!is_array($bannerIds)) {
|
177 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
|
178 |
+
} else {
|
179 |
+
try {
|
180 |
+
foreach ($bannerIds as $bannerId) {
|
181 |
+
$banner = Mage::getSingleton('bannerslider/bannerslider')
|
182 |
+
->load($bannerId)
|
183 |
+
->setStatus($this->getRequest()->getParam('status'))
|
184 |
+
->setIsMassupdate(true)
|
185 |
+
->save();
|
186 |
+
}
|
187 |
+
$this->_getSession()->addSuccess(
|
188 |
+
$this->__('Total of %d record(s) were successfully updated', count($bannerIds))
|
189 |
+
);
|
190 |
+
} catch (Exception $e) {
|
191 |
+
$this->_getSession()->addError($e->getMessage());
|
192 |
+
}
|
193 |
+
}
|
194 |
+
$this->_redirect('*/*/index', array('store' => $this->getRequest()->getParam("store")));
|
195 |
+
}
|
196 |
+
|
197 |
+
|
198 |
+
|
199 |
+
protected function _isAllowed() {
|
200 |
+
return Mage::getSingleton('admin/session')->isAllowed('banner');
|
201 |
+
}
|
202 |
+
|
203 |
+
}
|
app/code/local/Mss/Bannerslider/controllers/BannerController.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Bannerslider_BannerController extends Mage_Core_Controller_Front_Action {
|
4 |
+
|
5 |
+
private $key = 'bannerslider';
|
6 |
+
private $store = '1';
|
7 |
+
|
8 |
+
public function _construct(){
|
9 |
+
|
10 |
+
header('content-type: application/json; charset=utf-8');
|
11 |
+
header("access-control-allow-origin: *");
|
12 |
+
|
13 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
14 |
+
parent::_construct();
|
15 |
+
|
16 |
+
}
|
17 |
+
|
18 |
+
public function bannerAction(){
|
19 |
+
$bannerCollection = Mage::getModel('bannerslider/bannerslider')->getCollection();
|
20 |
+
$bannerCollection->addFieldToFilter( 'status', '1' );
|
21 |
+
|
22 |
+
/*check for cache*/
|
23 |
+
Mage::helper('connector')->checkcache($this->key,$this->store);
|
24 |
+
|
25 |
+
$alldata = array();
|
26 |
+
foreach($bannerCollection->getData() as $bannerdata){
|
27 |
+
|
28 |
+
|
29 |
+
$path = Mage::helper('bannerslider')->reImageName( $bannerdata['image']);
|
30 |
+
|
31 |
+
$imgeurl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'media/bannerslider/'.$path;
|
32 |
+
|
33 |
+
$data['name'] = $bannerdata['name'];
|
34 |
+
|
35 |
+
$data['image_description'] = $bannerdata['image_alt'];
|
36 |
+
$data['image_url'] = $imgeurl;
|
37 |
+
$data['category_name'] = Mage::getModel('catalog/category')->load($bannerdata['category_id'])->getName();
|
38 |
+
$data['link_type'] = $bannerdata['url_type'];
|
39 |
+
$data['product_id'] = $bannerdata['product_id'];
|
40 |
+
$data['category_id'] = $bannerdata['category_id'];
|
41 |
+
|
42 |
+
$alldata[] = $data;
|
43 |
+
|
44 |
+
}
|
45 |
+
if(Mage::getStoreConfig('mss/connector/email') != '1'):
|
46 |
+
$event_data_array = array(true);
|
47 |
+
Mage::dispatchEvent('send_email_store_data', $event_data_array);
|
48 |
+
endif;
|
49 |
+
|
50 |
+
if(sizeof($alldata)):
|
51 |
+
/*create new cache*/
|
52 |
+
Mage::helper('connector')->createNewcache($this->key,$this->store,json_encode(array('status'=>'success','data'=>$alldata)));
|
53 |
+
echo json_encode(array('status'=>'success','data'=>$alldata));
|
54 |
+
exit;
|
55 |
+
else:
|
56 |
+
echo json_encode(array('status'=>'error','message'=>'No banner uploaded'));
|
57 |
+
endif;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
?>
|
app/code/local/Mss/Bannerslider/etc/adminhtml.xml
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<config>
|
4 |
+
<menu>
|
5 |
+
<connector>
|
6 |
+
<children>
|
7 |
+
<banner module="bannerslider" translate="title">
|
8 |
+
<title>Manage Banners</title>
|
9 |
+
<sort_order>2</sort_order>
|
10 |
+
<action>admin_bannerslider/adminhtml_bannerslider</action>
|
11 |
+
</banner>
|
12 |
+
</children>
|
13 |
+
</connector>
|
14 |
+
</menu>
|
15 |
+
</config>
|
app/code/local/Mss/Bannerslider/etc/config.xml
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Bannerslider>
|
5 |
+
<version>0.1.0</version>
|
6 |
+
</Mss_Bannerslider>
|
7 |
+
</modules>
|
8 |
+
|
9 |
+
<frontend>
|
10 |
+
<routers>
|
11 |
+
<bannerslider>
|
12 |
+
<use>standard</use>
|
13 |
+
<args>
|
14 |
+
<module>Mss_Bannerslider</module>
|
15 |
+
<frontName>bannerslider</frontName>
|
16 |
+
</args>
|
17 |
+
</bannerslider>
|
18 |
+
</routers>
|
19 |
+
</frontend>
|
20 |
+
|
21 |
+
<global>
|
22 |
+
<helpers>
|
23 |
+
<bannerslider>
|
24 |
+
<class>Mss_Bannerslider_Helper</class>
|
25 |
+
</bannerslider>
|
26 |
+
|
27 |
+
</helpers>
|
28 |
+
<blocks>
|
29 |
+
<bannerslider>
|
30 |
+
<class>Mss_Bannerslider_Block</class>
|
31 |
+
</bannerslider>
|
32 |
+
</blocks>
|
33 |
+
<models>
|
34 |
+
<bannerslider>
|
35 |
+
<class>Mss_Bannerslider_Model</class>
|
36 |
+
<resourceModel>bannerslider_mysql4</resourceModel>
|
37 |
+
</bannerslider>
|
38 |
+
<bannerslider_mysql4>
|
39 |
+
<class>Mss_Bannerslider_Model_Mysql4</class>
|
40 |
+
<entities>
|
41 |
+
<bannerslider>
|
42 |
+
<table>magentomobile_bannerslider</table>
|
43 |
+
</bannerslider>
|
44 |
+
</entities>
|
45 |
+
</bannerslider_mysql4>
|
46 |
+
</models>
|
47 |
+
<resources>
|
48 |
+
<bannerslider_setup>
|
49 |
+
<setup>
|
50 |
+
<module>Mss_Bannerslider</module>
|
51 |
+
</setup>
|
52 |
+
<connection>
|
53 |
+
<use>core_setup</use>
|
54 |
+
</connection>
|
55 |
+
</bannerslider_setup>
|
56 |
+
<bannerslider_write>
|
57 |
+
<connection>
|
58 |
+
<use>core_write</use>
|
59 |
+
</connection>
|
60 |
+
</bannerslider_write>
|
61 |
+
<bannerslider_read>
|
62 |
+
<connection>
|
63 |
+
<use>core_read</use>
|
64 |
+
</connection>
|
65 |
+
</bannerslider_read>
|
66 |
+
</resources>
|
67 |
+
|
68 |
+
</global>
|
69 |
+
<admin>
|
70 |
+
<routers>
|
71 |
+
<bannerslider>
|
72 |
+
<use>admin</use>
|
73 |
+
<args>
|
74 |
+
<module>Mss_Bannerslider</module>
|
75 |
+
<frontName>admin_bannerslider</frontName>
|
76 |
+
</args>
|
77 |
+
</bannerslider>
|
78 |
+
</routers>
|
79 |
+
</admin>
|
80 |
+
<adminhtml>
|
81 |
+
<layout>
|
82 |
+
<updates>
|
83 |
+
<bannerslider>
|
84 |
+
<file>bannerslider.xml</file>
|
85 |
+
</bannerslider>
|
86 |
+
</updates>
|
87 |
+
</layout>
|
88 |
+
</adminhtml>
|
89 |
+
</config>
|
app/code/local/Mss/Bannerslider/sql/bannerslider_setup/mysql4-install-0.1.0.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$installer = $this;
|
3 |
+
$installer->startSetup();
|
4 |
+
$sql="CREATE TABLE {$this->getTable('magentomobile_bannerslider')} (
|
5 |
+
`banner_id` int(11) unsigned NOT NULL auto_increment,
|
6 |
+
`name` varchar(255) NOT NULL default '',
|
7 |
+
`order_banner` int(11) NULL default '0',
|
8 |
+
`status` smallint(6) NOT NULL default '0',
|
9 |
+
`url_type` varchar(20) NULL default '',
|
10 |
+
`product_id` int(11) NULL,
|
11 |
+
`category_id` int(11) NULL,
|
12 |
+
`image` varchar(255) NULL,
|
13 |
+
`image_alt` varchar(255) NULL,
|
14 |
+
|
15 |
+
PRIMARY KEY (`banner_id`)
|
16 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
17 |
+
|
18 |
+
$installer->run($sql);
|
19 |
+
|
20 |
+
$installer->endSetup();
|
21 |
+
|
app/code/local/Mss/Connector/Block/Adminhtml/Notifications.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_Block_Adminhtml_Notifications extends Mage_Adminhtml_Block_Template
|
3 |
+
{
|
4 |
+
|
5 |
+
const XML_SECURE_KEY = 'magentomobileshop/secure/key';
|
6 |
+
const ACTIVATION_URL = 'https://www.magentomobileshop.com/mobile-connect';
|
7 |
+
const TRNS_EMAIL = 'trans_email/ident_general/email';
|
8 |
+
|
9 |
+
public function getMessage()
|
10 |
+
{
|
11 |
+
$href ='';
|
12 |
+
if(!Mage::getStoreConfig(self::XML_SECURE_KEY))
|
13 |
+
|
14 |
+
$href = '<strong class="label">Magentomobileshop</strong> extension is not activated yet, <a href="'.self::ACTIVATION_URL.'?email='.Mage::getStoreConfig(self::TRNS_EMAIL).'&url='.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)
|
15 |
+
.'" target="_blank">Click here</a> to activate your extension.';
|
16 |
+
|
17 |
+
return $href;
|
18 |
+
|
19 |
+
|
20 |
+
}
|
21 |
+
|
22 |
+
}
|
app/code/local/Mss/Connector/Block/System/Config/About.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_Block_System_Config_About
|
4 |
+
extends Mage_Adminhtml_Block_Abstract
|
5 |
+
implements Varien_Data_Form_Element_Renderer_Interface
|
6 |
+
{
|
7 |
+
|
8 |
+
|
9 |
+
public function render(Varien_Data_Form_Element_Abstract $element)
|
10 |
+
{
|
11 |
+
$html = file_get_contents('http://magentomobileshop.com/wp-content/magentomobiledata/about_us.html');
|
12 |
+
return $html;
|
13 |
+
}
|
14 |
+
}
|
app/code/local/Mss/Connector/Block/System/Config/Authorizenet.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_Block_System_Config_Authorizenet
|
4 |
+
extends Mage_Adminhtml_Block_Abstract
|
5 |
+
implements Varien_Data_Form_Element_Renderer_Interface
|
6 |
+
{
|
7 |
+
public function render(Varien_Data_Form_Element_Abstract $element)
|
8 |
+
{
|
9 |
+
$html = '';
|
10 |
+
if(!Mage::getStoreConfig('payment/authorizenet/active')):
|
11 |
+
$html = "<div id='messages'><ul class='messages'><li class='error-msg'>Authorizenet Payment method is Disabled, Kindly Enable the Authorize.net Payment method to make it work with mobile app.<span></span></li></ul></div>";
|
12 |
+
endif;
|
13 |
+
return $html;
|
14 |
+
}
|
15 |
+
}
|
app/code/local/Mss/Connector/Block/System/Config/Banktransfer.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_Block_System_Config_Banktransfer
|
4 |
+
extends Mage_Adminhtml_Block_Abstract
|
5 |
+
implements Varien_Data_Form_Element_Renderer_Interface
|
6 |
+
{
|
7 |
+
public function render(Varien_Data_Form_Element_Abstract $element)
|
8 |
+
{
|
9 |
+
$html = '';
|
10 |
+
if(!Mage::getStoreConfig('payment/banktransfer/active')):
|
11 |
+
$html = "<div id='messages'><ul class='messages'><li class='error-msg'>Bank Transfer Payment method is Disabled, Kindly Enable the Bank Transfer Payment method to make it work with mobile app.<span></span></li></ul></div>";
|
12 |
+
endif;
|
13 |
+
return $html;
|
14 |
+
}
|
15 |
+
}
|
app/code/local/Mss/Connector/Block/System/Config/Checkmo.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_Block_System_Config_Checkmo
|
4 |
+
extends Mage_Adminhtml_Block_Abstract
|
5 |
+
implements Varien_Data_Form_Element_Renderer_Interface
|
6 |
+
{
|
7 |
+
public function render(Varien_Data_Form_Element_Abstract $element)
|
8 |
+
{
|
9 |
+
$html = '';
|
10 |
+
if(!Mage::getStoreConfig('payment/checkmo/active')):
|
11 |
+
$html = "<div id='messages'><ul class='messages'><li class='error-msg'>Check / Money Order method is Disabled, Kindly Enable the Check / Money Order method to make it work with mobile app.<span></span></li></ul></div>";
|
12 |
+
endif;
|
13 |
+
return $html;
|
14 |
+
}
|
15 |
+
}
|
app/code/local/Mss/Connector/Block/System/Config/Cod.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_Block_System_Config_Cod
|
4 |
+
extends Mage_Adminhtml_Block_Abstract
|
5 |
+
implements Varien_Data_Form_Element_Renderer_Interface
|
6 |
+
{
|
7 |
+
public function render(Varien_Data_Form_Element_Abstract $element)
|
8 |
+
{
|
9 |
+
$html = '';
|
10 |
+
if(!Mage::getStoreConfig('payment/cashondelivery/active')):
|
11 |
+
$html = "<div id='messages'><ul class='messages'><li class='error-msg'>Cashondelivery method is Disabled, Kindly Enable the cashondelivery Payment method to make it work with mobile app.<span></span></li></ul></div>";
|
12 |
+
endif;
|
13 |
+
return $html;
|
14 |
+
}
|
15 |
+
}
|
app/code/local/Mss/Connector/Block/System/Config/Mpaypal.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_Block_System_Config_Mpaypal
|
4 |
+
extends Mage_Adminhtml_Block_Abstract
|
5 |
+
implements Varien_Data_Form_Element_Renderer_Interface
|
6 |
+
{
|
7 |
+
public function render(Varien_Data_Form_Element_Abstract $element)
|
8 |
+
{
|
9 |
+
$html = '';
|
10 |
+
|
11 |
+
if(!Mage::getStoreConfig('payment/mpaypal/active')):
|
12 |
+
$html = "<div id='messages'><ul class='messages'><li class='error-msg'>PayPal (app) is Disabled, Kindly Enable the PayPal (app) to make it work with mobile app.<span></span></li></ul></div>";
|
13 |
+
endif;
|
14 |
+
return $html;
|
15 |
+
}
|
16 |
+
}
|
app/code/local/Mss/Connector/Block/System/Config/Payu.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_Block_System_Config_Payu
|
4 |
+
extends Mage_Adminhtml_Block_Abstract
|
5 |
+
implements Varien_Data_Form_Element_Renderer_Interface
|
6 |
+
{
|
7 |
+
public function render(Varien_Data_Form_Element_Abstract $element)
|
8 |
+
{
|
9 |
+
$html = '';
|
10 |
+
if(Mage::getStoreConfig('payment/payucheckout_shared/active') == ''):
|
11 |
+
$html = "<div id='messages'><ul class='messages'><li class='error-msg'>PayU extension is missing, Kindly install the PayU extension to make it work with mobile app.<span> <a href='https://github.com/PayU/plugin_magento/archive/master.zip'>Download Extension </a></span></li></ul></div>";
|
12 |
+
endif;
|
13 |
+
|
14 |
+
if(!Mage::getStoreConfig('payment/payucheckout_shared/active')):
|
15 |
+
$html = "<div id='messages'><ul class='messages'><li class='error-msg'>PayU extension is Disabled, Kindly Enable the PayU extension to make it work with mobile app.<span></span></li></ul></div>";
|
16 |
+
endif;
|
17 |
+
return $html;
|
18 |
+
}
|
19 |
+
}
|
app/code/local/Mss/Connector/Helper/Data.php
ADDED
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
|
5 |
+
/*resize image according to size*/
|
6 |
+
|
7 |
+
public function Imageresize($_file_name,$type,$width,$height){
|
8 |
+
try{
|
9 |
+
|
10 |
+
$_media_dir = Mage::getBaseDir('media') . DS . 'catalog' . DS . $type ;
|
11 |
+
$cache_dir = $_media_dir . DS. 'cache' . DS;
|
12 |
+
|
13 |
+
|
14 |
+
if (file_exists($cache_dir . $_file_name)):
|
15 |
+
$real_path = Mage::getBaseUrl('media') . 'catalog' . DS . $type . DS . 'cache' . $_file_name;
|
16 |
+
// elseif (file_exists($_media_dir . $_file_name)):
|
17 |
+
else:
|
18 |
+
if (!is_dir(Mage::getBaseDir('media') . DS . 'catalog' . DS . $type))
|
19 |
+
mkdir(Mage::getBaseDir('media') . DS . 'catalog' . DS . $type,0777);
|
20 |
+
|
21 |
+
if (!is_dir($cache_dir))
|
22 |
+
mkdir($cache_dir,0777);
|
23 |
+
endif;
|
24 |
+
|
25 |
+
if($type == 'thumbnail'):
|
26 |
+
$_media_dir = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product' ;
|
27 |
+
endif;
|
28 |
+
|
29 |
+
$_image = new Varien_Image($_media_dir . $_file_name);
|
30 |
+
|
31 |
+
$_image->constrainOnly(true);
|
32 |
+
$_image->keepAspectRatio(true);
|
33 |
+
$_image->backgroundColor(array(255,255,255));
|
34 |
+
$_image->keepFrame(true);
|
35 |
+
$_image->resize($width, $height);
|
36 |
+
$_image->save($cache_dir . $_file_name);
|
37 |
+
|
38 |
+
return Mage::getBaseUrl('media') . 'catalog' . DS . $type . DS . 'cache' . $_file_name;
|
39 |
+
}
|
40 |
+
catch(exception $e){
|
41 |
+
|
42 |
+
return Mage::getBaseUrl('media') . 'catalog' . DS . $type .$_file_name;
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
/*check cache according to request*/
|
47 |
+
|
48 |
+
public function checkcache($key,$store = 1){
|
49 |
+
try{
|
50 |
+
$cache = Mage::app()->getCache();
|
51 |
+
$cache_key = "mss_".$key."_store".$store;
|
52 |
+
|
53 |
+
if($cache->load($cache_key)):
|
54 |
+
|
55 |
+
echo $cache->load($cache_key);
|
56 |
+
exit;
|
57 |
+
endif;
|
58 |
+
return false;
|
59 |
+
}
|
60 |
+
catch(exception $e){
|
61 |
+
return false;
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
}
|
66 |
+
|
67 |
+
/*create cache according to request*/
|
68 |
+
public function createNewcache($key,$store = 1,$data){
|
69 |
+
|
70 |
+
try{
|
71 |
+
$CACHE_EXPIRY = 300;
|
72 |
+
$cache = Mage::app()->getCache();
|
73 |
+
$cache_key = "mss_".$key."_store".$store;
|
74 |
+
|
75 |
+
$cache->save($data, $cache_key, array("mss"), $CACHE_EXPIRY);
|
76 |
+
return true;
|
77 |
+
}
|
78 |
+
catch(exception $e){
|
79 |
+
return false;
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
public function loadParent($helper){
|
84 |
+
|
85 |
+
if(Mage::helper('connector')->compareExp() > 24):
|
86 |
+
echo json_encode(array('status'=>'error','code'=>'001'));
|
87 |
+
exit;
|
88 |
+
endif;
|
89 |
+
|
90 |
+
if(Mage::getStoreConfig('magentomobileshop/secure/token') != $helper):
|
91 |
+
echo json_encode(array('status'=>'error','code'=>'002'));
|
92 |
+
exit;
|
93 |
+
endif;
|
94 |
+
if(!Mage::getStoreConfig('magentomobileshop/key/status')):
|
95 |
+
echo json_encode(array('status'=>'error','code'=>'003'));
|
96 |
+
exit;
|
97 |
+
endif;
|
98 |
+
|
99 |
+
if(Mage::helper('connector')->compareExp() > 24 ||
|
100 |
+
Mage::getStoreConfig('magentomobileshop/secure/token') != isset($helper)
|
101 |
+
|| !Mage::getStoreConfig('magentomobileshop/key/status') || !$helper):
|
102 |
+
echo json_encode(array('status'=>'error','code'=>'004'));
|
103 |
+
exit;
|
104 |
+
endif;
|
105 |
+
}
|
106 |
+
|
107 |
+
|
108 |
+
public function compareExp(){
|
109 |
+
$saved_session = strtotime(Mage::getStoreConfig('secure/token/exp'));
|
110 |
+
$current_session = strtotime(Mage::getModel('core/date')->date('Y-m-d H:i:s'));
|
111 |
+
return round(($current_session - $saved_session) / 3600);
|
112 |
+
}
|
113 |
+
|
114 |
+
// Functionality to check product is in wishlist or not
|
115 |
+
|
116 |
+
public function check_wishlist($productId){
|
117 |
+
|
118 |
+
$customer = Mage::getSingleton("customer/session");
|
119 |
+
|
120 |
+
if($customer->isLoggedIn()):
|
121 |
+
|
122 |
+
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer->getId(), true);
|
123 |
+
$wishListItemCollection = $wishlist->getItemCollection();
|
124 |
+
$wishlist_product_id = array();
|
125 |
+
foreach ($wishListItemCollection as $item){
|
126 |
+
|
127 |
+
$wishlist_product_id[]= $item->getProductId();
|
128 |
+
}
|
129 |
+
if(in_array($productId, $wishlist_product_id))
|
130 |
+
return true;
|
131 |
+
else
|
132 |
+
return false;
|
133 |
+
|
134 |
+
else:
|
135 |
+
return false;
|
136 |
+
endif;
|
137 |
+
}
|
138 |
+
|
139 |
+
public function saveCc($data){
|
140 |
+
|
141 |
+
$data['user_id'] = Mage::getSingleton("customer/session")->getId();
|
142 |
+
|
143 |
+
$collection = Mage::getModel("connector/connector");
|
144 |
+
try{
|
145 |
+
$collection->setData($data)->save();
|
146 |
+
return true;
|
147 |
+
}
|
148 |
+
catch(Exception $e){
|
149 |
+
Mage::throwException(Mage::helper('payment')->__('Error in saving card.'));
|
150 |
+
}
|
151 |
+
|
152 |
+
return true;
|
153 |
+
}
|
154 |
+
|
155 |
+
public function reigesterGuestUser($userdata){
|
156 |
+
|
157 |
+
|
158 |
+
$customer = Mage::getModel("customer/customer");
|
159 |
+
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
|
160 |
+
$load_pre = $customer->loadByEmail($userdata['email']);
|
161 |
+
|
162 |
+
if($load_pre->getId())
|
163 |
+
return $load_pre->getId();
|
164 |
+
|
165 |
+
$customer = $customer->setId(null);
|
166 |
+
|
167 |
+
$customer->setData('email',$userdata['email']);
|
168 |
+
$customer->setData('firstname',$userdata['firstname']);
|
169 |
+
$customer->setData('lastname',$userdata['lastname']);
|
170 |
+
$customer->setData('password',$this->radPassoword());
|
171 |
+
|
172 |
+
try{
|
173 |
+
$customer->setConfirmation(null);
|
174 |
+
$customer->save();
|
175 |
+
$customer->sendNewAccountEmail ('registered','', Mage::app ()->getStore ()->getId ());
|
176 |
+
return $customer->getId();
|
177 |
+
|
178 |
+
}
|
179 |
+
catch(Exception $ex){
|
180 |
+
echo json_encode(array('status'=>'error','message'=>$ex->getMessage()));
|
181 |
+
exit;
|
182 |
+
}
|
183 |
+
|
184 |
+
}
|
185 |
+
|
186 |
+
private function radPassoword()
|
187 |
+
{
|
188 |
+
return substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(1,6))),1,6);
|
189 |
+
}
|
190 |
+
|
191 |
+
public function getProductStockInfoById($productId){
|
192 |
+
|
193 |
+
$stock_product = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
|
194 |
+
$stock_data = $stock_product->getIsInStock();
|
195 |
+
return $stock_data;
|
196 |
+
}
|
197 |
+
}
|
app/code/local/Mss/Connector/Model/Connector.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_Model_Connector extends Mage_Core_Model_Abstract
|
3 |
+
{
|
4 |
+
protected function _construct(){
|
5 |
+
|
6 |
+
$this->_init("connector/connector");
|
7 |
+
|
8 |
+
}
|
9 |
+
}
|
10 |
+
?>
|
app/code/local/Mss/Connector/Model/Mysql4/Connector.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_Model_Mysql4_Connector extends Mage_Core_Model_Mysql4_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
// Note that the web_id refers to the key field in your database table.
|
8 |
+
$this->_init('connector/connector','id');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/Mss/Connector/Model/Mysql4/Connector/Collection.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_Model_Mysql4_Connector_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
$this->_init('connector/connector');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/Mss/Connector/Model/Observer.php
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_Model_Observer
|
3 |
+
{
|
4 |
+
const XML_SECURE_KEY = 'magentomobileshop/secure/key';
|
5 |
+
const ACTIVATION_URL = 'https://www.magentomobileshop.com/mobile-connect';
|
6 |
+
const TRNS_EMAIL = 'trans_email/ident_general/email';
|
7 |
+
|
8 |
+
public function notificationMessage()
|
9 |
+
{
|
10 |
+
$adminsession = Mage::getSingleton('admin/session', array('name'=>'adminhtml'));
|
11 |
+
|
12 |
+
if(!Mage::getStoreConfig(self::XML_SECURE_KEY) AND $adminsession->isLoggedIn()):
|
13 |
+
|
14 |
+
$href = self::ACTIVATION_URL.'?email='.Mage::getStoreConfig(self::TRNS_EMAIL).'&url='.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
15 |
+
|
16 |
+
Mage::getSingleton('core/session')->addError('Magentomobileshop extension is not activated yet, <a href="'.$href.'" target="_blank">Click here</a> to activate your extension.');
|
17 |
+
|
18 |
+
endif;
|
19 |
+
|
20 |
+
$configValue = Mage::getStoreConfig('mss/connector/email');
|
21 |
+
|
22 |
+
if($configValue =='' AND $adminsession->isLoggedIn())
|
23 |
+
$this->sendemail();
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
}
|
28 |
+
|
29 |
+
public function sendemail(){
|
30 |
+
|
31 |
+
|
32 |
+
$current_store_url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);;
|
33 |
+
$current_store_name = Mage::getStoreConfig('general/store_information/name');
|
34 |
+
$current_store_phone =Mage::getStoreConfig('general/store_information/phone');
|
35 |
+
$current_store_address = Mage::getStoreConfig('general/store_information/address');
|
36 |
+
$current_store_email = Mage::getStoreConfig('trans_email/ident_general/email');
|
37 |
+
$message = <<<MESSAGE
|
38 |
+
Hello
|
39 |
+
My Store name is : $current_store_name
|
40 |
+
My Store URl is : $current_store_url
|
41 |
+
My Store Contact Number is : $current_store_phone
|
42 |
+
My Store Address is : $current_store_address
|
43 |
+
My Store Email is : $current_store_email
|
44 |
+
Thank you,
|
45 |
+
MagentoMobileshop Dev Tem
|
46 |
+
MESSAGE;
|
47 |
+
|
48 |
+
|
49 |
+
$to = "contact@magentomobileshop.com";
|
50 |
+
|
51 |
+
$subject = "New Connector Installation ";
|
52 |
+
$headers = "MIME-Version: 1.0" . "\r\n";
|
53 |
+
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
|
54 |
+
$headers .= 'From: <contact@magentomobileshop.com>' . "\r\n";
|
55 |
+
$headers .= 'Cc: mss.yogendra@gmail.com' . "\r\n";
|
56 |
+
$email = mail($to,$subject,$message,$headers);
|
57 |
+
|
58 |
+
if($email):
|
59 |
+
$mssSwitch = new Mage_Core_Model_Config();
|
60 |
+
$mssSwitch ->saveConfig('mss/connector/email', 1);
|
61 |
+
endif;
|
62 |
+
|
63 |
+
return true;
|
64 |
+
|
65 |
+
}
|
66 |
+
|
67 |
+
}
|
app/code/local/Mss/Connector/controllers/CartController.php
ADDED
@@ -0,0 +1,1394 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_CartController extends Mage_Core_Controller_Front_Action {
|
3 |
+
|
4 |
+
public $errors = '';
|
5 |
+
public $cc_type ='';
|
6 |
+
public $cc_number = '';
|
7 |
+
public $cc_month = '';
|
8 |
+
public $cc_year = '';
|
9 |
+
public $cc_cid ='';
|
10 |
+
|
11 |
+
public function _construct(){
|
12 |
+
|
13 |
+
header('content-type: application/json; charset=utf-8');
|
14 |
+
header("access-control-allow-origin: *");
|
15 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
16 |
+
parent::_construct();
|
17 |
+
|
18 |
+
}
|
19 |
+
public function getaddurlAction() {
|
20 |
+
$productid = $this->getRequest ()->getParam ( 'productid' );
|
21 |
+
$product = Mage::getModel ( "catalog/product" )->load ( $productid );
|
22 |
+
$url = Mage::helper ( 'checkout/cart' )->getAddUrl ( $product );
|
23 |
+
echo "{'url':'" . $url . "'}";
|
24 |
+
$cart = Mage::helper ( 'checkout/cart' )->getCart ();
|
25 |
+
$item_qty = $cart->getItemsQty ();
|
26 |
+
echo "{'item_qty':'" . $item_qty . "'}";
|
27 |
+
$summarycount = $cart->getSummaryCount ();
|
28 |
+
echo "{'summarycount':'" . $summarycount . "'}";
|
29 |
+
}
|
30 |
+
|
31 |
+
public function getMinimumorderAction(){
|
32 |
+
|
33 |
+
$cart_data = json_decode($this->getRequest ()->getParam('cart_data'),1);
|
34 |
+
|
35 |
+
|
36 |
+
if(!sizeof($cart_data)):
|
37 |
+
echo json_encode(array('status'=>'error','message'=> 'Nothing to add in cart, cart is empty.'));
|
38 |
+
exit;
|
39 |
+
endif;
|
40 |
+
|
41 |
+
$cart = Mage::helper ( 'checkout/cart' )->getCart ();
|
42 |
+
$cart->truncate();
|
43 |
+
|
44 |
+
|
45 |
+
$session = Mage::getSingleton ( 'core/session', array (
|
46 |
+
'name' => 'frontend'
|
47 |
+
) );
|
48 |
+
|
49 |
+
foreach($cart_data as $params):
|
50 |
+
|
51 |
+
|
52 |
+
try {
|
53 |
+
|
54 |
+
|
55 |
+
$product = Mage::getModel ('catalog/product')->load ($params['product']);
|
56 |
+
|
57 |
+
if ($product->getData('has_options')):
|
58 |
+
# validate options
|
59 |
+
$options=$params['options'];
|
60 |
+
if(count($options)>0):
|
61 |
+
$params['options']=$options;
|
62 |
+
endif;
|
63 |
+
endif;
|
64 |
+
|
65 |
+
if (isset ($params ['super_attribute'] )) :
|
66 |
+
|
67 |
+
if(isset($params['options'])):
|
68 |
+
$data = array("product"=>$params['product'],"options"=>$params['options'],"super_attribute"=>$params['super_attribute'],
|
69 |
+
'qty' => $params['qty']
|
70 |
+
);
|
71 |
+
else:
|
72 |
+
$data = array("product"=>$params ['product'],"super_attribute"=>$params['super_attribute'],
|
73 |
+
'qty' => $params['qty']
|
74 |
+
);
|
75 |
+
endif;
|
76 |
+
$cart->addProduct ( $product, $data );
|
77 |
+
else:
|
78 |
+
|
79 |
+
$cart->addProduct ( $product, $params );
|
80 |
+
endif;
|
81 |
+
$session->setLastAddedProductId ( $product->getId () );
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
} catch ( Exception $e ) {
|
86 |
+
|
87 |
+
|
88 |
+
$result = '{"status":"error"';
|
89 |
+
$result .= ', "message": "' . str_replace("\"","||",$e->getMessage ()) . '"}';
|
90 |
+
echo $result;
|
91 |
+
exit;
|
92 |
+
|
93 |
+
}
|
94 |
+
|
95 |
+
|
96 |
+
endforeach;
|
97 |
+
$session->setCartWasUpdated ( true );
|
98 |
+
$cart->save ();
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
if(Mage::getStoreConfig('sales/minimum_order/active')):
|
104 |
+
$check_grand_total = Mage::helper('checkout/cart')->getQuote()->getBaseSubtotalWithDiscount();
|
105 |
+
|
106 |
+
$amount = Mage::getStoreConfig('sales/minimum_order/amount');
|
107 |
+
if ($check_grand_total < $amount):
|
108 |
+
$message = Mage::getStoreConfig('sales/minimum_order/error_message');
|
109 |
+
if(!$message) $message = 'Minimum Order Limit is '.$amount;
|
110 |
+
echo json_encode(array('status'=>'error','message'=> $message));
|
111 |
+
exit;
|
112 |
+
endif;
|
113 |
+
|
114 |
+
endif;
|
115 |
+
echo json_encode(array('status'=>'success','message'=> 'true'));
|
116 |
+
exit;
|
117 |
+
|
118 |
+
}
|
119 |
+
|
120 |
+
|
121 |
+
public function updateCartAction()
|
122 |
+
{
|
123 |
+
|
124 |
+
$cart_data = json_decode($this->getRequest ()->getParam('cart_data'),1);
|
125 |
+
|
126 |
+
|
127 |
+
foreach($cart_data as $itemId => $qty):
|
128 |
+
|
129 |
+
$itemId=(int)$itemId;
|
130 |
+
$qty = (int)$qty;
|
131 |
+
$oldQty = 0;
|
132 |
+
$item = null;
|
133 |
+
|
134 |
+
try {
|
135 |
+
if ($itemId):
|
136 |
+
$cartData = array ();
|
137 |
+
|
138 |
+
$cartHelper = Mage::helper('checkout/cart');
|
139 |
+
$items = $cartHelper->getCart()->getItems();
|
140 |
+
|
141 |
+
foreach($items as $item):
|
142 |
+
if($item->getProduct()->getId() == $itemId):
|
143 |
+
$itemId = $item->getItemId();
|
144 |
+
$cartHelper->getCart()->removeItem($itemId)->save();
|
145 |
+
break;
|
146 |
+
endif;
|
147 |
+
endforeach;
|
148 |
+
|
149 |
+
endif;
|
150 |
+
|
151 |
+
|
152 |
+
}
|
153 |
+
catch ( Mage_Core_Exception $e ) {
|
154 |
+
echo json_encode (array('status'=>'error','message'=> $e->getMessage ()) );
|
155 |
+
exit;
|
156 |
+
}
|
157 |
+
endforeach;
|
158 |
+
echo json_encode(array('status'=>'success','message'=> 'true'));
|
159 |
+
exit;
|
160 |
+
}
|
161 |
+
public function clearcartAction()
|
162 |
+
{
|
163 |
+
|
164 |
+
$cart = Mage::helper ( 'checkout/cart' )->getCart ();
|
165 |
+
if($cart->getQuote ()->getItemsCount ()){
|
166 |
+
Mage::getSingleton('checkout/cart')->truncate()->save();
|
167 |
+
}
|
168 |
+
Mage::getSingleton('checkout/session')->clear();
|
169 |
+
|
170 |
+
|
171 |
+
$result = '{"result":"success"';
|
172 |
+
$result .= ', "message": "' . 'cart is empty!' . '"}';
|
173 |
+
echo $result;
|
174 |
+
|
175 |
+
|
176 |
+
}
|
177 |
+
|
178 |
+
# Add to cart product start
|
179 |
+
public function addAction() {
|
180 |
+
try {
|
181 |
+
|
182 |
+
$product_id = $this->getRequest ()->getParam ( 'product' );
|
183 |
+
|
184 |
+
$params = $this->getRequest ()->getParams ();
|
185 |
+
|
186 |
+
if (isset ( $params ['qty'] )) {
|
187 |
+
$filter = new Zend_Filter_LocalizedToNormalized ( array (
|
188 |
+
'locale' => Mage::app ()->getLocale ()->getLocaleCode ()
|
189 |
+
) );
|
190 |
+
$params ['qty'] = $filter->filter ( $params ['qty'] );
|
191 |
+
} else if ($product_id == '') {
|
192 |
+
$session->addError ( "Product Not Added
|
193 |
+
The SKU you entered ($sku) was not found." );
|
194 |
+
}
|
195 |
+
$request = Mage::app ()->getRequest ();
|
196 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $product_id );
|
197 |
+
|
198 |
+
if ($product->getData('has_options')):
|
199 |
+
# validate options
|
200 |
+
$options=json_decode($params['options'],true);
|
201 |
+
if(count($options)>0):
|
202 |
+
$params['options']=$options;
|
203 |
+
endif;
|
204 |
+
endif;
|
205 |
+
|
206 |
+
$session = Mage::getSingleton ( 'core/session', array (
|
207 |
+
'name' => 'frontend'
|
208 |
+
) );
|
209 |
+
$cart = Mage::helper ( 'checkout/cart' )->getCart ();
|
210 |
+
|
211 |
+
|
212 |
+
if (isset ( $params ['super_attribute'] )) :
|
213 |
+
|
214 |
+
if(isset($params['options'])):
|
215 |
+
$params = array("product"=>$params ['product'],"options"=>$params['options'],"super_attribute"=>json_decode($params ['super_attribute'],1),
|
216 |
+
'qty' => $params ['qty']
|
217 |
+
);
|
218 |
+
else:
|
219 |
+
$params = array("product"=>$params ['product'],"super_attribute"=>json_decode($params ['super_attribute'],1),
|
220 |
+
'qty' => $params ['qty']
|
221 |
+
);
|
222 |
+
endif;
|
223 |
+
|
224 |
+
$cart->addProduct ( $product,$params);
|
225 |
+
|
226 |
+
else:
|
227 |
+
|
228 |
+
$cart->addProduct ( $product, $params );
|
229 |
+
endif;
|
230 |
+
|
231 |
+
|
232 |
+
$session->setLastAddedProductId ( $product->getId () );
|
233 |
+
$session->setCartWasUpdated ( true );
|
234 |
+
$cart->save ();
|
235 |
+
|
236 |
+
|
237 |
+
$items_qty = floor ( Mage::getModel ( 'checkout/cart' )->getQuote ()->getItemsQty () );
|
238 |
+
$result = '{"result":"success"';
|
239 |
+
$result .= ', "items_qty": "' . $items_qty . '"}';
|
240 |
+
echo $result;
|
241 |
+
} catch ( Exception $e ) {
|
242 |
+
|
243 |
+
|
244 |
+
$result = '{"result":"error"';
|
245 |
+
$result .= ', "message": "' . str_replace("\"","||",$e->getMessage ()) . '"}';
|
246 |
+
echo $result;
|
247 |
+
|
248 |
+
}
|
249 |
+
}
|
250 |
+
|
251 |
+
|
252 |
+
# End add to cart product
|
253 |
+
public function getQtyAction() {
|
254 |
+
$items_qty = floor(Mage::getModel('checkout/cart')->getQuote()->getItemsQty());
|
255 |
+
$result = '{"items_qty": "' . $items_qty . '"}';
|
256 |
+
|
257 |
+
echo $result;
|
258 |
+
}
|
259 |
+
|
260 |
+
public function addpro($product_id,$qty) {
|
261 |
+
try {
|
262 |
+
$session = Mage::getSingleton ( 'core/session', array (
|
263 |
+
'name' => 'frontend'
|
264 |
+
) );
|
265 |
+
// $product_id = $this->getRequest ()->getParam ( 'product' );
|
266 |
+
$params['qty'] = $qty;//;$this->getRequest ()->getParams ();
|
267 |
+
if (isset ( $params ['qty'] )) {
|
268 |
+
$filter = new Zend_Filter_LocalizedToNormalized ( array (
|
269 |
+
'locale' => Mage::app ()->getLocale ()->getLocaleCode ()
|
270 |
+
) );
|
271 |
+
$params ['qty'] = $filter->filter ( $params ['qty'] );
|
272 |
+
} else if ($product_id == '') {
|
273 |
+
$session->addError ( "Product Not Added
|
274 |
+
The SKU you entered ($sku) was not found." );
|
275 |
+
}
|
276 |
+
$request = Mage::app ()->getRequest ();
|
277 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $product_id );
|
278 |
+
$cart = Mage::helper ( 'checkout/cart' )->getCart ();
|
279 |
+
$cart->addProduct ( $product, $params );
|
280 |
+
$session->setLastAddedProductId ( $product->getId () );
|
281 |
+
$session->setCartWasUpdated ( true );
|
282 |
+
$cart->save ();
|
283 |
+
return true;
|
284 |
+
} catch ( Exception $e ) {
|
285 |
+
return $e;
|
286 |
+
}
|
287 |
+
}
|
288 |
+
public function getCartInfoAction() {
|
289 |
+
echo json_encode ( $this->_getCartInformation () );
|
290 |
+
}
|
291 |
+
public function removeAction() {
|
292 |
+
$cart = Mage::getSingleton ( 'checkout/cart' );
|
293 |
+
$id = ( int ) $this->getRequest ()->getParam ( 'cart_item_id', 0 );
|
294 |
+
if ($id) {
|
295 |
+
try {
|
296 |
+
$cart->removeItem ( $id )->save ();
|
297 |
+
echo json_encode(array('cart_info'=>$this->_getCartInformation(),'total'=>$this->_getCartTotal ()));
|
298 |
+
} catch ( Mage_Core_Exception $e ) {
|
299 |
+
echo json_encode ( $e->getMessage () );
|
300 |
+
|
301 |
+
} catch ( Exception $e ) {
|
302 |
+
echo json_encode ( $e->getMessage () );
|
303 |
+
|
304 |
+
}
|
305 |
+
} else {
|
306 |
+
echo json_encode ( array (
|
307 |
+
false,
|
308 |
+
'0x5002',
|
309 |
+
'Param cart_item_id is empty.'
|
310 |
+
) );
|
311 |
+
}
|
312 |
+
}
|
313 |
+
|
314 |
+
|
315 |
+
public function updateAction() {
|
316 |
+
$itemId = ( int ) $this->getRequest ()->getParam ( 'cart_item_id', 0 );
|
317 |
+
$qty = ( int ) $this->getRequest ()->getParam ( 'qty', 0 );
|
318 |
+
$oldQty = 0;
|
319 |
+
$item = null;
|
320 |
+
try {
|
321 |
+
if ($itemId && $qty > 0) {
|
322 |
+
$cartData = array ();
|
323 |
+
$cartData [$itemId] ['qty'] = $qty;
|
324 |
+
$cart = Mage::getSingleton ( 'checkout/cart' );
|
325 |
+
/* * ****** if update fail rollback ********* */
|
326 |
+
if ($cart->getQuote ()->getItemById ( $itemId )) {
|
327 |
+
$item = $cart->getQuote ()->getItemById ( $itemId );
|
328 |
+
} else {
|
329 |
+
echo json_encode ( array (
|
330 |
+
'status' => 'error',
|
331 |
+
'message' => 'a wrong cart_item_id was given.'
|
332 |
+
) );
|
333 |
+
return false;
|
334 |
+
}
|
335 |
+
$oldQty = $item->getQty ();
|
336 |
+
if (! $cart->getCustomerSession ()->getCustomer ()->getId () && $cart->getQuote ()->getCustomerId ()) {
|
337 |
+
$cart->getQuote ()->setCustomerId ( null );
|
338 |
+
}
|
339 |
+
$cart->updateItems ( $cartData )->save ();
|
340 |
+
if ($cart->getQuote ()->getHasError ()) { // apply for 1.7.0.2
|
341 |
+
$mesg = current ( $cart->getQuote ()->getErrors () );
|
342 |
+
Mage::throwException ( $mesg->getText () );
|
343 |
+
return false;
|
344 |
+
}
|
345 |
+
}
|
346 |
+
$session = Mage::getSingleton ( 'checkout/session' );
|
347 |
+
$session->setCartWasUpdated ( true );
|
348 |
+
} catch ( Mage_Core_Exception $e ) { // rollback $quote->collectTotals()->save();
|
349 |
+
$item && $item->setData ( 'qty', $oldQty );
|
350 |
+
$cart->getQuote ()->setTotalsCollectedFlag ( false ); // reflash price
|
351 |
+
echo json_encode (array('status'=>'error','message'=> $e->getMessage ()) );
|
352 |
+
exit;
|
353 |
+
} catch ( Exception $e ) {
|
354 |
+
echo json_encode (array('status'=>'error','message'=> $e->getMessage ()) );
|
355 |
+
exit;
|
356 |
+
}
|
357 |
+
echo json_encode(array('cart_info'=>$this->_getCartInformation(),'total'=>$this->_getCartTotal ()));
|
358 |
+
}
|
359 |
+
|
360 |
+
|
361 |
+
public function getTotalAction() {
|
362 |
+
echo json_encode ( $this->_getCartTotal () );
|
363 |
+
}
|
364 |
+
|
365 |
+
|
366 |
+
public function postCouponAction() {
|
367 |
+
$couponCode = ( string ) Mage::app ()->getRequest ()->getParam ( 'coupon_code' );
|
368 |
+
$cart = Mage::helper ( 'checkout/cart' )->getCart ();
|
369 |
+
|
370 |
+
$coupan_codes = array();
|
371 |
+
$rulesCollection = Mage::getModel('salesrule/rule')->getCollection();
|
372 |
+
foreach($rulesCollection as $rule){
|
373 |
+
$coupan_codes[] = $rule->getCode();
|
374 |
+
}
|
375 |
+
|
376 |
+
if (!in_array($couponCode, $coupan_codes))
|
377 |
+
{
|
378 |
+
echo json_encode ( array (
|
379 |
+
'status' => 'error',
|
380 |
+
'message' => "Coupan Is not Valid"
|
381 |
+
) );
|
382 |
+
return false;
|
383 |
+
}
|
384 |
+
|
385 |
+
|
386 |
+
|
387 |
+
|
388 |
+
if (! $cart->getItemsCount ()) {
|
389 |
+
echo json_encode ( array (
|
390 |
+
'code' => '0X0001',
|
391 |
+
'message' => "You can't use coupon code with an empty shopping cart"
|
392 |
+
) );
|
393 |
+
return false;
|
394 |
+
}
|
395 |
+
if (Mage::app ()->getRequest ()->getParam ( 'remove' ) == 1) {
|
396 |
+
$couponCode = '';
|
397 |
+
}
|
398 |
+
$oldCouponCode = $cart->getQuote ()->getCouponCode ();
|
399 |
+
if (! strlen ( $couponCode ) && ! strlen ( $oldCouponCode )) {
|
400 |
+
echo json_encode ( array (
|
401 |
+
'code' => '0X0002',
|
402 |
+
'message' => "Emptyed."
|
403 |
+
) );
|
404 |
+
return false;
|
405 |
+
}
|
406 |
+
try {
|
407 |
+
$codeLength = strlen ( $couponCode );
|
408 |
+
$isCodeLengthValid = $codeLength && $codeLength <= Mage_Checkout_Helper_Cart::COUPON_CODE_MAX_LENGTH;
|
409 |
+
|
410 |
+
$cart->getQuote ()->getShippingAddress ()->setCollectShippingRates ( true );
|
411 |
+
$cart->getQuote ()->setCouponCode ( $isCodeLengthValid ? $couponCode : '' )->collectTotals ()->save ();
|
412 |
+
|
413 |
+
if ($codeLength) {
|
414 |
+
if ($isCodeLengthValid && $couponCode == $cart->getQuote ()->getCouponCode ()) {
|
415 |
+
$messages = array (
|
416 |
+
'code' => '0x0000',
|
417 |
+
'message' => $this->__ ( 'Coupon code "%s" was applied.', Mage::helper ( 'core' )->escapeHtml ( $couponCode ) )
|
418 |
+
);
|
419 |
+
} else {
|
420 |
+
$messages = array (
|
421 |
+
'code' => '0x0001',
|
422 |
+
'message' => $this->__ ( 'Coupon code "%s" is not valid.', Mage::helper ( 'core' )->escapeHtml ( $couponCode ) )
|
423 |
+
);
|
424 |
+
}
|
425 |
+
} else {
|
426 |
+
$messages = array (
|
427 |
+
'code' => '0x0002',
|
428 |
+
'message' => $this->__ ( 'Coupon code was canceled.' )
|
429 |
+
);
|
430 |
+
}
|
431 |
+
} catch ( Mage_Core_Exception $e ) {
|
432 |
+
$messages = array (
|
433 |
+
'code' => '0x0003',
|
434 |
+
'message' => $e->getMessage ()
|
435 |
+
);
|
436 |
+
} catch ( Exception $e ) {
|
437 |
+
$messages = array (
|
438 |
+
'code' => '0x0004',
|
439 |
+
'message' => $this->__ ( 'Cannot apply the coupon code.' )
|
440 |
+
);
|
441 |
+
}
|
442 |
+
|
443 |
+
echo json_encode ( $this->_getCartTotal () );
|
444 |
+
}
|
445 |
+
|
446 |
+
|
447 |
+
protected function _getCartInformation() {
|
448 |
+
$cart = Mage::getSingleton ( 'checkout/cart' );
|
449 |
+
if ($cart->getQuote ()->getItemsCount ()) {
|
450 |
+
$cart->init ();
|
451 |
+
$cart->save ();
|
452 |
+
}
|
453 |
+
$cart->getQuote ()->collectTotals ()->save ();
|
454 |
+
|
455 |
+
$cartInfo = array ();
|
456 |
+
$cartInfo ['is_virtual'] = Mage::helper ( 'checkout/cart' )->getIsVirtualQuote ();
|
457 |
+
$cartInfo ['cart_items'] = $this->_getCartItems ();
|
458 |
+
$cartInfo ['messages'] = sizeof ( $this->errors ) ? $this->errors : $this->_getMessage ();
|
459 |
+
$cartInfo ['cart_items_count'] = Mage::helper ( 'checkout/cart' )->getSummaryCount ();
|
460 |
+
$cartInfo ['grand_total'] = $cart->getQuote()->getGrandTotal();
|
461 |
+
$cartInfo ['sub_total'] = $cart->getQuote()->getSubtotal();
|
462 |
+
$cartInfo ['allow_guest_checkout'] = Mage::helper ( 'checkout' )->isAllowedGuestCheckout ( $cart->getQuote () );
|
463 |
+
|
464 |
+
return $cartInfo;
|
465 |
+
}
|
466 |
+
|
467 |
+
|
468 |
+
protected function _getCartTotal() {
|
469 |
+
$cart = Mage::getSingleton ( 'checkout/cart' );
|
470 |
+
$totalItemsInCart = Mage::helper ( 'checkout/cart' )->getItemsCount (); // total items in cart
|
471 |
+
$totals = Mage::getSingleton ( 'checkout/session' )->getQuote ()->getTotals (); // Total object
|
472 |
+
$oldCouponCode = $cart->getQuote ()->getCouponCode ();
|
473 |
+
$oCoupon = Mage::getModel ( 'salesrule/coupon' )->load ( $oldCouponCode, 'code' );
|
474 |
+
$oRule = Mage::getModel ( 'salesrule/rule' )->load ( $oCoupon->getRuleId () );
|
475 |
+
|
476 |
+
$subtotal = round ( $totals ["subtotal"]->getValue () ); // Subtotal value
|
477 |
+
$grandtotal = round ( $totals ["grand_total"]->getValue () ); // Grandtotal value
|
478 |
+
if (isset ( $totals ['discount'] )) { // $totals['discount']->getValue()) {
|
479 |
+
$discount = round ( $totals ['discount']->getValue () ); // Discount value if applied
|
480 |
+
} else {
|
481 |
+
$discount = '0';
|
482 |
+
}
|
483 |
+
if (isset ( $totals ['tax'] )) { // $totals['tax']->getValue()) {
|
484 |
+
$tax = round ( $totals ['tax']->getValue () ); // Tax value if present
|
485 |
+
} else {
|
486 |
+
$tax = '';
|
487 |
+
}
|
488 |
+
return array (
|
489 |
+
'subtotal' => $subtotal,
|
490 |
+
'grandtotal' => $grandtotal,
|
491 |
+
'discount' => str_replace('-','',$discount),
|
492 |
+
'tax' => $tax,
|
493 |
+
'coupon_code' => $oldCouponCode,
|
494 |
+
'coupon_rule' => $oRule->getData ()
|
495 |
+
);
|
496 |
+
}
|
497 |
+
|
498 |
+
|
499 |
+
protected function _getMessage() {
|
500 |
+
$cart = Mage::getSingleton ( 'checkout/cart' );
|
501 |
+
if (! Mage::getSingleton ( 'checkout/type_onepage' )->getQuote ()->hasItems ()) {
|
502 |
+
$this->errors [] = 'Cart is empty!';
|
503 |
+
return $this->errors;
|
504 |
+
}
|
505 |
+
if (! $cart->getQuote ()->validateMinimumAmount ()) {
|
506 |
+
$warning = Mage::getStoreConfig ( 'sales/minimum_order/description' );
|
507 |
+
$this->errors [] = $warning;
|
508 |
+
}
|
509 |
+
|
510 |
+
if (($messages = $cart->getQuote ()->getErrors ())) {
|
511 |
+
foreach ( $messages as $message ) {
|
512 |
+
if ($message) {
|
513 |
+
$message = str_replace("\"","||",$message);
|
514 |
+
$this->errors [] = $message->getText ();
|
515 |
+
}
|
516 |
+
}
|
517 |
+
}
|
518 |
+
|
519 |
+
return $this->errors;
|
520 |
+
}
|
521 |
+
|
522 |
+
|
523 |
+
private function _getPaymentInfo() {
|
524 |
+
$cart = Mage::getSingleton ( 'checkout/cart' );
|
525 |
+
$methods = $cart->getAvailablePayment ();
|
526 |
+
|
527 |
+
|
528 |
+
|
529 |
+
foreach ( $methods as $method ) {
|
530 |
+
if ($method->getCode () == 'paypal_express') {
|
531 |
+
return array (
|
532 |
+
'paypalec'
|
533 |
+
);
|
534 |
+
}
|
535 |
+
}
|
536 |
+
|
537 |
+
return array ();
|
538 |
+
}
|
539 |
+
|
540 |
+
|
541 |
+
protected function _getCartItems() {
|
542 |
+
$cartItemsArr = array ();
|
543 |
+
$cart = Mage::getSingleton ( 'checkout/cart' );
|
544 |
+
$quote = $cart->getQuote ();
|
545 |
+
$currency = $quote->getquote_currency_code ();
|
546 |
+
$displayCartPriceInclTax = Mage::helper ( 'tax' )->displayCartPriceInclTax ();
|
547 |
+
$displayCartPriceExclTax = Mage::helper ( 'tax' )->displayCartPriceExclTax ();
|
548 |
+
$displayCartBothPrices = Mage::helper ( 'tax' )->displayCartBothPrices ();
|
549 |
+
$items = $quote->getAllVisibleItems ();
|
550 |
+
foreach ( $items as $item ) {
|
551 |
+
$cartItemArr = array ();
|
552 |
+
$cartItemArr ['cart_item_id'] = $item->getId ();
|
553 |
+
$cartItemArr ['currency'] = $currency;
|
554 |
+
$cartItemArr ['entity_type'] = $item->getProductType ();
|
555 |
+
$cartItemArr ['item_id'] = $item->getProduct ()->getId ();
|
556 |
+
$cartItemArr ['item_title'] = strip_tags ( $item->getProduct ()->getName () );
|
557 |
+
$cartItemArr ['qty'] = $item->getQty ();
|
558 |
+
$cartItemArr ['thumbnail_pic_url'] = ( string ) Mage::getModel('catalog/product_media_config')
|
559 |
+
->getMediaUrl( $item->getImage() );
|
560 |
+
$cartItemArr ['custom_option'] = $this->_getCustomOptions ( $item );
|
561 |
+
if ($displayCartPriceExclTax || $displayCartBothPrices) {
|
562 |
+
if (Mage::helper ( 'weee' )->typeOfDisplay ( $item, array (
|
563 |
+
0,
|
564 |
+
1,
|
565 |
+
4
|
566 |
+
), 'sales' ) && $item->getWeeeTaxAppliedAmount ()) {
|
567 |
+
$exclPrice = $item->getCalculationPrice () + $item->getWeeeTaxAppliedAmount () + $item->getWeeeTaxDisposition ();
|
568 |
+
} else {
|
569 |
+
$exclPrice = $item->getCalculationPrice ();
|
570 |
+
}
|
571 |
+
}
|
572 |
+
$inclPrice = Mage::helper ( 'checkout' )->getPriceInclTax ( $item );
|
573 |
+
if ($displayCartPriceInclTax || $displayCartBothPrices) {
|
574 |
+
$_incl = Mage::helper ( 'checkout' )->getPriceInclTax ( $item );
|
575 |
+
if (Mage::helper ( 'weee' )->typeOfDisplay ( $item, array (
|
576 |
+
0,
|
577 |
+
1,
|
578 |
+
4
|
579 |
+
), 'sales' ) && $item->getWeeeTaxAppliedAmount ()) {
|
580 |
+
$inclPrice = $_incl + $item->getWeeeTaxAppliedAmount ();
|
581 |
+
} else {
|
582 |
+
$inclPrice = $_incl - $item->getWeeeTaxDisposition ();
|
583 |
+
}
|
584 |
+
}
|
585 |
+
|
586 |
+
//$cartItemArr ['item_price'] = max ( $exclPrice, $inclPrice );
|
587 |
+
$cartItemArr ['item_price'] = $exclPrice;
|
588 |
+
|
589 |
+
array_push ( $cartItemsArr, $cartItemArr );
|
590 |
+
}
|
591 |
+
|
592 |
+
return $cartItemsArr;
|
593 |
+
}
|
594 |
+
|
595 |
+
|
596 |
+
protected function _getCustomOptions($item) {
|
597 |
+
$session = Mage::getSingleton ( 'checkout/session' );
|
598 |
+
$options = $item->getProduct ()->getTypeInstance ( true )->getOrderOptions ( $item->getProduct () );
|
599 |
+
|
600 |
+
$result = array ();
|
601 |
+
if ($options) {
|
602 |
+
if (isset ( $options ['options'] )) {
|
603 |
+
$result = array_merge ( $result, $options ['options'] );
|
604 |
+
}
|
605 |
+
if (isset ( $options ['additional_options'] )) {
|
606 |
+
$result = $result = array_merge ( $result, $options ['additional_options'] );
|
607 |
+
}
|
608 |
+
if (! empty ( $options ['attributes_info'] )) {
|
609 |
+
$result = $result = array_merge ( $result, $options ['attributes_info'] );
|
610 |
+
}
|
611 |
+
}
|
612 |
+
|
613 |
+
return $result;
|
614 |
+
}
|
615 |
+
|
616 |
+
protected function _getCustomOption($item) {
|
617 |
+
$session = Mage::getSingleton ( 'checkout/session' );
|
618 |
+
$options = $item->getProduct ()->getTypeInstance ( true )->getOrderOptions ( $item->getProduct () );
|
619 |
+
|
620 |
+
$result = array ();
|
621 |
+
if (count($options['options'])) {
|
622 |
+
if (isset ( $options ['options'] )) {
|
623 |
+
$result = array_merge ( $result, $options ['options'] );
|
624 |
+
}
|
625 |
+
if (isset ( $options ['additional_options'] )) {
|
626 |
+
$result = $result = array_merge ( $result, $options ['additional_options'] );
|
627 |
+
}
|
628 |
+
/*if (! empty ( $options ['attributes_info'] )) {
|
629 |
+
$result = $result = array_merge ( $result, $options ['attributes_info'] );
|
630 |
+
}*/
|
631 |
+
}
|
632 |
+
|
633 |
+
return $result;
|
634 |
+
}
|
635 |
+
|
636 |
+
protected function _getConfigurableOptions($item) {
|
637 |
+
|
638 |
+
$options = $item->getProduct ()->getTypeInstance ( true )->getOrderOptions ( $item->getProduct () );
|
639 |
+
|
640 |
+
$result = array ();
|
641 |
+
if(count($options['info_buyRequest']['super_attribute'])):
|
642 |
+
$configurable = array();
|
643 |
+
$i = 0;
|
644 |
+
foreach($options['info_buyRequest']['super_attribute'] as $key => $value):
|
645 |
+
$configurable['attribute_id'] = $key;
|
646 |
+
$configurable['option_id'] = $value;
|
647 |
+
$configurable['attribute_name'] = $options['attributes_info'][$i]['label'];
|
648 |
+
$configurable['option_name'] = $options['attributes_info'][$i]['value'];
|
649 |
+
|
650 |
+
$i++;
|
651 |
+
$result[]= $configurable;
|
652 |
+
endforeach;
|
653 |
+
|
654 |
+
endif;
|
655 |
+
|
656 |
+
return $result;
|
657 |
+
}
|
658 |
+
|
659 |
+
|
660 |
+
public function _addToCart() {
|
661 |
+
$cart = Mage::getSingleton ( 'checkout/cart' );
|
662 |
+
$session = Mage::getSingleton ( 'core/session', array (
|
663 |
+
'name' => 'frontend'
|
664 |
+
) );
|
665 |
+
$params = $this->getRequest ()->getParams ();
|
666 |
+
if ($params ['isAjax'] == 1) {
|
667 |
+
$response = array ();
|
668 |
+
try {
|
669 |
+
if (isset ( $params ['qty'] )) {
|
670 |
+
$filter = new Zend_Filter_LocalizedToNormalized ( array (
|
671 |
+
'locale' => Mage::app ()->getLocale ()->getLocaleCode ()
|
672 |
+
) );
|
673 |
+
$params ['qty'] = $filter->filter ( $params ['qty'] );
|
674 |
+
}
|
675 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $params['product_id'] );
|
676 |
+
$related = $this->getRequest ()->getParam ( 'related_product' );
|
677 |
+
/**
|
678 |
+
* Check product availability
|
679 |
+
*/
|
680 |
+
if (! $product) {
|
681 |
+
$response ['status'] = 'ERROR';
|
682 |
+
$response ['message'] = $this->__ ( 'Unable to find Product ID' );
|
683 |
+
}
|
684 |
+
$cart->addProduct ( $product, $params );
|
685 |
+
if (! empty ( $related )) {
|
686 |
+
$cart->addProductsByIds ( explode ( ',', $related ) );
|
687 |
+
}
|
688 |
+
$cart->save ();
|
689 |
+
$session->setCartWasUpdated ( true );
|
690 |
+
/**
|
691 |
+
*
|
692 |
+
* @todo remove wishlist observer processAddToCart
|
693 |
+
*/
|
694 |
+
Mage::dispatchEvent ( 'checkout_cart_add_product_complete', array (
|
695 |
+
'product' => $product,
|
696 |
+
'request' => $this->getRequest (),
|
697 |
+
'response' => $this->getResponse ()
|
698 |
+
) );
|
699 |
+
if (! $session->getNoCartRedirect ( true )) {
|
700 |
+
if (! $cart->getQuote ()->getHasError ()) {
|
701 |
+
$message = $this->__ ( '%s was added to your shopping cart.', Mage::helper ( 'core' )->htmlEscape ( $product->getName () ) );
|
702 |
+
$response ['status'] = 'SUCCESS';
|
703 |
+
$response ['message'] = $message;
|
704 |
+
}
|
705 |
+
}
|
706 |
+
} catch ( Mage_Core_Exception $e ) {
|
707 |
+
$msg = "";
|
708 |
+
if ($session->getUseNotice ( true )) {
|
709 |
+
$msg = $e->getMessage ();
|
710 |
+
} else {
|
711 |
+
$messages = array_unique ( explode ( "\n", $e->getMessage () ) );
|
712 |
+
foreach ( $messages as $message ) {
|
713 |
+
$msg .= $message . '<br>';
|
714 |
+
}
|
715 |
+
}
|
716 |
+
$response ['status'] = 'ERROR';
|
717 |
+
$response ['message'] = $msg;
|
718 |
+
} catch ( Exception $e ) {
|
719 |
+
$response ['status'] = 'ERROR';
|
720 |
+
$response ['message'] = $this->__ ( 'Cannot add the item to shopping cart.' );
|
721 |
+
Mage::logException ( $e );
|
722 |
+
}
|
723 |
+
$this->getResponse ()->setBody ( Mage::helper ( 'core' )->jsonEncode ( $response ) );
|
724 |
+
return;
|
725 |
+
} else {
|
726 |
+
return parent::addAction ();
|
727 |
+
}
|
728 |
+
}
|
729 |
+
|
730 |
+
|
731 |
+
####get all enabled shipping methods
|
732 |
+
public function getshippingmethodsAction(){
|
733 |
+
|
734 |
+
$methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
|
735 |
+
$shipMethods = array();
|
736 |
+
foreach ($methods as $shippigCode=>$shippingModel)
|
737 |
+
{
|
738 |
+
|
739 |
+
if($shippigCode == 'freeshipping'):
|
740 |
+
if(Mage::getStoreConfig('carriers/'.$shippigCode.'/free_shipping_subtotal') < Mage::helper('checkout/cart')->getQuote()->getBaseSubtotalWithDiscount()):
|
741 |
+
$shippingTitle = Mage::getStoreConfig('carriers/'.$shippigCode.'/title');
|
742 |
+
$shippingPrice = Mage::getStoreConfig('carriers/'.$shippigCode.'/price');
|
743 |
+
$shipMethods[]=array(
|
744 |
+
'code'=>$shippigCode,
|
745 |
+
'value'=>$shippingTitle,
|
746 |
+
'price'=>(int)$shippingPrice
|
747 |
+
);
|
748 |
+
endif;
|
749 |
+
|
750 |
+
else:
|
751 |
+
$shippingTitle = Mage::getStoreConfig('carriers/'.$shippigCode.'/title');
|
752 |
+
$shippingPrice = Mage::getStoreConfig('carriers/'.$shippigCode.'/price');
|
753 |
+
$shipMethods[]=array(
|
754 |
+
'code'=>$shippigCode,
|
755 |
+
'value'=>$shippingTitle,
|
756 |
+
'price'=>(int)$shippingPrice
|
757 |
+
);
|
758 |
+
endif;
|
759 |
+
|
760 |
+
|
761 |
+
}
|
762 |
+
|
763 |
+
echo json_encode($shipMethods);
|
764 |
+
}
|
765 |
+
|
766 |
+
|
767 |
+
####get all payment methods for now only paypal and cod
|
768 |
+
public function getpaymentmethodsAction(){
|
769 |
+
|
770 |
+
$payments = Mage::getSingleton('payment/config')->getActiveMethods();
|
771 |
+
$methods = array();
|
772 |
+
foreach ($payments as $paymentCode=>$paymentModel) {
|
773 |
+
if(Mage::getStoreConfig('magentomobileshop_payment/'.$paymentCode.'/'.$paymentCode.'_status')):
|
774 |
+
$paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
|
775 |
+
if($paymentCode == 'authorizenet')
|
776 |
+
$methods[] = array(
|
777 |
+
'value' => $paymentTitle,
|
778 |
+
'code' => $paymentCode,
|
779 |
+
'cards' => array('Visa'=>'VI','Mastercard'=>'MC','American Express'=>'AE','Discover'=>'DI'),
|
780 |
+
);
|
781 |
+
else
|
782 |
+
$methods[] = array(
|
783 |
+
'value' => $paymentTitle,
|
784 |
+
'code' => $paymentCode,
|
785 |
+
);
|
786 |
+
endif;
|
787 |
+
}
|
788 |
+
/* if(Mage::getStoreConfig('magentomobileshop_payment/paypal_express/paypal_express_status') &&
|
789 |
+
Mage::getStoreConfig('magentomobileshop_payment/paypal_express/paypal_express_email'))
|
790 |
+
$methods[] = array('value'=> 'PayPal Express Checkout','code'=> 'paypal_express');
|
791 |
+
*/
|
792 |
+
|
793 |
+
echo json_encode($methods);
|
794 |
+
}
|
795 |
+
|
796 |
+
|
797 |
+
/*check for minium order*/
|
798 |
+
public function checkMinimumorder($price){
|
799 |
+
|
800 |
+
|
801 |
+
$amount = Mage::getStoreConfig('sales/minimum_order/amount');
|
802 |
+
if ($price < $amount):
|
803 |
+
$message = Mage::getStoreConfig('sales/minimum_order/error_message');
|
804 |
+
if(!$message) $message = 'Minimum Order Limit is '.$amount;
|
805 |
+
echo json_encode(array('status'=>'error','message'=> $message));
|
806 |
+
exit;
|
807 |
+
endif;
|
808 |
+
|
809 |
+
return true;
|
810 |
+
|
811 |
+
}
|
812 |
+
|
813 |
+
####place order api
|
814 |
+
public function placeOrderAction(){
|
815 |
+
|
816 |
+
if(Mage::getStoreConfig('sales/minimum_order/active')):
|
817 |
+
$check_grand_total = Mage::helper('checkout/cart')->getQuote()->getBaseSubtotalWithDiscount();
|
818 |
+
$this->checkMinimumorder($check_grand_total);
|
819 |
+
endif;
|
820 |
+
|
821 |
+
if (Mage::getSingleton ( 'customer/session' )->isLoggedIn ()) {
|
822 |
+
|
823 |
+
|
824 |
+
$session = Mage::getSingleton ( 'customer/session' );
|
825 |
+
$customerId=$session->getId();
|
826 |
+
|
827 |
+
|
828 |
+
|
829 |
+
##Get current quote
|
830 |
+
$totalItems = Mage::helper('checkout/cart')->getSummaryCount();
|
831 |
+
|
832 |
+
if($totalItems > 0):
|
833 |
+
#get the addressid
|
834 |
+
$addressId=(int)$this->getRequest()->getParam('addressid');
|
835 |
+
$shipping_method=$this->getRequest()->getParam('shippingmethod');
|
836 |
+
$paymentmethod=$this->getRequest()->getParam('paymentmethod');
|
837 |
+
$registration_id = $this->getRequest()->getParam('registration_id');
|
838 |
+
$card_details = $this->getRequest()->getParam('cards_details');
|
839 |
+
$save_cc = $this->getRequest()->getParam('save_cc');
|
840 |
+
|
841 |
+
|
842 |
+
|
843 |
+
if($paymentmethod == 'authorizenet')
|
844 |
+
$this->validateCarddtails(json_decode($card_details,1));
|
845 |
+
|
846 |
+
if (!Zend_Validate::is($addressId, 'NotEmpty')):
|
847 |
+
echo json_encode(array('Status'=>'error','message'=>'AddressId should not be empty'));
|
848 |
+
exit;
|
849 |
+
endif;
|
850 |
+
if (!Zend_Validate::is($shipping_method, 'NotEmpty')):
|
851 |
+
echo json_encode(array('Status'=>'error','message'=>'Shippingmethod should not be empty'));
|
852 |
+
exit;
|
853 |
+
endif;
|
854 |
+
if (!Zend_Validate::is($paymentmethod, 'NotEmpty')):
|
855 |
+
echo json_encode(array('Status'=>'error','message'=>'paymentmethod should not be empty'));
|
856 |
+
exit;
|
857 |
+
endif;
|
858 |
+
if($addressId==''){
|
859 |
+
$result=array(
|
860 |
+
'message'=>'address is missing!!!!',
|
861 |
+
'status'=>'success'
|
862 |
+
|
863 |
+
);
|
864 |
+
echo json_encode($result);
|
865 |
+
exit;
|
866 |
+
|
867 |
+
}
|
868 |
+
|
869 |
+
|
870 |
+
#load the customer
|
871 |
+
$customer = Mage::getModel('customer/customer')->load($customerId);
|
872 |
+
|
873 |
+
#address load
|
874 |
+
try {
|
875 |
+
$addressData=Mage::getModel('customer/address')->load($addressId)->getData();
|
876 |
+
$quote=Mage::getSingleton ( 'checkout/session' )->getQuote();
|
877 |
+
$quote->setMms_order_type('app')->save();
|
878 |
+
|
879 |
+
$billingAddress = $quote->getBillingAddress()->addData($addressData);
|
880 |
+
$shippingAddress = $quote->getShippingAddress()->addData($addressData);
|
881 |
+
|
882 |
+
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
|
883 |
+
->setShippingMethod($shipping_method.'_'.$shipping_method);
|
884 |
+
|
885 |
+
if($paymentmethod != 'authorizenet'):
|
886 |
+
$shippingAddress->setPaymentMethod($paymentmethod);
|
887 |
+
$quote->getPayment()->importData(array('method' => $paymentmethod));
|
888 |
+
|
889 |
+
endif;
|
890 |
+
|
891 |
+
|
892 |
+
|
893 |
+
|
894 |
+
$quote->collectTotals()->save();
|
895 |
+
|
896 |
+
|
897 |
+
$transaction = Mage::getModel('core/resource_transaction');
|
898 |
+
|
899 |
+
if ($quote->getCustomerId()) {
|
900 |
+
$transaction->addObject($quote->getCustomer());
|
901 |
+
}
|
902 |
+
$transaction->addObject($quote);
|
903 |
+
$quote->reserveOrderId();
|
904 |
+
|
905 |
+
|
906 |
+
if($paymentmethod == 'authorizenet')
|
907 |
+
$this->authorizePayment($quote,$transaction,$save_cc);
|
908 |
+
|
909 |
+
|
910 |
+
$service = Mage::getModel('sales/service_quote', $quote);
|
911 |
+
$service->submitAll();
|
912 |
+
$order = $service->getOrder();
|
913 |
+
$quote->delete();
|
914 |
+
|
915 |
+
$cart = Mage::helper ( 'checkout/cart' )->getCart ();
|
916 |
+
if($cart->getQuote ()->getItemsCount ()){
|
917 |
+
Mage::getSingleton('checkout/cart')->truncate()->save();
|
918 |
+
}
|
919 |
+
Mage::getSingleton('checkout/session')->clear();
|
920 |
+
|
921 |
+
$result=array( 'message'=>'Order placed successfully.',
|
922 |
+
'orderid'=>$order->getIncrementId(),
|
923 |
+
'result'=>'success'
|
924 |
+
|
925 |
+
);
|
926 |
+
|
927 |
+
|
928 |
+
|
929 |
+
echo json_encode($result);
|
930 |
+
|
931 |
+
} catch (Exception $e) {
|
932 |
+
|
933 |
+
echo json_encode(array('status'=>'error','message'=>$e->getMessage()));
|
934 |
+
exit;
|
935 |
+
|
936 |
+
}
|
937 |
+
else:
|
938 |
+
$result=array(
|
939 |
+
'message'=>'cart is empty',
|
940 |
+
'result'=>'success'
|
941 |
+
|
942 |
+
);
|
943 |
+
echo json_encode($result);
|
944 |
+
endif;
|
945 |
+
|
946 |
+
}else{
|
947 |
+
ini_set('memory_limit', '128M');
|
948 |
+
|
949 |
+
$getParams = $this->getRequest()->getParams();
|
950 |
+
|
951 |
+
$payment_method = $getParams['paymentmethod'];
|
952 |
+
$shipping_method = $getParams['shippingmethod'];
|
953 |
+
$registration_id = $this->getRequest()->getParam('registration_id');
|
954 |
+
$card_details = $this->getRequest()->getParam('cards_details');
|
955 |
+
$save_cc = $this->getRequest()->getParam('save_cc');
|
956 |
+
|
957 |
+
if($payment_method == 'authorizenet')
|
958 |
+
$this->validateCarddtails(json_decode($card_details,1));
|
959 |
+
|
960 |
+
|
961 |
+
try{
|
962 |
+
|
963 |
+
if(Mage::getStoreConfig('sales/minimum_order/active')):
|
964 |
+
$check_grand_total = Mage::helper('checkout/cart')->getQuote()->getBaseSubtotalWithDiscount();
|
965 |
+
$this->checkMinimumorder($check_grand_total);
|
966 |
+
endif;
|
967 |
+
|
968 |
+
$checkout_session =Mage::getModel ( 'checkout/session' )->getQuoteId();
|
969 |
+
Mage::getSingleton ( 'checkout/session' )->getQuote()->setMms_order_type('app')->save();
|
970 |
+
|
971 |
+
$quote = Mage::getModel('sales/quote')->load($checkout_session);
|
972 |
+
$quote->setStoreId(Mage::app()->getStore()->getId());
|
973 |
+
|
974 |
+
|
975 |
+
|
976 |
+
|
977 |
+
$billingAddress = array(
|
978 |
+
'firstname' => $getParams['firstname'],
|
979 |
+
'lastname' => $getParams['lastname'],
|
980 |
+
|
981 |
+
'email' => $getParams['email'],
|
982 |
+
'street' => array(
|
983 |
+
$getParams['street_line_1'],
|
984 |
+
@$getParams['street_line_2']
|
985 |
+
),
|
986 |
+
'city' => $getParams['city'],
|
987 |
+
/*'region' => $getParams['region'],*/
|
988 |
+
'postcode' => $getParams['postcode'],
|
989 |
+
'country_id' => $getParams['country_id'],
|
990 |
+
'telephone' => $getParams['telephone'],
|
991 |
+
'customer_password' => '',
|
992 |
+
'confirm_password' => '',
|
993 |
+
'save_in_address_book' => '0',
|
994 |
+
'use_for_shipping' => '1',
|
995 |
+
);
|
996 |
+
|
997 |
+
if(isset($data['region']))
|
998 |
+
$billingAddress['region']=$getParams['region'];
|
999 |
+
else
|
1000 |
+
$billingAddress['region_id']=$getParams['region_id'];
|
1001 |
+
|
1002 |
+
$quote->getBillingAddress()
|
1003 |
+
->addData($billingAddress);
|
1004 |
+
|
1005 |
+
$quote->getShippingAddress()
|
1006 |
+
->addData($billingAddress)
|
1007 |
+
->setShippingMethod($shipping_method.'_'.$shipping_method);
|
1008 |
+
|
1009 |
+
$quote->getShippingAddress()->setCollectShippingRates(true)->collectShippingRates();
|
1010 |
+
$quote->collectTotals();
|
1011 |
+
|
1012 |
+
if($payment_method != 'authorizenet'):
|
1013 |
+
$quote->setPaymentMethod($payment_method);
|
1014 |
+
$quote->getPayment()->importData( array('method' => $payment_method));
|
1015 |
+
|
1016 |
+
endif;
|
1017 |
+
|
1018 |
+
$customer_id = Mage::helper('connector')->reigesterGuestUser(array('firstname' => $getParams['firstname'],
|
1019 |
+
'lastname' => $getParams['lastname'],'email'=>$getParams['email']));
|
1020 |
+
|
1021 |
+
$quote->setCustomer(Mage::getSingleton('customer/customer')->load($customer_id));
|
1022 |
+
|
1023 |
+
$quote->save();
|
1024 |
+
|
1025 |
+
$transaction = Mage::getModel('core/resource_transaction');
|
1026 |
+
|
1027 |
+
if ($quote->getCustomerId())
|
1028 |
+
$transaction->addObject($quote->getCustomer());
|
1029 |
+
|
1030 |
+
if($payment_method == 'authorizenet')
|
1031 |
+
$this->authorizePayment($quote,$transaction,$save_cc);
|
1032 |
+
|
1033 |
+
|
1034 |
+
$service = Mage::getModel('sales/service_quote', $quote);
|
1035 |
+
$service->submitAll();
|
1036 |
+
$order = $service->getOrder();
|
1037 |
+
|
1038 |
+
$increment_id = $order->getRealOrderId();
|
1039 |
+
$quote = $customer = $service = null;
|
1040 |
+
|
1041 |
+
|
1042 |
+
$cart = Mage::helper ( 'checkout/cart' )->getCart ();
|
1043 |
+
if($cart->getQuote ()->getItemsCount ()){
|
1044 |
+
Mage::getSingleton('checkout/cart')->truncate()->save();
|
1045 |
+
}
|
1046 |
+
Mage::getSingleton('checkout/session')->clear();
|
1047 |
+
echo json_encode(array('status' =>'success','orderid' => $increment_id));
|
1048 |
+
exit;
|
1049 |
+
}
|
1050 |
+
catch (Exception $e)
|
1051 |
+
{
|
1052 |
+
echo json_encode(array('status' =>'error','message' => $e->getMessage()));
|
1053 |
+
exit;
|
1054 |
+
|
1055 |
+
}
|
1056 |
+
|
1057 |
+
}
|
1058 |
+
|
1059 |
+
}
|
1060 |
+
|
1061 |
+
public function authorizePayment($quoteObj,$transaction,$save_cc=false){
|
1062 |
+
|
1063 |
+
$ccInfo = array();
|
1064 |
+
$quotePaymentObj = $quoteObj->getPayment();
|
1065 |
+
$quotePaymentObj->setMethod('authorizenet');
|
1066 |
+
$quoteObj->setPayment($quotePaymentObj);
|
1067 |
+
|
1068 |
+
$quoteObj->getPayment()->setCcNumber($this->cc_number);
|
1069 |
+
$quoteObj->getPayment()->setCcType($this->cc_type);
|
1070 |
+
$quoteObj->getPayment()->setCcExpMonth($this->cc_month);
|
1071 |
+
$quoteObj->getPayment()->setCcExpYear($this->cc_year);
|
1072 |
+
$quoteObj->getPayment()->setCcLast4(substr($this->cc_number,-4));
|
1073 |
+
$quoteObj->getPayment()->setCcCid($this->cc_cid);
|
1074 |
+
|
1075 |
+
|
1076 |
+
$convertQuoteObj = Mage::getSingleton('sales/convert_quote');
|
1077 |
+
if ($quoteObj->getIsVirtual())
|
1078 |
+
$orderObj = $convertQuoteObj->addressToOrder($quoteObj->getBillingAddress());
|
1079 |
+
else
|
1080 |
+
$orderObj = $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());
|
1081 |
+
|
1082 |
+
$orderPaymentObj = $convertQuoteObj->paymentToOrderPayment($quotePaymentObj);
|
1083 |
+
|
1084 |
+
$orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getBillingAddress()));
|
1085 |
+
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
|
1086 |
+
|
1087 |
+
if (!$quoteObj->getIsVirtual())
|
1088 |
+
$orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()));
|
1089 |
+
|
1090 |
+
|
1091 |
+
// set payment options
|
1092 |
+
if (count($ccInfo) > 0):
|
1093 |
+
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
|
1094 |
+
$orderObj->getPayment()->setCcNumber($this->cc_number);
|
1095 |
+
$orderObj->getPayment()->setCcType($this->cc_type);
|
1096 |
+
$orderObj->getPayment()->setCcExpMonth($this->cc_month);
|
1097 |
+
$orderObj->getPayment()->setCcExpYear($this->cc_year);
|
1098 |
+
$orderObj->getPayment()->setCcLast4(substr($this->cc_number,-4));
|
1099 |
+
$orderObj->getPayment()->setCcCid($this->cc_cid);
|
1100 |
+
|
1101 |
+
else:
|
1102 |
+
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
|
1103 |
+
endif;
|
1104 |
+
|
1105 |
+
$items=$quoteObj->getAllItems();
|
1106 |
+
|
1107 |
+
foreach ($items as $item):
|
1108 |
+
|
1109 |
+
$orderItem = $convertQuoteObj->itemToOrderItem($item);
|
1110 |
+
|
1111 |
+
if ($item->getParentItem())
|
1112 |
+
$orderItem->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
|
1113 |
+
|
1114 |
+
$orderObj->addItem($orderItem);
|
1115 |
+
endforeach;
|
1116 |
+
|
1117 |
+
$orderObj->setCanShipPartiallyItem(false);
|
1118 |
+
|
1119 |
+
$totalDue = $orderObj->getTotalDue();
|
1120 |
+
|
1121 |
+
$transaction->addObject($orderObj);
|
1122 |
+
$transaction->addCommitCallback(array($orderObj, 'place'));
|
1123 |
+
$transaction->addCommitCallback(array($orderObj, 'save'));
|
1124 |
+
|
1125 |
+
try {
|
1126 |
+
$transaction->save();
|
1127 |
+
|
1128 |
+
$data = array('cc_number'=>(int)$this->cc_number,
|
1129 |
+
'cc_type'=>$this->cc_type,
|
1130 |
+
'cc_exp_month'=>(int)$this->cc_month,
|
1131 |
+
'cc_exp_year'=>(int)$this->cc_year,
|
1132 |
+
'cc_last4'=>(int)substr($this->cc_number,-4)
|
1133 |
+
);
|
1134 |
+
|
1135 |
+
if($save_cc =='true')Mage::helper('connector')->saveCc($data);
|
1136 |
+
|
1137 |
+
} catch (Exception $e){
|
1138 |
+
Mage::throwException('Order Cancelled Bad Response from Credit Authorization.');
|
1139 |
+
exit;
|
1140 |
+
}
|
1141 |
+
|
1142 |
+
$orderObj->sendNewOrderEmail();
|
1143 |
+
|
1144 |
+
try{
|
1145 |
+
$quoteObj->setIsActive(0);
|
1146 |
+
$quoteObj->save();
|
1147 |
+
$orderId =$orderObj->getRealOrderId();
|
1148 |
+
/*$quoteObj->delete();*/
|
1149 |
+
|
1150 |
+
$cart = Mage::helper ( 'checkout/cart' )->getCart ();
|
1151 |
+
if($cart->getQuote ()->getItemsCount ())
|
1152 |
+
Mage::getSingleton('checkout/cart')->truncate()->save();
|
1153 |
+
|
1154 |
+
Mage::getSingleton('checkout/session')->clear();
|
1155 |
+
}
|
1156 |
+
catch(exception $e){
|
1157 |
+
//add mail function
|
1158 |
+
}
|
1159 |
+
|
1160 |
+
|
1161 |
+
|
1162 |
+
$result=array( 'message'=>'Order placed successfully.',
|
1163 |
+
'orderid'=>$orderId,
|
1164 |
+
'result'=>'success'
|
1165 |
+
|
1166 |
+
);
|
1167 |
+
|
1168 |
+
echo json_encode($result);exit;
|
1169 |
+
|
1170 |
+
}
|
1171 |
+
|
1172 |
+
|
1173 |
+
// Authorize.net payment Implementation
|
1174 |
+
|
1175 |
+
public function validateCarddtails($card_details){
|
1176 |
+
|
1177 |
+
if(!sizeof($card_details)):
|
1178 |
+
echo json_encode(array('status' =>'error','message' => 'Card Information is required in case of authorize.net payment method.'));
|
1179 |
+
exit;
|
1180 |
+
endif;
|
1181 |
+
|
1182 |
+
if(!$card_details['cc_type'] || !$card_details['cc_number'] ||
|
1183 |
+
!$card_details['cc_month'] || !$card_details['cc_year'] || !$card_details['cc_cid']):
|
1184 |
+
echo json_encode(array('status' =>'error','message' => 'Some Required card information is missing.'));
|
1185 |
+
exit;
|
1186 |
+
endif;
|
1187 |
+
$this->cc_type = $card_details['cc_type'];
|
1188 |
+
$this->cc_number = $card_details['cc_number'];
|
1189 |
+
$this->cc_month = $card_details['cc_month'];
|
1190 |
+
$this->cc_year = $card_details['cc_year'];
|
1191 |
+
$this->cc_cid = $card_details['cc_cid'];
|
1192 |
+
|
1193 |
+
|
1194 |
+
return true;
|
1195 |
+
|
1196 |
+
|
1197 |
+
}
|
1198 |
+
|
1199 |
+
/* URL : /restapi/cart/getcheckoutcart/
|
1200 |
+
Route: Connector
|
1201 |
+
Controller: cart
|
1202 |
+
Action: getcheckoutcart
|
1203 |
+
Request Parameter : None
|
1204 |
+
Method : POST
|
1205 |
+
Response : JSON
|
1206 |
+
{"product":[{"id":"3","sku":"test3","qty":7,"Name":"test3","Price":3500}],"subtotal":"3500.0000","grandtotal":"3500.0000","totalitems":"1","totalquantity":"3500.0000"}
|
1207 |
+
*/
|
1208 |
+
|
1209 |
+
public function getcheckoutcartAction(){
|
1210 |
+
$customerId =(int)$this->getRequest()->getParam('customerid');
|
1211 |
+
|
1212 |
+
if ($customerId) {
|
1213 |
+
|
1214 |
+
$customer = Mage::getModel('customer/customer')->load($customerId);
|
1215 |
+
try{
|
1216 |
+
$cart = Mage::getModel('sales/quote') ->loadByCustomer($customer);
|
1217 |
+
|
1218 |
+
if(!count($cart->getAllItems())):
|
1219 |
+
echo json_encode(array('status'=>'success','message'=>$product));
|
1220 |
+
exit;
|
1221 |
+
endif;
|
1222 |
+
$product_model = Mage::getModel ( 'catalog/product' );
|
1223 |
+
foreach ($cart->getAllItems() as $item) {
|
1224 |
+
|
1225 |
+
|
1226 |
+
|
1227 |
+
$productName= array();
|
1228 |
+
$productName['id'] = $item->getProductId();
|
1229 |
+
$productName['sku'] = $item->getSku();
|
1230 |
+
$productName['qty'] = $item->getQty();
|
1231 |
+
$productName['Name'] = $item->getProduct()->getName();
|
1232 |
+
/*$productName['Price'] = $item->getPrice()* $item->getQty();*/
|
1233 |
+
$productName['Price'] = $item->getPrice();
|
1234 |
+
$productName['image'] =Mage::helper('connector')-> Imageresize($product_model->load($item->getProductId())->getImage()
|
1235 |
+
,'product','100','100');
|
1236 |
+
|
1237 |
+
if($product_model->load($item->getProductId())->isConfigurable())
|
1238 |
+
$productName['configurable'] = $this->_getConfigurableOptions( $item );
|
1239 |
+
|
1240 |
+
if($product_model->load($item->getProductId())->getData('has_options'))
|
1241 |
+
$productName['custom_option'] = $this->_getCustomOption( $item );
|
1242 |
+
|
1243 |
+
$product['product'][] = $productName;
|
1244 |
+
|
1245 |
+
}
|
1246 |
+
$product['subtotal'] = $cart->getSubtotal();
|
1247 |
+
$product['grandtotal'] = $cart->getGrandTotal();
|
1248 |
+
$product['totalitems'] = $cart->getItemsCount();
|
1249 |
+
$product['symbol'] = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
|
1250 |
+
|
1251 |
+
echo json_encode(array('status'=>'success','message'=>$product));
|
1252 |
+
|
1253 |
+
}
|
1254 |
+
catch(exception $e)
|
1255 |
+
{
|
1256 |
+
echo json_encode(array('status'=>'error','message'=>$e->getMessage()));
|
1257 |
+
}
|
1258 |
+
}
|
1259 |
+
else{
|
1260 |
+
|
1261 |
+
echo json_encode(array('status'=>'error','message'=>'Please Login.'));
|
1262 |
+
}
|
1263 |
+
|
1264 |
+
|
1265 |
+
}
|
1266 |
+
|
1267 |
+
/* Cancel Order API :
|
1268 |
+
|
1269 |
+
URL : /restapi/cart/cancelOrder/
|
1270 |
+
Route: Connector
|
1271 |
+
Controller: cart
|
1272 |
+
Action: cancelOrder
|
1273 |
+
Request Parameter orderId
|
1274 |
+
Method : POST
|
1275 |
+
Response : status(error,success),message
|
1276 |
+
|
1277 |
+
*/
|
1278 |
+
|
1279 |
+
public function cancelOrderAction(){
|
1280 |
+
$orderId =(int)$this->getRequest()->getParam('orderid');
|
1281 |
+
|
1282 |
+
if($orderId):
|
1283 |
+
if(Mage::getSingleton ( 'customer/session' )->isLoggedIn()):
|
1284 |
+
try{
|
1285 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
|
1286 |
+
if(!$order->getId()):
|
1287 |
+
echo json_encode(array('status'=>'error','message'=>'Invalid Order Id.'));
|
1288 |
+
exit;
|
1289 |
+
endif;
|
1290 |
+
|
1291 |
+
$order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
|
1292 |
+
|
1293 |
+
$history = $order->addStatusHistoryComment('Order marked as cancelled by User.', false);
|
1294 |
+
$history->setIsCustomerNotified(true);
|
1295 |
+
|
1296 |
+
if($order->canCancel())
|
1297 |
+
$order->cancel()->save();
|
1298 |
+
}
|
1299 |
+
catch(Exceptio $e)
|
1300 |
+
{
|
1301 |
+
echo json_encode(array('status'=>'error','message'=>$e->getMessage()));
|
1302 |
+
exit;
|
1303 |
+
}
|
1304 |
+
|
1305 |
+
echo json_encode(array('status'=>'success','message'=>'Order marked as cancelled by User.'));
|
1306 |
+
exit;
|
1307 |
+
else:
|
1308 |
+
echo json_encode(array('status'=>'error','message'=>'Login first tio cancel Order.'));
|
1309 |
+
exit;
|
1310 |
+
endif;
|
1311 |
+
|
1312 |
+
else:
|
1313 |
+
echo json_encode(array('status'=>'error','message'=>'Please send Order Id to cancel.'));
|
1314 |
+
exit;
|
1315 |
+
endif;
|
1316 |
+
|
1317 |
+
}
|
1318 |
+
|
1319 |
+
/* Get Saved Cards API :
|
1320 |
+
|
1321 |
+
URL : /restapi/cart/getsavedCc/
|
1322 |
+
Route: Connector
|
1323 |
+
Controller: cart
|
1324 |
+
Action: getsavedCc
|
1325 |
+
Method : POST
|
1326 |
+
|
1327 |
+
*/
|
1328 |
+
|
1329 |
+
public function getsavedCcAction(){
|
1330 |
+
|
1331 |
+
$user_id = Mage::getSingleton("customer/session")->getId();
|
1332 |
+
|
1333 |
+
$collection = Mage::getModel("connector/connector")->getCollection();
|
1334 |
+
$collection->addFieldToFilter('user_id',array('eq'=>$user_id))
|
1335 |
+
->addFieldToSelect(array('id','cc_number','cc_last4','cc_type','cc_exp_month','cc_exp_year'));
|
1336 |
+
|
1337 |
+
if($collection->getSize()):
|
1338 |
+
echo json_encode($collection->getData());
|
1339 |
+
exit;
|
1340 |
+
else:
|
1341 |
+
echo json_encode(array());
|
1342 |
+
exit;
|
1343 |
+
|
1344 |
+
endif;
|
1345 |
+
echo json_encode(array()); exit;
|
1346 |
+
|
1347 |
+
|
1348 |
+
}
|
1349 |
+
|
1350 |
+
/* Remove Saved Cards API :
|
1351 |
+
|
1352 |
+
URL : /restapi/cart/removesavedCc/
|
1353 |
+
Route: Connector
|
1354 |
+
Controller: cart
|
1355 |
+
Action: removesavedCc
|
1356 |
+
Parameter : id*
|
1357 |
+
Method : POST
|
1358 |
+
|
1359 |
+
*/
|
1360 |
+
|
1361 |
+
public function removesavedCcAction(){
|
1362 |
+
|
1363 |
+
$cc_id =(int)$this->getRequest()->getParam('id');
|
1364 |
+
|
1365 |
+
|
1366 |
+
$user_id = Mage::getSingleton("customer/session")->getId();
|
1367 |
+
|
1368 |
+
if($cc_id && $user_id):
|
1369 |
+
|
1370 |
+
$collection = Mage::getModel("connector/connector")->getCollection();
|
1371 |
+
|
1372 |
+
$collection->addFieldToFilter(array('user_id', 'id'), array( array('eq'=>$user_id),
|
1373 |
+
array('eq'=>$cc_id)
|
1374 |
+
));
|
1375 |
+
|
1376 |
+
if($collection->getSize()):
|
1377 |
+
foreach ($collection as $cc_card):
|
1378 |
+
try{$cc_card->delete();}
|
1379 |
+
catch(expection $e){
|
1380 |
+
echo json_encode( array('status' => 'error' , 'massage'=>$e->getMessage() ));
|
1381 |
+
exit;
|
1382 |
+
}
|
1383 |
+
endforeach;
|
1384 |
+
endif;
|
1385 |
+
echo json_encode( array('status' => 'success' , 'massage'=>'Card remove successfully' ));
|
1386 |
+
exit;
|
1387 |
+
else:
|
1388 |
+
echo json_encode( array('status' => 'error' , 'massage'=>'error in removing card' ));
|
1389 |
+
exit;
|
1390 |
+
endif;
|
1391 |
+
}
|
1392 |
+
|
1393 |
+
|
1394 |
+
}
|
app/code/local/Mss/Connector/controllers/CreditController.php
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_CreditController extends Mage_Core_Controller_Front_Action{
|
4 |
+
|
5 |
+
public function _construct(){
|
6 |
+
|
7 |
+
header('content-type: application/json; charset=utf-8');
|
8 |
+
header("access-control-allow-origin: *");
|
9 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
10 |
+
parent::_construct();
|
11 |
+
|
12 |
+
}
|
13 |
+
|
14 |
+
private function getCustomerId($customer)
|
15 |
+
{
|
16 |
+
$customerid = Mage::getModel('customer/customer')->load($customer);
|
17 |
+
if ($customerid->getData()) {
|
18 |
+
return $customerid->getId();
|
19 |
+
} else {
|
20 |
+
$collection = Mage::getModel('customer/customer')->getCollection();
|
21 |
+
$collection->addFieldToFilter('email', $customer);
|
22 |
+
return $collection->getFirstItem()->getId();
|
23 |
+
}
|
24 |
+
}
|
25 |
+
|
26 |
+
/* set transaction type
|
27 |
+
*
|
28 |
+
* return type_id
|
29 |
+
*/
|
30 |
+
|
31 |
+
private function setType($type)
|
32 |
+
{
|
33 |
+
$collection = Mage::getModel('customercredit/typetransaction')->getCollection();
|
34 |
+
$collection->addFieldToFilter('transaction_name', $type);
|
35 |
+
if (count($collection)) {
|
36 |
+
return $collection->getFirstItem()->getId();
|
37 |
+
} else {
|
38 |
+
$update_type = Mage::getModel('customercredit/typetransaction');
|
39 |
+
$update_type->setTransactionName($type);
|
40 |
+
try {
|
41 |
+
$update_type->save();
|
42 |
+
return $update_type->getId();
|
43 |
+
} catch (exception $e) {
|
44 |
+
return null;
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
/* update credit balance */
|
50 |
+
|
51 |
+
public function updateBalance($customer, $value)
|
52 |
+
{
|
53 |
+
$customer_id = $this->getCustomerId($customer);
|
54 |
+
$customer = Mage::getModel('customer/customer')->load($customer_id);
|
55 |
+
$customer->setCreditValue($customer->getCreditValue() + $value)->save();
|
56 |
+
}
|
57 |
+
|
58 |
+
public function getCreditBalanceAction()
|
59 |
+
{
|
60 |
+
$customer_id=Mage::app ()->getRequest ()->getParam ( 'customer_id' );
|
61 |
+
if (!Zend_Validate::is($customer_id, 'NotEmpty')):
|
62 |
+
echo json_encode(array('status'=>'error','message'=>'Customer Id should not be empty'));
|
63 |
+
exit;
|
64 |
+
endif;
|
65 |
+
$customer = Mage::getModel('customer/customer')->load($customer_id);
|
66 |
+
if(count($customer->getData())>0):
|
67 |
+
echo json_encode('The credit balance of customer id '.$customer_id.'is'.$customer->getCreditValue());
|
68 |
+
else:
|
69 |
+
echo json_encode(array('status'=>'error','message'=>'CustomerId does not exist'));
|
70 |
+
endif;
|
71 |
+
|
72 |
+
}
|
73 |
+
|
74 |
+
public function updateCreditAction()
|
75 |
+
{
|
76 |
+
$customer_id=Mage::app ()->getRequest ()->getParam ( 'customer_id' );
|
77 |
+
$transaction_type=Mage::app ()->getRequest ()->getParam ( 'transaction_type' );
|
78 |
+
$transaction_detail=Mage::app ()->getRequest ()->getParam ( 'transaction_detail' );
|
79 |
+
$order_id=Mage::app ()->getRequest ()->getParam ( 'order_id' );
|
80 |
+
$amount_credit=Mage::app ()->getRequest ()->getParam ( 'amount_credit' );
|
81 |
+
|
82 |
+
if (!Zend_Validate::is($customer_id, 'NotEmpty')):
|
83 |
+
echo json_encode(array('status'=>'error','message'=>'Customer Id should not be empty'));
|
84 |
+
exit;
|
85 |
+
endif;
|
86 |
+
|
87 |
+
if (!Zend_Validate::is($transaction_type, 'NotEmpty')):
|
88 |
+
echo json_encode(array('status'=>'error','message'=>'Transaction Type should not be empty'));
|
89 |
+
exit;
|
90 |
+
endif;
|
91 |
+
|
92 |
+
if (!Zend_Validate::is($amount_credit, 'NotEmpty')):
|
93 |
+
echo json_encode(array('status'=>'error','message'=>'Amount Credit should not be empty'));
|
94 |
+
exit;
|
95 |
+
endif;
|
96 |
+
|
97 |
+
Mage::getModel('customercredit/transaction')->addTransactionHistory($customer_id, $transaction_type, $transaction_detail, $order_id, $amount_credit);
|
98 |
+
$this->updateBalance($customer_id, $amount_credit);
|
99 |
+
echo json_encode(array('status'=>'success','message'=>'Credit has been updated'));
|
100 |
+
}
|
101 |
+
|
102 |
+
public function redeemCreditAction()
|
103 |
+
{
|
104 |
+
|
105 |
+
$customer_id=Mage::app ()->getRequest ()->getParam ( 'customer_id' );
|
106 |
+
$creditcode=Mage::app ()->getRequest ()->getParam ( 'creditcode' );
|
107 |
+
if (!Zend_Validate::is($customer_id, 'NotEmpty')):
|
108 |
+
echo json_encode(array('status'=>'error','message'=>'Customer Id should not be empty'));
|
109 |
+
exit;
|
110 |
+
endif;
|
111 |
+
|
112 |
+
if (!Zend_Validate::is($creditcode, 'NotEmpty')):
|
113 |
+
echo json_encode(array('status'=>'error','message'=>'Credit Code should not be empty'));
|
114 |
+
exit;
|
115 |
+
endif;
|
116 |
+
|
117 |
+
$credit = Mage::getModel('customercredit/creditcode')->getCollection()
|
118 |
+
->addFieldToFilter('credit_code', $creditcode);
|
119 |
+
if(count($credit->getData)):
|
120 |
+
echo json_encode(array('status'=>'error','message'=>'Customer ID does not be exist'));
|
121 |
+
exit;
|
122 |
+
endif;
|
123 |
+
if ($credit->getSize() == 0) {
|
124 |
+
json_encode(array('status'=>'error','message'=>' Code is invalid. Please check again!'));
|
125 |
+
exit;
|
126 |
+
}
|
127 |
+
if ($credit->getFirstItem()->getStatus() != 1) {
|
128 |
+
json_encode(array('status'=>'error','message'=>' Code was used. Please check again!'));
|
129 |
+
}
|
130 |
+
|
131 |
+
Mage::getModel('customercredit/creditcode')
|
132 |
+
->changeCodeStatus($credit->getFirstItem()->getId(), Magestore_Customercredit_Model_Status::STATUS_UNUSED);
|
133 |
+
$credit_amount = $credit->getFirstItem()->getAmountCredit();
|
134 |
+
Mage::getModel('customercredit/transaction')->addTransactionHistory($customer_id, Magestore_Customercredit_Model_TransactionType::TYPE_REDEEM_CREDIT, "redeemcredit", "", $credit_amount);
|
135 |
+
$this->updateBalance($customer_id, $credit_amount);
|
136 |
+
json_encode(array('status'=>'success','message'=>' Credit has been redeemed'));
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
|
141 |
+
|
142 |
+
|
143 |
+
?>
|
app/code/local/Mss/Connector/controllers/CustomerController.php
ADDED
@@ -0,0 +1,802 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_CustomerController extends Mage_Core_Controller_Front_Action {
|
3 |
+
|
4 |
+
|
5 |
+
const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template';
|
6 |
+
const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity';
|
7 |
+
const XML_PATH_REMIND_EMAIL_TEMPLATE = 'customer/password/remind_email_template';
|
8 |
+
const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'customer/password/forgot_email_template';
|
9 |
+
const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity';
|
10 |
+
const XML_PATH_DEFAULT_EMAIL_DOMAIN = 'customer/create_account/email_domain';
|
11 |
+
const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm';
|
12 |
+
const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template';
|
13 |
+
const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template';
|
14 |
+
const XML_PATH_GENERATE_HUMAN_FRIENDLY_ID = 'customer/create_account/generate_human_friendly_id';
|
15 |
+
|
16 |
+
public function _construct(){
|
17 |
+
|
18 |
+
header('content-type: application/json; charset=utf-8');
|
19 |
+
header("access-control-allow-origin: *");
|
20 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
21 |
+
parent::_construct();
|
22 |
+
|
23 |
+
}
|
24 |
+
|
25 |
+
/*confirm Login API
|
26 |
+
* Endpoint : baseurl/restapi/customer/loginStatus
|
27 |
+
* Return : json
|
28 |
+
* Return Parameters : status : true/false
|
29 |
+
*/
|
30 |
+
|
31 |
+
public function loginStatusAction(){
|
32 |
+
if (Mage::getSingleton ( 'customer/session' )->isLoggedIn()):
|
33 |
+
echo json_encode(array('status'=>true));
|
34 |
+
exit;
|
35 |
+
else:
|
36 |
+
echo json_encode(array('status'=>false));
|
37 |
+
exit;
|
38 |
+
endif;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function statusAction() {
|
42 |
+
|
43 |
+
$customerinfo = array ();
|
44 |
+
|
45 |
+
if (Mage::getSingleton ( 'customer/session' )->isLoggedIn()) {
|
46 |
+
$customer = Mage::getSingleton ( 'customer/session' )->getCustomer ();
|
47 |
+
$storeUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
|
48 |
+
|
49 |
+
$customerinfo = array (
|
50 |
+
'id'=>$customer->getId(),
|
51 |
+
'name' => $customer->getFirstname () .$customer->getLastname (),
|
52 |
+
'email' => $customer->getEmail (),
|
53 |
+
);
|
54 |
+
|
55 |
+
return $customerinfo;
|
56 |
+
} else
|
57 |
+
|
58 |
+
return false;
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
public function loginAction() {
|
63 |
+
|
64 |
+
if(Mage::app()->getRequest()->getParam('login_token') && Mage::app()->getRequest()->getParam ('sociallogintype'))
|
65 |
+
Mage::helper('sociallogin')->socialloginRequest(Mage::app()->getRequest()->getParam('login_token'),Mage::app()->getRequest()->getParam('sociallogintype'));
|
66 |
+
|
67 |
+
|
68 |
+
$session = Mage::getSingleton ( 'customer/session' );
|
69 |
+
if (Mage::getSingleton ( 'customer/session' )->isLoggedIn ()) {
|
70 |
+
$session->logout ();
|
71 |
+
}
|
72 |
+
$username = Mage::app ()->getRequest ()->getParam ( 'username' );
|
73 |
+
$password = Mage::app ()->getRequest ()->getParam ( 'password' );
|
74 |
+
|
75 |
+
try {
|
76 |
+
if (!$session->login ( $username, $password )) {
|
77 |
+
echo json_encode(array('status' => 'error','message'=>'wrong username or password.'));
|
78 |
+
exit;
|
79 |
+
} else {
|
80 |
+
|
81 |
+
echo json_encode(array('status' => 'success','message'=>$this->statusAction ()));
|
82 |
+
exit;
|
83 |
+
}
|
84 |
+
} catch ( Mage_Core_Exception $e ) {
|
85 |
+
switch ($e->getCode ()) {
|
86 |
+
case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED :
|
87 |
+
$value = Mage::helper ( 'customer' )->getEmailConfirmationUrl ( $uname );
|
88 |
+
$message = Mage::helper ( 'customer' )->__ ( 'This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value );
|
89 |
+
echo json_encode ( array (
|
90 |
+
'status' => 'error',
|
91 |
+
'message' => $message
|
92 |
+
) );
|
93 |
+
break;
|
94 |
+
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD :
|
95 |
+
$message = $e->getMessage ();
|
96 |
+
echo json_encode ( array (
|
97 |
+
'status' => 'error',
|
98 |
+
'message' => $message
|
99 |
+
) );
|
100 |
+
break;
|
101 |
+
default :
|
102 |
+
$message = $e->getMessage ();
|
103 |
+
echo json_encode ( array (
|
104 |
+
'status' => 'error',
|
105 |
+
'message' => $message
|
106 |
+
) );
|
107 |
+
}
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
|
112 |
+
public function registerAction() {
|
113 |
+
$params = Mage::app ()->getRequest ()->getParams ();
|
114 |
+
|
115 |
+
$session = Mage::getSingleton ( 'customer/session' );
|
116 |
+
$session->setEscapeMessages ( true );
|
117 |
+
|
118 |
+
$customer = Mage::registry ( 'current_customer' );
|
119 |
+
header('content-type: application/json; charset=utf-8');
|
120 |
+
header("access-control-allow-origin: *");
|
121 |
+
$errors = array ();
|
122 |
+
if (is_null ( $customer )) {
|
123 |
+
$customer = Mage::getModel ( 'customer/customer' )->setId ( null );
|
124 |
+
}
|
125 |
+
if (isset ( $params ['isSubscribed'] )) {
|
126 |
+
$customer->setIsSubscribed ( 1 );
|
127 |
+
}
|
128 |
+
if( (null==Mage::app ()->getRequest ()->getParam ('password') ) || (null==Mage::app ()->getRequest ()->getParam ('email')) ){
|
129 |
+
echo json_encode ( array (
|
130 |
+
false,
|
131 |
+
'0x1100',
|
132 |
+
'empty password or email.'
|
133 |
+
) );
|
134 |
+
return ;
|
135 |
+
}
|
136 |
+
$customer->getGroupId ();
|
137 |
+
try {
|
138 |
+
$customer->setPassword ( $params ['password'] );
|
139 |
+
$customer->setConfirmation ( $this->getRequest ()->getPost ( 'confirmation', $params ['password'] ) );
|
140 |
+
$customer->setData ( 'email', $params ['email'] );
|
141 |
+
$customer->setData ( 'firstname', $params ['firstname'] );
|
142 |
+
$customer->setData ( 'lastname', $params ['lastname'] );
|
143 |
+
$customer->setData ( 'gender', $params ['gender'] );
|
144 |
+
$customer->setData ( 'default_mobile_number', $params ['default_mobile_number'] );
|
145 |
+
$validationResult = count ( $errors ) == 0;
|
146 |
+
if (true === $validationResult) {
|
147 |
+
$customer->save ();
|
148 |
+
if ($customer->isConfirmationRequired ()) {
|
149 |
+
$customer->sendNewAccountEmail ( 'confirmation', $session->getBeforeAuthUrl (), Mage::app ()->getStore ()->getId () );
|
150 |
+
} else {
|
151 |
+
$session->setCustomerAsLoggedIn ( $customer );
|
152 |
+
$customer->sendNewAccountEmail ( 'registered', '', Mage::app ()->getStore ()->getId () );
|
153 |
+
}
|
154 |
+
|
155 |
+
$addressData = $session->getGuestAddress ();
|
156 |
+
if ($addressData && $customer->getId ()) {
|
157 |
+
$address = Mage::getModel ( 'customer/address' );
|
158 |
+
$address->setData ( $addressData );
|
159 |
+
$address->setCustomerId ( $customer->getId () );
|
160 |
+
$address->save ();
|
161 |
+
$session->unsGuestAddress ();
|
162 |
+
}
|
163 |
+
|
164 |
+
echo json_encode ( array (
|
165 |
+
true,
|
166 |
+
'0x0000',
|
167 |
+
array ()
|
168 |
+
) );
|
169 |
+
} else {
|
170 |
+
echo json_encode ( array (
|
171 |
+
false,
|
172 |
+
'0x1000',
|
173 |
+
$errors
|
174 |
+
) );
|
175 |
+
}
|
176 |
+
} catch ( Mage_Core_Exception $e ) {
|
177 |
+
if ($e->getCode () === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
|
178 |
+
$url = Mage::getUrl ( 'customer/account/forgotpassword' );
|
179 |
+
$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 );
|
180 |
+
$session->setEscapeMessages ( false );
|
181 |
+
} else {
|
182 |
+
$message = $e->getMessage ();
|
183 |
+
}
|
184 |
+
echo json_encode ( array (
|
185 |
+
false,
|
186 |
+
'0x1000',
|
187 |
+
array (
|
188 |
+
$message
|
189 |
+
)
|
190 |
+
) );
|
191 |
+
} catch ( Exception $e ) {
|
192 |
+
echo json_encode ( array (
|
193 |
+
false,
|
194 |
+
'0x1000',
|
195 |
+
$e->getMessage ()
|
196 |
+
) );
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
|
201 |
+
public function forgotpwdAction() {
|
202 |
+
$email = Mage::app ()->getRequest ()->getParam ( 'email' );
|
203 |
+
$session = Mage::getSingleton ( 'customer/session' );
|
204 |
+
$customer = Mage::registry ( 'current_customer' );
|
205 |
+
if (is_null ( $customer )) {
|
206 |
+
$customer = Mage::getModel ( 'customer/customer' )->setId ( null );
|
207 |
+
}
|
208 |
+
if ($this->_user_isexists ( $email )) {
|
209 |
+
$customer = Mage::getModel ( 'customer/customer' )->setWebsiteId ( Mage::app ()->getStore ()->getWebsiteId () )->loadByEmail ( $email );
|
210 |
+
$this->_sendEmailTemplate ( $customer,self::XML_PATH_FORGOT_EMAIL_TEMPLATE, self::XML_PATH_FORGOT_EMAIL_IDENTITY, array (
|
211 |
+
'customer' => $customer
|
212 |
+
), $storeId );
|
213 |
+
echo json_encode ( array (
|
214 |
+
'status' => 'error',
|
215 |
+
'message' => 'Request has sent to your Email.'
|
216 |
+
) );
|
217 |
+
} else
|
218 |
+
echo json_encode ( array (
|
219 |
+
'status' => 'error',
|
220 |
+
'message' => 'No matched email data.'
|
221 |
+
) );
|
222 |
+
}
|
223 |
+
public function logoutAction() {
|
224 |
+
header('content-type: application/json; charset=utf-8');
|
225 |
+
header("access-control-allow-origin: *");
|
226 |
+
try {
|
227 |
+
Mage::getSingleton ( 'customer/session' )->logout();
|
228 |
+
echo json_encode(array(true, '0x0000', null));
|
229 |
+
} catch (Exception $e) {
|
230 |
+
echo json_encode(array(false, '0x1000', $e->getMessage()));
|
231 |
+
}
|
232 |
+
}
|
233 |
+
protected function _user_isexists($email) {
|
234 |
+
$info = array ();
|
235 |
+
$customer = Mage::getModel ( 'customer/customer' )->setWebsiteId ( Mage::app ()->getStore ()->getWebsiteId () )->loadByEmail ( $email );
|
236 |
+
$info ['uname_is_exist'] = $customer->getId () > 0;
|
237 |
+
$result = array (
|
238 |
+
true,
|
239 |
+
'0x0000',
|
240 |
+
$info
|
241 |
+
);
|
242 |
+
return $customer->getId () > 0;
|
243 |
+
}
|
244 |
+
|
245 |
+
|
246 |
+
protected function _sendEmailTemplate($customer,$template, $sender, $templateParams = array(), $storeId = null)
|
247 |
+
{
|
248 |
+
/** @var $mailer Mage_Core_Model_Email_Template_Mailer */
|
249 |
+
$mailer = Mage::getModel('core/email_template_mailer');
|
250 |
+
$emailInfo = Mage::getModel('core/email_info');
|
251 |
+
$emailInfo->addTo($customer->getEmail(), $customer->getName());
|
252 |
+
$mailer->addEmailInfo($emailInfo);
|
253 |
+
|
254 |
+
// Set all required params and send emails
|
255 |
+
$mailer->setSender(Mage::getStoreConfig($sender, $storeId));
|
256 |
+
$mailer->setStoreId($storeId);
|
257 |
+
$mailer->setTemplateId(Mage::getStoreConfig($template, $storeId));
|
258 |
+
$mailer->setTemplateParams($templateParams);
|
259 |
+
$mailer->send();
|
260 |
+
return $this;
|
261 |
+
}
|
262 |
+
|
263 |
+
|
264 |
+
# set shipping Address and billing Address for customer
|
265 |
+
public function setAddressAction()
|
266 |
+
{
|
267 |
+
|
268 |
+
try {
|
269 |
+
$userid = Mage::app ()->getRequest ()->getParam ( 'userid' );
|
270 |
+
//$session = Mage::getSingleton ( 'customer/session' );
|
271 |
+
//if (Mage::getSingleton ( 'customer/session' )->isLoggedIn ()) {
|
272 |
+
if($userid){
|
273 |
+
$customerId = $userid;
|
274 |
+
$data=$this->getRequest()->getPost();
|
275 |
+
|
276 |
+
|
277 |
+
if (!Zend_Validate::is($data['firstname'], 'NotEmpty')):
|
278 |
+
echo json_encode(array('status'=>'error','message'=>'Firstname should not be empty'));
|
279 |
+
exit;
|
280 |
+
endif;
|
281 |
+
if (!Zend_Validate::is($data['lastname'], 'NotEmpty')):
|
282 |
+
echo json_encode(array('status'=>'error','message'=>'Lastname should not be empty'));
|
283 |
+
exit;
|
284 |
+
endif;
|
285 |
+
if (!Zend_Validate::is($data['street'], 'NotEmpty')):
|
286 |
+
echo json_encode(array('status'=>'error','message'=>'Street should not be empty'));
|
287 |
+
exit;
|
288 |
+
endif;
|
289 |
+
if (!Zend_Validate::is($data['city'], 'NotEmpty')):
|
290 |
+
echo json_encode(array('status'=>'error','message'=>'City should not be empty'));
|
291 |
+
exit;
|
292 |
+
endif;
|
293 |
+
if (!Zend_Validate::is($data['country_id'], 'NotEmpty') || $data['country_id'] == 'undefined'):
|
294 |
+
echo json_encode(array('status'=>'error','message'=>'Country_id should not be empty'));
|
295 |
+
exit;
|
296 |
+
endif;
|
297 |
+
if (!Zend_Validate::is($data['region'], 'NotEmpty')):
|
298 |
+
echo json_encode(array('status'=>'error','message'=>'Region should not be empty'));
|
299 |
+
exit;
|
300 |
+
endif;
|
301 |
+
if (!Zend_Validate::is($data['postcode'], 'NotEmpty')):
|
302 |
+
echo json_encode(array('status'=>'error','message'=>'Postcode should not be empty'));
|
303 |
+
exit;
|
304 |
+
endif;
|
305 |
+
if (!Zend_Validate::is($data['telephone'], 'NotEmpty')):
|
306 |
+
echo json_encode(array('status'=>'error','message'=>'Telephone should not be empty'));
|
307 |
+
exit;
|
308 |
+
endif;
|
309 |
+
|
310 |
+
if($data['firstname']==null):
|
311 |
+
echo json_encode ( array (
|
312 |
+
'status' => 'error',
|
313 |
+
'message' => 'please enter the firstname,'));
|
314 |
+
endif;
|
315 |
+
|
316 |
+
|
317 |
+
$addressData = array (
|
318 |
+
'firstname' => $data['firstname'],
|
319 |
+
'lastname'=> $data['lastname'],
|
320 |
+
'street' => $data['street'],
|
321 |
+
'city' => $data['city'],
|
322 |
+
'country_id' => $data['country_id'],
|
323 |
+
'region' => $data['region'],
|
324 |
+
'postcode' => $data['postcode'],
|
325 |
+
'telephone' => $data['telephone'],
|
326 |
+
'fax' => @$data['fax'],
|
327 |
+
'is_default_billing' => '1',
|
328 |
+
'is_default_shipping' => '1',
|
329 |
+
);
|
330 |
+
|
331 |
+
$address = Mage::getModel("customer/address");
|
332 |
+
$address->addData($addressData);
|
333 |
+
$address->setCustomerId($customerId);
|
334 |
+
|
335 |
+
try{
|
336 |
+
$address->save();
|
337 |
+
$result['id']=$address->getId();
|
338 |
+
$result['message']='Address added successfully.';
|
339 |
+
$result['status']='success';
|
340 |
+
|
341 |
+
echo json_encode($result);
|
342 |
+
}
|
343 |
+
catch (Exception $e) {
|
344 |
+
|
345 |
+
echo json_encode ( array (
|
346 |
+
'status' => 'error',
|
347 |
+
'message' => $e->getMessage()
|
348 |
+
) );
|
349 |
+
}
|
350 |
+
|
351 |
+
|
352 |
+
|
353 |
+
}
|
354 |
+
else{
|
355 |
+
|
356 |
+
echo json_encode ( array (
|
357 |
+
'status' => 'error',
|
358 |
+
'message' => 'No matched email data.'
|
359 |
+
) );
|
360 |
+
$session->logout();
|
361 |
+
}
|
362 |
+
|
363 |
+
} catch (Exception $e) {
|
364 |
+
echo $e->getMessage();
|
365 |
+
}
|
366 |
+
|
367 |
+
|
368 |
+
}
|
369 |
+
|
370 |
+
public function getAddressbyidAction()
|
371 |
+
{
|
372 |
+
$id=(int)$this->getRequest()->getParam('addressid');
|
373 |
+
|
374 |
+
|
375 |
+
$address=Mage::getModel('customer/address')->load($id);
|
376 |
+
|
377 |
+
if($address->getId()):
|
378 |
+
|
379 |
+
|
380 |
+
$result=array(
|
381 |
+
|
382 |
+
'id'=>$address->getId(),
|
383 |
+
'firstname'=>$address->getFirstname(),
|
384 |
+
'lastname'=>$address->getLastname(),
|
385 |
+
'street'=>$address->getStreet1().''.$address->getStreet2(),
|
386 |
+
'city'=>$address->getCity(),
|
387 |
+
'country_id'=>Mage::getModel('directory/country')->loadByCode($address->getCountryId())->getName(),
|
388 |
+
'region'=>$address->getRegion(),
|
389 |
+
'postcode'=>$address->getPostcode(),
|
390 |
+
'telephone'=>$address->getTelephone(),
|
391 |
+
'fax'=>$address->getFax(),
|
392 |
+
|
393 |
+
|
394 |
+
|
395 |
+
);
|
396 |
+
echo json_encode($result);
|
397 |
+
|
398 |
+
else:
|
399 |
+
echo json_encode ( array (
|
400 |
+
'code' => '0x0001',
|
401 |
+
'message' => 'No matched email data.'
|
402 |
+
) );
|
403 |
+
endif;
|
404 |
+
|
405 |
+
|
406 |
+
}
|
407 |
+
|
408 |
+
# get shipping Address listing of customer
|
409 |
+
public function getAddressAction()
|
410 |
+
{
|
411 |
+
|
412 |
+
try {
|
413 |
+
$session = Mage::getSingleton ( 'customer/session' );
|
414 |
+
$userid = Mage::app ()->getRequest ()->getParam ( 'userid' );
|
415 |
+
|
416 |
+
|
417 |
+
if($userid){
|
418 |
+
|
419 |
+
$customerId=$session->getId();
|
420 |
+
|
421 |
+
$customer = Mage::getModel('customer/customer')->load($userid); //insert cust ID
|
422 |
+
|
423 |
+
#create customer address array
|
424 |
+
$customerAddress = array();
|
425 |
+
#loop to create the array
|
426 |
+
foreach ($customer->getAddresses() as $address)
|
427 |
+
{
|
428 |
+
$customerAddress[] =array(
|
429 |
+
|
430 |
+
'id'=>$address->getId(),
|
431 |
+
'firstname'=>$address->getFirstname(),
|
432 |
+
'lastname'=>$address->getLastname(),
|
433 |
+
'street'=>$address->getStreet1().''.$address->getStreet2(),
|
434 |
+
'city'=>$address->getCity(),
|
435 |
+
// 'country_id'=>$address->getCountryId(),
|
436 |
+
'country_id'=>Mage::getModel('directory/country')->loadByCode($address->getCountryId())->getName(),
|
437 |
+
'region'=>$address->getRegion(),
|
438 |
+
'postcode'=>$address->getPostcode(),
|
439 |
+
'telephone'=>$address->getTelephone(),
|
440 |
+
'fax'=>$address->getFax(),
|
441 |
+
'email'=>$customer->getEmail(),
|
442 |
+
|
443 |
+
|
444 |
+
);
|
445 |
+
}
|
446 |
+
|
447 |
+
echo json_encode($customerAddress);
|
448 |
+
}
|
449 |
+
else{
|
450 |
+
|
451 |
+
echo json_encode ( array (
|
452 |
+
'code' => '0x0001',
|
453 |
+
'message' => 'No matched email data.'
|
454 |
+
) );
|
455 |
+
$session->logout();
|
456 |
+
}
|
457 |
+
|
458 |
+
} catch (Exception $e) {
|
459 |
+
|
460 |
+
echo $e->getMessage();
|
461 |
+
}
|
462 |
+
|
463 |
+
|
464 |
+
}
|
465 |
+
|
466 |
+
|
467 |
+
###Fetch all country and code
|
468 |
+
public function getcountriesAction()
|
469 |
+
{
|
470 |
+
|
471 |
+
$collection = Mage::getModel('directory/country')->getResourceCollection()
|
472 |
+
->loadByStore()
|
473 |
+
->toOptionArray(true);
|
474 |
+
|
475 |
+
|
476 |
+
|
477 |
+
$countriesArray=array();
|
478 |
+
foreach ($collection as $country)
|
479 |
+
{
|
480 |
+
|
481 |
+
if($country['value']):
|
482 |
+
$states = Mage::getModel('directory/country')->load($country['value'])->getRegions();
|
483 |
+
|
484 |
+
|
485 |
+
if($states->getData()):
|
486 |
+
$countriesArray[]=['value'=>$country['value'],'name'=>$country['label'],'state'=>$states->getData()];
|
487 |
+
else:
|
488 |
+
$countriesArray[]=['value'=>$country['value'],'name'=>$country['label'],'state'=>[]];
|
489 |
+
endif;
|
490 |
+
|
491 |
+
|
492 |
+
endif;
|
493 |
+
|
494 |
+
}
|
495 |
+
|
496 |
+
echo json_encode($countriesArray);
|
497 |
+
|
498 |
+
|
499 |
+
}
|
500 |
+
|
501 |
+
/*register device */
|
502 |
+
|
503 |
+
public function registerdeviceAction()
|
504 |
+
{
|
505 |
+
header('content-type: application/json; charset=utf-8');
|
506 |
+
header("access-control-allow-origin: *");
|
507 |
+
|
508 |
+
$data = $this->getRequest()->getParams();
|
509 |
+
|
510 |
+
if($data):
|
511 |
+
|
512 |
+
Mage::helper('pushnotification')->registerdevice($data);
|
513 |
+
echo json_encode(array('status'=>'success','message'=>'successfully registered.'));
|
514 |
+
exit;
|
515 |
+
else:
|
516 |
+
echo json_encode(array('status'=>'error','message'=>'Error in data format.'));
|
517 |
+
endif;
|
518 |
+
|
519 |
+
}
|
520 |
+
|
521 |
+
# Start Get My Orders listing
|
522 |
+
/***Convert Currency***/
|
523 |
+
public function convert_currency($price,$from,$to) {
|
524 |
+
$newPrice = Mage::helper('directory')->currencyConvert($price, $from, $to);
|
525 |
+
return $newPrice;
|
526 |
+
}
|
527 |
+
|
528 |
+
|
529 |
+
public function getMyOrdersAction()
|
530 |
+
{
|
531 |
+
|
532 |
+
|
533 |
+
$session = Mage::getSingleton ( 'customer/session' );
|
534 |
+
if (Mage::getSingleton ( 'customer/session' )->isLoggedIn ()) {
|
535 |
+
$cust_id=$session->getId();
|
536 |
+
|
537 |
+
$basecurrencycode = Mage::app()->getStore($store)->getBaseCurrencyCode();
|
538 |
+
$res = array();
|
539 |
+
$totorders = Mage::getResourceModel('sales/order_collection')
|
540 |
+
->addFieldToSelect('*')
|
541 |
+
->addFieldToFilter('customer_id', $cust_id);
|
542 |
+
$res["total"] = count($totorders);
|
543 |
+
$orders = Mage::getResourceModel('sales/order_collection')
|
544 |
+
->addFieldToSelect('*')
|
545 |
+
->addFieldToFilter('customer_id', $cust_id)
|
546 |
+
->setOrder('created_at', 'desc')
|
547 |
+
->setPage($curr_page,$page_size);
|
548 |
+
//$this->setOrders($orders);
|
549 |
+
# start order loop
|
550 |
+
foreach ($orders as $order) {
|
551 |
+
|
552 |
+
$shippingAddress = $order->getShippingAddress();
|
553 |
+
if(is_object($shippingAddress)) {
|
554 |
+
$shippadd = array();
|
555 |
+
$flag = 0;
|
556 |
+
if(count($orderData)>0)
|
557 |
+
$flag = 1;
|
558 |
+
$shippadd = array(
|
559 |
+
"firstname" => $shippingAddress->getFirstname(),
|
560 |
+
"lastname" => $shippingAddress->getLastname(),
|
561 |
+
"company" => $shippingAddress->getCompany(),
|
562 |
+
"street" => $shippingAddress->getStreetFull(),
|
563 |
+
"region" => $shippingAddress->getRegion(),
|
564 |
+
"city" => $shippingAddress->getCity(),
|
565 |
+
"pincode" => $shippingAddress->getPostcode(),
|
566 |
+
"countryid" => $shippingAddress->getCountry_id(),
|
567 |
+
"contactno" => $shippingAddress->getTelephone(),
|
568 |
+
"shipmyid" => $flag
|
569 |
+
);
|
570 |
+
}
|
571 |
+
$billingAddress = $order->getBillingAddress();
|
572 |
+
if(is_object($billingAddress)) {
|
573 |
+
$billadd = array();
|
574 |
+
$billadd = array(
|
575 |
+
"firstname" => $billingAddress->getFirstname(),
|
576 |
+
"lastname" => $billingAddress->getLastname(),
|
577 |
+
"company" => $billingAddress->getCompany(),
|
578 |
+
"street" => $billingAddress->getStreetFull(),
|
579 |
+
"region" => $billingAddress->getRegion(),
|
580 |
+
"city" => $billingAddress->getCity(),
|
581 |
+
"pincode" => $billingAddress->getPostcode(),
|
582 |
+
"countryid" => $billingAddress->getCountry_id(),
|
583 |
+
"contactno" => $billingAddress->getTelephone()
|
584 |
+
);
|
585 |
+
}
|
586 |
+
$payment = array();
|
587 |
+
$payment = $order->getPayment();
|
588 |
+
|
589 |
+
|
590 |
+
|
591 |
+
try {
|
592 |
+
$payment_result = array (
|
593 |
+
"payment_method_title" => $payment->getMethodInstance()->getTitle(),
|
594 |
+
"payment_method_code" => $payment->getMethodInstance()->getCode(),
|
595 |
+
);
|
596 |
+
if($payment->getMethodInstance()->getCode()=="banktransfer") {
|
597 |
+
|
598 |
+
$payment_result["payment_method_description"] = $payment->getMethodInstance()->getInstructions();
|
599 |
+
}
|
600 |
+
}
|
601 |
+
catch(Exception $ex2) {
|
602 |
+
|
603 |
+
}
|
604 |
+
|
605 |
+
$items = $order->getAllItems();
|
606 |
+
$itemcount=count($items);
|
607 |
+
$name=array();
|
608 |
+
$unitPrice=array();
|
609 |
+
$sku=array();
|
610 |
+
$ids=array();
|
611 |
+
$qty=array();
|
612 |
+
$images = array();
|
613 |
+
$test_p = array();
|
614 |
+
$itemsExcludingConfigurables = array();
|
615 |
+
$productlist = array();
|
616 |
+
foreach ($items as $itemId => $item) {
|
617 |
+
$name= $item->getName();
|
618 |
+
//echo $item->getName();
|
619 |
+
if($item->getOriginalPrice() > 0) {
|
620 |
+
$unitPrice = number_format($this->convert_currency(floatval($item->getOriginalPrice()),$basecurrencycode,$currency), 2, '.', '');
|
621 |
+
}
|
622 |
+
else {
|
623 |
+
$unitPrice = number_format($this->convert_currency(floatval($item->getPrice()),$basecurrencycode,$currency), 2, '.', '');
|
624 |
+
}
|
625 |
+
|
626 |
+
$sku=$item->getSku();
|
627 |
+
$ids=$item->getProductId();
|
628 |
+
//$qty[]=$item->getQtyToInvoice();
|
629 |
+
$qty= $item->getQtyOrdered();
|
630 |
+
$products = Mage::getModel('catalog/product')->load($item->getProductId());
|
631 |
+
$images= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'/media/catalog/product'.$products->getThumbnail();
|
632 |
+
|
633 |
+
$productlist[] = array (
|
634 |
+
"name" => $name,
|
635 |
+
"sku" => $sku,
|
636 |
+
"id" => $ids,
|
637 |
+
"quantity" => $qty,
|
638 |
+
"unitprice" => $unitPrice,
|
639 |
+
"image" => $images,
|
640 |
+
"total_item_count" => $itemcount,
|
641 |
+
"price_org" => $test_p,
|
642 |
+
"price_based_curr" => 1,
|
643 |
+
);
|
644 |
+
|
645 |
+
} # item foreach close
|
646 |
+
|
647 |
+
|
648 |
+
|
649 |
+
$order_date = $order->getCreatedAtStoreDate().'';
|
650 |
+
$orderData = array(
|
651 |
+
"id" => $order->getId(),
|
652 |
+
"order_id" => $order->getRealOrderId(),
|
653 |
+
"status" => $order->getStatus(),
|
654 |
+
"order_date" => $order_date,
|
655 |
+
"grand_total" => number_format($this->convert_currency(floatval($order->getGrandTotal()),$basecurrencycode,$currency), 2, '.', ''),
|
656 |
+
"shipping_address" => $shippadd,
|
657 |
+
"billing_address" => $billadd,
|
658 |
+
"shipping_message" => $order->getShippingDescription(),
|
659 |
+
"shipping_amount" => number_format($this->convert_currency(floatval($order->getShippingAmount()),$basecurrencycode,$currency), 2, '.', ''),
|
660 |
+
"payment_method" => $payment_result,
|
661 |
+
"tax_amount" => number_format($this->convert_currency(floatval($order->getTaxAmount()),$basecurrencycode,$currency), 2, '.', ''),
|
662 |
+
"products" => $productlist,
|
663 |
+
"order_currency" => $order->getOrderCurrencyCode(),
|
664 |
+
"order_currency_symbol" => Mage::app()->getLocale()->currency($order->getOrderCurrencyCode())->getSymbol(),
|
665 |
+
"currency" => $currency,
|
666 |
+
"couponUsed" => 0
|
667 |
+
);
|
668 |
+
$couponCode = $order->getCouponCode();
|
669 |
+
if($couponCode!="") {
|
670 |
+
$orderData["couponUsed"] = 1;
|
671 |
+
$orderData["couponCode"] = $couponCode;
|
672 |
+
$orderData["discount_amount"] = floatval(number_format($this->convert_currency(floatval($order->getDiscountAmount()),$basecurrencycode,$currency), 2, '.', ''))*-1;
|
673 |
+
}
|
674 |
+
|
675 |
+
$res["data"][] = $orderData;
|
676 |
+
} # end foreach
|
677 |
+
echo json_encode($res);
|
678 |
+
|
679 |
+
|
680 |
+
|
681 |
+
}
|
682 |
+
else{
|
683 |
+
|
684 |
+
echo json_encode(array('status'=>'error','message'=>'Please Login to see the Orders'));
|
685 |
+
|
686 |
+
}
|
687 |
+
|
688 |
+
} # end my orders
|
689 |
+
|
690 |
+
|
691 |
+
/*
|
692 |
+
URL : baseurl/restapi/customer/getuserinfo/
|
693 |
+
Controller : customer
|
694 |
+
Action : getuserinfo
|
695 |
+
Method : POST
|
696 |
+
Request Parameters :
|
697 |
+
Parameter Type :
|
698 |
+
Response : JSON
|
699 |
+
|
700 |
+
*/
|
701 |
+
public function getuserinfoAction(){
|
702 |
+
|
703 |
+
if(Mage::getSingleton('customer/session')->isLoggedIn()):
|
704 |
+
$info=array();
|
705 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
706 |
+
$info['firstname'] = $customer->getFirstname();
|
707 |
+
$info['lastname'] = $customer->getLastname();
|
708 |
+
$customerAddressId =$customer->getDefaultBilling();
|
709 |
+
|
710 |
+
if ($customerAddressId):
|
711 |
+
$address = Mage::getModel('customer/address')->load($customerAddressId);
|
712 |
+
|
713 |
+
if(sizeof( $address)){
|
714 |
+
$info['postcode'] = $address->getPostcode();
|
715 |
+
$info['city'] = $address->getCity();
|
716 |
+
$street = $address->getStreet();
|
717 |
+
$info['street'] = $street[0];
|
718 |
+
$info['telephone'] = $address->getTelephone();
|
719 |
+
$info['fax'] = $address->getFax();
|
720 |
+
$info['country'] = $address->getCountry();
|
721 |
+
$info['region'] = $address->getRegion();
|
722 |
+
}
|
723 |
+
|
724 |
+
echo json_encode(array('status' => 'success','data'=>$info));
|
725 |
+
exit;
|
726 |
+
else:
|
727 |
+
|
728 |
+
echo json_encode(array('status' => 'success','data'=>$info));
|
729 |
+
exit;
|
730 |
+
endif;
|
731 |
+
|
732 |
+
else:
|
733 |
+
echo json_encode(array('status' => 'error','message'=>'Login First.'));
|
734 |
+
exit;
|
735 |
+
|
736 |
+
endif;
|
737 |
+
}
|
738 |
+
|
739 |
+
/*
|
740 |
+
URL : baseurl/restapi/customer/setuserinfo/
|
741 |
+
Controller : customer
|
742 |
+
Action : setuserinfo
|
743 |
+
Method : POST
|
744 |
+
Request Parameters :Data*
|
745 |
+
Dummy Data: {
|
746 |
+
"firstname": "abc",
|
747 |
+
"lastname": "def",
|
748 |
+
"postcode": "123456",
|
749 |
+
"city": "delhi",
|
750 |
+
"street": "chandigarh",
|
751 |
+
"telephone": "9888898888",
|
752 |
+
"fax": null,
|
753 |
+
"country": "IN",
|
754 |
+
"region": null
|
755 |
+
}
|
756 |
+
Parameter Type:
|
757 |
+
Response : JSON
|
758 |
+
*/
|
759 |
+
|
760 |
+
public function setuserinfoAction(){
|
761 |
+
|
762 |
+
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
763 |
+
$customer = Mage::getModel('customer/customer')
|
764 |
+
->load(Mage::getSingleton('customer/session')->getId());
|
765 |
+
$data = Mage::app()->getRequest ()->getParam ('data');
|
766 |
+
|
767 |
+
|
768 |
+
$customer_info = json_decode($data, true);
|
769 |
+
if(isset($customer_info)){
|
770 |
+
|
771 |
+
|
772 |
+
$customer->setFirstname($customer_info['firstname']);
|
773 |
+
$customer->setLastname($customer_info['lastname']);
|
774 |
+
|
775 |
+
$address = $customer->getPrimaryBillingAddress();
|
776 |
+
|
777 |
+
$address->setFirstname($customer_info['firstname']);
|
778 |
+
$address->setLastname($customer_info['lastname']);
|
779 |
+
$address->setPhoneno($customer_info['telephone']);
|
780 |
+
$address->setCity($customer_info['city']);
|
781 |
+
$address->setState($customer_info['region']);
|
782 |
+
$address->setCountry($customer_info['country']);
|
783 |
+
$address->setPostcode($customer_info['postcode']);
|
784 |
+
try{
|
785 |
+
$address->save();
|
786 |
+
$customer->save();
|
787 |
+
echo json_encode(array('status' => 'success','message'=>'Data Updated successfully'));
|
788 |
+
}
|
789 |
+
catch(exception $e){
|
790 |
+
echo json_encode(array('status' => 'error','message'=>'Data Not Updated'));
|
791 |
+
}
|
792 |
+
}else{
|
793 |
+
echo json_encode(array('status' => 'error','message'=>'Data Not Updated'));
|
794 |
+
}
|
795 |
+
}
|
796 |
+
else {
|
797 |
+
echo json_encode(array('status' => 'error','message'=>'Login First.'));
|
798 |
+
}
|
799 |
+
|
800 |
+
}
|
801 |
+
|
802 |
+
}
|
app/code/local/Mss/Connector/controllers/FeedbackController.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_FeedbackController extends Mage_Core_Controller_Front_Action {
|
3 |
+
|
4 |
+
public function _construct(){
|
5 |
+
|
6 |
+
header('content-type: application/json; charset=utf-8');
|
7 |
+
header("access-control-allow-origin: *");
|
8 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
9 |
+
parent::_construct();
|
10 |
+
|
11 |
+
}
|
12 |
+
|
13 |
+
|
14 |
+
public function sendFeedbackAction()
|
15 |
+
{
|
16 |
+
|
17 |
+
$email = Mage::app()->getRequest()->getParams('email');
|
18 |
+
$message = Mage::app()->getRequest()->getParams('message');
|
19 |
+
|
20 |
+
if($email):
|
21 |
+
$result['message']='Thanks for your valuable feedback.';
|
22 |
+
$result['status']='success';
|
23 |
+
|
24 |
+
echo json_encode($result);
|
25 |
+
exit;
|
26 |
+
endif;
|
27 |
+
|
28 |
+
|
29 |
+
echo json_encode ( array (
|
30 |
+
'status' => 'error',
|
31 |
+
'message' =>'please enter the email !!'
|
32 |
+
) );
|
33 |
+
|
34 |
+
}
|
35 |
+
|
36 |
+
|
37 |
+
}
|
app/code/local/Mss/Connector/controllers/IndexController.php
ADDED
@@ -0,0 +1,753 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_IndexController extends Mage_Core_Controller_Front_Action {
|
3 |
+
|
4 |
+
public function _construct(){
|
5 |
+
|
6 |
+
header('content-type: application/json; charset=utf-8');
|
7 |
+
header("access-control-allow-origin: *");
|
8 |
+
|
9 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
10 |
+
parent::_construct();
|
11 |
+
|
12 |
+
}
|
13 |
+
|
14 |
+
|
15 |
+
public function CategoryListingAction()
|
16 |
+
{
|
17 |
+
|
18 |
+
echo json_encode($this->getCategoryTree(3));
|
19 |
+
exit;
|
20 |
+
|
21 |
+
}
|
22 |
+
|
23 |
+
protected function getCategoryTree($recursionLevel, $storeId = 1)
|
24 |
+
{
|
25 |
+
$parent = Mage::app()->getStore()->getRootCategoryId();
|
26 |
+
$tree = Mage::getResourceModel('catalog/category_tree');
|
27 |
+
|
28 |
+
|
29 |
+
$nodes = $tree->loadNode($parent)
|
30 |
+
->loadChildren()
|
31 |
+
->getChildren();
|
32 |
+
$tree->addCollectionData(null, false, $parent,true,false);
|
33 |
+
|
34 |
+
$categoryTreeData = array();
|
35 |
+
foreach ($nodes as $node) {
|
36 |
+
if($node->getIsActive())
|
37 |
+
$categoryTreeData[] = $this->getNodeChildrenData($node);
|
38 |
+
|
39 |
+
}
|
40 |
+
|
41 |
+
return $categoryTreeData;
|
42 |
+
}
|
43 |
+
|
44 |
+
protected function getNodeChildrenData(Varien_Data_Tree_Node $node)
|
45 |
+
{
|
46 |
+
|
47 |
+
|
48 |
+
$data = array(
|
49 |
+
'id' => $node->getData('entity_id'),
|
50 |
+
'title' => $node->getData('name'),
|
51 |
+
'url' => $node->getData('url_key'),
|
52 |
+
);
|
53 |
+
|
54 |
+
foreach ($node->getChildren() as $childNode) {
|
55 |
+
|
56 |
+
|
57 |
+
if (!array_key_exists('children', $data)) {
|
58 |
+
$data['children'] = array();
|
59 |
+
}
|
60 |
+
if($childNode->getIsActive())
|
61 |
+
$data['children'][] = $this->getNodeChildrenData($childNode);
|
62 |
+
}
|
63 |
+
return $data;
|
64 |
+
}
|
65 |
+
|
66 |
+
public function getSubcategoryAction()
|
67 |
+
{
|
68 |
+
|
69 |
+
|
70 |
+
$categoryid = ($this->getRequest ()->getParam ( 'categoryid' )) ? ($this->getRequest ()->getParam ( 'categoryid' )) : 2;
|
71 |
+
|
72 |
+
/*check for cache*/
|
73 |
+
Mage::helper('connector')->checkcache($categoryid,'1');
|
74 |
+
|
75 |
+
$_categorylist = array ();
|
76 |
+
$children = Mage::getModel('catalog/category')->getCategories($categoryid);
|
77 |
+
|
78 |
+
|
79 |
+
foreach ($children as $_category) {
|
80 |
+
$catimg=Mage::getModel ( 'catalog/category' )->load ( $_category->getId () )->getImageUrl ();
|
81 |
+
$thumbimg=Mage::getModel ( 'catalog/category' )->load ( $_category->getId () )->getThumbnailUrl ();
|
82 |
+
if(!$thumbimg):
|
83 |
+
$thumbimg=Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrl(). '/placeholder/default/small_image.jpg';
|
84 |
+
endif;
|
85 |
+
if(!$catimg):
|
86 |
+
$catimg=Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrl(). '/placeholder/default/small_image.jpg';
|
87 |
+
endif;
|
88 |
+
$_categorylist [] = array (
|
89 |
+
'category_id' => $_category->getId (),
|
90 |
+
'name' => $_category->getName (),
|
91 |
+
'is_active' => $_category->getIsActive (),
|
92 |
+
'position ' => $_category->getPosition (),
|
93 |
+
'level ' => $_category->getLevel (),
|
94 |
+
'url_key' => Mage::getModel ( 'catalog/category' )->load ( $_category->getId () )->getUrlPath (),
|
95 |
+
'thumbnail_url' => $thumbimg,
|
96 |
+
'image_url' => $catimg,
|
97 |
+
|
98 |
+
);
|
99 |
+
}
|
100 |
+
if(!sizeof($_categorylist))
|
101 |
+
$_categorylist=array("status"=>"error");
|
102 |
+
|
103 |
+
/*create new cache*/
|
104 |
+
Mage::helper('connector')->createNewcache($categoryid,'1',json_encode($_categorylist));
|
105 |
+
|
106 |
+
echo json_encode($_categorylist);
|
107 |
+
}
|
108 |
+
|
109 |
+
|
110 |
+
public function indexAction() {
|
111 |
+
Mage::app ()->cleanCache ();
|
112 |
+
$cmd = $this->getRequest ()->getParam ( 'cmd' );
|
113 |
+
if (!Zend_Validate::is($cmd, 'NotEmpty')):
|
114 |
+
echo json_encode(array('status'=>'error','message'=>'filter field should not be empty'));
|
115 |
+
exit;
|
116 |
+
endif;
|
117 |
+
switch ($cmd) {
|
118 |
+
case 'menu' :
|
119 |
+
|
120 |
+
/*check for cache*/
|
121 |
+
Mage::helper('connector')->checkcache('menu','1');
|
122 |
+
|
123 |
+
$_helper = Mage::helper ( 'catalog/category' );
|
124 |
+
$_categories = $_helper->getStoreCategories ();
|
125 |
+
$_categorylist = array ();
|
126 |
+
if (count ( $_categories ) > 0) {
|
127 |
+
foreach ( $_categories as $_category ) {
|
128 |
+
$_helper->getCategoryUrl ( $_category );
|
129 |
+
# if category have not image then set placeholder image
|
130 |
+
$catimg=Mage::getModel ( 'catalog/category' )->load ( $_category->getId () )->getImageUrl ();
|
131 |
+
$thumbimg=Mage::getModel ( 'catalog/category' )->load ( $_category->getId () )->getThumbnailUrl ();
|
132 |
+
if(!$thumbimg):
|
133 |
+
$thumbimg=Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrl(). '/placeholder/default/small_image.jpg';
|
134 |
+
endif;
|
135 |
+
if(!$catimg):
|
136 |
+
$catimg=Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrl(). '/placeholder/default/small_image.jpg';
|
137 |
+
endif;
|
138 |
+
$_categorylist [] = array (
|
139 |
+
'category_id' => $_category->getId (),
|
140 |
+
'name' => $_category->getName (),
|
141 |
+
'is_active' => $_category->getIsActive (),
|
142 |
+
'position ' => $_category->getPosition (),
|
143 |
+
'level ' => $_category->getLevel (),
|
144 |
+
'url_key' => Mage::getModel ( 'catalog/category' )->load ( $_category->getId () )->getUrlPath (),
|
145 |
+
'thumbnail_url' => $thumbimg,
|
146 |
+
'image_url' => $catimg,
|
147 |
+
'children' => Mage::getModel ( 'catalog/category' )->load ( $_category->getId () )->getAllChildren ()
|
148 |
+
);
|
149 |
+
|
150 |
+
|
151 |
+
}
|
152 |
+
}
|
153 |
+
else
|
154 |
+
{
|
155 |
+
|
156 |
+
$_categorylist = array('status'=>'error','message'=>'No Record Found');
|
157 |
+
exit;
|
158 |
+
}
|
159 |
+
|
160 |
+
/*create new cache*/
|
161 |
+
Mage::helper('connector')->createNewcache('menu','1',json_encode($_categorylist));
|
162 |
+
|
163 |
+
echo json_encode ( $_categorylist );
|
164 |
+
break;
|
165 |
+
case 'catalog' : // OK
|
166 |
+
//min=29022&max=95032&ajaxcatalog=true&dir=asc&order=weight&filter
|
167 |
+
$categoryid = $this->getRequest ()->getParam ( 'categoryid' );
|
168 |
+
|
169 |
+
if (!Zend_Validate::is($categoryid, 'NotEmpty')):
|
170 |
+
echo json_encode(array('status'=>'error','message'=>'category id should not be empty'));
|
171 |
+
exit;
|
172 |
+
endif;
|
173 |
+
|
174 |
+
$page = ($this->getRequest ()->getParam ( 'page' )) ? ($this->getRequest ()->getParam ( 'page' )) : 1;
|
175 |
+
$limit = ($this->getRequest ()->getParam ( 'limit' )) ? ($this->getRequest ()->getParam ( 'limit' )) : 10;
|
176 |
+
$order = ($this->getRequest ()->getParam ( 'order' )) ? ($this->getRequest ()->getParam ( 'order' )) : 'entity_id';
|
177 |
+
$dir = ($this->getRequest ()->getParam ( 'dir' )) ? ($this->getRequest ()->getParam ( 'dir' )) : 'desc';
|
178 |
+
|
179 |
+
$category = Mage::getModel ( 'catalog/category' )->load ( $categoryid );
|
180 |
+
|
181 |
+
|
182 |
+
if (!$category->getId()):
|
183 |
+
echo json_encode(array('status'=>'error','message'=>'category id does not exist'));
|
184 |
+
exit;
|
185 |
+
endif;
|
186 |
+
|
187 |
+
$model = Mage::getModel ( 'catalog/product' ); // getting product model
|
188 |
+
$collection = $category->getProductCollection ()->addAttributeToFilter ( 'status', 1 )
|
189 |
+
->addAttributeToFilter ( 'visibility', array ('neq' => 1 ) );
|
190 |
+
|
191 |
+
$price_filter = array();
|
192 |
+
|
193 |
+
/*filter added*/
|
194 |
+
if($this->getRequest ()->getParam ( 'filter' )){
|
195 |
+
$filters = json_decode($this->getRequest ()->getParam ( 'filter' ),1);
|
196 |
+
|
197 |
+
|
198 |
+
foreach($filters as $key => $filter):
|
199 |
+
|
200 |
+
if(sizeof($filter)):
|
201 |
+
|
202 |
+
if($key == 'price'):
|
203 |
+
|
204 |
+
$price = explode(',',$filter[0]);
|
205 |
+
$price_filter = array('gt'=>$price['0'],'lt'=>$price['1']);
|
206 |
+
$collection = $collection->addAttributeToFilter ( 'price', array ('gt' => $price['0'] ) );
|
207 |
+
$collection = $collection->addAttributeToFilter ( 'price', array ('lt' => $price['1']) );
|
208 |
+
else:
|
209 |
+
$collection = $collection->addAttributeToFilter ( $key, array('in' => $filter) );
|
210 |
+
endif;
|
211 |
+
endif;
|
212 |
+
endforeach;
|
213 |
+
}
|
214 |
+
/*filter added*/
|
215 |
+
|
216 |
+
|
217 |
+
if($this->getRequest ()->getParam ( 'min' )){
|
218 |
+
$collection=$collection->addAttributeToFilter ( 'price', array ('gt' => $this->getRequest ()->getParam ( 'min' ) ) );
|
219 |
+
}
|
220 |
+
if($this->getRequest ()->getParam ( 'max' )){
|
221 |
+
$collection=$collection->addAttributeToFilter ( 'price', array ('lt' => $this->getRequest ()->getParam ( 'max' ) ) );
|
222 |
+
}
|
223 |
+
|
224 |
+
$collection=$collection->addAttributeToSort ( $order, $dir )/* ->setPage ( $page, $limit ) */;
|
225 |
+
$pages = $collection->setPageSize ( $limit )->getLastPageNumber ();
|
226 |
+
$count=$collection->getSize();
|
227 |
+
|
228 |
+
if(!$count):
|
229 |
+
|
230 |
+
echo json_encode(array('status'=>'error','message'=>'No Record Found'));
|
231 |
+
exit;
|
232 |
+
endif;
|
233 |
+
|
234 |
+
if ($page <= $pages) {
|
235 |
+
$collection->setPage ( $page, $limit );
|
236 |
+
$productlist = $this->getProductlist ( $collection, 'catalog',$price_filter );
|
237 |
+
}
|
238 |
+
|
239 |
+
if(sizeof($productlist))
|
240 |
+
echo json_encode ( $productlist );
|
241 |
+
else
|
242 |
+
echo "[]";
|
243 |
+
|
244 |
+
|
245 |
+
break;
|
246 |
+
case 'coming_soon' :
|
247 |
+
|
248 |
+
$page = ($this->getRequest ()->getParam ( 'page' )) ? ($this->getRequest ()->getParam ( 'page' )) : 1;
|
249 |
+
$limit = ($this->getRequest ()->getParam ( 'limit' )) ? ($this->getRequest ()->getParam ( 'limit' )) : 5;
|
250 |
+
$order = ($this->getRequest ()->getParam ( 'order' )) ? ($this->getRequest ()->getParam ( 'order' )) : 'entity_id';
|
251 |
+
$dir = ($this->getRequest ()->getParam ( 'dir' )) ? ($this->getRequest ()->getParam ( 'dir' )) : 'desc';
|
252 |
+
;
|
253 |
+
$tomorrow = mktime ( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 1, date ( 'y' ) );
|
254 |
+
$dateTomorrow = date ( 'm/d/y', $tomorrow );
|
255 |
+
$tdatomorrow = mktime ( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 3, date ( 'y' ) );
|
256 |
+
$tdaTomorrow = date ( 'm/d/y', $tdatomorrow );
|
257 |
+
$_productCollection = Mage::getModel ( 'catalog/product' )->getCollection ();
|
258 |
+
$_productCollection->addAttributeToSelect ( '*' )->addAttributeToFilter ( 'visibility', array (
|
259 |
+
'neq' => 1
|
260 |
+
) )->addAttributeToFilter ( 'status', 1 )->addAttributeToFilter ( 'special_price', array (
|
261 |
+
'neq' => 0
|
262 |
+
) )->addAttributeToFilter ( 'special_from_date', array (
|
263 |
+
'date' => true,
|
264 |
+
'to' => $dateTomorrow
|
265 |
+
) )->addAttributeToFilter ( array (
|
266 |
+
array (
|
267 |
+
'attribute' => 'special_to_date',
|
268 |
+
'date' => true,
|
269 |
+
'from' => $tdaTomorrow
|
270 |
+
),
|
271 |
+
array (
|
272 |
+
'attribute' => 'special_to_date',
|
273 |
+
'null' => 1
|
274 |
+
)
|
275 |
+
) )
|
276 |
+
->addAttributeToFilter('visibility',array('eq'=>4))
|
277 |
+
->addAttributeToSort ( $order, $dir )/* ->setPage ( $page, $limit ) */;
|
278 |
+
$pages = $_productCollection->setPageSize ( $limit )->getLastPageNumber ();
|
279 |
+
$count=$collection->getSize();
|
280 |
+
if(!$count):
|
281 |
+
|
282 |
+
echo json_encode(array('status'=>'error','message'=>'No Record Found'));
|
283 |
+
exit;
|
284 |
+
endif;
|
285 |
+
if ($page <= $pages) {
|
286 |
+
$_productCollection->setPage ( $page, $limit );
|
287 |
+
$products = $_productCollection->getItems ();
|
288 |
+
$productlist = $this->getProductlist ( $products );
|
289 |
+
}
|
290 |
+
|
291 |
+
if(sizeof($productlist))
|
292 |
+
echo json_encode ( $productlist );
|
293 |
+
else
|
294 |
+
echo "[]";
|
295 |
+
|
296 |
+
break;
|
297 |
+
case 'best_seller' :
|
298 |
+
|
299 |
+
$order = ($this->getRequest ()->getParam ( 'order' )) ? ($this->getRequest ()->getParam ( 'order' )) : 'entity_id';
|
300 |
+
$dir = ($this->getRequest ()->getParam ( 'dir' )) ? ($this->getRequest ()->getParam ( 'dir' )) : 'desc'; // ------------------------------Home Pre Specials BEGIN------------------------------//
|
301 |
+
$page = ($this->getRequest ()->getParam ( 'page' )) ? ($this->getRequest ()->getParam ( 'page' )) : 1;
|
302 |
+
$limit = ($this->getRequest ()->getParam ( 'limit' )) ? ($this->getRequest ()->getParam ( 'limit' )) : 5;
|
303 |
+
$todayDate = Mage::app ()->getLocale ()->date ()->toString ( Varien_Date::DATETIME_INTERNAL_FORMAT );
|
304 |
+
$_products = Mage::getModel ( 'catalog/product' )->getCollection ()->addAttributeToSelect ('*')
|
305 |
+
->addAttributeToFilter ( 'status', 1 )->addAttributeToFilter ( 'news_from_date', array (
|
306 |
+
'or' => array (
|
307 |
+
0 => array (
|
308 |
+
'date' => true,
|
309 |
+
'to' => $todayDate
|
310 |
+
),
|
311 |
+
1 => array (
|
312 |
+
'is' => new Zend_Db_Expr ( 'null' )
|
313 |
+
)
|
314 |
+
)
|
315 |
+
), 'left' )->addAttributeToFilter ( 'news_to_date', array (
|
316 |
+
'or' => array (
|
317 |
+
0 => array (
|
318 |
+
'date' => true,
|
319 |
+
'from' => $todayDate
|
320 |
+
),
|
321 |
+
1 => array (
|
322 |
+
'is' => new Zend_Db_Expr ( 'null' )
|
323 |
+
)
|
324 |
+
)
|
325 |
+
), 'left' )->addAttributeToFilter ( array (
|
326 |
+
array (
|
327 |
+
'attribute' => 'news_from_date',
|
328 |
+
'is' => new Zend_Db_Expr ( 'not null' )
|
329 |
+
),
|
330 |
+
array (
|
331 |
+
'attribute' => 'news_to_date',
|
332 |
+
'is' => new Zend_Db_Expr ( 'not null' )
|
333 |
+
)
|
334 |
+
) )->addAttributeToFilter ( 'visibility', array (
|
335 |
+
'in' => array (
|
336 |
+
2,
|
337 |
+
4
|
338 |
+
)
|
339 |
+
) )
|
340 |
+
->addAttributeToFilter('visibility',array('eq'=>4))
|
341 |
+
->addAttributeToSort ( 'news_from_date', 'desc' )->addAttributeToSort ( $order, $dir )/* ->setPage ( $page, $limit ) */;
|
342 |
+
$pages = $_products->setPageSize ( $limit )->getLastPageNumber ();
|
343 |
+
$count=$collection->getSize();
|
344 |
+
if(!$count):
|
345 |
+
|
346 |
+
echo json_encode(array('status'=>'error','message'=>'No Record Found'));
|
347 |
+
exit;
|
348 |
+
endif;
|
349 |
+
if ($page <= $pages) {
|
350 |
+
$_products->setPage ( $page, $limit );
|
351 |
+
$products = $_products->getItems ();
|
352 |
+
$productlist = $this->getProductlist ( $products );
|
353 |
+
}
|
354 |
+
|
355 |
+
if(sizeof($productlist))
|
356 |
+
echo json_encode ( $productlist );
|
357 |
+
else
|
358 |
+
echo "[]";
|
359 |
+
|
360 |
+
break;
|
361 |
+
case 'daily_sale' :
|
362 |
+
|
363 |
+
$order = ($this->getRequest ()->getParam ( 'order' )) ? ($this->getRequest ()->getParam ( 'order' )) : 'entity_id';
|
364 |
+
$dir = ($this->getRequest ()->getParam ( 'dir' )) ? ($this->getRequest ()->getParam ( 'dir' )) : 'desc';
|
365 |
+
$page = ($this->getRequest ()->getParam ( 'page' )) ? ($this->getRequest ()->getParam ( 'page' )) : 1;
|
366 |
+
$limit = ($this->getRequest ()->getParam ( 'limit' )) ? ($this->getRequest ()->getParam ( 'limit' )) : 5;
|
367 |
+
$todayDate = Mage::app ()->getLocale ()->date ()->toString ( Varien_Date::DATETIME_INTERNAL_FORMAT );
|
368 |
+
$tomorrow = mktime ( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 1, date ( 'y' ) );
|
369 |
+
$dateTomorrow = date ( 'm/d/y', $tomorrow );
|
370 |
+
|
371 |
+
$collection = Mage::getModel ( 'catalog/product' )->getCollection ();
|
372 |
+
$collection->addAttributeToSelect ( '*' )->addAttributeToFilter ( 'visibility', array (
|
373 |
+
|
374 |
+
'neq' => 1
|
375 |
+
|
376 |
+
) )->addAttributeToFilter ( 'status', 1 )->addAttributeToFilter ( 'special_price', array (
|
377 |
+
'neq' => "0"
|
378 |
+
) )->addAttributeToFilter ( 'special_from_date', array (
|
379 |
+
'date' => true,
|
380 |
+
'to' => $todayDate
|
381 |
+
) )->addAttributeToFilter ( array (
|
382 |
+
array (
|
383 |
+
'attribute' => 'special_to_date',
|
384 |
+
'date' => true,
|
385 |
+
'from' => $dateTomorrow
|
386 |
+
),
|
387 |
+
array (
|
388 |
+
'attribute' => 'special_to_date',
|
389 |
+
'null' => 1
|
390 |
+
)
|
391 |
+
) )
|
392 |
+
->addAttributeToFilter('visibility',array('eq'=>4))
|
393 |
+
->addAttributeToSort ( $order, $dir );
|
394 |
+
$pages = $collection->setPageSize ( $limit )->getLastPageNumber ();
|
395 |
+
$count=$collection->getSize();
|
396 |
+
if(!$count):
|
397 |
+
echo json_encode(array('status'=>'error','message'=>'No Record Found'));
|
398 |
+
exit;
|
399 |
+
endif;
|
400 |
+
if ($page <= $pages) {
|
401 |
+
$collection->setPage ( $page, $limit );
|
402 |
+
$products = $collection->getItems ();
|
403 |
+
$productlist = $this->getProductlist ( $products );
|
404 |
+
}
|
405 |
+
if(sizeof($productlist))
|
406 |
+
echo json_encode ( $productlist );
|
407 |
+
else
|
408 |
+
echo "[]";
|
409 |
+
|
410 |
+
break;
|
411 |
+
case 'new_product' :
|
412 |
+
|
413 |
+
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
|
414 |
+
|
415 |
+
$_productCollection = Mage::getResourceModel('catalog/product_collection')
|
416 |
+
->addAttributeToSelect('*')
|
417 |
+
->addAttributeToFilter('status',array('eq'=>1))
|
418 |
+
->addAttributeToFilter('visibility',array('eq'=>4))
|
419 |
+
->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
|
420 |
+
->addAttributeToFilter('news_to_date', array('or'=> array(
|
421 |
+
0 => array('date' => true, 'from' => $todayDate),
|
422 |
+
1 => array('is' => new Zend_Db_Expr('null')))
|
423 |
+
), 'left');
|
424 |
+
|
425 |
+
$now = date('Y-m-d');
|
426 |
+
$newsFrom= substr($_productCollection->getData('news_from_date'),0,10);
|
427 |
+
$newsTo= substr($_productCollection->getData('news_to_date'),0,10);
|
428 |
+
|
429 |
+
if(!$_productCollection->count()):
|
430 |
+
echo json_encode(array('status'=>'error','message'=>'There are no products matching the selection'));
|
431 |
+
else:
|
432 |
+
if ($now>=$newsFrom && $now<=$newsTo)$i=0;
|
433 |
+
|
434 |
+
$productlist = array ();
|
435 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
436 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
437 |
+
foreach ( $_productCollection as $product ) {
|
438 |
+
|
439 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $product ['entity_id'] );
|
440 |
+
$rating = Mage::getModel('rating/rating')->getEntitySummary($product->getId());
|
441 |
+
$rating_final = ($rating->getSum()/$rating->getCount())/20;
|
442 |
+
|
443 |
+
$productlist [] = array (
|
444 |
+
'entity_id' => $product->getId (),
|
445 |
+
'sku' => $product->getSku (),
|
446 |
+
'name' => $product->getName (),
|
447 |
+
'news_from_date' => $product->getNewsFromDate (),
|
448 |
+
'news_to_date' => $product->getNewsToDate (),
|
449 |
+
'special_from_date' => $product->getSpecialFromDate (),
|
450 |
+
'special_to_date' => $product->getSpecialToDate (),
|
451 |
+
'image_url' => Mage::helper('connector')-> Imageresize($product->getImage(),'product','300','300'),
|
452 |
+
'url_key' => $product->getProductUrl (),
|
453 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
454 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
455 |
+
'symbol'=> Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(),
|
456 |
+
'qty'=>(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId())->getQty(),//$product->getStockItem()->getData('qty')
|
457 |
+
'rating' => $rating_final,
|
458 |
+
'wishlist' => Mage::helper('connector')->check_wishlist($product->getId ()),
|
459 |
+
|
460 |
+
);
|
461 |
+
}
|
462 |
+
|
463 |
+
if(sizeof($productlist))
|
464 |
+
echo json_encode ( $productlist );
|
465 |
+
else
|
466 |
+
echo "[]";
|
467 |
+
|
468 |
+
endif;
|
469 |
+
break;
|
470 |
+
|
471 |
+
default :
|
472 |
+
echo 'Parameters are invalid';
|
473 |
+
|
474 |
+
break;
|
475 |
+
}
|
476 |
+
}
|
477 |
+
|
478 |
+
public function getStaticBlockAction(){
|
479 |
+
$block = ($this->getRequest ()->getParam ( 'block' )) ? ($this->getRequest ()->getParam ( 'block' )) : 'footer_links';
|
480 |
+
echo $this->getLayout()->createBlock('cms/block')->setBlockId($block)->toHtml();
|
481 |
+
}
|
482 |
+
|
483 |
+
public function getProductlist($products, $mod = 'product',$price_filter = array()) {
|
484 |
+
|
485 |
+
$productlist = array ();
|
486 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
487 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
488 |
+
|
489 |
+
foreach ( $products as $product ) {
|
490 |
+
if ($mod == 'catalog') {
|
491 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $product ['entity_id'] );
|
492 |
+
|
493 |
+
$rating = Mage::getModel('rating/rating')->getEntitySummary($product->getId());
|
494 |
+
$rating_final = ($rating->getSum()/$rating->getCount())/20;
|
495 |
+
|
496 |
+
}
|
497 |
+
if($product->getTypeId() == "configurable")
|
498 |
+
$qty = Mage::helper('connector')->getProductStockInfoById($product->getId());
|
499 |
+
else
|
500 |
+
$qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId())->getQty();
|
501 |
+
|
502 |
+
if(sizeof($price_filter)):
|
503 |
+
|
504 |
+
if($product->getFinalPrice() > $price_filter['0'] AND $product->getFinalPrice() > $price_filter['1']):
|
505 |
+
|
506 |
+
$productlist [] = array (
|
507 |
+
'entity_id' => $product->getId (),
|
508 |
+
'sku' => $product->getSku (),
|
509 |
+
'name' => $product->getName (),
|
510 |
+
'news_from_date' => $product->getNewsFromDate (),
|
511 |
+
'news_to_date' => $product->getNewsToDate (),
|
512 |
+
'special_from_date' => $product->getSpecialFromDate (),
|
513 |
+
'special_to_date' => $product->getSpecialToDate (),
|
514 |
+
'image_url' => Mage::helper('connector')-> Imageresize($product->getImage(),'product','300','300'),
|
515 |
+
'url_key' => $product->getProductUrl (),
|
516 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
517 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
518 |
+
'symbol'=> Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol()?: Mage::app()->getStore()->getCurrentCurrencyCode(),
|
519 |
+
'qty'=>$qty,//$product->getStockItem()->getData('qty')
|
520 |
+
'rating' => $rating_final,
|
521 |
+
'wishlist' => Mage::helper('connector')->check_wishlist($product->getId ()),
|
522 |
+
);
|
523 |
+
endif;
|
524 |
+
else:
|
525 |
+
|
526 |
+
$productlist [] = array (
|
527 |
+
'entity_id' => $product->getId (),
|
528 |
+
'sku' => $product->getSku (),
|
529 |
+
'name' => $product->getName (),
|
530 |
+
'news_from_date' => $product->getNewsFromDate (),
|
531 |
+
'news_to_date' => $product->getNewsToDate (),
|
532 |
+
'special_from_date' => $product->getSpecialFromDate (),
|
533 |
+
'special_to_date' => $product->getSpecialToDate (),
|
534 |
+
'image_url' => Mage::helper('connector')-> Imageresize($product->getImage(),'product','300','300'),
|
535 |
+
'url_key' => $product->getProductUrl (),
|
536 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
537 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
538 |
+
'symbol'=> Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol()?: Mage::app()->getStore()->getCurrentCurrencyCode(),
|
539 |
+
'qty'=>$qty,//$product->getStockItem()->getData('qty')
|
540 |
+
'rating' => $rating_final,
|
541 |
+
'wishlist' => Mage::helper('connector')->check_wishlist($product->getId ()),
|
542 |
+
);
|
543 |
+
endif;
|
544 |
+
}
|
545 |
+
return $productlist;
|
546 |
+
}
|
547 |
+
|
548 |
+
# start dashboard api to return the new products sale products
|
549 |
+
public function getdashboardAction()
|
550 |
+
{
|
551 |
+
|
552 |
+
/*check for cache*/
|
553 |
+
Mage::helper('connector')->checkcache('dashboard','1');
|
554 |
+
|
555 |
+
|
556 |
+
$top_products=$this->getBestsellerProducts();
|
557 |
+
$new_pro_list=$this->getnewproducts();
|
558 |
+
$sale_pro_list=$this->getsaleproducts();
|
559 |
+
$topproductslist=array(
|
560 |
+
'Title'=>'Top Products',
|
561 |
+
'count'=>count($top_products),
|
562 |
+
'products'=>$top_products
|
563 |
+
|
564 |
+
);
|
565 |
+
$newproductslist=array(
|
566 |
+
'Title'=>'New Products',
|
567 |
+
'count'=>count($new_pro_list),
|
568 |
+
'products'=>$new_pro_list
|
569 |
+
|
570 |
+
);
|
571 |
+
|
572 |
+
$saleproductslist=array(
|
573 |
+
'Title'=>'Sale Products',
|
574 |
+
'count'=>count($sale_pro_list),
|
575 |
+
'products'=>$sale_pro_list
|
576 |
+
|
577 |
+
);
|
578 |
+
/*create new cache*/
|
579 |
+
Mage::helper('connector')->createNewcache('dashboard','1',json_encode(array($topproductslist,$newproductslist,$saleproductslist)));
|
580 |
+
|
581 |
+
echo json_encode(array($topproductslist,$newproductslist,$saleproductslist)); die;
|
582 |
+
}
|
583 |
+
|
584 |
+
public function getBestsellerProducts()
|
585 |
+
{
|
586 |
+
$products = Mage::getResourceModel('reports/product_collection')
|
587 |
+
->addOrderedQty()
|
588 |
+
->addAttributeToSelect('*')
|
589 |
+
->addAttributeToSelect(array('name', 'price', 'small_image'))
|
590 |
+
->addAttributeToFilter('visibility',array('eq'=>4))
|
591 |
+
// ->setStoreId($storeId)
|
592 |
+
// ->addStoreFilter($storeId)
|
593 |
+
|
594 |
+
->addViewsCount();
|
595 |
+
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
|
596 |
+
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
|
597 |
+
|
598 |
+
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);
|
599 |
+
$products->setPageSize(5)->setCurPage(1);
|
600 |
+
//->getLastPageNumber ();
|
601 |
+
$new_productlist = array ();
|
602 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
603 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
604 |
+
foreach ( $products as $product ) {
|
605 |
+
|
606 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $product ['entity_id'] );
|
607 |
+
$rating = Mage::getModel('rating/rating')->getEntitySummary($product->getId());
|
608 |
+
$rating_final = ($rating->getSum()/$rating->getCount())/20;
|
609 |
+
|
610 |
+
if($product->getTypeId() == "configurable")
|
611 |
+
$qty = Mage::helper('connector')->getProductStockInfoById($product->getId());
|
612 |
+
else
|
613 |
+
$qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId())->getQty();
|
614 |
+
|
615 |
+
$new_productlist [] = array (
|
616 |
+
'entity_id' => $product->getId (),
|
617 |
+
'sku' => $product->getSku (),
|
618 |
+
'name' => $product->getName (),
|
619 |
+
'news_from_date' => $product->getNewsFromDate (),
|
620 |
+
'news_to_date' => $product->getNewsToDate (),
|
621 |
+
'special_from_date' => $product->getSpecialFromDate (),
|
622 |
+
'special_to_date' => $product->getSpecialToDate (),
|
623 |
+
'image_url' => Mage::helper('connector')-> Imageresize($product->getImage(),'product','300','300'),
|
624 |
+
'url_key' => $product->getProductUrl (),
|
625 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
626 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
627 |
+
'symbol'=>Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol()?: Mage::app()->getStore()->getCurrentCurrencyCode(),
|
628 |
+
'qty'=>$qty,
|
629 |
+
'rating' => $rating_final,
|
630 |
+
'wishlist' => Mage::helper('connector')->check_wishlist($product->getId ()),
|
631 |
+
);
|
632 |
+
}
|
633 |
+
return $new_productlist;
|
634 |
+
}
|
635 |
+
public function getnewproducts()
|
636 |
+
{
|
637 |
+
# get New Products start
|
638 |
+
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
|
639 |
+
$_productCollection = Mage::getResourceModel('catalog/product_collection')
|
640 |
+
->addAttributeToSelect('*')
|
641 |
+
->addAttributeToFilter('status',array('eq'=>1))
|
642 |
+
->setPageSize (5)
|
643 |
+
->addAttributeToFilter('visibility',array('eq'=>4))
|
644 |
+
->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
|
645 |
+
->addAttributeToFilter('news_to_date', array('or'=> array(
|
646 |
+
0 => array('date' => true, 'from' => $todayDate),
|
647 |
+
1 => array('is' => new Zend_Db_Expr('null')))
|
648 |
+
), 'left');
|
649 |
+
|
650 |
+
$now = date('Y-m-d');
|
651 |
+
$newsFrom= substr($_productCollection->getData('news_from_date'),0,10);
|
652 |
+
$newsTo= substr($_productCollection->getData('news_to_date'),0,10);
|
653 |
+
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($_productCollection);
|
654 |
+
|
655 |
+
if(!$_productCollection->count()):
|
656 |
+
return $new_productlist = array ();
|
657 |
+
else:
|
658 |
+
if ($now>=$newsFrom && $now<=$newsTo)$i=0;
|
659 |
+
|
660 |
+
$new_productlist = array ();
|
661 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
662 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
663 |
+
foreach ( $_productCollection as $product ) {
|
664 |
+
|
665 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $product ['entity_id'] );
|
666 |
+
|
667 |
+
$rating = Mage::getModel('rating/rating')->getEntitySummary($product->getId());
|
668 |
+
$rating_final = ($rating->getSum()/$rating->getCount())/20;
|
669 |
+
|
670 |
+
if($product->getTypeId() == "configurable")
|
671 |
+
$qty = Mage::helper('connector')->getProductStockInfoById($product->getId());
|
672 |
+
else
|
673 |
+
$qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId())->getQty();
|
674 |
+
|
675 |
+
|
676 |
+
$new_productlist [] = array (
|
677 |
+
'entity_id' => $product->getId (),
|
678 |
+
'sku' => $product->getSku (),
|
679 |
+
'name' => $product->getName (),
|
680 |
+
'news_from_date' => $product->getNewsFromDate (),
|
681 |
+
'news_to_date' => $product->getNewsToDate (),
|
682 |
+
'special_from_date' => $product->getSpecialFromDate (),
|
683 |
+
'special_to_date' => $product->getSpecialToDate (),
|
684 |
+
'image_url' => Mage::helper('connector')-> Imageresize($product->getImage(),'product','300','300'),
|
685 |
+
'url_key' => $product->getProductUrl (),
|
686 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
687 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
688 |
+
'symbol'=>Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol()?: Mage::app()->getStore()->getCurrentCurrencyCode(),
|
689 |
+
'qty'=>$qty,
|
690 |
+
'rating' => $rating_final,
|
691 |
+
'wishlist' => Mage::helper('connector')->check_wishlist($product->getId ()),
|
692 |
+
);
|
693 |
+
}
|
694 |
+
|
695 |
+
return $new_productlist;
|
696 |
+
|
697 |
+
endif;
|
698 |
+
|
699 |
+
}
|
700 |
+
|
701 |
+
|
702 |
+
|
703 |
+
|
704 |
+
|
705 |
+
|
706 |
+
public function getsaleproducts()
|
707 |
+
{
|
708 |
+
|
709 |
+
$order = ($this->getRequest ()->getParam ( 'order' )) ? ($this->getRequest ()->getParam ( 'order' )) : 'entity_id';
|
710 |
+
$dir = ($this->getRequest ()->getParam ( 'dir' )) ? ($this->getRequest ()->getParam ( 'dir' )) : 'desc';
|
711 |
+
$page = ($this->getRequest ()->getParam ( 'page' )) ? ($this->getRequest ()->getParam ( 'page' )) : 1;
|
712 |
+
$limit = ($this->getRequest ()->getParam ( 'limit' )) ? ($this->getRequest ()->getParam ( 'limit' )) : 5;
|
713 |
+
$todayDate = Mage::app ()->getLocale ()->date ()->toString ( Varien_Date::DATETIME_INTERNAL_FORMAT );
|
714 |
+
$tomorrow = mktime ( 0, 0, 0, date ( 'm' ), date ( 'd' ) + 1, date ( 'y' ) );
|
715 |
+
$dateTomorrow = date ( 'm/d/y', $tomorrow );
|
716 |
+
|
717 |
+
$collection = Mage::getModel ( 'catalog/product' )->getCollection ();
|
718 |
+
$collection->addAttributeToSelect ( '*' )->addAttributeToFilter ( 'visibility', array (
|
719 |
+
|
720 |
+
'neq' => 1
|
721 |
+
|
722 |
+
) )->addAttributeToFilter ( 'status', 1 )->addAttributeToFilter ( 'special_price', array (
|
723 |
+
'neq' => "0"
|
724 |
+
) )->addAttributeToFilter ( 'special_from_date', array (
|
725 |
+
'date' => true,
|
726 |
+
'to' => $todayDate
|
727 |
+
) )->addAttributeToFilter ( array (
|
728 |
+
array (
|
729 |
+
'attribute' => 'special_to_date',
|
730 |
+
'date' => true,
|
731 |
+
'from' => $dateTomorrow
|
732 |
+
),
|
733 |
+
array (
|
734 |
+
'attribute' => 'special_to_date',
|
735 |
+
'null' => 1
|
736 |
+
)
|
737 |
+
) )
|
738 |
+
->addAttributeToFilter('visibility',array('eq'=>4))
|
739 |
+
->addAttributeToSort ( $order, $dir );
|
740 |
+
$pages = $collection->setPageSize ( $limit )->getLastPageNumber ();
|
741 |
+
$count=$collection->getSize();
|
742 |
+
if(!$count):
|
743 |
+
return array();
|
744 |
+
endif;
|
745 |
+
if ($page <= $pages) {
|
746 |
+
$collection->setPage ( $page, $limit );
|
747 |
+
$products = $collection->getItems ();
|
748 |
+
$productlist = $this->getProductlist ( $products );
|
749 |
+
}
|
750 |
+
return $productlist;
|
751 |
+
|
752 |
+
}
|
753 |
+
}
|
app/code/local/Mss/Connector/controllers/ItemController.php
ADDED
@@ -0,0 +1,798 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_ItemController extends Mage_Core_Controller_Front_Action {
|
3 |
+
/**
|
4 |
+
* Current product object
|
5 |
+
*
|
6 |
+
* @var Mage_Catalog_Model_Product
|
7 |
+
*/
|
8 |
+
protected $product;
|
9 |
+
protected $_keepFrame = true;
|
10 |
+
protected $_keepAspectRatio = true; // false stretch the image
|
11 |
+
protected $thumbnail_with = 320;
|
12 |
+
protected $thumbnail_height = null;
|
13 |
+
protected $main_with = 640;
|
14 |
+
protected $main_height = null;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* the item converted by the current product
|
18 |
+
*
|
19 |
+
*/
|
20 |
+
private $item = array ();
|
21 |
+
private $detail = false;
|
22 |
+
const OPTION_TYPE_SELECT = 'select';
|
23 |
+
const OPTION_TYPE_CHECKBOX = 'multiselect';
|
24 |
+
const OPTION_TYPE_MULTIPLE_SELECT = 'multiselect';
|
25 |
+
const OPTION_TYPE_TEXT = 'text';
|
26 |
+
const OPTION_TYPE_DATE = 'date';
|
27 |
+
const OPTION_TYPE_TIME = 'time';
|
28 |
+
const OPTION_TYPE_DATE_TIME = 'datetime';
|
29 |
+
|
30 |
+
public function _construct(){
|
31 |
+
|
32 |
+
header('content-type: application/json; charset=utf-8');
|
33 |
+
header("access-control-allow-origin: *");
|
34 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
35 |
+
parent::_construct();
|
36 |
+
|
37 |
+
}
|
38 |
+
public function getItemAction() {
|
39 |
+
return json_encode ( $this->_getitem () );
|
40 |
+
}
|
41 |
+
/**
|
42 |
+
* the API interface function
|
43 |
+
*
|
44 |
+
* @param type $apidata
|
45 |
+
* @return type
|
46 |
+
*/
|
47 |
+
public function _getitem() {
|
48 |
+
$apidata = $this->getRequest ()->getParams ();
|
49 |
+
$item_id = $apidata ['item_id'];
|
50 |
+
if ($this->loadProduct ( $item_id )) {
|
51 |
+
$this->detail = true;
|
52 |
+
$this->getItemBaseInfo ();
|
53 |
+
$this->getItemAttributes ();
|
54 |
+
$this->getItemPrices ();
|
55 |
+
$this->getItemImages ();
|
56 |
+
$this->getProductDescription ();
|
57 |
+
$this->getRecommendedItems ();
|
58 |
+
// $this->getRelatedItems();
|
59 |
+
}
|
60 |
+
return array (
|
61 |
+
true,
|
62 |
+
'0x0000',
|
63 |
+
array (
|
64 |
+
'item' => $this->item
|
65 |
+
)
|
66 |
+
);
|
67 |
+
}
|
68 |
+
public function getItemBaseInfo() {
|
69 |
+
$helper = Mage::helper ( 'catalog/image' );
|
70 |
+
$helper->init ( $this->product, $this->getProductImageType () )->keepAspectRatio ( $this->_keepAspectRatio )->keepFrame ( $this->_keepFrame );
|
71 |
+
$this->item ['item_id'] = $this->product->getId ();
|
72 |
+
$this->item ['item_title'] = $this->product->getName ();
|
73 |
+
$this->item ['item_url'] = $this->product->getProductUrl ();
|
74 |
+
$this->item ['cid'] = $this->product->getCategoryIds ();
|
75 |
+
$this->item ['qty'] = $this->product->getStockItem ()->getQty ();
|
76 |
+
$this->item ['thumbnail_pic_url'] = ( string ) $helper->resize ( $this->thumbnail_with, $this->thumbnail_height );
|
77 |
+
$this->item ['main_pic_url'] = ( string ) $helper->resize ( $this->main_with, $this->main_height );
|
78 |
+
$this->item ['is_virtual'] = $this->product->isVirtual ();
|
79 |
+
$this->item ['item_status'] = $this->product->isSaleable () ? 'instock' : 'outofstock';
|
80 |
+
if (! $this->product->getRatingSummary ()) {
|
81 |
+
Mage::getModel ( 'review/review' )->getEntitySummary ( $this->product, Mage::app ()->getStore ()->getId () );
|
82 |
+
}
|
83 |
+
$this->item ['allow_add_to_cart'] = ! $this->HasOptions ();
|
84 |
+
$this->item ['rating_score'] = round ( ( int ) $this->product->getRatingSummary ()->getRatingSummary () / 20 );
|
85 |
+
$this->item ['rating_count'] = $this->product->getRatingSummary ()->getReviewsCount ();
|
86 |
+
$this->item ['sales_type'] = ($this->product->isInStock ()) ? 'stock' : 'distribute';
|
87 |
+
$this->item ['qty_min_unit'] = 1;
|
88 |
+
$stockItem = $this->product->getStockItem ();
|
89 |
+
if ($stockItem) {
|
90 |
+
if ($stockItem->getMinSaleQty () && $stockItem->getMinSaleQty () > 0) {
|
91 |
+
$this->item ['qty_min_unit'] = $stockItem->getMinSaleQty ();
|
92 |
+
}
|
93 |
+
}
|
94 |
+
$this->item ['item_type'] = $this->product->getTypeId ();
|
95 |
+
return $this->item;
|
96 |
+
}
|
97 |
+
public function getItemPrices() {
|
98 |
+
$prices = array ();
|
99 |
+
$productType = $this->product->getTypeId ();
|
100 |
+
switch ($productType) {
|
101 |
+
case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE :
|
102 |
+
{
|
103 |
+
$prices = $this->collectBundleProductPrices ( $this->product );
|
104 |
+
}
|
105 |
+
break;
|
106 |
+
default :
|
107 |
+
{
|
108 |
+
$prices = $this->collectProductPrices ( $this->product );
|
109 |
+
}
|
110 |
+
break;
|
111 |
+
}
|
112 |
+
$this->item ['prices'] = $prices;
|
113 |
+
return $prices;
|
114 |
+
}
|
115 |
+
public function HasOptions() {
|
116 |
+
if (! $this->product->isSaleable ()) {
|
117 |
+
return false;
|
118 |
+
} else if ($this->product->getHasOptions ()) {
|
119 |
+
return true;
|
120 |
+
} else {
|
121 |
+
return $this->product->getTypeInstance ( true )->hasOptions ( $this->product );
|
122 |
+
}
|
123 |
+
}
|
124 |
+
public function getItemAttributes() {
|
125 |
+
$productType = $this->product->getTypeId ();
|
126 |
+
switch ($productType) {
|
127 |
+
case Mage_Catalog_Model_Product_Type::TYPE_SIMPLE :
|
128 |
+
{
|
129 |
+
$this->item ['attributes'] = $this->getProductCustomOptionsOption ( $this->product );
|
130 |
+
}
|
131 |
+
break;
|
132 |
+
case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE :
|
133 |
+
{
|
134 |
+
if ($this->product->getTypeInstance ( true )->hasOptions ( $this->product )) {
|
135 |
+
$this->item ['attributes'] = $this->getProductBundleOptions ( $this->product );
|
136 |
+
}
|
137 |
+
}
|
138 |
+
break;
|
139 |
+
case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE :
|
140 |
+
{
|
141 |
+
if ($this->product->isConfigurable ()) {
|
142 |
+
$this->item ['attributes'] = $this->getProductOptions ( $this->product );
|
143 |
+
}
|
144 |
+
}
|
145 |
+
break;
|
146 |
+
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED :
|
147 |
+
{
|
148 |
+
$this->item ['attributes'] = $this->getProductGroupedOptions ( $this->product );
|
149 |
+
}
|
150 |
+
break;
|
151 |
+
case Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE :
|
152 |
+
{ // downloadable/catalog_product_links
|
153 |
+
$this->item ['attributes'] = $this->getProductDownloadOptions ( $this->product );
|
154 |
+
}
|
155 |
+
break;
|
156 |
+
case Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL :
|
157 |
+
{
|
158 |
+
$this->item ['attributes'] = array ();
|
159 |
+
}
|
160 |
+
break;
|
161 |
+
default :
|
162 |
+
{
|
163 |
+
$this->item ['attributes'] = array ();
|
164 |
+
}
|
165 |
+
break;
|
166 |
+
}
|
167 |
+
return $this->item ['attributes'];
|
168 |
+
}
|
169 |
+
public function setProduct($product) {
|
170 |
+
$this->product = $product;
|
171 |
+
}
|
172 |
+
public function loadProduct($itemId) {
|
173 |
+
if ($this->product && $this->product->getId ()) {
|
174 |
+
return $this->product;
|
175 |
+
}
|
176 |
+
$this->product = Mage::getModel ( 'catalog/product' )->setStoreId ( Mage::app ()->getStore ()->getId () )->load ( $itemId );
|
177 |
+
if ($this->product && $this->product->getId ()) {
|
178 |
+
return true;
|
179 |
+
}
|
180 |
+
return false;
|
181 |
+
}
|
182 |
+
public function getItem() {
|
183 |
+
return $this->item;
|
184 |
+
}
|
185 |
+
private function getProductImageType() {
|
186 |
+
$imageType = 'image';
|
187 |
+
$itemData = $this->product->getData ();
|
188 |
+
if (isset ( $itemData ['image'] )) {
|
189 |
+
$imageType = 'image';
|
190 |
+
} else if (isset ( $itemData ['small_image'] )) {
|
191 |
+
$imageType = 'small_image';
|
192 |
+
} else if (isset ( $itemData ['thumbnail'] )) {
|
193 |
+
$imageType = 'thumbnail';
|
194 |
+
}
|
195 |
+
return $imageType;
|
196 |
+
}
|
197 |
+
|
198 |
+
/**
|
199 |
+
* add prefix to options to distinguish between options,super attribute,bunlde and super group
|
200 |
+
*
|
201 |
+
* @param type $options
|
202 |
+
*/
|
203 |
+
private function addPrefixTo(&$options, $type) {
|
204 |
+
if ($options) {
|
205 |
+
foreach ( $options as &$option ) {
|
206 |
+
$prefix = "{$type}_" . $option ['attribute_id'];
|
207 |
+
$option ['attribute_id'] = $prefix;
|
208 |
+
if ($option ['options']) {
|
209 |
+
foreach ( $option ['options'] as &$value ) {
|
210 |
+
$value ['attribute_id'] = $prefix;
|
211 |
+
}
|
212 |
+
}
|
213 |
+
}
|
214 |
+
}
|
215 |
+
}
|
216 |
+
public function getProductDescription() {
|
217 |
+
$_helper = Mage::helper ( 'catalog/output' );
|
218 |
+
$this->item ['short_description'] = $_helper->productAttribute ( $this->product, nl2br ( $this->product->getShortDescription () ), 'short_description' );
|
219 |
+
$this->item ['short_description'] = preg_replace ( '/(<img[^<>]+?src\s*=\s*\")([^:\"]+\")/i', '$1' . Mage::getBaseUrl () . '$2', $this->item ['short_description'] );
|
220 |
+
$this->item ['detail_description'] = $_helper->productAttribute ( $this->product, $this->product->getDescription (), 'description' );
|
221 |
+
if (preg_match ( '/{{(.+)}}/i', $this->item ['detail_description'] )) {
|
222 |
+
$this->item ['detail_description'] = preg_replace ( '/(\<img[^<>]+src\s*=\s*"){{(\w+)\s*url="(.+)}}/i', '$1' . Mage::getBaseUrl () . '/$2/$3', $this->item ['detail_description'] );
|
223 |
+
}
|
224 |
+
$this->item ['detail_description'] = preg_replace ( '/(<img[^<>]+?src\s*=\s*\")([^:\"]+\")/i', '$1' . Mage::getBaseUrl () . '$2', $this->item ['detail_description'] );
|
225 |
+
$this->item ['specifications'] = $this->getProductFeature ();
|
226 |
+
}
|
227 |
+
public function getProductFeature() {
|
228 |
+
$features = array ();
|
229 |
+
if (Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE == $this->product->getTypeId ()) {
|
230 |
+
$block = Mage::getBlockSingleton ( 'downloadable/catalog_product_samples' );
|
231 |
+
$block->setProduct ( $this->product );
|
232 |
+
if ($block->hasSamples ()) {
|
233 |
+
foreach ( $block->getSamples () as $sample ) {
|
234 |
+
$features [] = array (
|
235 |
+
'name' => $block->getSamplesTitle (),
|
236 |
+
'value' => '<a href="' . $block->getSampleUrl ( $sample ) . '" ' . ($block->getIsOpenInNewWindow () ? 'onclick="this.target=\'_blank\'">' : '>') . $block->escapeHtml ( $sample->getTitle () ) . '</a>'
|
237 |
+
);
|
238 |
+
}
|
239 |
+
}
|
240 |
+
} else {
|
241 |
+
Mage::register ( 'product', $this->product );
|
242 |
+
$block = Mage::getBlockSingleton ( 'catalog/product_view_Attributes' );
|
243 |
+
$helper = $block->helper ( 'catalog/output' );
|
244 |
+
$data = $block->getAdditionalData ();
|
245 |
+
foreach ( $data as $feature ) {
|
246 |
+
$features [] = array (
|
247 |
+
'name' => $block->htmlEscape ( $block->__ ( $feature ['label'] ) ),
|
248 |
+
'value' => $helper->productAttribute ( $this->product, $feature ['value'], $feature ['code'] )
|
249 |
+
);
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
return $features;
|
254 |
+
}
|
255 |
+
private function getItemImageUrl($imageFile = null) {
|
256 |
+
$imageType = $this->getProductImageType ();
|
257 |
+
$helper = Mage::helper ( 'catalog/image' );
|
258 |
+
return ( string ) $helper->init ( $this->product, $imageType, $imageFile )->keepAspectRatio ( $this->_keepAspectRatio )->keepFrame ( $this->_keepFrame )->resize ( $this->main_with, $this->main_height );
|
259 |
+
}
|
260 |
+
public function getItemImages() {
|
261 |
+
$this->item ['item_imgs'] = array ();
|
262 |
+
$name = basename ( $this->product->getImageUrl () );
|
263 |
+
if (($images = $this->product->getMediaGalleryImages ())) {
|
264 |
+
if (count ( $images ) > 0) {
|
265 |
+
$position = 0;
|
266 |
+
foreach ( $images as $image ) {
|
267 |
+
$itemImg = array ();
|
268 |
+
$itemImg ['img_id'] = $image->getId ();
|
269 |
+
$itemImg ['img_url'] = $this->getItemImageUrl ( $image->getFile () );
|
270 |
+
$itemImg ['position'] = ++ $position;
|
271 |
+
if ($position > 1 && $name == basename ( $image->getFile () )) {
|
272 |
+
$first = $itemImg;
|
273 |
+
$first ['position'] = 0;
|
274 |
+
} else {
|
275 |
+
$this->item ['item_imgs'] [] = $itemImg;
|
276 |
+
}
|
277 |
+
}
|
278 |
+
if (isset ( $first )) {
|
279 |
+
$this->item ['item_imgs'] = array_merge ( array (
|
280 |
+
$first
|
281 |
+
), $this->item ['item_imgs'] );
|
282 |
+
}
|
283 |
+
|
284 |
+
return $this->item ['item_imgs'];
|
285 |
+
}
|
286 |
+
}
|
287 |
+
$itemImg = array ();
|
288 |
+
$itemImg ['img_id'] = 0;
|
289 |
+
$itemImg ['img_url'] = $this->getItemImageUrl ();
|
290 |
+
$itemImg ['position'] = 0;
|
291 |
+
$this->item ['item_imgs'] [] = $itemImg;
|
292 |
+
return $this->item ['item_imgs'];
|
293 |
+
}
|
294 |
+
public function getRelatedItems() {
|
295 |
+
$items = array ();
|
296 |
+
$collection = $this->product->getRelatedProductCollection ();
|
297 |
+
$layer = Mage::getSingleton ( 'catalog/layer' );
|
298 |
+
$layer->prepareProductCollection ( $collection );
|
299 |
+
$products = $collection->getItems ();
|
300 |
+
if ($products) {
|
301 |
+
$itemObject = Kancart::getModel ( 'Item' );
|
302 |
+
foreach ( $products as $product ) {
|
303 |
+
$itemObject->setProduct ( $product );
|
304 |
+
$itemObject->getItemBaseInfo ();
|
305 |
+
$itemObject->getItemPrices ();
|
306 |
+
$items [] = $itemObject->getItem ();
|
307 |
+
$itemObject->clear ();
|
308 |
+
}
|
309 |
+
}
|
310 |
+
$this->item ['related_items'] = $items;
|
311 |
+
return $items;
|
312 |
+
}
|
313 |
+
public function getRecommendedItems() {
|
314 |
+
$items = array ();
|
315 |
+
$collection = $this->product->getUpSellProductCollection ();
|
316 |
+
$layer = Mage::getSingleton ( 'catalog/layer' );
|
317 |
+
$layer->prepareProductCollection ( $collection );
|
318 |
+
$products = $collection->getItems ();
|
319 |
+
if ($products) {
|
320 |
+
$itemObject = Kancart::getModel ( 'Item' );
|
321 |
+
foreach ( $products as $product ) {
|
322 |
+
$itemObject->setProduct ( $product );
|
323 |
+
$itemObject->getItemBaseInfo ();
|
324 |
+
$itemObject->getItemPrices ();
|
325 |
+
$items [] = $itemObject->getItem ();
|
326 |
+
$itemObject->clear ();
|
327 |
+
}
|
328 |
+
}
|
329 |
+
$this->item ['recommended_items'] = $items;
|
330 |
+
return $items;
|
331 |
+
}
|
332 |
+
private function getItemTierPrice($_product) { // getTierPrice
|
333 |
+
$result = array ();
|
334 |
+
if ($this->detail) {
|
335 |
+
foreach ( $_product->getTierPrice () as $discount ) {
|
336 |
+
$result [] = array (
|
337 |
+
'min_qty' => ( int ) $discount ['price_qty'],
|
338 |
+
'price' => $this->getCurrencyPrice ( $discount ['price'] )
|
339 |
+
);
|
340 |
+
}
|
341 |
+
}
|
342 |
+
return $result;
|
343 |
+
}
|
344 |
+
public function clear() {
|
345 |
+
$this->item = array ();
|
346 |
+
$this->product = null;
|
347 |
+
}
|
348 |
+
private function getProductGroupedOptions(Mage_Catalog_Model_Product $product) {
|
349 |
+
if (! $product->getId ()) {
|
350 |
+
return array ();
|
351 |
+
}
|
352 |
+
if (! $product->isSaleable ()) {
|
353 |
+
return array ();
|
354 |
+
}
|
355 |
+
/**
|
356 |
+
* Grouped (associated) products
|
357 |
+
*/
|
358 |
+
$_associatedProducts = $product->getTypeInstance ( true )->getAssociatedProducts ( $product );
|
359 |
+
if (! sizeof ( $_associatedProducts )) {
|
360 |
+
return array ();
|
361 |
+
}
|
362 |
+
$attributes = array ();
|
363 |
+
foreach ( $_associatedProducts as $_item ) {
|
364 |
+
if (! $_item->isSaleable ()) {
|
365 |
+
continue;
|
366 |
+
}
|
367 |
+
$attribute = array ();
|
368 |
+
|
369 |
+
$attribute ['attribute_id'] = $_item->getId ();
|
370 |
+
$attribute ['input'] = 'product';
|
371 |
+
$attribute ['title'] = strip_tags ( $_item->getName () );
|
372 |
+
$attribute ['qty'] = $_item->getQty () * 1;
|
373 |
+
$attribute ['is_editable'] = 1;
|
374 |
+
/**
|
375 |
+
* Process product price
|
376 |
+
*/
|
377 |
+
if ($_item->getPrice () != $_item->getFinalPrice ()) {
|
378 |
+
$productPrice = $_item->getFinalPrice ();
|
379 |
+
} else {
|
380 |
+
$productPrice = $_item->getPrice ();
|
381 |
+
}
|
382 |
+
if ($productPrice > 0.00) {
|
383 |
+
// add
|
384 |
+
$attribute ['price'] = $this->getCurrencyPrice ( $productPrice );
|
385 |
+
}
|
386 |
+
$attribute ['options'] = array ();
|
387 |
+
$attributes [] = $attribute;
|
388 |
+
}
|
389 |
+
return $attributes;
|
390 |
+
}
|
391 |
+
private function getProductBundleOptions(Mage_Catalog_Model_Product $product) {
|
392 |
+
if ($product->getTypeInstance ( true )->hasOptions ( $product )) {
|
393 |
+
$product->getTypeInstance ( true )->setStoreFilter ( $product->getStoreId (), $product );
|
394 |
+
$optionCollection = $product->getTypeInstance ( true )->getOptionsCollection ( $product );
|
395 |
+
$selectionCollection = $product->getTypeInstance ( true )->getSelectionsCollection ( $product->getTypeInstance ( true )->getOptionsIds ( $product ), $product );
|
396 |
+
$bundleOptions = $optionCollection->appendSelections ( $selectionCollection, false, false );
|
397 |
+
if (! sizeof ( $bundleOptions )) {
|
398 |
+
return array ();
|
399 |
+
}
|
400 |
+
$attributes = array ();
|
401 |
+
foreach ( $bundleOptions as $_option ) {
|
402 |
+
$selections = $_option->getSelections ();
|
403 |
+
if (empty ( $selections )) {
|
404 |
+
continue;
|
405 |
+
}
|
406 |
+
$type = self::OPTION_TYPE_SELECT;
|
407 |
+
if ($_option->isMultiSelection ()) {
|
408 |
+
$type = self::OPTION_TYPE_MULTIPLE_SELECT;
|
409 |
+
}
|
410 |
+
$code = $_option->getId ();
|
411 |
+
if ($type == self::OPTION_TYPE_MULTIPLE_SELECT) {
|
412 |
+
$code .= '';
|
413 |
+
}
|
414 |
+
$attribute = array ();
|
415 |
+
$attribute ['attribute_id'] = $code;
|
416 |
+
$attribute ['parent_id'] = $_option->getParentId ();
|
417 |
+
$attribute ['position'] = $_option->getPosition ();
|
418 |
+
$attribute ['required'] = $_option->getRequired () || $_option->getIsRequired () || $_option->getIsRequire ();
|
419 |
+
$attribute ['input'] = $this->_getOptionTypeForKanCartByRealType ( $_option->getType () );
|
420 |
+
$attribute ['title'] = $_option->getTitle ();
|
421 |
+
$attribute ['options'] = array ();
|
422 |
+
if (! $attribute ['required'] && $attribute ['input'] == self::OPTION_TYPE_SELECT) {
|
423 |
+
$none = array (
|
424 |
+
'attribute_id' => 'none',
|
425 |
+
'option_id' => '',
|
426 |
+
'title' => 'None'
|
427 |
+
);
|
428 |
+
$attribute ['options'] [] = $none;
|
429 |
+
}
|
430 |
+
if (empty ( $selections )) {
|
431 |
+
$attributes [] = $attribute;
|
432 |
+
continue;
|
433 |
+
}
|
434 |
+
foreach ( $_option->getSelections () as $_selection ) {
|
435 |
+
if (! $_selection->isSaleable ()) {
|
436 |
+
continue;
|
437 |
+
}
|
438 |
+
$finalValue = array ();
|
439 |
+
$finalValue ['attribute_id'] = $_option->getOptionId ();
|
440 |
+
$finalValue ['option_id'] = $_selection->getSelectionId ();
|
441 |
+
$finalValue ['title'] = $_selection->getName ();
|
442 |
+
$finalValue ['qty'] = ! ($_selection->getSelectionQty () * 1) ? '1' : $_selection->getSelectionQty () * 1;
|
443 |
+
$finalValue ['is_default'] = $_selection->getIsDefault ();
|
444 |
+
if (! $_option->isMultiSelection ()) {
|
445 |
+
if ($_selection->getSelectionCanChangeQty ()) {
|
446 |
+
$finalValue ['is_qty_editable'] = 1;
|
447 |
+
}
|
448 |
+
}
|
449 |
+
$price = $product->getPriceModel ()->getSelectionPreFinalPrice ( $product, $_selection );
|
450 |
+
if (( float ) $price != 0.00) {
|
451 |
+
$finalValue ['price'] = $this->getCurrencyPrice ( $price );
|
452 |
+
} else {
|
453 |
+
$finalValue ['price'] = null;
|
454 |
+
}
|
455 |
+
$attribute ['options'] [] = $finalValue;
|
456 |
+
}
|
457 |
+
$attributes [] = $attribute;
|
458 |
+
}
|
459 |
+
return $attributes;
|
460 |
+
}
|
461 |
+
return false;
|
462 |
+
}
|
463 |
+
|
464 |
+
/**
|
465 |
+
* 仅仅将$attributes中的数据提取出来,其中价格已经是根据当前汇率转换后的价格
|
466 |
+
*
|
467 |
+
* @param type $attributes
|
468 |
+
* @return type
|
469 |
+
*/
|
470 |
+
private function getProductConfigurableAttributes($configurableProductAttributes) {
|
471 |
+
$attributes = array ();
|
472 |
+
foreach ( $configurableProductAttributes as $attrId => $attribute ) {
|
473 |
+
$eachAttribute = array ();
|
474 |
+
$eachAttribute ['attribute_id'] = $attrId;
|
475 |
+
$eachAttribute ['required'] = $attribute ['is_required'] == '1' ? true : false;
|
476 |
+
$eachAttribute ['input'] = 'select';
|
477 |
+
$eachAttribute ['title'] = $attribute ['label'];
|
478 |
+
$eachAttribute ['options'] = array ();
|
479 |
+
if (isset ( $attribute ['options'] )) {
|
480 |
+
foreach ( $attribute ['options'] as $option ) {
|
481 |
+
$value = array ();
|
482 |
+
$value ['attribute_id'] = $attrId;
|
483 |
+
$value ['option_id'] = $option ['id'];
|
484 |
+
$value ['title'] = $option ['label'];
|
485 |
+
$value ['price'] = $option ['price'];
|
486 |
+
$eachAttribute ['options'] [] = $value;
|
487 |
+
}
|
488 |
+
}
|
489 |
+
$attributes [] = $eachAttribute;
|
490 |
+
}
|
491 |
+
return $attributes;
|
492 |
+
}
|
493 |
+
private function getProductOptions(Mage_Catalog_Model_Product $product) {
|
494 |
+
$orgiOptions = $this->getProductCustomOptionsOption ( $product );
|
495 |
+
$options = array ();
|
496 |
+
if (! $product->isSaleable ()) {
|
497 |
+
return $orgiOptions;
|
498 |
+
}
|
499 |
+
$_attributes = $product->getTypeInstance ( true )->getConfigurableAttributes ( $product );
|
500 |
+
if (! sizeof ( $_attributes )) {
|
501 |
+
return $orgiOptions;
|
502 |
+
}
|
503 |
+
$_allowProducts = array ();
|
504 |
+
$_allProducts = $product->getTypeInstance ( true )->getUsedProducts ( null, $product );
|
505 |
+
foreach ( $_allProducts as $_product ) {
|
506 |
+
if ($_product->isSaleable ()) {
|
507 |
+
$_allowProducts [] = $_product;
|
508 |
+
}
|
509 |
+
}
|
510 |
+
foreach ( $_allowProducts as $_item ) {
|
511 |
+
$_productId = $_item->getId ();
|
512 |
+
foreach ( $_attributes as $attribute ) {
|
513 |
+
$productAttribute = $attribute->getProductAttribute ();
|
514 |
+
$attributeValue = $_item->getData ( $productAttribute->getAttributeCode () );
|
515 |
+
$options [$productAttribute->getId ()] [$_productId] = $attributeValue;
|
516 |
+
}
|
517 |
+
}
|
518 |
+
$this->item ['attribute_relation'] = $this->getAttributeRelation ( $options );
|
519 |
+
foreach ( $_attributes as $attribute ) {
|
520 |
+
$productAttribute = $attribute->getProductAttribute ();
|
521 |
+
$attributeId = $productAttribute->getId ();
|
522 |
+
$info = array (
|
523 |
+
'id' => $productAttribute->getId (),
|
524 |
+
'label' => $attribute->getLabel (),
|
525 |
+
'is_required' => $productAttribute->getRequired () || $productAttribute->getIsRequired () || $productAttribute->getIsRequire (),
|
526 |
+
'options' => array ()
|
527 |
+
);
|
528 |
+
$prices = $attribute->getPrices ();
|
529 |
+
if (is_array ( $prices )) {
|
530 |
+
foreach ( $prices as $value ) {
|
531 |
+
if (! in_array ( $value ['value_index'], $options [$attributeId] )) {
|
532 |
+
continue;
|
533 |
+
}
|
534 |
+
$info ['options'] [] = array (
|
535 |
+
'id' => $value ['value_index'],
|
536 |
+
'label' => $value ['label'],
|
537 |
+
'price' => $this->_preparePrice ( $product, $value ['pricing_value'], $value ['is_percent'] )
|
538 |
+
);
|
539 |
+
}
|
540 |
+
}
|
541 |
+
if (sizeof ( $info ['options'] ) > 0) {
|
542 |
+
$attributes [$attributeId] = $info;
|
543 |
+
}
|
544 |
+
}
|
545 |
+
$configurabeAttributes = $this->getProductConfigurableAttributes ( $attributes );
|
546 |
+
$this->addPrefixTo ( $orgiOptions, 'option' );
|
547 |
+
$this->addPrefixTo ( $configurabeAttributes, 'super_attribute' );
|
548 |
+
foreach ( $orgiOptions as $opt ) {
|
549 |
+
$configurabeAttributes [] = $opt;
|
550 |
+
}
|
551 |
+
return $configurabeAttributes;
|
552 |
+
}
|
553 |
+
private function getProductCustomOptionsOption(Mage_Catalog_Model_Product $product) {
|
554 |
+
$options = array ();
|
555 |
+
if (! $product->getId ()) {
|
556 |
+
return $options;
|
557 |
+
}
|
558 |
+
if (! $product->isSaleable () || ! sizeof ( $product->getOptions () )) {
|
559 |
+
return $options;
|
560 |
+
}
|
561 |
+
foreach ( $product->getOptions () as $option ) {
|
562 |
+
$optionObj = array ();
|
563 |
+
$type = $this->_getOptionTypeForKanCartByRealType ( $option->getType () );
|
564 |
+
$optionObj ['attribute_id'] = $option->getId ();
|
565 |
+
$optionObj ['required'] = $option->getRequired () || $option->getIsRequire () || $option->getIsRequired ();
|
566 |
+
$optionObj ['input'] = $type;
|
567 |
+
$optionObj ['title'] = $option->getTitle ();
|
568 |
+
$price = $option->getPrice ();
|
569 |
+
if ($price) {
|
570 |
+
$optionObj ['price'] = $this->getCurrencyPrice ( $price );
|
571 |
+
} else {
|
572 |
+
$optionObj ['price'] = null;
|
573 |
+
}
|
574 |
+
$optionObj ['options'] = array ();
|
575 |
+
if (! $optionObj ['required'] && $optionObj ['input'] == self::OPTION_TYPE_SELECT) {
|
576 |
+
$none = array (
|
577 |
+
'attribute_id' => 'none',
|
578 |
+
'option_id' => '',
|
579 |
+
'title' => 'None'
|
580 |
+
);
|
581 |
+
$optionObj ['options'] [] = $none;
|
582 |
+
}
|
583 |
+
foreach ( $option->getValues () as $value ) {
|
584 |
+
$optionValueObj = array ();
|
585 |
+
$optionValueObj ['attribute_id'] = $option->getId ();
|
586 |
+
$optionValueObj ['option_id'] = $value->getId ();
|
587 |
+
$optionValueObj ['title'] = $value->getTitle ();
|
588 |
+
$price = $value->getPrice ();
|
589 |
+
if ($price) {
|
590 |
+
$optionValueObj ['price'] = $this->getCurrencyPrice ( $price );
|
591 |
+
} else {
|
592 |
+
$optionValueObj ['price'] = null;
|
593 |
+
}
|
594 |
+
$optionObj ['options'] [] = $optionValueObj;
|
595 |
+
}
|
596 |
+
$options [] = $optionObj;
|
597 |
+
}
|
598 |
+
return $options;
|
599 |
+
}
|
600 |
+
private function _getOptionTypeForKanCartByRealType($realType) {
|
601 |
+
static $map = null;
|
602 |
+
|
603 |
+
if (is_null ( $map )) {
|
604 |
+
$maps = array (
|
605 |
+
Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN => self::OPTION_TYPE_SELECT,
|
606 |
+
Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO => self::OPTION_TYPE_SELECT,
|
607 |
+
Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT => self::OPTION_TYPE_SELECT,
|
608 |
+
Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE => self::OPTION_TYPE_MULTIPLE_SELECT,
|
609 |
+
Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX => self::OPTION_TYPE_MULTIPLE_SELECT,
|
610 |
+
Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE => self::OPTION_TYPE_DATE,
|
611 |
+
Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME => self::OPTION_TYPE_TIME,
|
612 |
+
Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME => self::OPTION_TYPE_DATE_TIME,
|
613 |
+
Mage_Catalog_Model_Product_Option::OPTION_TYPE_FIELD => self::OPTION_TYPE_TEXT,
|
614 |
+
Mage_Catalog_Model_Product_Option::OPTION_TYPE_AREA => self::OPTION_TYPE_TEXT,
|
615 |
+
'multi' => self::OPTION_TYPE_MULTIPLE_SELECT
|
616 |
+
);
|
617 |
+
}
|
618 |
+
|
619 |
+
return isset ( $maps [$realType] ) ? $maps [$realType] : self::OPTION_TYPE_TEXT;
|
620 |
+
}
|
621 |
+
|
622 |
+
/**
|
623 |
+
* dowload options
|
624 |
+
*
|
625 |
+
* @param type $attributes
|
626 |
+
* @return type
|
627 |
+
*/
|
628 |
+
private function getProductDownloadOptions($product) {
|
629 |
+
$block = Mage::getBlockSingleton ( 'downloadable/catalog_product_links' );
|
630 |
+
$block->setProduct ( $product );
|
631 |
+
$links = $block->getLinks ();
|
632 |
+
|
633 |
+
$attributes = array ();
|
634 |
+
if ($block->hasLinks ()) {
|
635 |
+
$eachAttribute = array ();
|
636 |
+
$attrId = strtolower ( $block->getLinksTitle () );
|
637 |
+
$eachAttribute ['attribute_id'] = $attrId;
|
638 |
+
$eachAttribute ['required'] = ( bool ) $block->getLinkSelectionRequired ();
|
639 |
+
$eachAttribute ['input'] = self::OPTION_TYPE_MULTIPLE_SELECT;
|
640 |
+
$eachAttribute ['title'] = $block->getLinksTitle ();
|
641 |
+
$eachAttribute ['options'] = array ();
|
642 |
+
foreach ( $links as $link ) {
|
643 |
+
$value = array ();
|
644 |
+
preg_match ( '/\d+\.\d+/', $block->getFormattedLinkPrice ( $link ), $prices );
|
645 |
+
if ($link->getSampleFile () || $link->getSampleUrl ()) {
|
646 |
+
$title = $link->getTitle () . ' (<a href="' . $block->getLinkSamlpeUrl ( $link ) . '" ' . ($block->getIsOpenInNewWindow () ? 'onclick="this.target=\'_blank\'">' : '>') . Mage::helper ( 'downloadable' )->__ ( 'sample' ) . '</a>)';
|
647 |
+
} else {
|
648 |
+
$title = $link->getTitle ();
|
649 |
+
}
|
650 |
+
$value ['attribute_id'] = $attrId;
|
651 |
+
$value ['option_id'] = $link->getId ();
|
652 |
+
$value ['title'] = $title;
|
653 |
+
$value ['price'] = floatval ( $prices [0] );
|
654 |
+
$eachAttribute ['options'] [] = $value;
|
655 |
+
}
|
656 |
+
$attributes [] = $eachAttribute;
|
657 |
+
}
|
658 |
+
return $attributes;
|
659 |
+
}
|
660 |
+
private function getAttributeRelation($options, $type = 'associate') {
|
661 |
+
$attributeRelation = array ();
|
662 |
+
|
663 |
+
if ($type == 'associate') {
|
664 |
+
if ($options && sizeof ( $options ) > 1) {
|
665 |
+
$min = 100;
|
666 |
+
$parentAttributeId = 0;
|
667 |
+
$parentOption = array ();
|
668 |
+
foreach ( $options as $attributeId => $option ) {
|
669 |
+
$optionSize = sizeof ( array_flip ( $option ) );
|
670 |
+
if ($optionSize < $min) {
|
671 |
+
$min = $optionSize;
|
672 |
+
$parentAttributeId = $attributeId;
|
673 |
+
$parentOption = $option;
|
674 |
+
}
|
675 |
+
}
|
676 |
+
|
677 |
+
foreach ( $options as $attributeId => $option ) {
|
678 |
+
if ($parentAttributeId == $attributeId) {
|
679 |
+
continue;
|
680 |
+
}
|
681 |
+
$relations = array ();
|
682 |
+
foreach ( $option as $key => $value ) {
|
683 |
+
$parentOptionId = $parentOption [$key];
|
684 |
+
$relations [$parentOptionId] ['parent_option_id'] = $parentOptionId;
|
685 |
+
$relations [$parentOptionId] ['child_option_id'] [] = $value;
|
686 |
+
}
|
687 |
+
$attributeRelation [] = array (
|
688 |
+
'parent_attribute_id' => 'super_attribute_' . $parentAttributeId,
|
689 |
+
'child_attribute_id' => 'super_attribute_' . $attributeId,
|
690 |
+
'type' => $type,
|
691 |
+
'value' => array_values ( $relations )
|
692 |
+
);
|
693 |
+
}
|
694 |
+
}
|
695 |
+
} elseif ($type == 'display') {
|
696 |
+
}
|
697 |
+
|
698 |
+
return $attributeRelation;
|
699 |
+
}
|
700 |
+
private function _preparePrice($product, $price, $isPercent = false) {
|
701 |
+
if ($isPercent && ! empty ( $price )) {
|
702 |
+
$price = $product->getFinalPrice () * $price / 100;
|
703 |
+
}
|
704 |
+
$price = Mage::app ()->getStore ()->convertPrice ( $price );
|
705 |
+
$price = Mage::app ()->getStore ()->roundPrice ( $price );
|
706 |
+
return $price;
|
707 |
+
}
|
708 |
+
private function collectProductPrices($product) {
|
709 |
+
$DisplayMinimalPrice = true;
|
710 |
+
$UseLinkForAsLowAs = false;
|
711 |
+
$prices = array ();
|
712 |
+
$prices ['currency'] = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
713 |
+
$display_prices = array ();
|
714 |
+
$prices ['tier_prices'] = $this->getItemTierPrice ( $product );
|
715 |
+
|
716 |
+
$_minimalPriceValue = $product->getMinimalPrice ();
|
717 |
+
|
718 |
+
if (! $product->isGrouped ()) {
|
719 |
+
$_price = $product->getPrice ();
|
720 |
+
$_finalPrice = $product->getFinalPrice ();
|
721 |
+
if ($DisplayMinimalPrice && $_minimalPriceValue && $_minimalPriceValue < $_finalPrice) {
|
722 |
+
if (! $UseLinkForAsLowAs) {
|
723 |
+
if ($_finalPrice > 0) {
|
724 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'Price:' ), $this->getCurrencyPrice ( $_finalPrice ) );
|
725 |
+
}
|
726 |
+
if (! $this->detail) { // items list show different
|
727 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'As low as:' ) . $this->getCurrencyPrice ( $_minimalPriceValue, true, false ), 0, 'free' );
|
728 |
+
} else if (! $_finalPrice) {
|
729 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'As low as:' ), $this->getCurrencyPrice ( $_minimalPriceValue ) );
|
730 |
+
}
|
731 |
+
}
|
732 |
+
} else {
|
733 |
+
if ($_finalPrice == $_price) {
|
734 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'Price:' ), $this->getCurrencyPrice ( $_price ) );
|
735 |
+
} else {
|
736 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'Regular Price:' ), $this->getCurrencyPrice ( $_price ), 'line-through' );
|
737 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'Special Price:' ), $this->getCurrencyPrice ( $_finalPrice ) );
|
738 |
+
$this->item ['discount'] = round ( 100 - ($_finalPrice * 100) / $_price );
|
739 |
+
}
|
740 |
+
}
|
741 |
+
} else {
|
742 |
+
if ($DisplayMinimalPrice && $_minimalPriceValue) {
|
743 |
+
if (! $this->detail) { // items list show different
|
744 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'Starting at:' ) . $this->getCurrencyPrice ( $_minimalPriceValue, true, false ), 0, 'free' );
|
745 |
+
} else {
|
746 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'Starting at:' ), $this->getCurrencyPrice ( $_minimalPriceValue ) );
|
747 |
+
}
|
748 |
+
}
|
749 |
+
$_finalPrice = $_minimalPriceValue;
|
750 |
+
}
|
751 |
+
$prices ['base_price'] = array (
|
752 |
+
'price' => $this->getCurrencyPrice ( $_finalPrice )
|
753 |
+
);
|
754 |
+
$prices ['display_prices'] = $display_prices;
|
755 |
+
return $prices;
|
756 |
+
}
|
757 |
+
private function collectBundleProductPrices($product) {
|
758 |
+
$prices = array ();
|
759 |
+
$prices ['currency'] = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
760 |
+
$display_prices = array ();
|
761 |
+
$prices ['tier_prices'] = $this->getItemTierPrice ( $product );
|
762 |
+
|
763 |
+
/* @var $_weeeHelper Mage_Weee_Helper_Data */
|
764 |
+
/* @var $_taxHelper Mage_Tax_Helper_Data */
|
765 |
+
list ( $_minimalPrice, $_maximalPrice ) = $product->getPriceModel ()->getPrices ( $product );
|
766 |
+
$_finalPrice = $product->getFinalPrice ();
|
767 |
+
if ($product->getPriceView ()) {
|
768 |
+
if ($_finalPrice > 0) {
|
769 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'Price:' ), $this->getCurrencyPrice ( $_finalPrice ) );
|
770 |
+
}
|
771 |
+
if (! $this->detail) { // items list show different
|
772 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'As low as: ' ) . $this->getCurrencyPrice ( $_minimalPrice, true, false ), 0, 'free' );
|
773 |
+
} else if (! $_finalPrice) {
|
774 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'As low as: ' ), $this->getCurrencyPrice ( $_minimalPrice ) );
|
775 |
+
}
|
776 |
+
} else {
|
777 |
+
if ($_minimalPrice != $_maximalPrice) {
|
778 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'From:' ), $this->getCurrencyPrice ( $_minimalPrice ), 'from' );
|
779 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'To:' ), $this->getCurrencyPrice ( $_maximalPrice ), 'to' );
|
780 |
+
} else {
|
781 |
+
$this->addtoDisplayPrices ( $display_prices, $this->__ ( 'Price:' ), $this->getCurrencyPrice ( $_minimalPrice ), 'normal' );
|
782 |
+
}
|
783 |
+
}
|
784 |
+
$prices ['base_price'] = array (
|
785 |
+
'price' => $this->getCurrencyPrice ( $_finalPrice )
|
786 |
+
);
|
787 |
+
$prices ['display_prices'] = $display_prices;
|
788 |
+
return $prices;
|
789 |
+
}
|
790 |
+
private function addtoDisplayPrices(&$display_prices, $title, $value, $style = 'normal') {
|
791 |
+
$display_prices [] = array (
|
792 |
+
'title' => $title,
|
793 |
+
'price' => $value,
|
794 |
+
'style' => $style ? $style : 'normal'
|
795 |
+
);
|
796 |
+
return $display_prices;
|
797 |
+
}
|
798 |
+
}
|
app/code/local/Mss/Connector/controllers/ItemsController.php
ADDED
@@ -0,0 +1,398 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_ItemsController extends Mage_Core_Controller_Front_Action {
|
3 |
+
protected $_keepFrame = true;
|
4 |
+
protected $_keepAspectRatio = true; // false stretch the image
|
5 |
+
|
6 |
+
public function _construct(){
|
7 |
+
|
8 |
+
header('content-type: application/json; charset=utf-8');
|
9 |
+
header("access-control-allow-origin: *");
|
10 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
11 |
+
parent::_construct();
|
12 |
+
|
13 |
+
}
|
14 |
+
|
15 |
+
public function getItemsAction() {
|
16 |
+
echo json_encode ( $this->_getItems () );
|
17 |
+
}
|
18 |
+
public function getSortingListAction() {
|
19 |
+
echo json_decode ( $this->_getSortingList () );
|
20 |
+
}
|
21 |
+
public function _getSortingList() {
|
22 |
+
$options = Mage::getModel ( 'catalog/config' )->getAttributeUsedForSortByArray ();
|
23 |
+
return $options;
|
24 |
+
}
|
25 |
+
public function getProductByFilterAction() {
|
26 |
+
$categoryid = $this->getRequest ()->getParam ( 'categoryid' );
|
27 |
+
$pageNo = $this->getRequest ()->getParam ( 'page_no', 1 );
|
28 |
+
$pageSize = $this->getRequest ()->getParam ( 'page_size', 20 );
|
29 |
+
$orderBy = $this->getRequest ()->getParam ( 'order_by', false );
|
30 |
+
$orderBy = $orderBy && strpos ( $orderBy, ':' ) > 0 ? $orderBy : 'postion:desc';
|
31 |
+
list ( $order, $direction ) = explode ( ':', $orderBy, 2 );
|
32 |
+
|
33 |
+
$category = Mage::getModel ( 'catalog/category' )->load ( $categoryid );
|
34 |
+
$model = Mage::getModel ( 'catalog/product' );
|
35 |
+
$collection = $category->getProductCollection ()->addAttributeToFilter ( 'status', 1 )->addAttributeToFilter ( 'visibility', array (
|
36 |
+
|
37 |
+
'neq' => 1
|
38 |
+
) );
|
39 |
+
$filter = $this->getRequest ()->getParam ( 'filter', array () );
|
40 |
+
if ($filter && is_array ( $filter )) {
|
41 |
+
foreach ( $filter as $key => $o ) {
|
42 |
+
|
43 |
+
$collection->addAttributeToFilter ( $o ['attribute'], array (
|
44 |
+
$o ['key'] => $o ['value']
|
45 |
+
) );
|
46 |
+
}
|
47 |
+
}
|
48 |
+
$collection = $collection->addAttributeToSort ( $order, $direction );
|
49 |
+
$pages = $collection->setPageSize ( $pageSize )->getLastPageNumber ();
|
50 |
+
$size = $collection->getSize ();
|
51 |
+
$productList = $collection->getItems ();
|
52 |
+
if ($pageNo <= $pages) {
|
53 |
+
$items = array ();
|
54 |
+
foreach ( $productList as $key => $product ) {
|
55 |
+
if ($product->getId ()) {
|
56 |
+
$items [$key] = $this->_getItemBaseInfo ( $product );
|
57 |
+
}
|
58 |
+
}
|
59 |
+
$products = array ();
|
60 |
+
$products ['items'] = $items;
|
61 |
+
$products ['total_results'] = $size;
|
62 |
+
echo json_encode ( $products );
|
63 |
+
}
|
64 |
+
|
65 |
+
|
66 |
+
}
|
67 |
+
public function getProductlist($products, $mod = 'product') {
|
68 |
+
$productlist = array ();
|
69 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
70 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
71 |
+
foreach ( $products as $product ) {
|
72 |
+
if ($mod == 'catalog') {
|
73 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $product ['entity_id'] );
|
74 |
+
|
75 |
+
}
|
76 |
+
|
77 |
+
$productlist [] = array (
|
78 |
+
'entity_id' => $product->getId (),
|
79 |
+
'sku' => $product->getSku (),
|
80 |
+
'name' => $product->getName (),
|
81 |
+
'news_from_date' => $product->getNewsFromDate (),
|
82 |
+
'news_to_date' => $product->getNewsToDate (),
|
83 |
+
'special_from_date' => $product->getSpecialFromDate (),
|
84 |
+
'special_to_date' => $product->getSpecialToDate (),
|
85 |
+
'image_url' => $product->getImageUrl (),
|
86 |
+
'url_key' => $product->getProductUrl (),
|
87 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
88 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
89 |
+
'symbol' => Mage::app ()->getLocale ()->currency ( Mage::app ()->getStore ()->getCurrentCurrencyCode () )->getSymbol ()
|
90 |
+
);
|
91 |
+
}
|
92 |
+
return $productlist;
|
93 |
+
}
|
94 |
+
public function getfilterableattributesAction() {
|
95 |
+
$categoryid = $this->getRequest ()->getParam ( 'categoryid', false );
|
96 |
+
echo json_encode ( $this->_getfilterableattributes ( $categoryid ) );
|
97 |
+
}
|
98 |
+
protected function _getfilterableattributes($categoryid) {
|
99 |
+
$layer = Mage::getModel ( "catalog/layer" );
|
100 |
+
$category = Mage::getModel ( "catalog/category" )->load ( $categoryid );
|
101 |
+
$layer->setCurrentCategory ( $category );
|
102 |
+
$attributes = $layer->getFilterableAttributes ();
|
103 |
+
|
104 |
+
foreach ( $attributes as $key => $attribute ) {
|
105 |
+
if ($attribute->getAttributeCode () == 'price') {
|
106 |
+
$filterBlockName = 'catalog/layer_filter_price';
|
107 |
+
} elseif ($attribute->getBackendType () == 'decimal') {
|
108 |
+
$filterBlockName = 'catalog/layer_filter_decimal';
|
109 |
+
} else {
|
110 |
+
$filterBlockName = 'catalog/layer_filter_attribute';
|
111 |
+
}
|
112 |
+
if ($filterBlockName !== 'catalog/layer_filter_price') {
|
113 |
+
$result = $this->getLayout ()->createBlock ( $filterBlockName )->setLayer ( $layer )->setAttributeModel ( $attribute )->init ();
|
114 |
+
$filter_options [$key] ['att_code'] = $attribute->getAttributeCode ();
|
115 |
+
foreach ( $result->getItems () as $option ) {
|
116 |
+
$filter_options [$key] ['options'] [] = array (
|
117 |
+
'laber' => $option->getLabel (),
|
118 |
+
'value' => $option->getValue ()
|
119 |
+
);
|
120 |
+
}
|
121 |
+
} elseif ($filterBlockName == 'catalog/layer_filter_price') {
|
122 |
+
try {
|
123 |
+
if ($this->getLayout ()->createBlock ( $filterBlockName )) {
|
124 |
+
$result = $this->getLayout ()->createBlock ( $filterBlockName )->setLayer ( $layer )->setAttributeModel ( $attribute )->init ();
|
125 |
+
$filter_options [$key] ['att_code'] = $attribute->getAttributeCode ();
|
126 |
+
foreach ( $result->getItems () as $option ) {
|
127 |
+
$filter_options [$key] ['options'] [] = array (
|
128 |
+
'laber' => $option->getLabel (),
|
129 |
+
'value' => $option->getValue ()
|
130 |
+
);
|
131 |
+
}
|
132 |
+
} else
|
133 |
+
$filter_options [$key] ['att_code'] = 'price';
|
134 |
+
} catch ( Exception $e ) {
|
135 |
+
$filter_options [$key] ['att_code'] = 'price';
|
136 |
+
}
|
137 |
+
}
|
138 |
+
}
|
139 |
+
return $filter_options;
|
140 |
+
}
|
141 |
+
private function _getProductImageType($product) {
|
142 |
+
$imageType = 'image';
|
143 |
+
$itemData = $product->getData ();
|
144 |
+
if (isset ( $itemData ['image'] )) {
|
145 |
+
$imageType = 'image';
|
146 |
+
} else if (isset ( $itemData ['small_image'] )) {
|
147 |
+
$imageType = 'small_image';
|
148 |
+
} else if (isset ( $itemData ['thumbnail'] )) {
|
149 |
+
$imageType = 'thumbnail';
|
150 |
+
}
|
151 |
+
return $imageType;
|
152 |
+
}
|
153 |
+
public function _HasOptions($product) {
|
154 |
+
if (! $product->isSaleable ()) {
|
155 |
+
return false;
|
156 |
+
} else if ($product->getHasOptions ()) {
|
157 |
+
return true;
|
158 |
+
} else {
|
159 |
+
return $product->getTypeInstance ( true )->hasOptions ( $product );
|
160 |
+
}
|
161 |
+
}
|
162 |
+
public function _getItemBaseInfo($product) {
|
163 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
164 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
165 |
+
$helper = Mage::helper ( 'catalog/image' );
|
166 |
+
$helper->init ( $product, $this->_getProductImageType ( $product ) )->keepAspectRatio ( $this->_keepAspectRatio )->keepFrame ( $this->_keepFrame );
|
167 |
+
$item = array ();
|
168 |
+
$item ['item_id'] = $product->getId ();
|
169 |
+
$item ['item_title'] = $product->getName ();
|
170 |
+
$item ['item_url'] = $product->getProductUrl ();
|
171 |
+
$item ['cid'] = $product->getCategoryIds ();
|
172 |
+
$item ['qty'] = $product->getStockItem ()->getQty ();
|
173 |
+
$item ['special_from_date'] = $product->getSpecialFromDate ();
|
174 |
+
$item ['special_to_date'] = $product->getSpecialToDate ();
|
175 |
+
$item ['regular_price_with_tax'] = number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' );
|
176 |
+
$item ['final_price_with_tax'] = number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' );
|
177 |
+
$item ['symbol'] = Mage::app ()->getLocale ()->currency ( Mage::app ()->getStore ()->getCurrentCurrencyCode () )->getSymbol ();
|
178 |
+
$item ['thumbnail_pic_url'] = ( string ) $helper->resize ( $this->thumbnail_with, $this->thumbnail_height );
|
179 |
+
$item ['main_pic_url'] = ( string ) $helper->resize ( $this->main_with, $this->main_height );
|
180 |
+
$item ['is_virtual'] = $product->isVirtual ();
|
181 |
+
$item ['item_status'] = $product->isSaleable () ? 'instock' : 'outofstock';
|
182 |
+
if (! $product->getRatingSummary ()) {
|
183 |
+
Mage::getModel ( 'review/review' )->getEntitySummary ( $product, Mage::app ()->getStore ()->getId () );
|
184 |
+
}
|
185 |
+
$item ['allow_add_to_cart'] = ! $this->_HasOptions ( $product );
|
186 |
+
$item ['rating_score'] = round ( ( int ) $product->getRatingSummary ()->getRatingSummary () / 20 );
|
187 |
+
$item ['rating_count'] = $product->getRatingSummary ()->getReviewsCount ();
|
188 |
+
$item ['sales_type'] = ($product->isInStock ()) ? 'stock' : 'distribute';
|
189 |
+
$item ['qty_min_unit'] = 1;
|
190 |
+
$stockItem = $product->getStockItem ();
|
191 |
+
if ($stockItem) {
|
192 |
+
if ($stockItem->getMinSaleQty () && $stockItem->getMinSaleQty () > 0) {
|
193 |
+
$item ['qty_min_unit'] = $stockItem->getMinSaleQty ();
|
194 |
+
}
|
195 |
+
}
|
196 |
+
$item ['item_type'] = $product->getTypeId ();
|
197 |
+
return $item;
|
198 |
+
}
|
199 |
+
public function _getItems() {
|
200 |
+
try {
|
201 |
+
$cid = $this->getRequest ()->getParam ( 'cid', false );
|
202 |
+
$query = str_replace ( '%20', ' ', $this->getRequest ()->getParam ( 'query', '' ) );
|
203 |
+
$pageNo = $this->getRequest ()->getParam ( 'page_no', 1 );
|
204 |
+
$pageSize = $this->getRequest ()->getParam ( 'page_size', 20 );
|
205 |
+
$itemIds = $this->getRequest ()->getParam ( 'item_ids', false );
|
206 |
+
$orderBy = $this->getRequest ()->getParam ( 'order_by', false );
|
207 |
+
$orderBy = $orderBy && strpos ( $orderBy, ':' ) > 0 ? $orderBy : 'postion:desc';
|
208 |
+
list ( $order, $direction ) = explode ( ':', $orderBy, 2 );
|
209 |
+
var_dump ( $direction );
|
210 |
+
var_dump ( $order );
|
211 |
+
if ($itemIds && trim ( $itemIds )) {
|
212 |
+
// get by item ids
|
213 |
+
$products = $this->getSpecifiedProducts ( $itemIds, $pageNo, $pageSize, $order, $direction );
|
214 |
+
} else if (( int ) $this->getRequest ()->getParam ( 'is_specials', 0 )) {
|
215 |
+
// get Special Products
|
216 |
+
$products = $this->getSpecialProducts ( $pageNo, $pageSize, $order, $direction );
|
217 |
+
} else if (strlen ( $query ) || isset ( $_POST ['query'] ) && (! $cid)) {
|
218 |
+
// get by query
|
219 |
+
$products = $this->getProductsByQuery ( $query, $pageNo, $pageSize, $order, $direction );
|
220 |
+
} else if ($cid == - 1) {
|
221 |
+
// get all products
|
222 |
+
$products = $this->getAllProducts ( $pageNo, $pageSize, $order, $direction );
|
223 |
+
} else {
|
224 |
+
// get by category
|
225 |
+
$products = $this->getProductsByCategory ( $cid, $pageNo, $pageSize, $order, $direction );
|
226 |
+
}
|
227 |
+
return array (
|
228 |
+
true,
|
229 |
+
'0x0000',
|
230 |
+
$products
|
231 |
+
);
|
232 |
+
} catch ( Exception $e ) {
|
233 |
+
return array (
|
234 |
+
false,
|
235 |
+
'0x0013',
|
236 |
+
$e->getMessage ()
|
237 |
+
);
|
238 |
+
}
|
239 |
+
}
|
240 |
+
private function getSpecifiedProducts($ids, $pageNo, $pageSize, $order, $direction) {
|
241 |
+
$collection = Mage::getResourceModel ( 'catalog/product_collection' )->addAttributeToSelect ( Mage::getSingleton ( 'catalog/config' )->getProductAttributes () )->addMinimalPrice ()->addFinalPrice ()->addTaxPercents ()->setCurPage ( $pageNo )->setPageSize ( $pageSize );
|
242 |
+
|
243 |
+
if (strlen ( $ids )) {
|
244 |
+
is_string ( $ids ) && $ids = explode ( ',', $ids );
|
245 |
+
$count = count ( $ids );
|
246 |
+
$start = max ( $pageNo - 1, 0 ) * $pageSize;
|
247 |
+
$itemIds = array_splice ( $ids, $start, $pageSize );
|
248 |
+
$collection->addIdFilter ( $itemIds );
|
249 |
+
} else {
|
250 |
+
return array (
|
251 |
+
'items' => array (),
|
252 |
+
'total_results' => 0
|
253 |
+
);
|
254 |
+
}
|
255 |
+
|
256 |
+
$collection->load ();
|
257 |
+
$productList = $collection->getItems ();
|
258 |
+
|
259 |
+
$items = array ();
|
260 |
+
$sortOrder = array ();
|
261 |
+
foreach ( $productList as $key => $product ) {
|
262 |
+
if ($product->getId ()) {
|
263 |
+
$items [$key] = $this->_getItemBaseInfo ( $product );
|
264 |
+
$sortOrder [] = array_search ( $product->getId (), $itemIds );
|
265 |
+
}
|
266 |
+
}
|
267 |
+
array_multisort ( $sortOrder, SORT_ASC, $items );
|
268 |
+
|
269 |
+
$products = array ();
|
270 |
+
$products ['items'] = $items;
|
271 |
+
$products ['total_results'] = $count;
|
272 |
+
return $products;
|
273 |
+
}
|
274 |
+
private function getSpecialProducts($pageNo, $pageSize, $order, $direction) {
|
275 |
+
return $this->getAllProducts ( $pageNo, $pageSize, $order, $direction, true );
|
276 |
+
}
|
277 |
+
private function getAllProducts($pageNo, $pageSize, $order, $direction, $specials = false) {
|
278 |
+
$collection = Mage::getSingleton ( 'catalog/layer' )->setCurrentCategory ( Mage::app ()->getStore ()->getRootCategoryId () )->getProductCollection ()->setCurPage ( $pageNo )->setPageSize ( $pageSize )->setOrder ( $order, $direction );
|
279 |
+
$fromPart = $collection->getSelect ()->getPart ( Zend_Db_Select::FROM );
|
280 |
+
if (isset ( $fromPart ['cat_index'] )) {
|
281 |
+
$fromPart ['cat_index'] ['joinCondition'] = preg_replace ( '/category_id\s*=\s*\'\d+\'/', 'category_id > \'0\'', $fromPart ['cat_index'] ['joinCondition'] );
|
282 |
+
$collection->getSelect ()->setPart ( Zend_Db_Select::FROM, $fromPart );
|
283 |
+
}
|
284 |
+
|
285 |
+
if ($specials) {
|
286 |
+
$collection->getSelect ()->where ( '`price` > `final_price`' );
|
287 |
+
}
|
288 |
+
$size = $collection->getSize ();
|
289 |
+
$collection->getSelect ()->group ( 'e.entity_id' );
|
290 |
+
$collection->load ();
|
291 |
+
$productList = $collection->getItems ();
|
292 |
+
|
293 |
+
$items = array ();
|
294 |
+
foreach ( $productList as $key => $product ) {
|
295 |
+
if ($product->getId ()) {
|
296 |
+
$items [$key] = $this->_getItemBaseInfo ( $product );
|
297 |
+
}
|
298 |
+
}
|
299 |
+
$products = array ();
|
300 |
+
$products ['items'] = $items;
|
301 |
+
$products ['total_results'] = $size;
|
302 |
+
return $products;
|
303 |
+
}
|
304 |
+
private function getProductsByQuery($query, $pageNo, $pageSize, $order, $direction) {
|
305 |
+
$products = array ();
|
306 |
+
if ($query) {
|
307 |
+
$helper = Mage::helper ( 'catalogsearch' );
|
308 |
+
$this->getRequest ()->setParam ( $helper->getQueryParamName (), $query );
|
309 |
+
$query = $helper->getQuery ();
|
310 |
+
var_dump ( $query->getQueryText () );
|
311 |
+
$query->setStoreId ( Mage::app ()->getStore ()->getId () );
|
312 |
+
if ($query->getQueryText ()) {
|
313 |
+
if ($helper->isMinQueryLength ()) {
|
314 |
+
$query->setId ( 0 )->setIsActive ( 1 )->setIsProcessed ( 1 );
|
315 |
+
} else {
|
316 |
+
if ($query->getId ()) {
|
317 |
+
$query->setPopularity ( $query->getPopularity () + 1 );
|
318 |
+
} else {
|
319 |
+
$query->setPopularity ( 1 );
|
320 |
+
}
|
321 |
+
if (false && $query->getRedirect ()) {
|
322 |
+
$query->save ();
|
323 |
+
return array ();
|
324 |
+
} else {
|
325 |
+
$query->prepare ();
|
326 |
+
}
|
327 |
+
}
|
328 |
+
$helper->checkNotes ();
|
329 |
+
if (! Mage::helper ( 'catalogsearch' )->isMinQueryLength ()) {
|
330 |
+
$query->save ();
|
331 |
+
}
|
332 |
+
}
|
333 |
+
|
334 |
+
$layer = Mage::getSingleton ( 'catalogsearch/layer' );
|
335 |
+
$collection = $layer->getProductCollection ()->setCurPage ( $pageNo )->setPageSize ( $pageSize )->setOrder ( $order, $direction );
|
336 |
+
|
337 |
+
$collection->load ();
|
338 |
+
$size = $collection->getSize ();
|
339 |
+
$productList = $collection->getItems ();
|
340 |
+
$items = array ();
|
341 |
+
foreach ( $productList as $key => $product ) {
|
342 |
+
if ($product->getId ()) {
|
343 |
+
$items [$key] = $this->_getItemBaseInfo ( $product );
|
344 |
+
}
|
345 |
+
}
|
346 |
+
|
347 |
+
$products ['items'] = $items;
|
348 |
+
$products ['total_results'] = $size;
|
349 |
+
}
|
350 |
+
|
351 |
+
return $products;
|
352 |
+
}
|
353 |
+
private function getProductsByCategory($cid = false, $pageNo = 1, $pageSize = 20, $order = 'entity_id', $direction = 'asc') {
|
354 |
+
$layer = Mage::getSingleton ( 'catalog/layer' )->setCurrentCategory ( $cid );
|
355 |
+
$filter = $this->getRequest ()->getParam ( 'filter', array () );
|
356 |
+
if ($filter && is_array ( $filter )) {
|
357 |
+
foreach ( $filter as $key => $value ) {
|
358 |
+
$this->getRequest ()->setParam ( $key, $value );
|
359 |
+
}
|
360 |
+
Mage::getBlockSingleton ( 'catalog/layer_view' );
|
361 |
+
}
|
362 |
+
|
363 |
+
|
364 |
+
$collection = $layer->getProductCollection ()->setCurPage ( $pageNo )->setPageSize ( $pageSize )->setOrder ( $order, $direction );
|
365 |
+
|
366 |
+
$collection->load ();
|
367 |
+
$size = $collection->getSize ();
|
368 |
+
$productList = $collection->getItems ();
|
369 |
+
|
370 |
+
$items = array ();
|
371 |
+
foreach ( $productList as $key => $product ) {
|
372 |
+
if ($product->getId ()) {
|
373 |
+
$items [$key] = $this->_getItemBaseInfo ( $product );
|
374 |
+
}
|
375 |
+
}
|
376 |
+
$products = array ();
|
377 |
+
$products ['items'] = $items;
|
378 |
+
$products ['total_results'] = $size;
|
379 |
+
return $products;
|
380 |
+
}
|
381 |
+
public function setCollection($collection) {
|
382 |
+
$this->_collection = $collection;
|
383 |
+
$this->_collection->setCurPage ( $this->getCurrentPage () );
|
384 |
+
// we need to set pagination only if passed value integer and more that 0
|
385 |
+
$limit = ( int ) $this->getLimit ();
|
386 |
+
if ($limit) {
|
387 |
+
$this->_collection->setPageSize ( $limit );
|
388 |
+
}
|
389 |
+
if ($this->getCurrentOrder () == 'review') {
|
390 |
+
$this->_collection->sortByReview ( $this->getCurrentDirection () );
|
391 |
+
} else if ($this->getCurrentOrder ()) {
|
392 |
+
$this->_collection->setOrder ( $this->getCurrentOrder (), $this->getCurrentDirection () );
|
393 |
+
}
|
394 |
+
return $this;
|
395 |
+
}
|
396 |
+
}
|
397 |
+
|
398 |
+
?>
|
app/code/local/Mss/Connector/controllers/MenuController.php
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Connector_MenuController extends Mage_Core_Controller_Front_Action {
|
4 |
+
public function _construct(){
|
5 |
+
|
6 |
+
header('content-type: application/json; charset=utf-8');
|
7 |
+
header("access-control-allow-origin: *");
|
8 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
9 |
+
parent::_construct();
|
10 |
+
|
11 |
+
}
|
12 |
+
|
13 |
+
public function suggestAction() {
|
14 |
+
|
15 |
+
|
16 |
+
}
|
17 |
+
|
18 |
+
public function getproductinfoAction() {
|
19 |
+
|
20 |
+
$productid=$this->getRequest ()->getParam ( 'productid' );
|
21 |
+
|
22 |
+
//$productid = '1'; // test sentence
|
23 |
+
|
24 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $productid );
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
foreach ( $product->getAttributes () as $att ) {
|
29 |
+
|
30 |
+
$group_id = $att->getData ( 'attribute_group_id' );
|
31 |
+
|
32 |
+
$group = Mage::getModel ( 'eav/entity_attribute_group' )->load ( $group_id );
|
33 |
+
|
34 |
+
var_dump ( $group );
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
$attrSetName = 'my_custom_attribute';
|
39 |
+
|
40 |
+
$attributeSetId = Mage::getModel ( 'eav/entity_attribute_set' )->load ( $attrSetName, 'attribute_set_name' )->getAttributeSetId ();
|
41 |
+
|
42 |
+
// get a drop down lists options for a mulit-select attribute
|
43 |
+
|
44 |
+
$attribute = Mage::getModel ( 'eav/config' )->getAttribute ( 'catalog_product', 'attribute_id' );
|
45 |
+
|
46 |
+
foreach ( $attribute->getSource ()->getAllOptions ( true, true ) as $option ) {
|
47 |
+
|
48 |
+
$attributeArray [$option ['value']] = $option ['label'];
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
var_dump ( $$attributeArray );
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
$sets = Mage::getResourceModel ( 'eav/entity_attribute_set_collection' )->setEntityTypeFilter ( Mage::getModel ( 'catalog/product' )->getResource ()->getTypeId () )->load ()->toOptionHash ();
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
public function getcustomeroptionAction(){
|
61 |
+
|
62 |
+
$productid=$this->getRequest ()->getParam ( 'productid' );
|
63 |
+
|
64 |
+
$product = Mage::getModel("catalog/product")->load($productid);
|
65 |
+
|
66 |
+
$i = 1;
|
67 |
+
|
68 |
+
echo "<pre>";
|
69 |
+
|
70 |
+
foreach ($product->getOptions() as $o) {
|
71 |
+
|
72 |
+
echo "<strong>Custom Option:" . $i . "</strong><br/>";
|
73 |
+
|
74 |
+
echo "Custom Option TYPE: " . $o->getType() . "<br/>";
|
75 |
+
|
76 |
+
echo "Custom Option TITLE: " . $o->getTitle() . "<br/>";
|
77 |
+
|
78 |
+
echo "Custom Option Values: <br/>";
|
79 |
+
|
80 |
+
// Getting Values if it has option values, case of select,dropdown,radio,multiselect
|
81 |
+
|
82 |
+
$values = $o->getValues();
|
83 |
+
|
84 |
+
foreach ($values as $v) {
|
85 |
+
|
86 |
+
print_r($v->getData());
|
87 |
+
|
88 |
+
}
|
89 |
+
|
90 |
+
$i++;
|
91 |
+
|
92 |
+
echo "----------------------------------<br/>";
|
93 |
+
|
94 |
+
}
|
95 |
+
|
96 |
+
}
|
97 |
+
|
98 |
+
}
|
app/code/local/Mss/Connector/controllers/ProductsController.php
ADDED
@@ -0,0 +1,594 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_ProductsController extends Mage_Core_Controller_Front_Action {
|
3 |
+
|
4 |
+
public function _construct(){
|
5 |
+
|
6 |
+
header('content-type: application/json; charset=utf-8');
|
7 |
+
header("access-control-allow-origin: *");
|
8 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
9 |
+
parent::_construct();
|
10 |
+
|
11 |
+
}
|
12 |
+
|
13 |
+
public function getcustomoptionAction() {
|
14 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
15 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
16 |
+
$productid = $this->getRequest ()->getParam ( 'productid' );
|
17 |
+
$product = Mage::getModel ( "catalog/product" )->load ( $productid );
|
18 |
+
$selectid = 1;
|
19 |
+
$select = array ();
|
20 |
+
foreach ( $product->getOptions () as $o ) {
|
21 |
+
if (($o->getType () == "field") || ($o->getType () == "file")) {
|
22 |
+
$select [$selectid] = array (
|
23 |
+
'option_id' => $o->getId (),
|
24 |
+
'custom_option_type' => $o->getType (),
|
25 |
+
'custom_option_title' => $o->getTitle (),
|
26 |
+
'is_require' => $o->getIsRequire (),
|
27 |
+
'price' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $o->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
28 |
+
'price_type' => $o->getPriceType (),
|
29 |
+
'sku' => $o->getSku (),
|
30 |
+
'max_characters' => $o->getMaxCharacters ()
|
31 |
+
);
|
32 |
+
} else {
|
33 |
+
$max_characters = $o->getMaxCharacters ();
|
34 |
+
$optionid = 1;
|
35 |
+
$options = array ();
|
36 |
+
$values = $o->getValues ();
|
37 |
+
foreach ( $values as $v ) {
|
38 |
+
$options [$optionid] = $v->getData ();
|
39 |
+
if(null!==$v->getData('price') && null!==$v->getData('default_price')){
|
40 |
+
$options [$optionid]['price']=number_format ( Mage::helper ( 'directory' )->currencyConvert ( $v->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' );
|
41 |
+
$options [$optionid]['default_price']=number_format ( Mage::helper ( 'directory' )->currencyConvert ( $v->getDefaultPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' );
|
42 |
+
}
|
43 |
+
|
44 |
+
|
45 |
+
$optionid ++;
|
46 |
+
}
|
47 |
+
$select [$selectid] = array (
|
48 |
+
'option_id' => $o->getId (),
|
49 |
+
'custom_option_type' => $o->getType (),
|
50 |
+
'custom_option_title' => $o->getTitle (),
|
51 |
+
'is_require' => $o->getIsRequire (),
|
52 |
+
'price' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $o->getFormatedPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
53 |
+
'max_characters' => $max_characters,
|
54 |
+
'custom_option_value' => $options
|
55 |
+
);
|
56 |
+
}
|
57 |
+
|
58 |
+
$selectid ++;
|
59 |
+
|
60 |
+
}
|
61 |
+
echo json_encode ( $select );
|
62 |
+
}
|
63 |
+
|
64 |
+
/***Convert Currency***/
|
65 |
+
public function convert_currency($price,$from,$to) {
|
66 |
+
return 1;
|
67 |
+
$newPrice = Mage::helper('directory')->currencyConvert($price, $from, $to);
|
68 |
+
return $newPrice;
|
69 |
+
}
|
70 |
+
|
71 |
+
public function getproductdetailAction() {
|
72 |
+
$productdetail = array ();
|
73 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
74 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
75 |
+
$productid = $this->getRequest ()->getParam ( 'productid' );
|
76 |
+
|
77 |
+
$model = Mage::getModel ( "catalog/product" );
|
78 |
+
$product = $model->load ( $productid );
|
79 |
+
|
80 |
+
/*get product rating*/
|
81 |
+
|
82 |
+
$reviews = Mage::getModel('review/review')
|
83 |
+
->getResourceCollection()
|
84 |
+
->addStoreFilter(Mage::app()->getStore()->getId())
|
85 |
+
->addEntityFilter('product', $productid)
|
86 |
+
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
|
87 |
+
->setDateOrder()
|
88 |
+
->addRateVotes();
|
89 |
+
$avg = 0;
|
90 |
+
$ratings = array();
|
91 |
+
$rdetails=array();
|
92 |
+
|
93 |
+
if (count($reviews) > 0) {
|
94 |
+
foreach ($reviews->getItems() as $review) {
|
95 |
+
|
96 |
+
$review_rating=0;
|
97 |
+
foreach( $review->getRatingVotes() as $vote ) {
|
98 |
+
$review_rating = $vote->getPercent();
|
99 |
+
$ratings[] = $vote->getPercent();
|
100 |
+
}
|
101 |
+
if($review_rating)
|
102 |
+
$rating_by = ($review_rating/20);
|
103 |
+
|
104 |
+
$rdetails[]= array(
|
105 |
+
'title'=>$review->getTitle(),
|
106 |
+
'description'=>$review->getDetail(),
|
107 |
+
'reviewby'=>$review->getNickname(),
|
108 |
+
'rating_by'=>$rating_by,
|
109 |
+
'rating_date'=>date("d-m-Y", strtotime($review->getCreatedAt())),
|
110 |
+
);
|
111 |
+
}
|
112 |
+
$avg = array_sum($ratings)/count($ratings);
|
113 |
+
}
|
114 |
+
$rating=ceil($avg/20);
|
115 |
+
$reviews=$rdetails;
|
116 |
+
|
117 |
+
/*get product rating*/
|
118 |
+
|
119 |
+
if($product->getTypeId() == "configurable"):
|
120 |
+
$productdetail = array();
|
121 |
+
$config = $product->getTypeInstance(true);
|
122 |
+
|
123 |
+
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($product);
|
124 |
+
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions()->getData();
|
125 |
+
|
126 |
+
$storeUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
|
127 |
+
$description = nl2br ( $product->getDescription () );
|
128 |
+
$description = str_replace("{{media url=\"",$storeUrl,$description);
|
129 |
+
$description = str_replace("\"}}","",$description);
|
130 |
+
|
131 |
+
$c_ops=array();
|
132 |
+
|
133 |
+
if ($product->getData('has_options'))
|
134 |
+
{
|
135 |
+
$has_custom_options = true;
|
136 |
+
// Start custom options
|
137 |
+
$all_custom_option_array = array();
|
138 |
+
$attVal = $product->getOptions();
|
139 |
+
$optStr = "";
|
140 |
+
$inc=0;
|
141 |
+
$has_custom_option = 0;
|
142 |
+
foreach($attVal as $optionKey => $optionVal)
|
143 |
+
{
|
144 |
+
|
145 |
+
$has_custom_option = 1;
|
146 |
+
$all_custom_option_array[$inc]['custom_option_name']=$optionVal->getTitle();
|
147 |
+
$all_custom_option_array[$inc]['custom_option_id']=$optionVal->getId();
|
148 |
+
$all_custom_option_array[$inc]['custom_option_is_required']=$optionVal->getIsRequire();
|
149 |
+
$all_custom_option_array[$inc]['custom_option_type']=$optionVal->getType();
|
150 |
+
$all_custom_option_array[$inc]['sort_order'] = $optionVal->getSortOrder();
|
151 |
+
$all_custom_option_array[$inc]['all'] = $optionVal->getData();
|
152 |
+
if($all_custom_option_array[$inc]['all']['default_price_type'] == "percent") {
|
153 |
+
$all_custom_option_array[$inc]['all']['price'] = number_format((($product->getFinalPrice()*round($all_custom_option_array[$inc]['all']['price']*10,2)/10)/100),2);
|
154 |
+
|
155 |
+
}
|
156 |
+
else {
|
157 |
+
$all_custom_option_array[$inc]['all']['price'] = number_format($all_custom_option_array[$inc]['all']['price'],2);
|
158 |
+
}
|
159 |
+
|
160 |
+
$all_custom_option_array[$inc]['all']['price'] = str_replace(",","",$all_custom_option_array[$inc]['all']['price']);
|
161 |
+
$all_custom_option_array[$inc]['all']['price'] = strval(round($this->convert_currency($all_custom_option_array[$inc]['all']['price'],$basecurrencycode,$currentcurrencycode),2));
|
162 |
+
|
163 |
+
$all_custom_option_array[$inc]['custom_option_value_array'];
|
164 |
+
$inner_inc =0;
|
165 |
+
|
166 |
+
foreach($optionVal->getValues() as $valuesKey => $valuesVal)
|
167 |
+
{
|
168 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['id'] = $valuesVal->getId();
|
169 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['title'] = $valuesVal->getTitle();
|
170 |
+
|
171 |
+
$defaultcustomprice = str_replace(",","",($valuesVal->getPrice()));
|
172 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['price'] = strval(round($this->convert_currency($defaultcustomprice,$basecurrencycode,$currentcurrencycode),2));
|
173 |
+
|
174 |
+
//$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['price'] = number_format($valuesVal->getPrice(),2);
|
175 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['price_type'] = $valuesVal->getPriceType();
|
176 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['sku'] = $valuesVal->getSku();
|
177 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['sort_order'] = $valuesVal->getSortOrder();
|
178 |
+
if($valuesVal->getPriceType() == "percent") {
|
179 |
+
|
180 |
+
$defaultcustomprice = str_replace(",","", ($product->getFinalPrice()));
|
181 |
+
$customproductprice = strval(round($this->convert_currency($defaultcustomprice,$basecurrencycode,$currentcurrencycode),2));
|
182 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['price'] = str_replace(",","", round((floatval($customproductprice) * floatval(round($valuesVal->getPrice(),1))/100),2));
|
183 |
+
|
184 |
+
}
|
185 |
+
$inner_inc++;
|
186 |
+
}
|
187 |
+
$inc++;
|
188 |
+
}
|
189 |
+
|
190 |
+
}
|
191 |
+
else
|
192 |
+
{ $has_custom_options = false;}
|
193 |
+
|
194 |
+
|
195 |
+
$addtionatt=$this->_getAditional();
|
196 |
+
|
197 |
+
/*get confiogurable product attributes*/
|
198 |
+
Mage::register('product', $product);
|
199 |
+
Mage::helper('catalog/product')->setSkipSaleableCheck(true);
|
200 |
+
$config_attributes = new Mage_Catalog_Block_Product_View_Type_Configurable;
|
201 |
+
$condigurable_data = json_decode($config_attributes->getJsonConfig(),1);
|
202 |
+
$configurable = array();
|
203 |
+
foreach($condigurable_data['attributes'] as $key => $value)
|
204 |
+
$configurable[] = $value;
|
205 |
+
|
206 |
+
/*get confiogurable product attributes*/
|
207 |
+
|
208 |
+
$productdetail = array (
|
209 |
+
'entity_id' => $product->getId (),
|
210 |
+
'sku' => $product->getSku (),
|
211 |
+
'name' => $product->getName (),
|
212 |
+
'news_from_date' => $product->getNewsFromDate (),
|
213 |
+
'news_to_date' => $product->getNewsToDate (),
|
214 |
+
'special_from_date' => $product->getSpecialFromDate (),
|
215 |
+
'special_to_date' => $product->getSpecialToDate (),
|
216 |
+
'image_url' => Mage::helper('connector')-> Imageresize($product->getImage(),'product','500','500'),
|
217 |
+
'url_key' => $product->getProductUrl (),
|
218 |
+
'is_in_stock' => $product->isAvailable (),
|
219 |
+
'has_custom_options' => $has_custom_options,
|
220 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
221 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
222 |
+
'storeUrl' => $storeUrl,
|
223 |
+
'description' => $description,
|
224 |
+
'short_description'=>nl2br ($product->getShortDescription()),
|
225 |
+
'symbol' => Mage::app ()->getLocale ()->currency ( Mage::app ()->getStore ()->getCurrentCurrencyCode () )->getSymbol () ,
|
226 |
+
'weight'=>$product->getWeight(),
|
227 |
+
'review'=>$reviews,
|
228 |
+
'rating'=>$rating,
|
229 |
+
'wishlist' => Mage::helper('connector')->check_wishlist($product->getId ()),
|
230 |
+
'additional'=>$addtionatt,
|
231 |
+
//'configurable'=>$config->getConfigurableAttributesAsArray($product)
|
232 |
+
//'configurable'=>$configurable
|
233 |
+
);
|
234 |
+
|
235 |
+
if(count($all_custom_option_array))
|
236 |
+
$productdetail["custom_option"] = $all_custom_option_array;
|
237 |
+
|
238 |
+
if(count($configurable))
|
239 |
+
$productdetail["configurable"] = $configurable;
|
240 |
+
|
241 |
+
|
242 |
+
|
243 |
+
echo json_encode ( $productdetail );
|
244 |
+
else:
|
245 |
+
$storeUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
|
246 |
+
$description = nl2br ( $product->getDescription () );
|
247 |
+
$description = str_replace("{{media url=\"",$storeUrl,$description);
|
248 |
+
$description = str_replace("\"}}","",$description);
|
249 |
+
|
250 |
+
|
251 |
+
$c_ops=array();
|
252 |
+
|
253 |
+
if ($product->getData('has_options'))
|
254 |
+
{
|
255 |
+
$has_custom_options = true;
|
256 |
+
// Start custom options
|
257 |
+
$all_custom_option_array = array();
|
258 |
+
$attVal = $product->getOptions();
|
259 |
+
$optStr = "";
|
260 |
+
$inc=0;
|
261 |
+
$has_custom_option = 0;
|
262 |
+
foreach($attVal as $optionKey => $optionVal)
|
263 |
+
{
|
264 |
+
|
265 |
+
$has_custom_option = 1;
|
266 |
+
$all_custom_option_array[$inc]['custom_option_name']=$optionVal->getTitle();
|
267 |
+
$all_custom_option_array[$inc]['custom_option_id']=$optionVal->getId();
|
268 |
+
$all_custom_option_array[$inc]['custom_option_is_required']=$optionVal->getIsRequire();
|
269 |
+
$all_custom_option_array[$inc]['custom_option_type']=$optionVal->getType();
|
270 |
+
$all_custom_option_array[$inc]['sort_order'] = $optionVal->getSortOrder();
|
271 |
+
$all_custom_option_array[$inc]['all'] = $optionVal->getData();
|
272 |
+
if($all_custom_option_array[$inc]['all']['default_price_type'] == "percent") {
|
273 |
+
$all_custom_option_array[$inc]['all']['price'] = number_format((($product->getFinalPrice()*round($all_custom_option_array[$inc]['all']['price']*10,2)/10)/100),2);
|
274 |
+
|
275 |
+
}
|
276 |
+
else {
|
277 |
+
$all_custom_option_array[$inc]['all']['price'] = number_format($all_custom_option_array[$inc]['all']['price'],2);
|
278 |
+
}
|
279 |
+
|
280 |
+
$all_custom_option_array[$inc]['all']['price'] = str_replace(",","",$all_custom_option_array[$inc]['all']['price']);
|
281 |
+
$all_custom_option_array[$inc]['all']['price'] = strval(round($this->convert_currency($all_custom_option_array[$inc]['all']['price'],$basecurrencycode,$currentcurrencycode),2));
|
282 |
+
|
283 |
+
$all_custom_option_array[$inc]['custom_option_value_array'];
|
284 |
+
$inner_inc =0;
|
285 |
+
|
286 |
+
foreach($optionVal->getValues() as $valuesKey => $valuesVal)
|
287 |
+
{
|
288 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['id'] = $valuesVal->getId();
|
289 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['title'] = $valuesVal->getTitle();
|
290 |
+
|
291 |
+
$defaultcustomprice = str_replace(",","",($valuesVal->getPrice()));
|
292 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['price'] = strval(round($this->convert_currency($defaultcustomprice,$basecurrencycode,$currentcurrencycode),2));
|
293 |
+
|
294 |
+
//$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['price'] = number_format($valuesVal->getPrice(),2);
|
295 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['price_type'] = $valuesVal->getPriceType();
|
296 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['sku'] = $valuesVal->getSku();
|
297 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['sort_order'] = $valuesVal->getSortOrder();
|
298 |
+
if($valuesVal->getPriceType() == "percent") {
|
299 |
+
|
300 |
+
$defaultcustomprice = str_replace(",","", ($product->getFinalPrice()));
|
301 |
+
$customproductprice = strval(round($this->convert_currency($defaultcustomprice,$basecurrencycode,$currentcurrencycode),2));
|
302 |
+
$all_custom_option_array[$inc]['custom_option_value_array'][$inner_inc]['price'] = str_replace(",","", round((floatval($customproductprice) * floatval(round($valuesVal->getPrice(),1))/100),2));
|
303 |
+
|
304 |
+
}
|
305 |
+
$inner_inc++;
|
306 |
+
}
|
307 |
+
$inc++;
|
308 |
+
}
|
309 |
+
|
310 |
+
}
|
311 |
+
else
|
312 |
+
{ $has_custom_options = false;}
|
313 |
+
|
314 |
+
$addtionatt=$this->_getAditional();
|
315 |
+
$productdetail = array (
|
316 |
+
'entity_id' => $product->getId (),
|
317 |
+
'sku' => $product->getSku (),
|
318 |
+
'name' => $product->getName (),
|
319 |
+
'news_from_date' => $product->getNewsFromDate (),
|
320 |
+
'news_to_date' => $product->getNewsToDate (),
|
321 |
+
'special_from_date' => $product->getSpecialFromDate (),
|
322 |
+
'special_to_date' => $product->getSpecialToDate (),
|
323 |
+
'image_url' => Mage::helper('connector')-> Imageresize($product->getImage(),'product','500','500'),
|
324 |
+
'url_key' => $product->getProductUrl (),
|
325 |
+
'is_in_stock' => $product->isAvailable (),
|
326 |
+
'has_custom_options' => $has_custom_options,
|
327 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
328 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
329 |
+
'storeUrl' => $storeUrl,
|
330 |
+
'description' => $description,
|
331 |
+
'short_description'=>nl2br ($product->getShortDescription()),
|
332 |
+
'symbol' => Mage::app ()->getLocale ()->currency ( Mage::app ()->getStore ()->getCurrentCurrencyCode () )->getSymbol () ,
|
333 |
+
'weight'=>$product->getWeight(),
|
334 |
+
'qty'=>(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId())->getQty(),
|
335 |
+
'review'=>$reviews,
|
336 |
+
'rating'=>$rating,
|
337 |
+
'wishlist' => Mage::helper('connector')->check_wishlist($product->getId ()),
|
338 |
+
'additional'=>$addtionatt
|
339 |
+
);
|
340 |
+
if(count($all_custom_option_array))
|
341 |
+
$productdetail["custom_option"] = $all_custom_option_array;
|
342 |
+
|
343 |
+
|
344 |
+
|
345 |
+
echo json_encode ( $productdetail );
|
346 |
+
|
347 |
+
endif;
|
348 |
+
}
|
349 |
+
public function getPicListsAction() {
|
350 |
+
$productId = ( int ) $this->getRequest ()->getParam ( 'product' );
|
351 |
+
|
352 |
+
$_images = Mage::getModel ( 'catalog/product' )->load ( $productId );
|
353 |
+
$media = $_images->getMediaGalleryImages();
|
354 |
+
|
355 |
+
$images = array ();
|
356 |
+
foreach ($media as $_image ) {
|
357 |
+
|
358 |
+
$images [] = array (
|
359 |
+
'url' => Mage::helper('connector')-> Imageresize($_image->getFile (),'product','500','500'),
|
360 |
+
'thumbnail' => Mage::helper('connector')-> Imageresize($_image->getFile (),'thumbnail','100','100'),
|
361 |
+
'position' => $_image->getPosition ()
|
362 |
+
);
|
363 |
+
|
364 |
+
}
|
365 |
+
if(!sizeof($images) && $_images->getImage()):
|
366 |
+
|
367 |
+
$images [] = array (
|
368 |
+
'url' => Mage::helper('connector')-> Imageresize($_images->getImage(),'product','500','500'),
|
369 |
+
'thumbnail' => Mage::helper('connector')-> Imageresize($_images->getImage(),'thumbnail','100','100'),
|
370 |
+
'position' => 1
|
371 |
+
);
|
372 |
+
endif;
|
373 |
+
echo json_encode ( $images );
|
374 |
+
}
|
375 |
+
|
376 |
+
|
377 |
+
###get Rating and review summary
|
378 |
+
public function getRatingAction() {
|
379 |
+
$productId = ( int ) $this->getRequest ()->getParam ( 'product' );
|
380 |
+
$reviews = Mage::getModel('review/review')
|
381 |
+
->getResourceCollection()
|
382 |
+
->addStoreFilter(Mage::app()->getStore()->getId())
|
383 |
+
->addEntityFilter('product', $productId)
|
384 |
+
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
|
385 |
+
->setDateOrder()
|
386 |
+
->addRateVotes();
|
387 |
+
$avg = 0;
|
388 |
+
$ratings = array();
|
389 |
+
$rdetails=array();
|
390 |
+
|
391 |
+
if (count($reviews) > 0) {
|
392 |
+
foreach ($reviews->getItems() as $review) {
|
393 |
+
$rdetails[]= array(
|
394 |
+
'title'=>$review->getTitle(),
|
395 |
+
'description'=>$review->getDetail(),
|
396 |
+
'reviewby'=>$review->getNickname(),
|
397 |
+
);
|
398 |
+
foreach( $review->getRatingVotes() as $vote ) {
|
399 |
+
$ratings[] = $vote->getPercent();
|
400 |
+
}
|
401 |
+
}
|
402 |
+
$avg = array_sum($ratings)/count($ratings);
|
403 |
+
}
|
404 |
+
$response['rating']=ceil($avg/20);
|
405 |
+
$response['reviews']=$rdetails;
|
406 |
+
|
407 |
+
echo json_encode ($response);
|
408 |
+
}
|
409 |
+
|
410 |
+
|
411 |
+
public function _getAditional(array $excludeAttr = array()) {
|
412 |
+
$data = array ();
|
413 |
+
$productId = ( int ) $this->getRequest ()->getParam ( 'productid' );
|
414 |
+
$product = Mage::getModel ( "catalog/product" )->load ( $productId );
|
415 |
+
$attributes = $product->getAttributes ();
|
416 |
+
foreach ( $attributes as $attribute ) {
|
417 |
+
if ($attribute->getIsVisibleOnFront () && ! in_array ( $attribute->getAttributeCode (), $excludeAttr )) {
|
418 |
+
$value = $attribute->getFrontend ()->getValue ( $product );
|
419 |
+
|
420 |
+
if (! $product->hasData ( $attribute->getAttributeCode () )) {
|
421 |
+
$value = Mage::helper ( 'catalog' )->__ ( 'N/A' );
|
422 |
+
} elseif (( string ) $value == '') {
|
423 |
+
$value = Mage::helper ( 'catalog' )->__ ( 'No' );
|
424 |
+
} elseif ($attribute->getFrontendInput () == 'price' && is_string ( $value )) {
|
425 |
+
$value = Mage::app ()->getStore ()->convertPrice ( $value, true );
|
426 |
+
}
|
427 |
+
|
428 |
+
if (is_string ( $value ) && strlen ( $value )) {
|
429 |
+
$data [] = array (
|
430 |
+
'label' => $attribute->getStoreLabel (),
|
431 |
+
'value' => $value,
|
432 |
+
'code' => $attribute->getAttributeCode ()
|
433 |
+
);
|
434 |
+
}
|
435 |
+
}
|
436 |
+
}
|
437 |
+
|
438 |
+
return $data;
|
439 |
+
}
|
440 |
+
|
441 |
+
###Getting price range
|
442 |
+
|
443 |
+
|
444 |
+
public function getpricerange()
|
445 |
+
{
|
446 |
+
|
447 |
+
|
448 |
+
$maincategoryId=2;
|
449 |
+
|
450 |
+
$pricerange =array();
|
451 |
+
$layer = Mage::getModel('catalog/layer');
|
452 |
+
$category = Mage::getModel('catalog/category')->load($maincategoryId);
|
453 |
+
if ($category->getId()) {
|
454 |
+
$origCategory = $layer->getCurrentCategory();
|
455 |
+
$layer->setCurrentCategory($category);
|
456 |
+
}
|
457 |
+
$r=Mage::getModel('catalog/layer_filter_price')
|
458 |
+
->setLayer($layer);
|
459 |
+
|
460 |
+
$range = $r->getPriceRange();
|
461 |
+
$dbRanges = $r->getRangeItemCounts($range);
|
462 |
+
$data = array();
|
463 |
+
|
464 |
+
foreach ($dbRanges as $index=>$count) {
|
465 |
+
$data[] = array(
|
466 |
+
'label' => $this->_renderItemLabel($range, $index),
|
467 |
+
'value' => $this->_renderItemValue($range, $index),
|
468 |
+
'count' => $count,
|
469 |
+
);
|
470 |
+
}
|
471 |
+
return $data;
|
472 |
+
}
|
473 |
+
|
474 |
+
|
475 |
+
public function _renderItemLabel($range, $value)
|
476 |
+
{
|
477 |
+
$storename='default';
|
478 |
+
$store = Mage::app()->getStore();
|
479 |
+
$fromPrice = ($value-1)*$range;
|
480 |
+
$toPrice = $value*$range;
|
481 |
+
|
482 |
+
return array($fromPrice, $toPrice);
|
483 |
+
}
|
484 |
+
|
485 |
+
public function _renderItemValue($range, $value)
|
486 |
+
{
|
487 |
+
$storename='default';
|
488 |
+
$store = Mage::app()->getStore();
|
489 |
+
$fromPrice = ($value-1)*$range;
|
490 |
+
$toPrice = $value*$range;
|
491 |
+
|
492 |
+
return $fromPrice.','. $toPrice;
|
493 |
+
}
|
494 |
+
|
495 |
+
|
496 |
+
/*search API*/
|
497 |
+
public function searchAction()
|
498 |
+
{
|
499 |
+
$searchstring = $this->getRequest ()->getParam ( 'search' );
|
500 |
+
$page = ($this->getRequest ()->getParam ( 'page' )) ? ($this->getRequest ()->getParam ( 'page' )) : 1;
|
501 |
+
$limit = ($this->getRequest ()->getParam ( 'limit' )) ? ($this->getRequest ()->getParam ( 'limit' )) : 10;
|
502 |
+
$order = ($this->getRequest ()->getParam ( 'order' )) ? ($this->getRequest ()->getParam ( 'order' )) : 'entity_id';
|
503 |
+
|
504 |
+
if($searchstring):
|
505 |
+
|
506 |
+
$products = Mage::getModel('catalog/product')->getCollection();
|
507 |
+
$products->addAttributeToSelect(array('name','entity_id','status','visibility'),'inner')
|
508 |
+
->setPageSize ($limit)
|
509 |
+
->addAttributeToFilter('name', array('like' => '%'.$searchstring.'%'))
|
510 |
+
->addAttributeToFilter ( 'status', 1 )
|
511 |
+
->addAttributeToFilter ( 'visibility', array ('neq' => 1 ) )
|
512 |
+
->setPage ( $page, $limit );
|
513 |
+
|
514 |
+
$productlist = array ();
|
515 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
516 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
517 |
+
foreach ( $products as $product ) {
|
518 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $product ['entity_id'] );
|
519 |
+
$rating = Mage::getModel('rating/rating')->getEntitySummary($product->getId());
|
520 |
+
$rating_final = ($rating->getSum()/$rating->getCount())/20;
|
521 |
+
|
522 |
+
|
523 |
+
$productlist [] = array (
|
524 |
+
'entity_id' => $product->getId (),
|
525 |
+
'sku' => $product->getSku (),
|
526 |
+
'name' => $product->getName (),
|
527 |
+
'news_from_date' => $product->getNewsFromDate (),
|
528 |
+
'news_to_date' => $product->getNewsToDate (),
|
529 |
+
'special_from_date' => $product->getSpecialFromDate (),
|
530 |
+
'special_to_date' => $product->getSpecialToDate (),
|
531 |
+
/*'image_url' => Mage::getModel('catalog/product_media_config')->getMediaUrl( $product->getImage() ),*/
|
532 |
+
'image_url' => Mage::helper('connector')-> Imageresize($product->getImage(),'product','300','300'),
|
533 |
+
'url_key' => $product->getProductUrl (),
|
534 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
535 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
536 |
+
'symbol'=> Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(),
|
537 |
+
'qty'=>(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId())->getQty(),//$product->getStockItem()->getData('qty')
|
538 |
+
'rating' => $rating_final,
|
539 |
+
'wishlist' => Mage::helper('connector')->check_wishlist($product->getId ()),
|
540 |
+
'categoryid' => end($product->getCategoryIds())
|
541 |
+
);
|
542 |
+
}
|
543 |
+
|
544 |
+
if(sizeof($productlist))
|
545 |
+
echo json_encode($productlist);
|
546 |
+
else
|
547 |
+
echo json_encode(array('status'=>'error','message'=>'There are no products matching the selection'));
|
548 |
+
else:
|
549 |
+
echo json_encode(array('status'=>'error','message'=>'Search string is required'));
|
550 |
+
endif;
|
551 |
+
}
|
552 |
+
|
553 |
+
|
554 |
+
/*getFilter API*/
|
555 |
+
/*
|
556 |
+
URL : baseurl/restapi/products/getFilters
|
557 |
+
Name : getFilters
|
558 |
+
Method : GET
|
559 |
+
Response : JSON
|
560 |
+
*/
|
561 |
+
public function getFiltersAction(){
|
562 |
+
|
563 |
+
try{
|
564 |
+
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
|
565 |
+
$collection
|
566 |
+
->setItemObjectClass('catalog/resource_eav_attribute')
|
567 |
+
->setOrder('position', 'ASC');
|
568 |
+
$collection->addIsFilterableFilter();
|
569 |
+
$result = array();
|
570 |
+
foreach ($collection as $attribute) {
|
571 |
+
|
572 |
+
$name=$attribute->getData('attribute_code');
|
573 |
+
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
|
574 |
+
$attributeId = $attributeInfo->getAttributeId();
|
575 |
+
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
|
576 |
+
$attributeOptions = $attribute ->getSource()->getAllOptions(false);
|
577 |
+
|
578 |
+
if($attribute->getAttributeCode() == 'price')
|
579 |
+
$result[] = array('code' => $attribute->getAttributeCode(), 'label'=>$attribute->getFrontendLabel(),'value'=>$this->getpricerange());
|
580 |
+
else
|
581 |
+
$result[] = array('code' => $attribute->getAttributeCode(), 'label'=>$attribute->getFrontendLabel(),'value'=>$attributeOptions);
|
582 |
+
|
583 |
+
}
|
584 |
+
|
585 |
+
echo json_encode($result);
|
586 |
+
}
|
587 |
+
catch(exception $e){
|
588 |
+
|
589 |
+
echo json_encode(array('status'=>'error','message'=>'Server side error'.$e->getMessage()));
|
590 |
+
}
|
591 |
+
}
|
592 |
+
|
593 |
+
/*getFilter API*/
|
594 |
+
}
|
app/code/local/Mss/Connector/controllers/SearchController.php
ADDED
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
|
5 |
+
* Catalog Search Controller
|
6 |
+
|
7 |
+
*/
|
8 |
+
|
9 |
+
class Mss_Connector_SearchController extends Mage_Core_Controller_Front_Action {
|
10 |
+
public function _construct(){
|
11 |
+
|
12 |
+
header('content-type: application/json; charset=utf-8');
|
13 |
+
header("access-control-allow-origin: *");
|
14 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
15 |
+
parent::_construct();
|
16 |
+
|
17 |
+
}
|
18 |
+
|
19 |
+
protected function _getSession() {
|
20 |
+
|
21 |
+
return Mage::getSingleton ( 'catalog/session' );
|
22 |
+
|
23 |
+
}
|
24 |
+
|
25 |
+
public function indexAction() {
|
26 |
+
|
27 |
+
$query = Mage::helper ( 'catalogsearch' )->getQuery ();
|
28 |
+
|
29 |
+
/* @var $query Mage_CatalogSearch_Model_Query */
|
30 |
+
|
31 |
+
$query->setStoreId ( Mage::app ()->getStore ()->getId () );
|
32 |
+
|
33 |
+
|
34 |
+
if ($query->getQueryText () != '') {
|
35 |
+
|
36 |
+
if (Mage::helper ( 'catalogsearch' )->isMinQueryLength ()) {
|
37 |
+
|
38 |
+
$query->setId ( 0 )->setIsActive ( 1 )->setIsProcessed ( 1 );
|
39 |
+
|
40 |
+
} else {
|
41 |
+
|
42 |
+
if ($query->getId ()) {
|
43 |
+
|
44 |
+
$query->setPopularity ( $query->getPopularity () + 1 );
|
45 |
+
|
46 |
+
} else {
|
47 |
+
|
48 |
+
$query->setPopularity ( 1 );
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
if ($query->getRedirect ()) {
|
55 |
+
|
56 |
+
$query->save ();
|
57 |
+
|
58 |
+
$this->getResponse ()->setRedirect ( $query->getRedirect () );
|
59 |
+
|
60 |
+
return;
|
61 |
+
|
62 |
+
} else {
|
63 |
+
|
64 |
+
$query->prepare ();
|
65 |
+
|
66 |
+
}
|
67 |
+
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
Mage::helper ( 'catalogsearch' )->checkNotes ();
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
$collection = $query->getResultCollection ();
|
77 |
+
|
78 |
+
$i = 1;
|
79 |
+
|
80 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
81 |
+
|
82 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
83 |
+
|
84 |
+
foreach($collection as $product){
|
85 |
+
|
86 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $product->getId () );
|
87 |
+
|
88 |
+
$productlist [] = array (
|
89 |
+
|
90 |
+
'entity_id' => $product->getId (),
|
91 |
+
|
92 |
+
'sku' => $product->getSku (),
|
93 |
+
|
94 |
+
'name' => $product->getName (),
|
95 |
+
|
96 |
+
'news_from_date' => $product->getNewsFromDate (),
|
97 |
+
|
98 |
+
'news_to_date' => $product->getNewsToDate (),
|
99 |
+
|
100 |
+
'special_from_date' => $product->getSpecialFromDate (),
|
101 |
+
|
102 |
+
'special_to_date' => $product->getSpecialToDate (),
|
103 |
+
|
104 |
+
'image_url' => $product->getImageUrl (),
|
105 |
+
|
106 |
+
'url_key' => $product->getProductUrl (),
|
107 |
+
|
108 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
109 |
+
|
110 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
111 |
+
|
112 |
+
'symbol' => Mage::app ()->getLocale ()->currency ( Mage::app ()->getStore ()->getCurrentCurrencyCode () )->getSymbol ()
|
113 |
+
|
114 |
+
);
|
115 |
+
|
116 |
+
$i ++;
|
117 |
+
|
118 |
+
}
|
119 |
+
|
120 |
+
echo json_encode($productlist);
|
121 |
+
|
122 |
+
if (! Mage::helper ( 'catalogsearch' )->isMinQueryLength ()) {
|
123 |
+
|
124 |
+
$query->save ();
|
125 |
+
|
126 |
+
}
|
127 |
+
|
128 |
+
} else {
|
129 |
+
|
130 |
+
|
131 |
+
}
|
132 |
+
|
133 |
+
}
|
134 |
+
|
135 |
+
public function testAction() {
|
136 |
+
|
137 |
+
$query = Mage::helper ( 'catalogSearch' )->getQuery ();
|
138 |
+
|
139 |
+
$searcher = Mage::getSingleton ( 'catalogsearch/advanced' )->addFilters ( array (
|
140 |
+
|
141 |
+
'name' => $query->getQueryText (),
|
142 |
+
|
143 |
+
'description' => $query->getQueryText ()
|
144 |
+
|
145 |
+
) );
|
146 |
+
|
147 |
+
// $obj = new stdClass ();
|
148 |
+
|
149 |
+
// $obj->query = $query->getQueryText ();
|
150 |
+
|
151 |
+
// $obj->results = $searcher->getProductCollection (); // nothing returned
|
152 |
+
|
153 |
+
$result = $searcher->getProductCollection()->getData()/* ->getItems () */;
|
154 |
+
|
155 |
+
//$mod = Mage::getModel ( 'catalog/product' );
|
156 |
+
|
157 |
+
//echo $result;
|
158 |
+
|
159 |
+
foreach ( $result as $product ) {
|
160 |
+
|
161 |
+
//var_dump ( $product);
|
162 |
+
|
163 |
+
// $product = Mage::getModel ( 'catalog/product' )->load ( $product ['entity_id'] );
|
164 |
+
|
165 |
+
// $productlist [] = array (
|
166 |
+
|
167 |
+
// 'entity_id' => $product->getId (),
|
168 |
+
|
169 |
+
// 'sku' => $product->getSku (),
|
170 |
+
|
171 |
+
// 'name' => $product->getName (),
|
172 |
+
|
173 |
+
// 'news_from_date' => $product->getNewsFromDate (),
|
174 |
+
|
175 |
+
// 'news_to_date' => $product->getNewsToDate (),
|
176 |
+
|
177 |
+
// 'special_from_date' => $product->getSpecialFromDate (),
|
178 |
+
|
179 |
+
// 'special_to_date' => $product->getSpecialToDate (),
|
180 |
+
|
181 |
+
// 'image_url' => $product->getImageUrl (),
|
182 |
+
|
183 |
+
// 'url_key' => $product->getProductUrl (),
|
184 |
+
|
185 |
+
// 'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
186 |
+
|
187 |
+
// 'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
188 |
+
|
189 |
+
// 'symbol' => Mage::app ()->getLocale ()->currency ( Mage::app ()->getStore ()->getCurrentCurrencyCode () )->getSymbol ()
|
190 |
+
|
191 |
+
// );
|
192 |
+
|
193 |
+
}
|
194 |
+
|
195 |
+
var_dump($result);
|
196 |
+
|
197 |
+
}
|
198 |
+
|
199 |
+
}
|
200 |
+
|
app/code/local/Mss/Connector/controllers/StaticpagesController.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_StaticpagesController extends Mage_Core_Controller_Front_Action {
|
3 |
+
|
4 |
+
|
5 |
+
const MSS_ABOUT_US_PAGE = 'mss/mss_config_group/about_us_page';
|
6 |
+
const MSS_TERM_CONDITION_PAGE = 'mss/mss_config_group/term_condition_page';
|
7 |
+
const MSS_PRIVACY_POLICY_PAGE = 'mss/mss_config_group/privacy_policy_page';
|
8 |
+
const MSS_RETURN_PRIVACY_POLICY_PAGE = 'mss/mss_config_group/return_privacy_policy_page';
|
9 |
+
|
10 |
+
public function _construct(){
|
11 |
+
|
12 |
+
header('content-type: application/json; charset=utf-8');
|
13 |
+
header("access-control-allow-origin: *");
|
14 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
15 |
+
parent::_construct();
|
16 |
+
|
17 |
+
}
|
18 |
+
|
19 |
+
|
20 |
+
/*
|
21 |
+
URL : baseurl/restapi/staticpages/getPages/
|
22 |
+
Name : getCmspages
|
23 |
+
Method : GET
|
24 |
+
Response : JSON
|
25 |
+
Return Response : {
|
26 |
+
"status": "success",
|
27 |
+
"data": [
|
28 |
+
{
|
29 |
+
"page_title": "About Us",
|
30 |
+
"page_content": "content"
|
31 |
+
},
|
32 |
+
]
|
33 |
+
}
|
34 |
+
*/
|
35 |
+
public function getPagesAction()
|
36 |
+
{
|
37 |
+
try{
|
38 |
+
$pages = array(
|
39 |
+
|
40 |
+
self::MSS_ABOUT_US_PAGE,
|
41 |
+
self::MSS_TERM_CONDITION_PAGE,
|
42 |
+
self::MSS_PRIVACY_POLICY_PAGE,
|
43 |
+
self::MSS_RETURN_PRIVACY_POLICY_PAGE
|
44 |
+
);
|
45 |
+
$data = array();
|
46 |
+
|
47 |
+
foreach($pages as $page):
|
48 |
+
|
49 |
+
if($page):
|
50 |
+
$identifier = Mage::getStoreConfig($page);
|
51 |
+
$page_model = Mage::getModel('cms/page')->load($identifier, 'identifier');
|
52 |
+
|
53 |
+
$data [] = array('page_title'=>$page_model->getTitle(),
|
54 |
+
'page_content'=>$page_model->getContent());
|
55 |
+
endif;
|
56 |
+
endforeach;
|
57 |
+
|
58 |
+
if(sizeof($data)):
|
59 |
+
echo json_encode(array('status'=>'success','data'=>$data));
|
60 |
+
exit;
|
61 |
+
else:
|
62 |
+
echo json_encode(array('status'=>'error','message'=>'No page configured, please configure page first'));
|
63 |
+
exit;
|
64 |
+
endif;
|
65 |
+
}
|
66 |
+
catch(exception $e){
|
67 |
+
|
68 |
+
echo json_encode(array('status'=>'error','message'=>'Problem in loading data.'));
|
69 |
+
exit;
|
70 |
+
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
}
|
75 |
+
|
76 |
+
}
|
app/code/local/Mss/Connector/controllers/StoreController.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_StoreController extends Mage_Core_Controller_Front_Action {
|
3 |
+
public function _construct(){
|
4 |
+
|
5 |
+
header('content-type: application/json; charset=utf-8');
|
6 |
+
header("access-control-allow-origin: *");
|
7 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
8 |
+
parent::_construct();
|
9 |
+
|
10 |
+
}
|
11 |
+
public function websiteInfoAction() {
|
12 |
+
|
13 |
+
$basicinfo = array ();
|
14 |
+
foreach ( Mage::app ()->getWebsites () as $sk=> $website ) {
|
15 |
+
$basicinfo[$sk]['webside']['name']=$website->getName();
|
16 |
+
$basicinfo[$sk]['webside']['id']=$website->getId();
|
17 |
+
foreach ( $website->getGroups () as $key=> $group ) {
|
18 |
+
$basicinfo [$sk]['webside'][$key]['store']=$group->getName();
|
19 |
+
$basicinfo [$sk]['webside'][$key]['store_id']=$group->getGroupId ();
|
20 |
+
$basicinfo [$sk]['webside'][$key]['root_category_id']=$group->getRootCategoryId ();
|
21 |
+
$stores = $group->getStores ();
|
22 |
+
foreach ( $stores as $oo =>$_store ) {
|
23 |
+
$basicinfo [$sk]['webside'][$key]['view'][$oo] = array (
|
24 |
+
'name' => $_store->getName (),
|
25 |
+
'store_id' => $_store->getStoreId (),
|
26 |
+
'store_url' => $_store->getUrl (),
|
27 |
+
'store_code'=>$_store->getCode(),
|
28 |
+
'sort_order' => $_store->getSortOrder(),
|
29 |
+
'is_active' =>$_store->getIsActive()
|
30 |
+
);
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
}
|
35 |
+
echo json_encode($basicinfo);
|
36 |
+
|
37 |
+
}
|
38 |
+
public function storeInfoAction(){
|
39 |
+
$website_id = Mage::app()->getStore()->getWebsiteId();
|
40 |
+
$website_name = Mage::app ()->getWebsite($website_id) -> getName();
|
41 |
+
$group_id = Mage::app()->getStore()->getGroupId();
|
42 |
+
$group_name = Mage::app ()->getGroup($group_id) -> getName();
|
43 |
+
|
44 |
+
|
45 |
+
echo json_encode(array('store_id'=>Mage::app()->getStore()->getStoreId(),
|
46 |
+
'store_code'=>Mage::app()->getStore()->getCode(),
|
47 |
+
'website_id'=>$website_id,
|
48 |
+
'website_name'=>$website_name,
|
49 |
+
'group_id'=>$group_id,
|
50 |
+
'group_name'=>$group_name,
|
51 |
+
'name'=>Mage::app()->getStore()->getName(),
|
52 |
+
'sort_order' => Mage::app()->getStore()->getSortOrder(),
|
53 |
+
'is_active'=>Mage::app()->getStore()->getIsActive(),
|
54 |
+
'root_category_id' => Mage::app()->getStore()->getRootCategoryId(),
|
55 |
+
|
56 |
+
'url'=> Mage::helper('core/url')->getHomeUrl()
|
57 |
+
|
58 |
+
));
|
59 |
+
}
|
60 |
+
|
61 |
+
}
|
app/code/local/Mss/Connector/controllers/StoreinfoController.php
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_StoreinfoController extends Mage_Core_Controller_Front_Action {
|
3 |
+
|
4 |
+
const MSS_STORE_EMAIL = 'mss/mss_info_group/store_email';
|
5 |
+
const MSS_STORE_PHONENO = 'mss/mss_info_group/store_phoneno';
|
6 |
+
|
7 |
+
|
8 |
+
public function _construct(){
|
9 |
+
|
10 |
+
header('content-type: application/json; charset=utf-8');
|
11 |
+
header("access-control-allow-origin: *");
|
12 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
13 |
+
parent::_construct();
|
14 |
+
|
15 |
+
}
|
16 |
+
|
17 |
+
/*
|
18 |
+
|
19 |
+
|
20 |
+
Working url : baseURL/restapi/storeinfo/getstoreinfo/
|
21 |
+
URL : baseurl/restapi/storeinfo/getstoreinfo/
|
22 |
+
Name : getstoreinfo
|
23 |
+
Method : GET
|
24 |
+
Response : JSON
|
25 |
+
Return Response :
|
26 |
+
{
|
27 |
+
"status": "success",
|
28 |
+
"data": {
|
29 |
+
"store_phoneno": "dummy text",
|
30 |
+
"store_email": "dummy text",
|
31 |
+
"store_weburl": "dummy text"
|
32 |
+
}
|
33 |
+
}
|
34 |
+
*/
|
35 |
+
|
36 |
+
public function getstoreinfoAction(){
|
37 |
+
try{
|
38 |
+
$recipient_email = Mage::getStoreConfig('contacts/email/recipient_email');
|
39 |
+
$store_name = Mage::getBaseUrl();
|
40 |
+
$store_phone = Mage::getStoreConfig('general/store_information/phone');
|
41 |
+
|
42 |
+
|
43 |
+
$storeinfo = array();
|
44 |
+
if(Mage::getStoreConfig(self::MSS_STORE_PHONENO)):
|
45 |
+
$result['store_phoneno'] = Mage::getStoreConfig(self::MSS_STORE_PHONENO);
|
46 |
+
else:
|
47 |
+
$result['store_phoneno'] = $store_phone;
|
48 |
+
endif;
|
49 |
+
|
50 |
+
if(Mage::getStoreConfig(self::MSS_STORE_EMAIL)):
|
51 |
+
$result['store_email'] = Mage::getStoreConfig(self::MSS_STORE_EMAIL);
|
52 |
+
else:
|
53 |
+
$result['store_email'] = $recipient_email;
|
54 |
+
endif;
|
55 |
+
|
56 |
+
$result['store_weburl'] = $store_name;
|
57 |
+
|
58 |
+
$storeinfo = $result;
|
59 |
+
|
60 |
+
echo json_encode(array('status'=>'success','data'=>$storeinfo));
|
61 |
+
}
|
62 |
+
catch(exception $e){
|
63 |
+
|
64 |
+
echo json_encode(array('status'=>'error','message'=>'Problem in loading data.'));
|
65 |
+
exit;
|
66 |
+
}
|
67 |
+
|
68 |
+
}
|
69 |
+
}
|
app/code/local/Mss/Connector/controllers/TokenController.php
ADDED
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_TokenController extends Mage_Core_Controller_Front_Action {
|
3 |
+
|
4 |
+
const XML_SECURE_KEY_STATUS = 'magentomobileshop/key/status';
|
5 |
+
const XML_SECURE_KEY = 'magentomobileshop/secure/key';
|
6 |
+
const XML_SECURE_TOKEN = 'magentomobileshop/secure/token';
|
7 |
+
const XML_SECURE_TOKEN_EXP = 'secure/token/exp';
|
8 |
+
|
9 |
+
|
10 |
+
public function _construct(){
|
11 |
+
|
12 |
+
header('content-type: application/json; charset=utf-8');
|
13 |
+
header("access-control-allow-origin: *");
|
14 |
+
parent::_construct();
|
15 |
+
|
16 |
+
}
|
17 |
+
|
18 |
+
/*
|
19 |
+
|
20 |
+
URL : baseurl/restapi/token/setToken/
|
21 |
+
Name : setToken
|
22 |
+
Method : GET
|
23 |
+
Parameters : secure_key*,status*
|
24 |
+
Response : JSON
|
25 |
+
Return Response :
|
26 |
+
{
|
27 |
+
"status": "success",
|
28 |
+
"message": "return message"
|
29 |
+
}
|
30 |
+
*/
|
31 |
+
|
32 |
+
public function setTokenAction(){
|
33 |
+
|
34 |
+
try{
|
35 |
+
$params = $this->getRequest ()->getParams ();
|
36 |
+
//$params = apache_request_headers();
|
37 |
+
|
38 |
+
|
39 |
+
if(isset($params['secure_key']) && isset($params['status'])):
|
40 |
+
|
41 |
+
$configuration = array(
|
42 |
+
self::XML_SECURE_KEY_STATUS=>$params['status'],
|
43 |
+
self::XML_SECURE_KEY =>$params['secure_key']
|
44 |
+
);
|
45 |
+
|
46 |
+
foreach($configuration as $path => $value){
|
47 |
+
$this->saveConfig($path,$value);
|
48 |
+
}
|
49 |
+
|
50 |
+
$tags = array("CONFIG");
|
51 |
+
Mage::app ()->cleanCache($tags);
|
52 |
+
|
53 |
+
echo json_encode(array('status'=>'success','message'=>'Data updated.'));
|
54 |
+
else:
|
55 |
+
|
56 |
+
echo json_encode(array('status'=>'error','message'=>'Required parameters are missing.'));
|
57 |
+
|
58 |
+
endif;
|
59 |
+
|
60 |
+
}
|
61 |
+
catch(exception $e){
|
62 |
+
|
63 |
+
echo json_encode(array('status'=>'error','message'=>$e->getMessage()));
|
64 |
+
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
/*
|
69 |
+
|
70 |
+
URL : baseurl/restapi/token/getToken/
|
71 |
+
Name : getToken
|
72 |
+
Method : Header
|
73 |
+
Parameters : secure_key*,status*
|
74 |
+
Response : JSON
|
75 |
+
Return Response :
|
76 |
+
{
|
77 |
+
"status": "error"/"success",
|
78 |
+
"message"/"token": "return message"
|
79 |
+
}
|
80 |
+
*/
|
81 |
+
|
82 |
+
public function getTokenAction(){
|
83 |
+
|
84 |
+
try{
|
85 |
+
if(Mage::getStoreConfig(self::XML_SECURE_KEY_STATUS)):
|
86 |
+
|
87 |
+
|
88 |
+
$params = Mage::app()->getFrontController()->getRequest()->getHeader('token');
|
89 |
+
|
90 |
+
if(isset($params)):
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
if($params == Mage::getStoreConfig(self::XML_SECURE_KEY)):
|
95 |
+
|
96 |
+
if(Mage::getStoreConfig(self::XML_SECURE_TOKEN_EXP) &&
|
97 |
+
Mage::helper('connector')->compareExp() < 24):
|
98 |
+
|
99 |
+
echo json_encode(array('status'=>'success','token'=> Mage::getStoreConfig(self::XML_SECURE_TOKEN)));
|
100 |
+
exit;
|
101 |
+
endif;
|
102 |
+
|
103 |
+
$token = $this->radToken();
|
104 |
+
$current_session = Mage::getModel('core/date')->date('Y-m-d H:i:s');
|
105 |
+
|
106 |
+
$configuration = array(
|
107 |
+
self::XML_SECURE_TOKEN=>$token,
|
108 |
+
self::XML_SECURE_TOKEN_EXP =>$current_session
|
109 |
+
);
|
110 |
+
foreach($configuration as $path => $value){
|
111 |
+
$this->saveConfig($path,$value);
|
112 |
+
}
|
113 |
+
|
114 |
+
//clearing cache
|
115 |
+
$tags = array("CONFIG");
|
116 |
+
Mage::app ()->cleanCache($tags);
|
117 |
+
|
118 |
+
$this->getSession();
|
119 |
+
|
120 |
+
if(Mage::app()->getFrontController()->getRequest()->getHeader('username') && Mage::app()->getFrontController()->getRequest()->getHeader('password')):
|
121 |
+
echo json_encode(array('status'=>'success','token'=>$token,'user'=>$this->usersession(Mage::app()->getFrontController()->getRequest()->getHeader('username'),Mage::app()->getFrontController()->getRequest()->getHeader('username'))));
|
122 |
+
exit;
|
123 |
+
else:
|
124 |
+
echo json_encode(array('status'=>'success','token'=>$token));
|
125 |
+
exit;
|
126 |
+
endif;
|
127 |
+
else:
|
128 |
+
echo json_encode(array('status'=>'error','message'=> 'Invalid secure key.'));
|
129 |
+
endif;
|
130 |
+
else:
|
131 |
+
|
132 |
+
echo json_encode(array('status'=>'error','message'=>'Secure key is required.'));
|
133 |
+
|
134 |
+
endif;
|
135 |
+
|
136 |
+
else:
|
137 |
+
echo json_encode(array('status'=>'error','message'=>'App is disabled by magentomobileshop admin.'));
|
138 |
+
endif;
|
139 |
+
|
140 |
+
}
|
141 |
+
catch(exception $e){
|
142 |
+
|
143 |
+
echo json_encode(array('status'=>'error','message'=>$e->getMessage()));
|
144 |
+
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
|
149 |
+
|
150 |
+
private function radToken()
|
151 |
+
{
|
152 |
+
return substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(1,25))),1,25);
|
153 |
+
}
|
154 |
+
|
155 |
+
private function saveConfig($path,$value){
|
156 |
+
|
157 |
+
Mage::getModel('core/config')->saveConfig($path,$value);
|
158 |
+
return true;
|
159 |
+
}
|
160 |
+
|
161 |
+
public function getSession(){
|
162 |
+
|
163 |
+
$adminSessionLifetime = (int)Mage::getStoreConfig('admin/security/session_cookie_lifetime');
|
164 |
+
if($adminSessionLifetime < 86400)
|
165 |
+
$this->saveConfig('admin/security/session_cookie_lifetime','86400');
|
166 |
+
|
167 |
+
return true;
|
168 |
+
}
|
169 |
+
|
170 |
+
private function usersession($username,$password){
|
171 |
+
$session = Mage::getSingleton ( 'customer/session' );
|
172 |
+
|
173 |
+
if (Mage::getSingleton ( 'customer/session' )->isLoggedIn ())
|
174 |
+
return true;
|
175 |
+
|
176 |
+
try
|
177 |
+
{
|
178 |
+
if (!$session->login ( $username, $password ))
|
179 |
+
return false;
|
180 |
+
else
|
181 |
+
return true;
|
182 |
+
}
|
183 |
+
catch ( Mage_Core_Exception $e )
|
184 |
+
{
|
185 |
+
return false;
|
186 |
+
}
|
187 |
+
|
188 |
+
}
|
189 |
+
}
|
app/code/local/Mss/Connector/controllers/WishlistController.php
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Connector_WishlistController extends Mage_Core_Controller_Front_Action {
|
3 |
+
|
4 |
+
|
5 |
+
public function _construct(){
|
6 |
+
|
7 |
+
header('content-type: application/json; charset=utf-8');
|
8 |
+
header("access-control-allow-origin: *");
|
9 |
+
Mage::helper('connector')->loadParent(Mage::app()->getFrontController()->getRequest()->getHeader('token'));
|
10 |
+
parent::_construct();
|
11 |
+
|
12 |
+
}
|
13 |
+
|
14 |
+
public function addToWishlistAction() {
|
15 |
+
$response = array ();
|
16 |
+
if (! Mage::getStoreConfigFlag ( 'wishlist/general/active' )) {
|
17 |
+
$response ['status'] = 'error';
|
18 |
+
$response ['message'] = $this->__ ( 'Wishlist Has Been Disabled By Admin' );
|
19 |
+
}
|
20 |
+
if (! Mage::getSingleton ( 'customer/session' )->isLoggedIn ()) {
|
21 |
+
$response ['status'] = 'error';
|
22 |
+
$response ['message'] = $this->__ ( 'Please Login First' );
|
23 |
+
}
|
24 |
+
|
25 |
+
if (empty ( $response )) {
|
26 |
+
|
27 |
+
|
28 |
+
$session = Mage::getSingleton ( 'customer/session' );
|
29 |
+
$customer=Mage::getModel("customer/customer")->load($session->getCustomer()->getId());
|
30 |
+
$wishlist=Mage::getModel("wishlist/wishlist")->loadByCustomer($customer,true);
|
31 |
+
|
32 |
+
if (! $wishlist) {
|
33 |
+
$response ['status'] = 'error';
|
34 |
+
$response ['message'] = $this->__ ( 'Unable to Create Wishlist' );
|
35 |
+
} else {
|
36 |
+
|
37 |
+
$productId = ( int ) $this->getRequest ()->getParam ( 'product' );
|
38 |
+
if (! $productId) {
|
39 |
+
$response ['status'] = 'error';
|
40 |
+
$response ['message'] = $this->__ ( 'Product Not Found' );
|
41 |
+
} else {
|
42 |
+
|
43 |
+
$product = Mage::getModel ( 'catalog/product' )->load ( $productId );
|
44 |
+
if (! $product->getId () || ! $product->isVisibleInCatalog ()) {
|
45 |
+
$response ['status'] = 'error';
|
46 |
+
$response ['message'] = $this->__ ( 'Cannot specify product.' );
|
47 |
+
} else {
|
48 |
+
|
49 |
+
try {
|
50 |
+
//$requestParams = $this->getRequest ()->getParams ();
|
51 |
+
$requestParams = array();
|
52 |
+
$buyRequest = new Varien_Object ( $requestParams );
|
53 |
+
|
54 |
+
$result = $wishlist->addNewItem ( $product, $buyRequest );
|
55 |
+
if (is_string ( $result )) {
|
56 |
+
Mage::throwException ( $result );
|
57 |
+
}
|
58 |
+
$wishlist->save ();
|
59 |
+
|
60 |
+
Mage::dispatchEvent ( 'wishlist_add_product', array (
|
61 |
+
'wishlist' => $wishlist,
|
62 |
+
'product' => $product,
|
63 |
+
'item' => $result
|
64 |
+
) );
|
65 |
+
|
66 |
+
Mage::helper ( 'wishlist' )->calculate ();
|
67 |
+
|
68 |
+
$message = $this->__ ( '%1$s has been added to your wishlist.', $product->getName (), $referer );
|
69 |
+
$response ['status'] = 'success';
|
70 |
+
$response ['message'] = $message;
|
71 |
+
|
72 |
+
Mage::unregister ( 'wishlist' );
|
73 |
+
} catch ( Mage_Core_Exception $e ) {
|
74 |
+
$response ['status'] = 'error';
|
75 |
+
$response ['message'] = $this->__ ( 'An error occurred while adding item to wishlist: %s', $e->getMessage () );
|
76 |
+
} catch ( Exception $e ) {
|
77 |
+
|
78 |
+
$response ['status'] = 'error';
|
79 |
+
$response ['message'] = $this->__ ( 'An error occurred while adding item to wishlist.' );
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
echo json_encode ( $response );
|
87 |
+
return;
|
88 |
+
}
|
89 |
+
|
90 |
+
public function getWishlistAction() {
|
91 |
+
echo json_encode ( $this->_getWishlist () );
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
protected function _getWishlist() {
|
96 |
+
$wishlist = Mage::registry ( 'wishlist' );
|
97 |
+
$baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode ();
|
98 |
+
$currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
|
99 |
+
if ($wishlist) {
|
100 |
+
return $wishlist;
|
101 |
+
}
|
102 |
+
|
103 |
+
try {
|
104 |
+
$wishlist = Mage::getModel ( 'wishlist/wishlist' )->loadByCustomer ( Mage::getSingleton ( 'customer/session' )->getCustomer (), true );
|
105 |
+
Mage::register ( 'wishlist', $wishlist );
|
106 |
+
} catch ( Mage_Core_Exception $e ) {
|
107 |
+
Mage::getSingleton ( 'wishlist/session' )->addError ( $e->getMessage () );
|
108 |
+
} catch ( Exception $e ) {
|
109 |
+
Mage::getSingleton ( 'wishlist/session' )->addException ( $e, Mage::helper ( 'wishlist' )->__ ( 'Cannot create wishlist.' ) );
|
110 |
+
return false;
|
111 |
+
}
|
112 |
+
$items = array ();
|
113 |
+
foreach ( $wishlist->getItemCollection () as $item ) {
|
114 |
+
$item = Mage::getModel ( 'catalog/product' )->setStoreId ( $item->getStoreId () )->load ( $item->getProductId () );
|
115 |
+
if ($item->getId ()) {
|
116 |
+
$items [] = array (
|
117 |
+
'name' => $item->getName (),
|
118 |
+
'entity_id' => $item->getId (),
|
119 |
+
'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $item->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
120 |
+
'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $item->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ),
|
121 |
+
'sku' => $item->getSku () ,
|
122 |
+
'symbol' => Mage::app ()->getLocale ()->currency ( Mage::app ()->getStore ()->getCurrentCurrencyCode () )->getSymbol (),
|
123 |
+
'image_url' => Mage::helper('connector')-> Imageresize($item->getImage(),'product','100','100')
|
124 |
+
|
125 |
+
);
|
126 |
+
}
|
127 |
+
}
|
128 |
+
return array (
|
129 |
+
'wishlist' => $wishlist->getData (),
|
130 |
+
'items' => $items
|
131 |
+
);
|
132 |
+
}
|
133 |
+
|
134 |
+
|
135 |
+
/*
|
136 |
+
|
137 |
+
URL : baseurl/restapi/Wishlist/getWishlist
|
138 |
+
Name : removeWishlist
|
139 |
+
Method : GET
|
140 |
+
Parameters : product_id*
|
141 |
+
Response : JSON
|
142 |
+
Return Response :
|
143 |
+
{
|
144 |
+
"status": "success"/"error",
|
145 |
+
"message": "return message"
|
146 |
+
}
|
147 |
+
*/
|
148 |
+
public function removeWishlistAction(){
|
149 |
+
|
150 |
+
$params = $this->getRequest()->getParam('product_id');
|
151 |
+
|
152 |
+
if(!$params){
|
153 |
+
echo json_encode(array('status'=>'error','message'=>'Product Id is missing.'));
|
154 |
+
exit;
|
155 |
+
}
|
156 |
+
$session = Mage::getSingleton ( 'customer/session' );
|
157 |
+
|
158 |
+
if($session->getCustomer()->getId()):
|
159 |
+
$itemCollection = Mage::getModel('wishlist/item')->getCollection()
|
160 |
+
->addCustomerIdFilter($session->getCustomer()->getId());
|
161 |
+
|
162 |
+
foreach($itemCollection as $item):
|
163 |
+
if($item->getProduct()->getId() == $params):
|
164 |
+
try{
|
165 |
+
$item->delete();
|
166 |
+
$response['status'] = 'success';
|
167 |
+
$response['message'] = 'item removed from wishlist.';
|
168 |
+
}
|
169 |
+
catch(exception $e){
|
170 |
+
$response['status'] = 'error';
|
171 |
+
$response['message'] = $e->getMessage();
|
172 |
+
}
|
173 |
+
endif;
|
174 |
+
endforeach;
|
175 |
+
else:
|
176 |
+
$response['status'] = 'error';
|
177 |
+
$response['message'] = $this->__ ( 'Unable to Create Wishlist' );
|
178 |
+
endif;
|
179 |
+
|
180 |
+
echo json_encode($response);
|
181 |
+
}
|
182 |
+
}
|
app/code/local/Mss/Connector/controllers/_new_ProductsController.php
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?phpclass Mss_Connector_ProductsController extends Mage_Core_Controller_Front_Action { public function getcustomoptionAction() { $baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode (); $currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode (); $productid = $this->getRequest ()->getParam ( 'productid' ); $product = Mage::getModel ( "catalog/product" )->load ( $productid ); $selectid = 1; $select = array (); foreach ( $product->getOptions () as $o ) { if (($o->getType () == "field") || ($o->getType () =="file")) { $select [$selectid] = array ( 'option_id' => $o->getId (), 'custom_option_type' => $o->getType (), 'custom_option_title' => $o->getTitle (), 'is_require' => $o->getIsRequire (), 'price' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $o->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ), 'price_type'=>$o->getPriceType(), 'sku'=>$o->getSku(), 'max_characters' => $o->getMaxCharacters (), ); } else { $max_characters = $o->getMaxCharacters (); $optionid = 1; $options = array (); $values = $o->getValues (); foreach ( $values as $v ) { $options [$optionid] = $v->getData (); $optionid ++; } $select [$selectid] = array ( 'option_id' => $o->getId (), 'custom_option_type' => $o->getType (), 'custom_option_title' => $o->getTitle (), 'is_require' => $o->getIsRequire (), 'price' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $o->getFormatedPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ), 'max_characters' => $max_characters, 'custom_option_value' => $options ); } $selectid ++; } echo json_encode ( $select ); } public function getproductdetailAction() { $productdetail = array (); $baseCurrency = Mage::app ()->getStore ()->getBaseCurrency ()->getCode (); $currentCurrency = Mage::app ()->getStore ()->getCurrentCurrencyCode (); $productid = $this->getRequest ()->getParam ( 'productid' ); $product = Mage::getModel ( "catalog/product" )->load ( $productid ); $productdetail = array ( 'entity_id' => $product->getId (), 'sku' => $product->getSku (), 'name' => $product->getName (), 'news_from_date' => $product->getNewsFromDate (), 'news_to_date' => $product->getNewsToDate (), 'special_from_date' => $product->getSpecialFromDate (), 'special_to_date' => $product->getSpecialToDate (), 'image_url' => $product->getImageUrl (), 'url_key' => $product->getProductUrl (), 'regular_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ), 'final_price_with_tax' => number_format ( Mage::helper ( 'directory' )->currencyConvert ( $product->getSpecialPrice (), $baseCurrency, $currentCurrency ), 2, '.', '' ), 'description' => nl2br ( $product->getDescription () ), 'symbol' => Mage::app ()->getLocale ()->currency ( Mage::app ()->getStore ()->getCurrentCurrencyCode () )->getSymbol () ); echo json_encode ( $productdetail ); } public function getPicListsAction(){ $productId = ( int ) $this->getRequest ()->getParam ( 'product' ); $_product=Mage::getModel ( "catalog/product" )->load ( $productid ); $_images = Mage::getModel('catalog/product')->load($productId)->getMediaGalleryImages(); $images=array(); foreach ($_images as $_image){ $images[]=array('url'=>$_image->getUrl(), 'position'=>$_image->getPosition() ); } echo json_encode($images); } public function gettest(){ $attributes = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection(); // Localize attribute label (if you need it) $attributes->addStoreLabel(Mage::app()->getStore()->getId()); // Loop over all attributes foreach ($attributes as $attr) { /* @var $attr Mage_Eav_Model_Entity_Attribute */ // get the store label value $label = $attr->getStoreLabel() ? $attr->getStoreLabel() : $attr->getFrontendLabel(); echo "Attribute: {$label}\n<br>"; // If it is an attribute with predefined values if ($attr->usesSource()) { // Get all option values ans labels $options = $attr->getSource()->getAllOptions(); // Output all option labels and values foreach ($options as $option) { echo " {$option['label']} =========> (Value {$option['value']})\n<br>"; } } else { // Just for clarification of the debug code echo " No select or multiselect attribute\n<br>"; } } }}
|
app/code/local/Mss/Connector/etc/adminhtml.xml
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<acl>
|
4 |
+
<resources>
|
5 |
+
<admin>
|
6 |
+
<children>
|
7 |
+
<system>
|
8 |
+
<children>
|
9 |
+
<config>
|
10 |
+
<children>
|
11 |
+
<mss translate="title" module="connector">
|
12 |
+
<title>Magentomobileshop Connector</title>
|
13 |
+
<sort_order>1000</sort_order>
|
14 |
+
</mss>
|
15 |
+
<magentomobileshop_payment translate="title" module="connector">
|
16 |
+
<title>Magentomobileshop Payment</title>
|
17 |
+
<sort_order>1001</sort_order>
|
18 |
+
</magentomobileshop_payment>
|
19 |
+
</children>
|
20 |
+
</config>
|
21 |
+
</children>
|
22 |
+
</system>
|
23 |
+
</children>
|
24 |
+
</admin>
|
25 |
+
</resources>
|
26 |
+
</acl>
|
27 |
+
<menu>
|
28 |
+
<connector module="connector" translate="title">
|
29 |
+
<title> MagentoMobileShop</title>
|
30 |
+
<sort_order>100</sort_order>
|
31 |
+
<children>
|
32 |
+
|
33 |
+
<configuration module="connector" translate="title">
|
34 |
+
<title>Configuration</title>
|
35 |
+
<sort_order>1</sort_order>
|
36 |
+
<action>adminhtml/system_config/edit/section/mss/</action>
|
37 |
+
</configuration>
|
38 |
+
|
39 |
+
|
40 |
+
</children>
|
41 |
+
</connector>
|
42 |
+
</menu>
|
43 |
+
</config>
|
app/code/local/Mss/Connector/etc/config.xml
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Connector>
|
5 |
+
<version>1.4.5</version>
|
6 |
+
</Mss_Connector>
|
7 |
+
</modules>
|
8 |
+
<frontend>
|
9 |
+
|
10 |
+
<routers>
|
11 |
+
<connector>
|
12 |
+
<use>standard</use>
|
13 |
+
<args>
|
14 |
+
<module>Mss_Connector</module>
|
15 |
+
<frontName>restapi</frontName>
|
16 |
+
</args>
|
17 |
+
</connector>
|
18 |
+
</routers>
|
19 |
+
</frontend>
|
20 |
+
<global>
|
21 |
+
<models>
|
22 |
+
<connector>
|
23 |
+
<class>Mss_Connector_Model</class>
|
24 |
+
<resourceModel>connector_mysql4</resourceModel>
|
25 |
+
</connector>
|
26 |
+
<connector_mysql4>
|
27 |
+
<class>Mss_Connector_Model_Mysql4</class>
|
28 |
+
<entities>
|
29 |
+
<connector>
|
30 |
+
<table>magentomobilecc</table>
|
31 |
+
</connector>
|
32 |
+
</entities>
|
33 |
+
</connector_mysql4>
|
34 |
+
</models>
|
35 |
+
<resources>
|
36 |
+
<connector_setup>
|
37 |
+
<setup>
|
38 |
+
<module>Mss_Connector</module>
|
39 |
+
|
40 |
+
</setup>
|
41 |
+
<connection>
|
42 |
+
<use>core_setup</use>
|
43 |
+
</connection>
|
44 |
+
</connector_setup>
|
45 |
+
<connector_write>
|
46 |
+
<connection>
|
47 |
+
<use>core_write</use>
|
48 |
+
</connection>
|
49 |
+
</connector_write>
|
50 |
+
<connector_read>
|
51 |
+
<connection>
|
52 |
+
<use>core_read</use>
|
53 |
+
</connection>
|
54 |
+
</connector_read>
|
55 |
+
</resources>
|
56 |
+
|
57 |
+
<helpers>
|
58 |
+
<connector>
|
59 |
+
<class>Mss_Connector_Helper</class>
|
60 |
+
</connector>
|
61 |
+
</helpers>
|
62 |
+
<blocks>
|
63 |
+
<connector>
|
64 |
+
<class>Mss_Connector_Block</class>
|
65 |
+
</connector>
|
66 |
+
</blocks>
|
67 |
+
|
68 |
+
</global>
|
69 |
+
|
70 |
+
<adminhtml>
|
71 |
+
|
72 |
+
<events>
|
73 |
+
<controller_action_predispatch>
|
74 |
+
<observers>
|
75 |
+
<activation_notification>
|
76 |
+
<type>singleton</type>
|
77 |
+
<class>Mss_Connector_Model_Observer</class>
|
78 |
+
<method>notificationMessage</method>
|
79 |
+
</activation_notification>
|
80 |
+
</observers>
|
81 |
+
</controller_action_predispatch>
|
82 |
+
</events>
|
83 |
+
|
84 |
+
|
85 |
+
<layout>
|
86 |
+
<updates>
|
87 |
+
<mss_connector>
|
88 |
+
<file>connector.xml</file>
|
89 |
+
</mss_connector>
|
90 |
+
</updates>
|
91 |
+
</layout>
|
92 |
+
</adminhtml>
|
93 |
+
</config>
|
app/code/local/Mss/Connector/etc/system.xml
ADDED
@@ -0,0 +1,427 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<tabs>
|
4 |
+
<connector translate="label" module="connector">
|
5 |
+
<label><![CDATA[<div style="position: fix;"><img id="magentomobileshop_block" src="" alt="" border="0" /></div> <script>$('magentomobileshop_block').src = "http://magentomobileshop.com/wp-content/magentomobiledata/logo.png";</script>]]></label>
|
6 |
+
<sort_order>1</sort_order>
|
7 |
+
|
8 |
+
</connector>
|
9 |
+
</tabs>
|
10 |
+
<sections>
|
11 |
+
<mss translate="label" module="connector">
|
12 |
+
<label>General</label>
|
13 |
+
<tab>connector</tab>
|
14 |
+
<sort_order>1</sort_order>
|
15 |
+
<show_in_default>1</show_in_default>
|
16 |
+
<show_in_website>1</show_in_website>
|
17 |
+
<show_in_store>1</show_in_store>
|
18 |
+
<groups>
|
19 |
+
<my_aboutus translate="label" module="connector">
|
20 |
+
<label>About Magento Mobile</label>
|
21 |
+
<frontend_type>text</frontend_type>
|
22 |
+
<sort_order>0</sort_order>
|
23 |
+
<show_in_default>1</show_in_default>
|
24 |
+
<show_in_website>1</show_in_website>
|
25 |
+
<show_in_store>1</show_in_store>
|
26 |
+
<fields>
|
27 |
+
<about>
|
28 |
+
|
29 |
+
<frontend_model>connector/system_config_about</frontend_model>
|
30 |
+
<sort_order>0</sort_order>
|
31 |
+
<show_in_default>1</show_in_default>
|
32 |
+
<show_in_website>1</show_in_website>
|
33 |
+
<show_in_store>1</show_in_store>
|
34 |
+
</about>
|
35 |
+
</fields>
|
36 |
+
</my_aboutus>
|
37 |
+
<mss_info_group translate="label" module="connector">
|
38 |
+
<label>Contact Information</label>
|
39 |
+
<frontend_type>text</frontend_type>
|
40 |
+
<sort_order>3</sort_order>
|
41 |
+
<show_in_default>1</show_in_default>
|
42 |
+
<show_in_website>1</show_in_website>
|
43 |
+
<show_in_store>1</show_in_store>
|
44 |
+
<fields>
|
45 |
+
<store_email translate="label">
|
46 |
+
<label>Contact email address </label>
|
47 |
+
<frontend_type>text</frontend_type>
|
48 |
+
<sort_order>2</sort_order>
|
49 |
+
<show_in_default>1</show_in_default>
|
50 |
+
<show_in_website>1</show_in_website>
|
51 |
+
<show_in_store>1</show_in_store>
|
52 |
+
|
53 |
+
</store_email>
|
54 |
+
<store_phoneno translate="label">
|
55 |
+
<label>Phone number: </label>
|
56 |
+
<frontend_type>text</frontend_type>
|
57 |
+
<sort_order>1</sort_order>
|
58 |
+
<show_in_default>1</show_in_default>
|
59 |
+
<show_in_website>1</show_in_website>
|
60 |
+
<show_in_store>1</show_in_store>
|
61 |
+
|
62 |
+
</store_phoneno>
|
63 |
+
<!-- <store_weburl translate="label">
|
64 |
+
<label>Store Website URL: </label>
|
65 |
+
<frontend_type>text</frontend_type>
|
66 |
+
<sort_order>3</sort_order>
|
67 |
+
<show_in_default>1</show_in_default>
|
68 |
+
<show_in_website>1</show_in_website>
|
69 |
+
<show_in_store>1</show_in_store>
|
70 |
+
|
71 |
+
</store_weburl> -->
|
72 |
+
</fields>
|
73 |
+
</mss_info_group>
|
74 |
+
<mss_config_group translate="label" module="connector">
|
75 |
+
<label>CMS Pages</label>
|
76 |
+
<frontend_type>text</frontend_type>
|
77 |
+
<sort_order>4</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 |
+
<fields>
|
82 |
+
|
83 |
+
<about_us_page translate="label">
|
84 |
+
<label>About Us</label>
|
85 |
+
<frontend_type>select</frontend_type>
|
86 |
+
<sort_order>2</sort_order>
|
87 |
+
<show_in_default>1</show_in_default>
|
88 |
+
<show_in_website>1</show_in_website>
|
89 |
+
<show_in_store>1</show_in_store>
|
90 |
+
<source_model>adminhtml/system_config_source_cms_page</source_model>
|
91 |
+
</about_us_page>
|
92 |
+
<term_condition_page translate="label">
|
93 |
+
<label>Term And Condition </label>
|
94 |
+
<frontend_type>select</frontend_type>
|
95 |
+
<sort_order>3</sort_order>
|
96 |
+
<show_in_default>1</show_in_default>
|
97 |
+
<show_in_website>1</show_in_website>
|
98 |
+
<show_in_store>1</show_in_store>
|
99 |
+
<source_model>adminhtml/system_config_source_cms_page</source_model>
|
100 |
+
</term_condition_page>
|
101 |
+
<privacy_policy_page translate="label">
|
102 |
+
<label>Privacy Policy </label>
|
103 |
+
<frontend_type>select</frontend_type>
|
104 |
+
<sort_order>4</sort_order>
|
105 |
+
<show_in_default>1</show_in_default>
|
106 |
+
<show_in_website>1</show_in_website>
|
107 |
+
<show_in_store>1</show_in_store>
|
108 |
+
<source_model>adminhtml/system_config_source_cms_page</source_model>
|
109 |
+
</privacy_policy_page>
|
110 |
+
<return_privacy_policy_page translate="label">
|
111 |
+
<label>Return Policy </label>
|
112 |
+
<frontend_type>select</frontend_type>
|
113 |
+
<sort_order>5</sort_order>
|
114 |
+
<show_in_default>1</show_in_default>
|
115 |
+
<show_in_website>1</show_in_website>
|
116 |
+
<show_in_store>1</show_in_store>
|
117 |
+
<source_model>adminhtml/system_config_source_cms_page</source_model>
|
118 |
+
</return_privacy_policy_page>
|
119 |
+
</fields>
|
120 |
+
</mss_config_group>
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
</groups>
|
125 |
+
|
126 |
+
</mss>
|
127 |
+
<magentomobileshop_payment translate="label" module="connector">
|
128 |
+
<label>Payment Methods</label>
|
129 |
+
<tab>connector</tab>
|
130 |
+
<sort_order>1</sort_order>
|
131 |
+
<show_in_default>1</show_in_default>
|
132 |
+
<show_in_website>1</show_in_website>
|
133 |
+
<show_in_store>1</show_in_store>
|
134 |
+
<groups>
|
135 |
+
<about_us translate="label" module="connector">
|
136 |
+
<label>About Us</label>
|
137 |
+
<frontend_type>text</frontend_type>
|
138 |
+
<sort_order>1</sort_order>
|
139 |
+
<show_in_default>1</show_in_default>
|
140 |
+
<show_in_website>1</show_in_website>
|
141 |
+
<show_in_store>1</show_in_store>
|
142 |
+
<fields>
|
143 |
+
<about>
|
144 |
+
|
145 |
+
<frontend_model>connector/system_config_about</frontend_model>
|
146 |
+
<sort_order>0</sort_order>
|
147 |
+
<show_in_default>1</show_in_default>
|
148 |
+
<show_in_website>1</show_in_website>
|
149 |
+
<show_in_store>1</show_in_store>
|
150 |
+
</about>
|
151 |
+
</fields>
|
152 |
+
</about_us>
|
153 |
+
</groups>
|
154 |
+
<!-- <groups>
|
155 |
+
<ccsave translate="label" module="connector">
|
156 |
+
<label>Saved CC</label>
|
157 |
+
<frontend_type>text</frontend_type>
|
158 |
+
<sort_order>2</sort_order>
|
159 |
+
<show_in_default>1</show_in_default>
|
160 |
+
<show_in_website>1</show_in_website>
|
161 |
+
<show_in_store>1</show_in_store>
|
162 |
+
<fields>
|
163 |
+
<ccsave_status>
|
164 |
+
|
165 |
+
<label>Enable/Disable</label>
|
166 |
+
<frontend_type>select</frontend_type>
|
167 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
168 |
+
<sort_order>1</sort_order>
|
169 |
+
<show_in_default>1</show_in_default>
|
170 |
+
<show_in_website>1</show_in_website>
|
171 |
+
<show_in_store>1</show_in_store>
|
172 |
+
<comment>(Enable/Disable payment method for App Only.)</comment>
|
173 |
+
</ccsave_status>
|
174 |
+
</fields>
|
175 |
+
</ccsave>
|
176 |
+
</groups> -->
|
177 |
+
<groups>
|
178 |
+
<banktransfer translate="label" module="connector">
|
179 |
+
<label>Bank Transfer Payment</label>
|
180 |
+
<frontend_type>text</frontend_type>
|
181 |
+
<sort_order>3</sort_order>
|
182 |
+
<show_in_default>1</show_in_default>
|
183 |
+
<show_in_website>1</show_in_website>
|
184 |
+
<show_in_store>1</show_in_store>
|
185 |
+
<fields>
|
186 |
+
<banktransfer_message>
|
187 |
+
|
188 |
+
<frontend_model>connector/system_config_banktransfer</frontend_model>
|
189 |
+
<sort_order>0</sort_order>
|
190 |
+
<show_in_default>1</show_in_default>
|
191 |
+
<show_in_website>1</show_in_website>
|
192 |
+
<show_in_store>1</show_in_store>
|
193 |
+
</banktransfer_message>
|
194 |
+
<banktransfer_status>
|
195 |
+
|
196 |
+
<label>Enable/Disable</label>
|
197 |
+
<frontend_type>select</frontend_type>
|
198 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
199 |
+
<sort_order>1</sort_order>
|
200 |
+
<show_in_default>1</show_in_default>
|
201 |
+
<show_in_website>1</show_in_website>
|
202 |
+
<show_in_store>1</show_in_store>
|
203 |
+
<comment>(Enable/Disable payment method for App Only.)</comment>
|
204 |
+
</banktransfer_status>
|
205 |
+
</fields>
|
206 |
+
</banktransfer>
|
207 |
+
</groups>
|
208 |
+
<groups>
|
209 |
+
<checkmo translate="label" module="connector">
|
210 |
+
<label>Check / Money Order</label>
|
211 |
+
<frontend_type>text</frontend_type>
|
212 |
+
<sort_order>4</sort_order>
|
213 |
+
<show_in_default>1</show_in_default>
|
214 |
+
<show_in_website>1</show_in_website>
|
215 |
+
<show_in_store>1</show_in_store>
|
216 |
+
<fields>
|
217 |
+
<checkmo_message>
|
218 |
+
|
219 |
+
<frontend_model>connector/system_config_checkmo</frontend_model>
|
220 |
+
<sort_order>0</sort_order>
|
221 |
+
<show_in_default>1</show_in_default>
|
222 |
+
<show_in_website>1</show_in_website>
|
223 |
+
<show_in_store>1</show_in_store>
|
224 |
+
</checkmo_message>
|
225 |
+
<checkmo_status>
|
226 |
+
|
227 |
+
<label>Enable/Disable</label>
|
228 |
+
<frontend_type>select</frontend_type>
|
229 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
230 |
+
<sort_order>1</sort_order>
|
231 |
+
<show_in_default>1</show_in_default>
|
232 |
+
<show_in_website>1</show_in_website>
|
233 |
+
<show_in_store>1</show_in_store>
|
234 |
+
<comment>(Enable/Disable payment method for App Only.)</comment>
|
235 |
+
</checkmo_status>
|
236 |
+
</fields>
|
237 |
+
</checkmo>
|
238 |
+
</groups>
|
239 |
+
<groups>
|
240 |
+
<authorizenet translate="label" module="connector">
|
241 |
+
<label>Authorize.net</label>
|
242 |
+
<frontend_type>text</frontend_type>
|
243 |
+
<sort_order>5</sort_order>
|
244 |
+
<show_in_default>1</show_in_default>
|
245 |
+
<show_in_website>1</show_in_website>
|
246 |
+
<show_in_store>1</show_in_store>
|
247 |
+
<fields>
|
248 |
+
<authorizenet_message>
|
249 |
+
|
250 |
+
<frontend_model>connector/system_config_authorizenet</frontend_model>
|
251 |
+
<sort_order>0</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 |
+
</authorizenet_message>
|
256 |
+
<authorizenet_status>
|
257 |
+
|
258 |
+
<label>Enable/Disable</label>
|
259 |
+
<frontend_type>select</frontend_type>
|
260 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
261 |
+
<sort_order>1</sort_order>
|
262 |
+
<show_in_default>1</show_in_default>
|
263 |
+
<show_in_website>1</show_in_website>
|
264 |
+
<show_in_store>1</show_in_store>
|
265 |
+
<comment>(Enable/Disable payment method for App Only.)</comment>
|
266 |
+
</authorizenet_status>
|
267 |
+
</fields>
|
268 |
+
</authorizenet>
|
269 |
+
</groups>
|
270 |
+
<groups>
|
271 |
+
<cashondelivery translate="label" module="connector">
|
272 |
+
<label>Cash On Delivery Payment</label>
|
273 |
+
<frontend_type>text</frontend_type>
|
274 |
+
<sort_order>6</sort_order>
|
275 |
+
<show_in_default>1</show_in_default>
|
276 |
+
<show_in_website>1</show_in_website>
|
277 |
+
<show_in_store>1</show_in_store>
|
278 |
+
<fields>
|
279 |
+
<cashondelivery_message>
|
280 |
+
|
281 |
+
<frontend_model>connector/system_config_cod</frontend_model>
|
282 |
+
<sort_order>0</sort_order>
|
283 |
+
<show_in_default>1</show_in_default>
|
284 |
+
<show_in_website>1</show_in_website>
|
285 |
+
<show_in_store>1</show_in_store>
|
286 |
+
</cashondelivery_message>
|
287 |
+
<cashondelivery_status>
|
288 |
+
|
289 |
+
<label>Enable/Disable</label>
|
290 |
+
<frontend_type>select</frontend_type>
|
291 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
292 |
+
<sort_order>1</sort_order>
|
293 |
+
<show_in_default>1</show_in_default>
|
294 |
+
<show_in_website>1</show_in_website>
|
295 |
+
<show_in_store>1</show_in_store>
|
296 |
+
<comment>(Enable/Disable payment method for App Only.)</comment>
|
297 |
+
</cashondelivery_status>
|
298 |
+
</fields>
|
299 |
+
</cashondelivery>
|
300 |
+
</groups>
|
301 |
+
<groups>
|
302 |
+
<payucheckout_shared translate="label" module="connector">
|
303 |
+
<label>Payu</label>
|
304 |
+
<frontend_type>text</frontend_type>
|
305 |
+
<sort_order>7</sort_order>
|
306 |
+
<show_in_default>1</show_in_default>
|
307 |
+
<show_in_website>1</show_in_website>
|
308 |
+
<show_in_store>1</show_in_store>
|
309 |
+
<fields>
|
310 |
+
<payu_message>
|
311 |
+
|
312 |
+
<frontend_model>connector/system_config_payu</frontend_model>
|
313 |
+
<sort_order>0</sort_order>
|
314 |
+
<show_in_default>1</show_in_default>
|
315 |
+
<show_in_website>1</show_in_website>
|
316 |
+
<show_in_store>1</show_in_store>
|
317 |
+
</payu_message>
|
318 |
+
<payucheckout_shared_status>
|
319 |
+
|
320 |
+
<label>Enable/Disable</label>
|
321 |
+
<frontend_type>select</frontend_type>
|
322 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
323 |
+
<sort_order>1</sort_order>
|
324 |
+
<show_in_default>1</show_in_default>
|
325 |
+
<show_in_website>1</show_in_website>
|
326 |
+
<show_in_store>1</show_in_store>
|
327 |
+
<comment>(Enable/Disable payment method for App Only.)</comment>
|
328 |
+
</payucheckout_shared_status>
|
329 |
+
<!-- <payu_title>
|
330 |
+
|
331 |
+
<label>Title</label>
|
332 |
+
<frontend_type>text</frontend_type>
|
333 |
+
<sort_order>2</sort_order>
|
334 |
+
<show_in_default>1</show_in_default>
|
335 |
+
<show_in_website>1</show_in_website>
|
336 |
+
<show_in_store>1</show_in_store>
|
337 |
+
<comment> This is what the customers will see as the name of the payment option</comment>
|
338 |
+
</payu_title> -->
|
339 |
+
<payu_key>
|
340 |
+
|
341 |
+
<label>Merchant Id</label>
|
342 |
+
<frontend_type>text</frontend_type>
|
343 |
+
<sort_order>3</sort_order>
|
344 |
+
<show_in_default>1</show_in_default>
|
345 |
+
<show_in_website>1</show_in_website>
|
346 |
+
<show_in_store>1</show_in_store>
|
347 |
+
<comment>Enter the merchant key provided by PayUMoney here.</comment>
|
348 |
+
</payu_key>
|
349 |
+
<payu_salt>
|
350 |
+
<label>Salt</label>
|
351 |
+
<frontend_type>text</frontend_type>
|
352 |
+
<sort_order>4</sort_order>
|
353 |
+
<show_in_default>1</show_in_default>
|
354 |
+
<show_in_website>1</show_in_website>
|
355 |
+
<show_in_store>1</show_in_store>
|
356 |
+
<comment>Enter the salt provided by PayUMoney here.</comment>
|
357 |
+
</payu_salt>
|
358 |
+
<payu_mode>
|
359 |
+
<label>Transaction Mode Production</label>
|
360 |
+
<frontend_type>select</frontend_type>
|
361 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
362 |
+
<sort_order>5</sort_order>
|
363 |
+
<show_in_default>1</show_in_default>
|
364 |
+
<show_in_website>1</show_in_website>
|
365 |
+
<show_in_store>1</show_in_store>
|
366 |
+
|
367 |
+
</payu_mode>
|
368 |
+
</fields>
|
369 |
+
</payucheckout_shared>
|
370 |
+
</groups>
|
371 |
+
<groups>
|
372 |
+
<mpaypal translate="label" module="connector">
|
373 |
+
<label>PayPal (app)</label>
|
374 |
+
<frontend_type>text</frontend_type>
|
375 |
+
<sort_order>8</sort_order>
|
376 |
+
<show_in_default>1</show_in_default>
|
377 |
+
<show_in_website>1</show_in_website>
|
378 |
+
<show_in_store>1</show_in_store>
|
379 |
+
<fields>
|
380 |
+
<mpaypal_message>
|
381 |
+
|
382 |
+
<frontend_model>connector/system_config_mpaypal</frontend_model>
|
383 |
+
<sort_order>0</sort_order>
|
384 |
+
<show_in_default>1</show_in_default>
|
385 |
+
<show_in_website>1</show_in_website>
|
386 |
+
<show_in_store>1</show_in_store>
|
387 |
+
</mpaypal_message>
|
388 |
+
<mpaypal_status>
|
389 |
+
|
390 |
+
<label>Enable/Disable</label>
|
391 |
+
<frontend_type>select</frontend_type>
|
392 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
393 |
+
<sort_order>1</sort_order>
|
394 |
+
<show_in_default>1</show_in_default>
|
395 |
+
<show_in_website>1</show_in_website>
|
396 |
+
<show_in_store>1</show_in_store>
|
397 |
+
<comment>(Enable/Disable payment method for App Only.)</comment>
|
398 |
+
</mpaypal_status>
|
399 |
+
|
400 |
+
<mpaypal_email>
|
401 |
+
|
402 |
+
<label>Merchant Email</label>
|
403 |
+
<frontend_type>text</frontend_type>
|
404 |
+
<sort_order>3</sort_order>
|
405 |
+
<show_in_default>1</show_in_default>
|
406 |
+
<show_in_website>1</show_in_website>
|
407 |
+
<show_in_store>1</show_in_store>
|
408 |
+
<comment>Merchant Email Id.</comment>
|
409 |
+
</mpaypal_email>
|
410 |
+
|
411 |
+
<mpaypal_mode>
|
412 |
+
<label>Transaction Mode Production</label>
|
413 |
+
<frontend_type>select</frontend_type>
|
414 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
415 |
+
<sort_order>5</sort_order>
|
416 |
+
<show_in_default>1</show_in_default>
|
417 |
+
<show_in_website>1</show_in_website>
|
418 |
+
<show_in_store>1</show_in_store>
|
419 |
+
|
420 |
+
</mpaypal_mode>
|
421 |
+
</fields>
|
422 |
+
</mpaypal>
|
423 |
+
</groups>
|
424 |
+
</magentomobileshop_payment>
|
425 |
+
</sections>
|
426 |
+
|
427 |
+
</config>
|
app/code/local/Mss/Connector/sql/connector_setup/mysql4-install-0.1.0.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$installer = $this;
|
3 |
+
|
4 |
+
$installer->startSetup();
|
5 |
+
|
6 |
+
/*Create table script*/
|
7 |
+
|
8 |
+
$installer->run("DROP TABLE IF EXISTS {$this->getTable('magentomobilecc')};
|
9 |
+
CREATE TABLE {$this->getTable('magentomobilecc')} (
|
10 |
+
`id` int(11) unsigned NOT NULL auto_increment,
|
11 |
+
`user_id` int(11),
|
12 |
+
`cc_number` varchar(50),
|
13 |
+
`cc_last4` varchar(50),
|
14 |
+
`cc_type` varchar(10),
|
15 |
+
`cc_exp_month` varchar(10),
|
16 |
+
`cc_exp_year` varchar(10),
|
17 |
+
PRIMARY KEY (`id`)
|
18 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
19 |
+
");
|
20 |
+
$installer->endSetup();
|
21 |
+
|
app/code/local/Mss/Connector/sql/connector_setup/mysql4-upgrade-0.1.0-0.1.1.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = Mage::getResourceModel('sales/setup', 'sales_setup');
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
|
7 |
+
|
8 |
+
$attribute = array(
|
9 |
+
'type' => 'text',
|
10 |
+
'backend_type' => 'text',
|
11 |
+
'frontend_input' => 'text',
|
12 |
+
'is_user_defined' => true,
|
13 |
+
'label' => 'mms_order_type',
|
14 |
+
'visible' => true,
|
15 |
+
'required' => false,
|
16 |
+
'user_defined' => false,
|
17 |
+
'searchable' => false,
|
18 |
+
'filterable' => false,
|
19 |
+
'comparable' => false,
|
20 |
+
'default' => ''
|
21 |
+
);
|
22 |
+
$installer->addAttribute("order", "mms_order_type",$attribute);
|
23 |
+
$installer->addAttribute("quote", "mms_order_type",$attribute);
|
24 |
+
|
25 |
+
$installer->endSetup();
|
26 |
+
|
app/code/local/Mss/Mpaypal/Helper/Data.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Mpaypal_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
}
|
5 |
+
|
app/code/local/Mss/Mpaypal/Model/Mpaypal.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Mpaypal_Model_Mpaypal extends Mage_Payment_Model_Method_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
protected $_code = 'mpaypal';
|
7 |
+
|
8 |
+
}
|
app/code/local/Mss/Mpaypal/Model/Observer.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Mpaypal_Model_Observer {
|
4 |
+
|
5 |
+
public function paymentMethodIsActive(Varien_Event_Observer $observer) {
|
6 |
+
$event = $observer->getEvent();
|
7 |
+
$method = $event->getMethodInstance();
|
8 |
+
$result = $event->getResult();
|
9 |
+
|
10 |
+
$quote=Mage::getSingleton ( 'checkout/session' )->getQuote();
|
11 |
+
if($method->getCode() == 'mpaypal'):
|
12 |
+
if($quote->getMms_order_type() == 'app')
|
13 |
+
$result->isAvailable = true;
|
14 |
+
else
|
15 |
+
$result->isAvailable = false;
|
16 |
+
|
17 |
+
endif;
|
18 |
+
return true;
|
19 |
+
}
|
20 |
+
|
21 |
+
}
|
app/code/local/Mss/Mpaypal/controllers/IndexController.php
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Mpaypal_IndexController extends Mage_Core_Controller_Front_Action{
|
3 |
+
|
4 |
+
public function _construct(){
|
5 |
+
|
6 |
+
|
7 |
+
parent::_construct();
|
8 |
+
|
9 |
+
}
|
10 |
+
/*
|
11 |
+
public function IndexAction() {
|
12 |
+
|
13 |
+
$this->loadLayout();
|
14 |
+
$this->renderLayout();
|
15 |
+
|
16 |
+
}
|
17 |
+
*/
|
18 |
+
public function PaypalAction() {
|
19 |
+
|
20 |
+
echo $block = $this->getLayout()->createBlock('core/template')->setTemplate('mpaypal/index.phtml')->toHtml();
|
21 |
+
|
22 |
+
}
|
23 |
+
|
24 |
+
public function successAction(){
|
25 |
+
|
26 |
+
$result = $this->getRequest()->getParams();
|
27 |
+
|
28 |
+
if($result):
|
29 |
+
$orderIncrementId = $result['item_name'];
|
30 |
+
|
31 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
|
32 |
+
$order->addStatusToHistory(Mage_Sales_Model_Order::STATE_COMPLETE);
|
33 |
+
|
34 |
+
|
35 |
+
if($order->getId()):
|
36 |
+
$payment = $order->getPayment();
|
37 |
+
$payment->setTransactionId($result['txn_id'])
|
38 |
+
->setCurrencyCode()
|
39 |
+
->setPreparedMessage("Payment Done")
|
40 |
+
->setShouldCloseParentTransaction(true)
|
41 |
+
->setIsTransactionClosed(1)
|
42 |
+
->registerCaptureNotification();
|
43 |
+
|
44 |
+
endif;
|
45 |
+
|
46 |
+
$order->save();
|
47 |
+
|
48 |
+
|
49 |
+
echo "Thank You !";
|
50 |
+
else:
|
51 |
+
echo "No data found";
|
52 |
+
endif;
|
53 |
+
|
54 |
+
}
|
55 |
+
public function failureAction(){
|
56 |
+
|
57 |
+
$result = $this->getRequest()->getParams();
|
58 |
+
|
59 |
+
if($result):
|
60 |
+
$orderIncrementId = $result['productinfo'];
|
61 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
|
62 |
+
$order->addStatusToHistory(Mage_Sales_Model_Order::STATE_CANCELED);
|
63 |
+
if($order->getId()):
|
64 |
+
$payment = $order->getPayment();
|
65 |
+
$payment->setTransactionId($result['txnid'])
|
66 |
+
->setCurrencyCode()
|
67 |
+
->setPreparedMessage("Payment Error")
|
68 |
+
->setShouldCloseParentTransaction(true)
|
69 |
+
->setIsTransactionClosed(1)
|
70 |
+
->registerCaptureNotification();
|
71 |
+
|
72 |
+
endif;
|
73 |
+
|
74 |
+
$order->save();
|
75 |
+
|
76 |
+
echo "Found Some Problem! Try Again";
|
77 |
+
else:
|
78 |
+
echo "Found Some Problem! Try Again";
|
79 |
+
endif;
|
80 |
+
|
81 |
+
|
82 |
+
}
|
83 |
+
|
84 |
+
/* public function validate_ipn($paypal_url, $postdata)
|
85 |
+
{
|
86 |
+
$ipn_response;
|
87 |
+
$log_ipn_results;
|
88 |
+
// parse the paypal URL
|
89 |
+
$url_parsed=parse_url($paypal_url);
|
90 |
+
$post_string = '';
|
91 |
+
|
92 |
+
foreach ($postdata as $field=>$value):
|
93 |
+
$ipn_data["$field"] = $value;
|
94 |
+
$post_string .= $field.'='.urlencode(stripslashes($value)).'&';
|
95 |
+
endforeach;
|
96 |
+
|
97 |
+
$post_string.="cmd=_notify-validate"; // append ipn command
|
98 |
+
$fp = fsockopen("ssl://" . $url_parsed['host'],"443",$err_num,$err_str,30);
|
99 |
+
if(!$fp) {
|
100 |
+
$last_error = "fsockopen error no. $errnum: $errstr";
|
101 |
+
return false;
|
102 |
+
}
|
103 |
+
else {
|
104 |
+
fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
|
105 |
+
fputs($fp, "Host: $url_parsed[host]\r\n");
|
106 |
+
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
|
107 |
+
fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
|
108 |
+
fputs($fp, "Connection: close\r\n\r\n");
|
109 |
+
fputs($fp, $post_string . "\r\n\r\n");
|
110 |
+
while(!feof($fp)) {
|
111 |
+
$ipn_response .= fgets($fp, 1024);
|
112 |
+
}
|
113 |
+
fclose($fp); // close connection
|
114 |
+
}
|
115 |
+
|
116 |
+
if (eregi("VERIFIED",$ipn_response)):
|
117 |
+
return true;
|
118 |
+
|
119 |
+
else
|
120 |
+
return false;
|
121 |
+
|
122 |
+
|
123 |
+
}*/
|
124 |
+
|
125 |
+
|
126 |
+
}
|
app/code/local/Mss/Mpaypal/etc/config.xml
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Mpaypal>
|
5 |
+
<version>0.1.0</version>
|
6 |
+
</Mss_Mpaypal>
|
7 |
+
</modules>
|
8 |
+
<frontend>
|
9 |
+
<routers>
|
10 |
+
<mpaypal>
|
11 |
+
<use>standard</use>
|
12 |
+
<args>
|
13 |
+
<module>Mss_Mpaypal</module>
|
14 |
+
<frontName>mpaypal</frontName>
|
15 |
+
</args>
|
16 |
+
</mpaypal>
|
17 |
+
</routers>
|
18 |
+
<layout>
|
19 |
+
<updates>
|
20 |
+
<mpaypal>
|
21 |
+
<file>mpaypal.xml</file>
|
22 |
+
</mpaypal>
|
23 |
+
</updates>
|
24 |
+
</layout>
|
25 |
+
|
26 |
+
<events>
|
27 |
+
<payment_method_is_active>
|
28 |
+
<observers>
|
29 |
+
<mpaypal_payment_method_is_active>
|
30 |
+
<type>singleton</type>
|
31 |
+
<class>mpaypal/observer</class>
|
32 |
+
<method>paymentMethodIsActive</method>
|
33 |
+
</mpaypal_payment_method_is_active>
|
34 |
+
</observers>
|
35 |
+
</payment_method_is_active>
|
36 |
+
</events>
|
37 |
+
|
38 |
+
</frontend>
|
39 |
+
<global>
|
40 |
+
<models>
|
41 |
+
<mpaypal>
|
42 |
+
<class>Mss_Mpaypal_Model</class>
|
43 |
+
</mpaypal>
|
44 |
+
</models>
|
45 |
+
<helpers>
|
46 |
+
<mpaypal>
|
47 |
+
<class>Mss_Mpaypal_Helper</class>
|
48 |
+
</mpaypal>
|
49 |
+
</helpers>
|
50 |
+
<blocks>
|
51 |
+
<mpaypal>
|
52 |
+
<class>Mss_Mpaypal_Block</class>
|
53 |
+
</mpaypal>
|
54 |
+
</blocks>
|
55 |
+
</global>
|
56 |
+
|
57 |
+
<default>
|
58 |
+
<payment>
|
59 |
+
<mpaypal>
|
60 |
+
|
61 |
+
<active>1</active>
|
62 |
+
<order_status>pending</order_status>
|
63 |
+
<title>Paypal (app)</title>
|
64 |
+
|
65 |
+
<model>mpaypal/mpaypal</model>
|
66 |
+
|
67 |
+
</mpaypal>
|
68 |
+
</payment>
|
69 |
+
</default>
|
70 |
+
</config>
|
app/code/local/Mss/Mpaypal/etc/system.xml
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<payment>
|
5 |
+
<groups>
|
6 |
+
<mpaypal translate="label comment" module="mpaypal">
|
7 |
+
<label>Paypal Payment for Mobile App</label>
|
8 |
+
<frontend_type>text</frontend_type>
|
9 |
+
<sort_order>10</sort_order>
|
10 |
+
<show_in_default>1</show_in_default>
|
11 |
+
<show_in_website>1</show_in_website>
|
12 |
+
<show_in_store>1</show_in_store>
|
13 |
+
<fields>
|
14 |
+
<active translate="label">
|
15 |
+
<label>Enabled</label>
|
16 |
+
<frontend_type>select</frontend_type>
|
17 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
18 |
+
<sort_order>10</sort_order>
|
19 |
+
<show_in_default>1</show_in_default>
|
20 |
+
<show_in_website>1</show_in_website>
|
21 |
+
<show_in_store>0</show_in_store>
|
22 |
+
</active>
|
23 |
+
<title translate="label">
|
24 |
+
<label>Title</label>
|
25 |
+
<frontend_type>text</frontend_type>
|
26 |
+
<sort_order>20</sort_order>
|
27 |
+
<show_in_default>1</show_in_default>
|
28 |
+
<show_in_website>1</show_in_website>
|
29 |
+
<show_in_store>1</show_in_store>
|
30 |
+
</title>
|
31 |
+
<order_status translate="label">
|
32 |
+
<label>New Order Status</label>
|
33 |
+
<frontend_type>select</frontend_type>
|
34 |
+
<source_model>adminhtml/system_config_source_order_status</source_model>
|
35 |
+
<sort_order>50</sort_order>
|
36 |
+
<show_in_default>1</show_in_default>
|
37 |
+
<show_in_website>1</show_in_website>
|
38 |
+
<show_in_store>0</show_in_store>
|
39 |
+
</order_status>
|
40 |
+
|
41 |
+
</fields>
|
42 |
+
</mpaypal>
|
43 |
+
</groups>
|
44 |
+
</payment>
|
45 |
+
</sections>
|
46 |
+
</config>
|
app/code/local/Mss/Payu/Block/Index.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Payu_Block_Index extends Mage_Core_Block_Template{
|
3 |
+
|
4 |
+
function getdata(){
|
5 |
+
return "hello";
|
6 |
+
}
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
}
|
app/code/local/Mss/Payu/Helper/Data.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Payu_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
}
|
5 |
+
|
app/code/local/Mss/Payu/controllers/IndexController.php
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Payu_IndexController extends Mage_Core_Controller_Front_Action{
|
3 |
+
|
4 |
+
public function _construct(){
|
5 |
+
|
6 |
+
|
7 |
+
parent::_construct();
|
8 |
+
|
9 |
+
}
|
10 |
+
|
11 |
+
public function IndexAction() {
|
12 |
+
|
13 |
+
$this->loadLayout();
|
14 |
+
$this->renderLayout();
|
15 |
+
|
16 |
+
}
|
17 |
+
|
18 |
+
public function payuAction() {
|
19 |
+
|
20 |
+
echo $block = $this->getLayout()->createBlock('core/template')->setTemplate('payu/index.phtml')->toHtml();
|
21 |
+
|
22 |
+
}
|
23 |
+
|
24 |
+
public function successAction(){
|
25 |
+
|
26 |
+
$result = $this->getRequest()->getParams();
|
27 |
+
|
28 |
+
if($result):
|
29 |
+
$orderIncrementId = $result['productinfo'];
|
30 |
+
|
31 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
|
32 |
+
$order->addStatusToHistory(Mage_Sales_Model_Order::STATE_COMPLETE);
|
33 |
+
|
34 |
+
|
35 |
+
if($order->getId()):
|
36 |
+
$payment = $order->getPayment();
|
37 |
+
$payment->setTransactionId($result['txnid'])
|
38 |
+
->setCurrencyCode()
|
39 |
+
->setPreparedMessage("Payment Done")
|
40 |
+
->setShouldCloseParentTransaction(true)
|
41 |
+
->setIsTransactionClosed(1)
|
42 |
+
->registerCaptureNotification();
|
43 |
+
|
44 |
+
endif;
|
45 |
+
|
46 |
+
$order->save();
|
47 |
+
|
48 |
+
|
49 |
+
echo "Thank You !";
|
50 |
+
else:
|
51 |
+
echo "No data found";
|
52 |
+
endif;
|
53 |
+
|
54 |
+
}
|
55 |
+
public function failureAction(){
|
56 |
+
|
57 |
+
$result = $this->getRequest()->getParams();
|
58 |
+
|
59 |
+
if($result):
|
60 |
+
$orderIncrementId = $result['productinfo'];
|
61 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
|
62 |
+
$order->addStatusToHistory(Mage_Sales_Model_Order::STATE_CANCELED);
|
63 |
+
if($order->getId()):
|
64 |
+
$payment = $order->getPayment();
|
65 |
+
$payment->setTransactionId($result['txnid'])
|
66 |
+
->setCurrencyCode()
|
67 |
+
->setPreparedMessage("Payment Error")
|
68 |
+
->setShouldCloseParentTransaction(true)
|
69 |
+
->setIsTransactionClosed(1)
|
70 |
+
->registerCaptureNotification();
|
71 |
+
|
72 |
+
endif;
|
73 |
+
|
74 |
+
$order->save();
|
75 |
+
|
76 |
+
echo "Found Some Problem! Try Again";
|
77 |
+
else:
|
78 |
+
echo "Found Some Problem! Try Again";
|
79 |
+
endif;
|
80 |
+
|
81 |
+
|
82 |
+
}
|
83 |
+
public function testAction(){
|
84 |
+
echo $block = $this->getLayout()->createBlock('core/template')->setTemplate('payu/test.phtml')->toHtml();
|
85 |
+
|
86 |
+
}
|
87 |
+
|
88 |
+
|
89 |
+
}
|
app/code/local/Mss/Payu/etc/config.xml
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Payu>
|
5 |
+
<version>0.1.0</version>
|
6 |
+
</Mss_Payu>
|
7 |
+
</modules>
|
8 |
+
<frontend>
|
9 |
+
<routers>
|
10 |
+
<payu>
|
11 |
+
<use>standard</use>
|
12 |
+
<args>
|
13 |
+
<module>Mss_Payu</module>
|
14 |
+
<frontName>payu</frontName>
|
15 |
+
</args>
|
16 |
+
</payu>
|
17 |
+
</routers>
|
18 |
+
<layout>
|
19 |
+
<updates>
|
20 |
+
<payu>
|
21 |
+
<file>payu.xml</file>
|
22 |
+
</payu>
|
23 |
+
</updates>
|
24 |
+
</layout>
|
25 |
+
</frontend>
|
26 |
+
<global>
|
27 |
+
<helpers>
|
28 |
+
<payu>
|
29 |
+
<class>Mss_Payu_Helper</class>
|
30 |
+
</payu>
|
31 |
+
</helpers>
|
32 |
+
<blocks>
|
33 |
+
<payu>
|
34 |
+
<class>Mss_Payu_Block</class>
|
35 |
+
</payu>
|
36 |
+
</blocks>
|
37 |
+
</global>
|
38 |
+
</config>
|
app/code/local/Mss/Pushnotification/Block/Adminhtml/Pushnotificationbackend.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Pushnotification_Block_Adminhtml_Pushnotificationbackend extends Mage_Adminhtml_Block_Template {
|
4 |
+
|
5 |
+
}
|
app/code/local/Mss/Pushnotification/Helper/Data.php
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Pushnotification_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
const SEND_IOS_PASSWORD = 'mss_pushnotification/setting/passphrase';
|
5 |
+
const GOOGLE_API_KEY ='mss_pushnotification/setting_and/googlekey';
|
6 |
+
|
7 |
+
const IOS_PEM = 'mss_pushnotification/setting/pem';
|
8 |
+
const IOS_MODE='mss_pushnotification/setting/ios_mode';
|
9 |
+
const large_icon='mss_pushnotification/setting_and/notificationimage';
|
10 |
+
const small_icon='mss_pushnotification/setting_and/notificationthumbnail';
|
11 |
+
|
12 |
+
public $total_notification=0;
|
13 |
+
public $ios_notification=0;
|
14 |
+
public $android_notification=0;
|
15 |
+
public $total_android_success=0;
|
16 |
+
public $total_ios_success=0;
|
17 |
+
public $total_ios_error=0;
|
18 |
+
public $total_android_error=0;
|
19 |
+
|
20 |
+
public function sendnotification($message,$notification_type)
|
21 |
+
{
|
22 |
+
/*get user to send notification*/
|
23 |
+
|
24 |
+
$activeuser_collection = Mage::getModel('pushnotification/pushnotification')->getCollection();
|
25 |
+
|
26 |
+
/*notification message*/
|
27 |
+
if($notification_type)
|
28 |
+
$activeuser_collection ->addFieldToFilter('device_type',array('eq'=>($notification_type-1)));
|
29 |
+
|
30 |
+
//$message_android = array("message" => $message,'largeIcon'=> 'large_icon', 'smallIcon'=> 'small_icon');
|
31 |
+
$message_android = array("message" => $message);
|
32 |
+
foreach($activeuser_collection->getData() as $collection)
|
33 |
+
{
|
34 |
+
($collection['device_type'])? $this->sendPushIOS($collection['registration_id'],$message) : $this->sendPushAndroid(array($collection['registration_id']),$message_android);
|
35 |
+
|
36 |
+
$this->total_notification++;
|
37 |
+
|
38 |
+
}
|
39 |
+
$html='';
|
40 |
+
$html.= 'Total Notification sent : '.$this->total_notification.'</br>';
|
41 |
+
if($notification_type == 0 || $notification_type == 2)
|
42 |
+
{
|
43 |
+
$html.='Total IOS Device : '.$this->ios_notification.'</br>Total Notification success in IOS : '. $this->total_ios_success.'</br>Total IOS Notification error : '.$this->total_ios_error;
|
44 |
+
}
|
45 |
+
if($notification_type == 0 || $notification_type == 1)
|
46 |
+
{
|
47 |
+
$html.='</br> Total Android Devices : '.$this->android_notification.'</br> Total Notification success in Android : '.$this->total_android_success.'</br> Total Android Notification Error : '.$this->total_android_error;
|
48 |
+
}
|
49 |
+
return $html;
|
50 |
+
}
|
51 |
+
/**
|
52 |
+
* Sending Push Notification IOS
|
53 |
+
*/
|
54 |
+
|
55 |
+
public function sendPushIOS($registration_id,$message)
|
56 |
+
{
|
57 |
+
|
58 |
+
$this->ios_notification++;
|
59 |
+
|
60 |
+
$passphrase = Mage::getStoreConfig(self::SEND_IOS_PASSWORD);
|
61 |
+
|
62 |
+
$ctx = stream_context_create();
|
63 |
+
stream_context_set_option($ctx, 'ssl', 'local_cert', Mage::getBaseUrl('media') . Mage::getStoreConfig(self::IOS_PEM));
|
64 |
+
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
|
65 |
+
|
66 |
+
$ios_mode=(!Mage::getStoreConfig(self::IOS_MODE))?'ssl://gateway.sandbox.push.apple.com:2195':'ssl://gateway.push.apple.com:2195';
|
67 |
+
// Open a connection to the APNS server
|
68 |
+
$fp = stream_socket_client(
|
69 |
+
$ios_mode, $err,
|
70 |
+
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
|
71 |
+
|
72 |
+
if (!$fp)
|
73 |
+
exit("The detail entered for IOS is not correct: $err $errstr" . PHP_EOL);
|
74 |
+
|
75 |
+
echo 'Connected to APNS' . PHP_EOL;
|
76 |
+
|
77 |
+
// Create the payload body
|
78 |
+
$body['aps'] = array(
|
79 |
+
'alert' => $message,
|
80 |
+
'sound' => 'default'
|
81 |
+
);
|
82 |
+
|
83 |
+
// Encode the payload as JSON
|
84 |
+
$payload = json_encode($body);
|
85 |
+
|
86 |
+
// Build the binary notification
|
87 |
+
$msg = chr(0) . pack('n', 32) . pack('H*', $registration_id) . pack('n', strlen($payload)) . $payload;
|
88 |
+
|
89 |
+
// Send it to the server
|
90 |
+
$result = fwrite($fp, $msg, strlen($msg));
|
91 |
+
|
92 |
+
if (!$result):
|
93 |
+
$this->total_ios_error++;
|
94 |
+
echo 'Message not delivered' . PHP_EOL;
|
95 |
+
else:
|
96 |
+
$this->total_ios_success++;
|
97 |
+
echo 'Message successfully delivered' . PHP_EOL;
|
98 |
+
endif;
|
99 |
+
// Close the connection to the server
|
100 |
+
fclose($fp);
|
101 |
+
return;
|
102 |
+
|
103 |
+
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Sending Push Notification Android
|
108 |
+
*/
|
109 |
+
|
110 |
+
public function sendPushAndroid($registration_id,$message)
|
111 |
+
{
|
112 |
+
|
113 |
+
$this->android_notification++;
|
114 |
+
// Set POST variables
|
115 |
+
$url = 'https://android.googleapis.com/gcm/send';
|
116 |
+
|
117 |
+
$fields = array(
|
118 |
+
'registration_ids' => $registration_id,
|
119 |
+
'data' => $message
|
120 |
+
|
121 |
+
);
|
122 |
+
|
123 |
+
$headers = array(
|
124 |
+
'Authorization: key=' . Mage::getStoreConfig(self::GOOGLE_API_KEY),
|
125 |
+
'Content-Type: application/json'
|
126 |
+
);
|
127 |
+
|
128 |
+
// Open connection
|
129 |
+
$ch = curl_init();
|
130 |
+
|
131 |
+
// Set the url, number of POST vars, POST data
|
132 |
+
curl_setopt($ch, CURLOPT_URL, $url);
|
133 |
+
|
134 |
+
curl_setopt($ch, CURLOPT_POST, true);
|
135 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
136 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
137 |
+
|
138 |
+
// Disabling SSL Certificate support temporarly
|
139 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
140 |
+
|
141 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
|
142 |
+
|
143 |
+
// Execute post
|
144 |
+
$result = curl_exec($ch);
|
145 |
+
|
146 |
+
if ($result === FALSE):
|
147 |
+
$this->total_android_error++;
|
148 |
+
//echo 'Curl failed: ' . curl_error($ch);
|
149 |
+
else:
|
150 |
+
$this->total_android_success++;
|
151 |
+
//echo 'Success';
|
152 |
+
endif;
|
153 |
+
|
154 |
+
// Close connection
|
155 |
+
curl_close($ch);
|
156 |
+
return;
|
157 |
+
}
|
158 |
+
|
159 |
+
|
160 |
+
|
161 |
+
/* Register device
|
162 |
+
use below code to register device .
|
163 |
+
Mage::helper('pushnotification')->registerdevice($data);
|
164 |
+
where $data = array('registration_id'=>'xyz','user_id'=>'1','device_type'=>0);
|
165 |
+
Device type 0 for android and 1 for IOS
|
166 |
+
*/
|
167 |
+
|
168 |
+
public function registerdevice($notification)
|
169 |
+
{
|
170 |
+
|
171 |
+
$collection = Mage::getModel('pushnotification/pushnotification');
|
172 |
+
$filter=$collection->getCollection()->addFieldToFilter('user_id',array(eq=>$notification['user_id']))
|
173 |
+
->addFieldToFilter('registration_id',array(eq=>$notification['registration_id']));
|
174 |
+
|
175 |
+
if(!$filter->count()):
|
176 |
+
$collection->setData($notification)->save();
|
177 |
+
endif;
|
178 |
+
|
179 |
+
}
|
180 |
+
|
181 |
+
}
|
182 |
+
|
app/code/local/Mss/Pushnotification/Model/Entity/Resource.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Pushnotification_Model_Entity_Resource extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
|
4 |
+
|
5 |
+
{
|
6 |
+
public function getAllOptions()
|
7 |
+
{
|
8 |
+
if ($this->_options === null) {
|
9 |
+
$this->_options = array(
|
10 |
+
|
11 |
+
array(
|
12 |
+
'value' => '1',
|
13 |
+
'label' => 'yes',
|
14 |
+
),
|
15 |
+
array(
|
16 |
+
'value' => '0',
|
17 |
+
'label' => 'no',
|
18 |
+
),
|
19 |
+
|
20 |
+
);
|
21 |
+
}
|
22 |
+
return $this->_options;
|
23 |
+
}
|
24 |
+
}
|
app/code/local/Mss/Pushnotification/Model/Mysql4/Pushnotification.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Pushnotification_Model_Mysql4_Pushnotification extends Mage_Core_Model_Mysql4_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
// Note that the web_id refers to the key field in your database table.
|
8 |
+
$this->_init('pushnotification/pushnotification','id');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/Mss/Pushnotification/Model/Mysql4/Pushnotification/Collection.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Pushnotification_Model_Mysql4_Pushnotification_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
$this->_init('pushnotification/pushnotification');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/Mss/Pushnotification/Model/Pushnotification.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Pushnotification_Model_Pushnotification extends Mage_Core_Model_Abstract
|
3 |
+
{
|
4 |
+
protected function _construct(){
|
5 |
+
|
6 |
+
$this->_init("pushnotification/pushnotification");
|
7 |
+
|
8 |
+
}
|
9 |
+
}
|
10 |
+
?>
|
app/code/local/Mss/Pushnotification/Model/System/Config/Backend/File.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Pushnotification_Model_System_Config_Backend_File extends Mage_Adminhtml_Model_System_Config_Backend_File
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Getter for allowed extensions of uploaded files
|
6 |
+
*
|
7 |
+
* @return array
|
8 |
+
*/
|
9 |
+
protected function _getAllowedExtensions()
|
10 |
+
{
|
11 |
+
return array('pem');
|
12 |
+
}
|
13 |
+
}
|
app/code/local/Mss/Pushnotification/Model/System/Config/Backend/Image.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Pushnotification_Model_System_Config_Backend_Image extends Mage_Adminhtml_Model_System_Config_Backend_File
|
3 |
+
{
|
4 |
+
protected function _getAllowedExtensions()
|
5 |
+
{
|
6 |
+
$extension=array('png','jpeg','gif');
|
7 |
+
return $extension;
|
8 |
+
}
|
9 |
+
}
|
10 |
+
?>
|
app/code/local/Mss/Pushnotification/Model/System/Config/Backend/Iosmode.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-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 Mage
|
22 |
+
* @package Mage_Adminhtml
|
23 |
+
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Used in creating options for Yes|No config value selection
|
29 |
+
*
|
30 |
+
*/
|
31 |
+
class Mss_Pushnotification_Model_System_Config_Backend_Iosmode
|
32 |
+
{
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Options getter
|
36 |
+
*
|
37 |
+
* @return array
|
38 |
+
*/
|
39 |
+
public function toOptionArray()
|
40 |
+
{
|
41 |
+
return array(
|
42 |
+
array('value' => 1, 'label'=>Mage::helper('adminhtml')->__('Production')),
|
43 |
+
array('value' => 0, 'label'=>Mage::helper('adminhtml')->__('Sandbox')),
|
44 |
+
);
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Get options in "key-value" format
|
49 |
+
*
|
50 |
+
* @return array
|
51 |
+
*/
|
52 |
+
public function toArray()
|
53 |
+
{
|
54 |
+
return array(
|
55 |
+
0 => Mage::helper('adminhtml')->__('Sandbox'),
|
56 |
+
1 => Mage::helper('adminhtml')->__('Production'),
|
57 |
+
);
|
58 |
+
}
|
59 |
+
|
60 |
+
}
|
app/code/local/Mss/Pushnotification/controllers/Adminhtml/PushnotificationbackendController.php
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Pushnotification_Adminhtml_PushnotificationbackendController extends Mage_Adminhtml_Controller_Action
|
3 |
+
{
|
4 |
+
public function indexAction()
|
5 |
+
{
|
6 |
+
$this->loadLayout();
|
7 |
+
$this->_title($this->__("pushnotification"));
|
8 |
+
$this->renderLayout();
|
9 |
+
}
|
10 |
+
public function notificationsendAction()
|
11 |
+
{
|
12 |
+
$params= $this->getRequest()->getParams();
|
13 |
+
$result=Mage::helper('pushnotification')->sendnotification($params['message'],$params['notification_type']);
|
14 |
+
$this->getResponse()->setHeader('Content-type', 'application/json');
|
15 |
+
$this->getResponse()->setBody($result);
|
16 |
+
return;
|
17 |
+
}
|
18 |
+
}
|
app/code/local/Mss/Pushnotification/etc/config.xml
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Pushnotification>
|
5 |
+
<version>0.1.6</version>
|
6 |
+
</Mss_Pushnotification>
|
7 |
+
</modules>
|
8 |
+
<adminhtml>
|
9 |
+
<acl>
|
10 |
+
<resources>
|
11 |
+
<admin>
|
12 |
+
<children>
|
13 |
+
<system>
|
14 |
+
<children>
|
15 |
+
<config>
|
16 |
+
<children>
|
17 |
+
<mss_pushnotification>
|
18 |
+
<title>MSS Extensions</title>
|
19 |
+
</mss_pushnotification>
|
20 |
+
|
21 |
+
</children>
|
22 |
+
</config>
|
23 |
+
</children>
|
24 |
+
</system>
|
25 |
+
</children>
|
26 |
+
</admin>
|
27 |
+
</resources>
|
28 |
+
</acl>
|
29 |
+
</adminhtml>
|
30 |
+
<global>
|
31 |
+
<helpers>
|
32 |
+
<pushnotification>
|
33 |
+
<class>Mss_Pushnotification_Helper</class>
|
34 |
+
</pushnotification>
|
35 |
+
</helpers>
|
36 |
+
<blocks>
|
37 |
+
<pushnotification>
|
38 |
+
<class>Mss_Pushnotification_Block</class>
|
39 |
+
</pushnotification>
|
40 |
+
</blocks>
|
41 |
+
<models>
|
42 |
+
<pushnotification>
|
43 |
+
<class>Mss_Pushnotification_Model</class>
|
44 |
+
<resourceModel>pushnotification_mysql4</resourceModel>
|
45 |
+
</pushnotification>
|
46 |
+
<pushnotification_mysql4>
|
47 |
+
<class>Mss_Pushnotification_Model_Mysql4</class>
|
48 |
+
<entities>
|
49 |
+
<pushnotification>
|
50 |
+
<table>notification</table>
|
51 |
+
</pushnotification>
|
52 |
+
</entities>
|
53 |
+
</pushnotification_mysql4>
|
54 |
+
</models>
|
55 |
+
|
56 |
+
<resources>
|
57 |
+
<pushnotification_setup>
|
58 |
+
<setup>
|
59 |
+
<module>Mss_Pushnotification</module>
|
60 |
+
<class>Mage_Customer_Model_Entity_Setup</class>
|
61 |
+
</setup>
|
62 |
+
<connection>
|
63 |
+
<use>core_setup</use>
|
64 |
+
</connection>
|
65 |
+
</pushnotification_setup>
|
66 |
+
<pushnotification_write>
|
67 |
+
<connection>
|
68 |
+
<use>core_write</use>
|
69 |
+
</connection>
|
70 |
+
</pushnotification_write>
|
71 |
+
<pushnotification_read>
|
72 |
+
<connection>
|
73 |
+
<use>core_read</use>
|
74 |
+
</connection>
|
75 |
+
</pushnotification_read>
|
76 |
+
</resources>
|
77 |
+
|
78 |
+
</global>
|
79 |
+
|
80 |
+
|
81 |
+
<admin>
|
82 |
+
<routers>
|
83 |
+
<pushnotification>
|
84 |
+
<use>admin</use>
|
85 |
+
<args>
|
86 |
+
<module>Mss_Pushnotification</module>
|
87 |
+
<frontName>admin_pushnotification</frontName>
|
88 |
+
</args>
|
89 |
+
</pushnotification>
|
90 |
+
</routers>
|
91 |
+
</admin>
|
92 |
+
<adminhtml>
|
93 |
+
<menu>
|
94 |
+
<connector>
|
95 |
+
<children>
|
96 |
+
<pushnotificationbackend module="pushnotification">
|
97 |
+
<title>Push Notification</title>
|
98 |
+
<sort_order>2</sort_order>
|
99 |
+
<action>admin_pushnotification/adminhtml_pushnotificationbackend</action>
|
100 |
+
</pushnotificationbackend>
|
101 |
+
</children>
|
102 |
+
</connector>
|
103 |
+
</menu>
|
104 |
+
<acl>
|
105 |
+
<resources>
|
106 |
+
<all>
|
107 |
+
<title>Allow Everything</title>
|
108 |
+
</all>
|
109 |
+
<!-- <admin>
|
110 |
+
<children>
|
111 |
+
<pushnotification translate="title" module="pushnotification">
|
112 |
+
<title>Pushnotification</title>
|
113 |
+
<sort_order>1000</sort_order>
|
114 |
+
<children>
|
115 |
+
<pushnotificationbackend translate="title">
|
116 |
+
<title>pushnotification</title>
|
117 |
+
</pushnotificationbackend>
|
118 |
+
</children>
|
119 |
+
</pushnotification>
|
120 |
+
</children>
|
121 |
+
</admin> -->
|
122 |
+
</resources>
|
123 |
+
</acl>
|
124 |
+
<layout>
|
125 |
+
<updates>
|
126 |
+
<pushnotification>
|
127 |
+
<file>pushnotification.xml</file>
|
128 |
+
</pushnotification>
|
129 |
+
</updates>
|
130 |
+
</layout>
|
131 |
+
|
132 |
+
</adminhtml>
|
133 |
+
</config>
|
app/code/local/Mss/Pushnotification/etc/system.xml
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
|
4 |
+
<sections>
|
5 |
+
<mss_pushnotification module="pushnotification">
|
6 |
+
<label>Pushnotification</label>
|
7 |
+
<tab>connector</tab>
|
8 |
+
<frontend_type>text</frontend_type>
|
9 |
+
<sort_order>3</sort_order>
|
10 |
+
<show_in_default>1</show_in_default>
|
11 |
+
<show_in_website>1</show_in_website>
|
12 |
+
<show_in_store>1</show_in_store>
|
13 |
+
|
14 |
+
<groups>
|
15 |
+
<mss_aboutus translate="label" module="connector">
|
16 |
+
<label>About Magento Mobile</label>
|
17 |
+
<frontend_type>text</frontend_type>
|
18 |
+
<sort_order>0</sort_order>
|
19 |
+
<show_in_default>1</show_in_default>
|
20 |
+
<show_in_website>1</show_in_website>
|
21 |
+
<show_in_store>1</show_in_store>
|
22 |
+
<fields>
|
23 |
+
<about>
|
24 |
+
<frontend_model>connector/system_config_about</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 |
+
</about>
|
30 |
+
</fields>
|
31 |
+
</mss_aboutus>
|
32 |
+
|
33 |
+
<setting translate="label">
|
34 |
+
<label>IOS Notification Configuration</label>
|
35 |
+
<frontend_type>text</frontend_type>
|
36 |
+
<sort_order>11</sort_order>
|
37 |
+
<show_in_default>1</show_in_default>
|
38 |
+
<show_in_website>1</show_in_website>
|
39 |
+
<show_in_store>1</show_in_store>
|
40 |
+
<fields>
|
41 |
+
<!-- <active translate="label">
|
42 |
+
<label>Enabled Pushnotification</label>
|
43 |
+
<frontend_type>select</frontend_type>
|
44 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
45 |
+
<sort_order>9</sort_order>
|
46 |
+
<show_in_default>1</show_in_default>
|
47 |
+
<show_in_website>1</show_in_website>
|
48 |
+
<show_in_store>1</show_in_store>
|
49 |
+
</active> -->
|
50 |
+
|
51 |
+
<ios_mode translate="label">
|
52 |
+
<label>IOS mode</label>
|
53 |
+
<frontend_type>select</frontend_type>
|
54 |
+
<source_model>pushnotification/system_config_backend_iosmode</source_model>
|
55 |
+
<sort_order>12</sort_order>
|
56 |
+
<show_in_default>1</show_in_default>
|
57 |
+
<show_in_website>1</show_in_website>
|
58 |
+
<show_in_store>1</show_in_store>
|
59 |
+
</ios_mode>
|
60 |
+
<passphrase translate="label">
|
61 |
+
<label>IOS Passphrase</label>
|
62 |
+
<frontend_type>text</frontend_type>
|
63 |
+
<sort_order>13</sort_order>
|
64 |
+
<show_in_default>1</show_in_default>
|
65 |
+
<show_in_website>1</show_in_website>
|
66 |
+
<show_in_store>1</show_in_store>
|
67 |
+
</passphrase>
|
68 |
+
<!--googlekey translate="label">
|
69 |
+
<label>Google API Key</label>
|
70 |
+
<frontend_type>text</frontend_type>
|
71 |
+
<sort_order>14</sort_order>
|
72 |
+
<show_in_default>1</show_in_default>
|
73 |
+
<show_in_website>1</show_in_website>
|
74 |
+
<show_in_store>1</show_in_store>
|
75 |
+
</googlekey-->
|
76 |
+
|
77 |
+
<pem translate="label comment">
|
78 |
+
<label>pem file for IOS : </label>
|
79 |
+
<comment>Allowed file types: .pem.</comment>
|
80 |
+
<frontend_type>image</frontend_type>
|
81 |
+
<backend_model>pushnotification/system_config_backend_file</backend_model>
|
82 |
+
<upload_dir config="system/filesystem/media" scope_info="1">pem</upload_dir>
|
83 |
+
<base_url type="media" scope_info="1">pem</base_url>
|
84 |
+
<sort_order>1</sort_order>
|
85 |
+
<show_in_default>1</show_in_default>
|
86 |
+
<show_in_website>1</show_in_website>
|
87 |
+
<show_in_store>1</show_in_store>
|
88 |
+
</pem>
|
89 |
+
<!--notificationimage translate="label comment">
|
90 |
+
<label>Notification Icon : </label>
|
91 |
+
<comment>Allowed file types: .jpeg,.png,.gif.(only for android)</comment>
|
92 |
+
<frontend_type>image</frontend_type>
|
93 |
+
<backend_model>pushnotification/system_config_backend_image</backend_model>
|
94 |
+
<upload_dir config="system/filesystem/media" scope_info="1">notification</upload_dir>
|
95 |
+
<base_url type="media" scope_info="1">notification</base_url>
|
96 |
+
<sort_order>2</sort_order>
|
97 |
+
<show_in_default>1</show_in_default>
|
98 |
+
<show_in_website>1</show_in_website>
|
99 |
+
<show_in_store>1</show_in_store>
|
100 |
+
</notificationimage>
|
101 |
+
<notificationthumbnail translate="label comment">
|
102 |
+
<label>Notification Thumbnail Icon : </label>
|
103 |
+
<comment>Allowed file types: .jpeg,.png,.gif.(only for android)</comment>
|
104 |
+
<frontend_type>image</frontend_type>
|
105 |
+
<backend_model>pushnotification/system_config_backend_image</backend_model>
|
106 |
+
<upload_dir config="system/filesystem/media" scope_info="1">notification</upload_dir>
|
107 |
+
<base_url type="media" scope_info="1">notification</base_url>
|
108 |
+
<sort_order>5</sort_order>
|
109 |
+
<show_in_default>1</show_in_default>
|
110 |
+
<show_in_website>1</show_in_website>
|
111 |
+
<show_in_store>1</show_in_store>
|
112 |
+
</notificationthumbnail-->
|
113 |
+
</fields>
|
114 |
+
</setting>
|
115 |
+
|
116 |
+
<setting_and translate="label">
|
117 |
+
<label>Android Notification Configuration</label>
|
118 |
+
<frontend_type>text</frontend_type>
|
119 |
+
<sort_order>3</sort_order>
|
120 |
+
<show_in_default>1</show_in_default>
|
121 |
+
<show_in_website>1</show_in_website>
|
122 |
+
<show_in_store>1</show_in_store>
|
123 |
+
<fields>
|
124 |
+
<active translate="label">
|
125 |
+
<label>Enabled Pushnotification</label>
|
126 |
+
<frontend_type>select</frontend_type>
|
127 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
128 |
+
<sort_order>1</sort_order>
|
129 |
+
<show_in_default>1</show_in_default>
|
130 |
+
<show_in_website>1</show_in_website>
|
131 |
+
<show_in_store>1</show_in_store>
|
132 |
+
</active>
|
133 |
+
<googlekey translate="label">
|
134 |
+
<label>Google API Key</label>
|
135 |
+
<frontend_type>text</frontend_type>
|
136 |
+
<sort_order>2</sort_order>
|
137 |
+
<show_in_default>1</show_in_default>
|
138 |
+
<show_in_website>1</show_in_website>
|
139 |
+
<show_in_store>1</show_in_store>
|
140 |
+
</googlekey>
|
141 |
+
<notificationimage translate="label comment">
|
142 |
+
<label>Notification Icon : </label>
|
143 |
+
<comment>Allowed file types: .jpeg,.png,.gif.(only for android)</comment>
|
144 |
+
<frontend_type>image</frontend_type>
|
145 |
+
<backend_model>pushnotification/system_config_backend_image</backend_model>
|
146 |
+
<upload_dir config="system/filesystem/media" scope_info="1">notification</upload_dir>
|
147 |
+
<base_url type="media" scope_info="1">notification</base_url>
|
148 |
+
<sort_order>3</sort_order>
|
149 |
+
<show_in_default>1</show_in_default>
|
150 |
+
<show_in_website>1</show_in_website>
|
151 |
+
<show_in_store>1</show_in_store>
|
152 |
+
</notificationimage>
|
153 |
+
<notificationthumbnail translate="label comment">
|
154 |
+
<label>Notification Thumbnail Icon : </label>
|
155 |
+
<comment>Allowed file types: .jpeg,.png,.gif.(only for android)</comment>
|
156 |
+
<frontend_type>image</frontend_type>
|
157 |
+
<backend_model>pushnotification/system_config_backend_image</backend_model>
|
158 |
+
<upload_dir config="system/filesystem/media" scope_info="1">notification</upload_dir>
|
159 |
+
<base_url type="media" scope_info="1">notification</base_url>
|
160 |
+
<sort_order>5</sort_order>
|
161 |
+
<show_in_default>1</show_in_default>
|
162 |
+
<show_in_website>1</show_in_website>
|
163 |
+
<show_in_store>1</show_in_store>
|
164 |
+
</notificationthumbnail>
|
165 |
+
|
166 |
+
|
167 |
+
</fields>
|
168 |
+
</setting_and>
|
169 |
+
|
170 |
+
</groups>
|
171 |
+
</mss_pushnotification>
|
172 |
+
</sections>
|
173 |
+
</config>
|
app/code/local/Mss/Pushnotification/sql/pushnotification_setup/mysql4-upgrade-0.1.5-0.1.6.php
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$installer = $this;
|
3 |
+
|
4 |
+
$installer->startSetup();
|
5 |
+
|
6 |
+
|
7 |
+
/*create user Attribute*/
|
8 |
+
|
9 |
+
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
10 |
+
|
11 |
+
$entityTypeId = $setup->getEntityTypeId('customer');
|
12 |
+
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
|
13 |
+
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
|
14 |
+
|
15 |
+
$installer->addAttribute("customer", "pushnotification", array(
|
16 |
+
"type" => "int",
|
17 |
+
"backend" => "",
|
18 |
+
"label" => "Push Notification",
|
19 |
+
"input" => "select",
|
20 |
+
"source" => "pushnotification/entity_resource",
|
21 |
+
"visible" => true,
|
22 |
+
"required" => false,
|
23 |
+
"default" => "",
|
24 |
+
"frontend" => "",
|
25 |
+
"unique" => false,
|
26 |
+
"note" => "Push Notification"
|
27 |
+
|
28 |
+
));
|
29 |
+
|
30 |
+
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "pushnotification");
|
31 |
+
|
32 |
+
|
33 |
+
$setup->addAttributeToGroup(
|
34 |
+
$entityTypeId,
|
35 |
+
$attributeSetId,
|
36 |
+
$attributeGroupId,
|
37 |
+
'module',
|
38 |
+
'999' //sort_order
|
39 |
+
);
|
40 |
+
|
41 |
+
$used_in_forms=array();
|
42 |
+
|
43 |
+
$used_in_forms[]="adminhtml_customer";
|
44 |
+
|
45 |
+
$attribute->setData("used_in_forms", $used_in_forms)
|
46 |
+
->setData("is_used_for_customer_segment", true)
|
47 |
+
->setData("is_system", 0)
|
48 |
+
->setData("is_user_defined", 1)
|
49 |
+
->setData("is_visible", 1)
|
50 |
+
->setData("sort_order", 100)
|
51 |
+
;
|
52 |
+
$attribute->save();
|
53 |
+
|
54 |
+
/*Create table script*/
|
55 |
+
|
56 |
+
|
57 |
+
$installer->run("DROP TABLE IF EXISTS {$this->getTable('notification')};
|
58 |
+
CREATE TABLE {$this->getTable('notification')} (
|
59 |
+
`id` int(11) unsigned NOT NULL auto_increment,
|
60 |
+
`user_id` int(11),
|
61 |
+
`registration_id` varchar(250),
|
62 |
+
`device_type` int(11),
|
63 |
+
PRIMARY KEY (`id`)
|
64 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
65 |
+
");
|
66 |
+
$installer->endSetup();
|
67 |
+
|
app/code/local/Mss/Sociallogin/Helper/Data.php
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Sociallogin_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
|
5 |
+
private $sociallogin_support = array('facebook','google');
|
6 |
+
private $f_url = 'https://graph.facebook.com/me?fields=first_name,last_name,gender,email&format=json&access_token=';
|
7 |
+
private $g_url = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&alt=json&access_token=';
|
8 |
+
private $sociallogin_type;
|
9 |
+
|
10 |
+
public function socialloginRequest($token,$sociallogintype){
|
11 |
+
|
12 |
+
if($token && $sociallogintype):
|
13 |
+
|
14 |
+
$this->sociallogin_type = $sociallogintype;
|
15 |
+
|
16 |
+
$this->sociallogin_support($sociallogintype);
|
17 |
+
$this->getSocialdetails($token,$sociallogintype);
|
18 |
+
|
19 |
+
else:
|
20 |
+
return true;
|
21 |
+
endif;
|
22 |
+
|
23 |
+
|
24 |
+
}
|
25 |
+
|
26 |
+
private function sociallogin_support($sociallogintype)
|
27 |
+
{
|
28 |
+
if(!in_array($sociallogintype, $this->sociallogin_support)):
|
29 |
+
echo json_encode(array('status'=>'error','message'=>'Social Login is not supported by Magentomobileshop.'));
|
30 |
+
exit;
|
31 |
+
else:
|
32 |
+
return true;
|
33 |
+
endif;
|
34 |
+
return true;
|
35 |
+
}
|
36 |
+
|
37 |
+
private function getSocialdetails($token,$sociallogintype){
|
38 |
+
switch($sociallogintype)
|
39 |
+
{
|
40 |
+
case 'facebook':
|
41 |
+
$this->getfacebookdetails($token);
|
42 |
+
break;
|
43 |
+
case 'google':
|
44 |
+
$this->getgoogledetails($token);
|
45 |
+
break;
|
46 |
+
default:
|
47 |
+
echo json_encode(array('status'=>'error','message'=>'Social Login is not supported by Magentomobileshop.'));
|
48 |
+
exit;
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
private function getFacebookdetails($token){
|
53 |
+
|
54 |
+
$user_details = $this->f_url.$token;
|
55 |
+
$response = file_get_contents($user_details);
|
56 |
+
$response = json_decode($response);
|
57 |
+
if($response->email):
|
58 |
+
$this->checkuser($response);
|
59 |
+
else:
|
60 |
+
echo json_encode(array('status'=>'error','message'=>'Token is invalid.'));
|
61 |
+
exit;
|
62 |
+
endif;
|
63 |
+
}
|
64 |
+
|
65 |
+
private function getgoogledetails($token){
|
66 |
+
|
67 |
+
$user_details = $this->g_url.$token;
|
68 |
+
$response = file_get_contents($user_details);
|
69 |
+
$response = json_decode($response);
|
70 |
+
|
71 |
+
if($response->email):
|
72 |
+
$this->checkuser($response);
|
73 |
+
else:
|
74 |
+
echo json_encode(array('status'=>'error','message'=>'Token is invalid.'));
|
75 |
+
exit;
|
76 |
+
endif;
|
77 |
+
|
78 |
+
}
|
79 |
+
|
80 |
+
private function checkuser($response){
|
81 |
+
try{
|
82 |
+
$customer = Mage::getModel("customer/customer")->setWebsiteId(1)->loadByEmail($response->email);
|
83 |
+
|
84 |
+
if($customer->getId()):
|
85 |
+
Mage::getSingleton('customer/session')->loginById($customer->getId());
|
86 |
+
echo json_encode(array('status'=>'success','message'=>Mss_Connector_CustomerController::statusAction()));
|
87 |
+
exit;
|
88 |
+
|
89 |
+
else:
|
90 |
+
$this->registerUser($response);
|
91 |
+
endif;
|
92 |
+
}
|
93 |
+
catch(exception $e){
|
94 |
+
echo json_encode(array('status'=>'error','message'=>$e->getMessage()));
|
95 |
+
exit;
|
96 |
+
}
|
97 |
+
|
98 |
+
}
|
99 |
+
|
100 |
+
private function registerUser($response){
|
101 |
+
$session = Mage::getSingleton ( 'customer/session' );
|
102 |
+
$customer = Mage::getModel ( 'customer/customer' )->setId(null);
|
103 |
+
|
104 |
+
$customer->setData('email',$response->email);
|
105 |
+
$customer->setData('firstname',$response->first_name);
|
106 |
+
$customer->setData('lastname',$response->last_name);
|
107 |
+
$customer->setData('gender',$response->gender);
|
108 |
+
$customer->setData('sociallogin_type',$this->sociallogin_type);
|
109 |
+
$customer->setData('password',$this->radPassoword());
|
110 |
+
|
111 |
+
try{
|
112 |
+
$customer->setConfirmation(null);
|
113 |
+
$customer->save();
|
114 |
+
if ($customer->isConfirmationRequired ()):
|
115 |
+
$customer->sendNewAccountEmail ( 'confirmation', $session->getBeforeAuthUrl (), Mage::app ()->getStore ()->getId () );
|
116 |
+
echo json_encode(array('status'=>'error','message'=>'Account confirmation required.'));
|
117 |
+
exit;
|
118 |
+
else:
|
119 |
+
$session->setCustomerAsLoggedIn($customer);
|
120 |
+
$customer->sendNewAccountEmail ('registered','', Mage::app ()->getStore ()->getId ());
|
121 |
+
endif;
|
122 |
+
|
123 |
+
echo json_encode(array('status'=>'success','message'=>Mss_Connector_CustomerController::statusAction()));
|
124 |
+
exit;
|
125 |
+
|
126 |
+
}
|
127 |
+
catch(Exception $ex){
|
128 |
+
echo json_encode(array('status'=>'error','message'=>'Error in creating user account.'));
|
129 |
+
exit;
|
130 |
+
}
|
131 |
+
|
132 |
+
|
133 |
+
}
|
134 |
+
|
135 |
+
private function radPassoword()
|
136 |
+
{
|
137 |
+
return substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(1,6))),1,6);
|
138 |
+
}
|
139 |
+
|
140 |
+
}
|
app/code/local/Mss/Sociallogin/Model/Mysql4/Sociallogin.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Mss_Sociallogin_Model_Mysql4_Sociallogin extends Mage_Core_Model_Mysql4_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
// Note that the web_id refers to the key field in your database table.
|
8 |
+
$this->_init('sociallogin/sociallogin');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/Mss/Sociallogin/Model/Sociallogin.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Mss_Sociallogin_Model_Sociallogin extends Mage_Core_Model_Abstract
|
3 |
+
{
|
4 |
+
protected function _construct(){
|
5 |
+
|
6 |
+
$this->_init("sociallogin/sociallogin");
|
7 |
+
|
8 |
+
}
|
9 |
+
}
|
10 |
+
?>
|
app/code/local/Mss/Sociallogin/etc/config.xml
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Sociallogin>
|
5 |
+
<version>0.1.0</version>
|
6 |
+
</Mss_Sociallogin>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
|
10 |
+
<helpers>
|
11 |
+
<sociallogin>
|
12 |
+
<class>Mss_Sociallogin_Helper</class>
|
13 |
+
</sociallogin>
|
14 |
+
</helpers>
|
15 |
+
|
16 |
+
<models>
|
17 |
+
<sociallogin>
|
18 |
+
<class>Mss_Sociallogin_Model</class>
|
19 |
+
<resourceModel>sociallogin_mysql4</resourceModel>
|
20 |
+
</sociallogin>
|
21 |
+
</models>
|
22 |
+
|
23 |
+
<resources>
|
24 |
+
<sociallogin_setup>
|
25 |
+
<setup>
|
26 |
+
<module>Mss_Sociallogin</module>
|
27 |
+
<class>Mage_Customer_Model_Entity_Setup</class>
|
28 |
+
</setup>
|
29 |
+
<connection>
|
30 |
+
<use>core_setup</use>
|
31 |
+
</connection>
|
32 |
+
</sociallogin_setup>
|
33 |
+
<sociallogin_write>
|
34 |
+
<connection>
|
35 |
+
<use>core_write</use>
|
36 |
+
</connection>
|
37 |
+
</sociallogin_write>
|
38 |
+
<sociallogin_read>
|
39 |
+
<connection>
|
40 |
+
<use>core_read</use>
|
41 |
+
</connection>
|
42 |
+
</sociallogin_read>
|
43 |
+
</resources>
|
44 |
+
|
45 |
+
</global>
|
46 |
+
|
47 |
+
</config>
|
app/code/local/Mss/Sociallogin/sql/sociallogin_setup/mysql4-install-0.1.0.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$installer = $this;
|
3 |
+
|
4 |
+
$installer->startSetup();
|
5 |
+
|
6 |
+
|
7 |
+
/*create user Attribute*/
|
8 |
+
|
9 |
+
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
10 |
+
|
11 |
+
$entityTypeId = $setup->getEntityTypeId('customer');
|
12 |
+
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
|
13 |
+
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
|
14 |
+
|
15 |
+
$installer->addAttribute("customer", "sociallogin_type", array(
|
16 |
+
"type" => "varchar",
|
17 |
+
"backend" => "",
|
18 |
+
"label" => "Social Login Type",
|
19 |
+
"input" => "text",
|
20 |
+
"visible" => true,
|
21 |
+
"required" => false,
|
22 |
+
"default" => "",
|
23 |
+
"frontend" => "",
|
24 |
+
"unique" => false,
|
25 |
+
"note" => "Social Login Type"
|
26 |
+
|
27 |
+
));
|
28 |
+
|
29 |
+
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "sociallogin_type");
|
30 |
+
|
31 |
+
|
32 |
+
$setup->addAttributeToGroup(
|
33 |
+
$entityTypeId,
|
34 |
+
$attributeSetId,
|
35 |
+
$attributeGroupId,
|
36 |
+
'module',
|
37 |
+
'999' //sort_order
|
38 |
+
);
|
39 |
+
|
40 |
+
$used_in_forms=array();
|
41 |
+
|
42 |
+
$used_in_forms[]="adminhtml_customer";
|
43 |
+
|
44 |
+
$attribute->setData("used_in_forms", $used_in_forms)
|
45 |
+
->setData("is_used_for_customer_segment", true)
|
46 |
+
->setData("is_system", 0)
|
47 |
+
->setData("is_user_defined", 1)
|
48 |
+
->setData("is_visible", 1)
|
49 |
+
->setData("sort_order", 100)
|
50 |
+
;
|
51 |
+
$attribute->save();
|
app/design/adminhtml/default/default/layout/bannerslider.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<bannerslider_adminhtml_bannerslider_index>
|
4 |
+
<reference name="content">
|
5 |
+
<block type="bannerslider/adminhtml_grid" name="bannerslider" />
|
6 |
+
</reference>
|
7 |
+
</bannerslider_adminhtml_bannerslider_index>
|
8 |
+
</layout>
|
app/design/adminhtml/default/default/layout/connector.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout>
|
3 |
+
<default>
|
4 |
+
<reference name="notifications">
|
5 |
+
<block type="connector/adminhtml_notifications" name="connector_notifications" template="connector/notification.phtml"/>
|
6 |
+
</reference>
|
7 |
+
</default>
|
8 |
+
</layout>
|
app/design/adminhtml/default/default/layout/pushnotification.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<pushnotification_adminhtml_pushnotificationbackend_index>
|
4 |
+
<reference name="content">
|
5 |
+
<block type="pushnotification/adminhtml_pushnotificationbackend" name="pushnotificationbackend" template="pushnotification/pushnotificationbackend.phtml"/>
|
6 |
+
</reference>
|
7 |
+
</pushnotification_adminhtml_pushnotificationbackend_index>
|
8 |
+
</layout>
|
app/design/adminhtml/default/default/template/connector/notification.phtml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
<?php if ($message = $this->getMessage()) : ?>
|
2 |
+
<div class="notification-global"><?php echo $message ?></div>
|
3 |
+
<?php endif; ?>
|
app/design/adminhtml/default/default/template/pushnotification/pushnotificationbackend.phtml
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="container" align="center" >
|
2 |
+
<div class="row" style="background-color:#DCDCDC; width:50%" >
|
3 |
+
<h1>PUSH NOTIFICATION</h1>
|
4 |
+
<form id='notification-form' role="form">
|
5 |
+
<div class="form-group">
|
6 |
+
<label class="type" id="label"><h4>Notification Type :</h4></label>
|
7 |
+
<select id="notification_type">
|
8 |
+
<option value="0">Send Notification to Both IOS/Android</option>
|
9 |
+
<option value="1">Send Notification to Android Only</option>
|
10 |
+
<option value="2">Send Notification to IOS only</option>
|
11 |
+
</select>
|
12 |
+
|
13 |
+
</div>
|
14 |
+
<div class="form-group" style="margin-top:23px;">
|
15 |
+
<div><label id="label"><h4>Pushnotification Message:</h4></label></div>
|
16 |
+
<div><textarea rows="10" cols="50" id="message"></textarea></div>
|
17 |
+
|
18 |
+
</div>
|
19 |
+
<div style="margin-top:23px; padding:18px;">
|
20 |
+
<button style="width:140px;height:35px" type="button" id="butt" class="btn btn-default" onclick="pushnotification()">Send Notification</button>
|
21 |
+
</div>
|
22 |
+
<div id="information">
|
23 |
+
</div>
|
24 |
+
</form>
|
25 |
+
</div>
|
26 |
+
</div>
|
27 |
+
<script>
|
28 |
+
function pushnotification()
|
29 |
+
{
|
30 |
+
|
31 |
+
var url='<?php echo Mage::helper("adminhtml")->getUrl("admin_pushnotification/adminhtml_pushnotificationbackend/notificationsend");?>';
|
32 |
+
var message = document.getElementById("message").value;
|
33 |
+
if(!message){
|
34 |
+
alert('Pushnotification Message field is required.');
|
35 |
+
return;
|
36 |
+
}
|
37 |
+
|
38 |
+
new Ajax.Request(url, {
|
39 |
+
method:'get',
|
40 |
+
parameters: {'message':message,'notification_type':document.getElementById("notification_type").options[document.getElementById("notification_type").selectedIndex].value},
|
41 |
+
onSuccess: function(transport) {
|
42 |
+
var response = transport.responseText;
|
43 |
+
document.getElementById("information").innerHTML = response;
|
44 |
+
},
|
45 |
+
onFailure: function() {
|
46 |
+
document.getElementById("information").innerHTML = 'There is error in sending notification.';
|
47 |
+
|
48 |
+
}
|
49 |
+
});
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
+
</script>
|
54 |
+
<style>
|
55 |
+
.type {
|
56 |
+
margin-left: -51px;
|
57 |
+
}
|
58 |
+
</style>
|
app/design/frontend/base/default/layout/mpaypal.xml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<mpaypal_index_mpaypal>
|
4 |
+
<action method="setCacheLifetime" />
|
5 |
+
<reference name="root">
|
6 |
+
<action method="setTemplate"><template>page/1column.phtml</template></action>
|
7 |
+
</reference>
|
8 |
+
<reference name="content">
|
9 |
+
<block type="mpaypal/index" name="mpaypal_index" template="mpaypal/index.phtml"/>
|
10 |
+
</reference>
|
11 |
+
</mpaypal_index_mpaypal>
|
12 |
+
</layout>
|
13 |
+
|
app/design/frontend/base/default/layout/payu.xml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<payu_index_index>
|
4 |
+
<action method="setCacheLifetime" />
|
5 |
+
<reference name="root">
|
6 |
+
<action method="setTemplate"><template>page/1column.phtml</template></action>
|
7 |
+
</reference>
|
8 |
+
<reference name="content">
|
9 |
+
<block type="payu/index" name="payu_index" template="payu/index.phtml"/>
|
10 |
+
</reference>
|
11 |
+
</payu_index_index>
|
12 |
+
</layout>
|
13 |
+
|
app/design/frontend/base/default/template/mpaypal/index.phtml
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<SCRIPT LANGUAGE="JavaScript">
|
4 |
+
function fnSubmit() {
|
5 |
+
|
6 |
+
window.document.paypalForm.submit();
|
7 |
+
return;
|
8 |
+
}
|
9 |
+
</SCRIPT>
|
10 |
+
<style>
|
11 |
+
#loader::after {
|
12 |
+
bottom: 0;
|
13 |
+
content: "Please Wait...";
|
14 |
+
height: 40px;
|
15 |
+
left: 0px;
|
16 |
+
position: absolute;
|
17 |
+
right: 0;
|
18 |
+
text-align: center;
|
19 |
+
top: 58%;
|
20 |
+
}
|
21 |
+
#loader {
|
22 |
+
height: 100%;
|
23 |
+
position: fixed;
|
24 |
+
text-align: center;
|
25 |
+
width: 100%;
|
26 |
+
}
|
27 |
+
#loader img {
|
28 |
+
position: absolute;
|
29 |
+
text-align: center;
|
30 |
+
top: 50%;
|
31 |
+
}
|
32 |
+
#loader img {
|
33 |
+
left: 50%;
|
34 |
+
position: absolute;
|
35 |
+
text-align: center;
|
36 |
+
top: 50%;
|
37 |
+
transform: translate(-50%, -50%);
|
38 |
+
}
|
39 |
+
</style>
|
40 |
+
</head>
|
41 |
+
|
42 |
+
|
43 |
+
<body LANGUAGE="javascript" onload="return fnSubmit()" >
|
44 |
+
|
45 |
+
<div id="loader">
|
46 |
+
<img src="<?php echo $this->getSkinUrl('images/magentomobileshop/magentomobileshop_loader.gif') ?>"/>
|
47 |
+
</div>
|
48 |
+
<?php
|
49 |
+
|
50 |
+
$order_id = Mage::app()->getRequest()->getParam('orderid');
|
51 |
+
|
52 |
+
if(isset($order_id)):
|
53 |
+
|
54 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
|
55 |
+
if (!$order->getId()):
|
56 |
+
echo "<script type='text/javascript'>location.href ='".
|
57 |
+
Mage::getBaseUrl()."mpaypal/index/failure'</script>";
|
58 |
+
|
59 |
+
exit;
|
60 |
+
endif;
|
61 |
+
|
62 |
+
|
63 |
+
$MERCHANT_EMAIL = Mage::getStoreConfig('magentomobileshop_payment/mpaypal/mpaypal_email');
|
64 |
+
|
65 |
+
|
66 |
+
if(!$MERCHANT_EMAIL):
|
67 |
+
echo "<script type='text/javascript'>location.href ='".
|
68 |
+
Mage::getBaseUrl()."mpaypal/index/failure'</script>";
|
69 |
+
exit;
|
70 |
+
endif;
|
71 |
+
|
72 |
+
if(Mage::getStoreConfig('magentomobileshop_payment/mpaypal/mpaypal_mode')):
|
73 |
+
$PAYPAL_BASE_URL = "https://www.paypal.com/cgi-bin/webscr";
|
74 |
+
else:
|
75 |
+
$PAYPAL_BASE_URL = "https://www.sandbox.paypal.com/cgi-bin/webscr";
|
76 |
+
endif;
|
77 |
+
|
78 |
+
|
79 |
+
?>
|
80 |
+
|
81 |
+
|
82 |
+
<div id="container" style="display: none;" >
|
83 |
+
<h2>Mpaypal Form</h2>
|
84 |
+
|
85 |
+
<form name="paypalForm" action="<?php echo $PAYPAL_BASE_URL; ?>" method='post'>
|
86 |
+
<input type="hidden" name="business" value="<?php echo $MERCHANT_EMAIL?>" />
|
87 |
+
<input type="hidden" name="notify_url" value="<?php echo Mage::getBaseUrl()?>mpaypal/index/ipn" />
|
88 |
+
<input type="hidden" name="cancel_return" value="<?php echo Mage::getBaseUrl()?>mpaypal/index/failure" />
|
89 |
+
<input type="hidden" name="return" value="<?php echo Mage::getBaseUrl()?>mpaypal/index/success" />
|
90 |
+
<input type="hidden" name="return_url" value="<?php echo Mage::getBaseUrl()?>mpaypal/index/success" />
|
91 |
+
<input type="hidden" name="rm" value="2" />
|
92 |
+
|
93 |
+
<input type="hidden" name="lc" value="" />
|
94 |
+
<input type="hidden" name="no_shipping" value="1" />
|
95 |
+
<input type="hidden" name="no_note" value="1" />
|
96 |
+
|
97 |
+
<input type="hidden" name="currency_code" value="<?php echo $order->getOrderCurrencyCode()?>" />
|
98 |
+
<input type="hidden" name="page_style" value="paypal" />
|
99 |
+
<input type="hidden" name="charset" value="utf-8" />
|
100 |
+
<input type="hidden" name="item_name" value="<?php echo $order->getIncrementId() ?>" />
|
101 |
+
|
102 |
+
<input type="hidden" value="_xclick" name="cmd"/>
|
103 |
+
<input type="hidden" name="amount" value="<?php echo sprintf('%0.2f',$order->getGrandTotal())?>" />
|
104 |
+
<input type='submit' name='pay_now' id='pay_now' value='Pay' />
|
105 |
+
</form>
|
106 |
+
|
107 |
+
|
108 |
+
</div>
|
109 |
+
</body>
|
110 |
+
</html>
|
111 |
+
<?php
|
112 |
+
else:
|
113 |
+
echo "<script type='text/javascript'>location.href ='".
|
114 |
+
Mage::getBaseUrl()."mpaypal/index/failure'</script>";
|
115 |
+
exit;
|
116 |
+
endif;
|
117 |
+
?>
|
app/design/frontend/base/default/template/payu/index.phtml
ADDED
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<SCRIPT LANGUAGE="JavaScript">
|
4 |
+
function fnSubmit() {
|
5 |
+
|
6 |
+
window.document.payuForm.submit();
|
7 |
+
return;
|
8 |
+
}
|
9 |
+
</SCRIPT>
|
10 |
+
<style>
|
11 |
+
#loader::after {
|
12 |
+
bottom: 0;
|
13 |
+
content: "Please Wait...";
|
14 |
+
height: 40px;
|
15 |
+
left: 0px;
|
16 |
+
position: absolute;
|
17 |
+
right: 0;
|
18 |
+
text-align: center;
|
19 |
+
top: 58%;
|
20 |
+
}
|
21 |
+
#loader {
|
22 |
+
height: 100%;
|
23 |
+
position: fixed;
|
24 |
+
text-align: center;
|
25 |
+
width: 100%;
|
26 |
+
}
|
27 |
+
#loader img {
|
28 |
+
position: absolute;
|
29 |
+
text-align: center;
|
30 |
+
top: 50%;
|
31 |
+
}
|
32 |
+
#loader img {
|
33 |
+
left: 50%;
|
34 |
+
position: absolute;
|
35 |
+
text-align: center;
|
36 |
+
top: 50%;
|
37 |
+
transform: translate(-50%, -50%);
|
38 |
+
}
|
39 |
+
</style>
|
40 |
+
</head>
|
41 |
+
|
42 |
+
|
43 |
+
<body LANGUAGE="javascript" onload="return fnSubmit()" >
|
44 |
+
|
45 |
+
<div id="loader">
|
46 |
+
<img src="<?php echo $this->getSkinUrl('images/magentomobileshop/magentomobileshop_loader.gif') ?>"/>
|
47 |
+
</div>
|
48 |
+
<?php
|
49 |
+
|
50 |
+
$order_id = Mage::app()->getRequest()->getParam('orderid');
|
51 |
+
|
52 |
+
if(isset($order_id)):
|
53 |
+
|
54 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
|
55 |
+
if (!$order->getId()):
|
56 |
+
echo "<script type='text/javascript'>location.href ='".
|
57 |
+
Mage::getBaseUrl()."payu/index/failure'</script>";
|
58 |
+
|
59 |
+
exit;
|
60 |
+
endif;
|
61 |
+
|
62 |
+
$street = implode($order->getShippingAddress()->getStreet(),',');
|
63 |
+
$contact = $order->getShippingAddress()->getTelephone();
|
64 |
+
$city = $order->getShippingAddress()->getCity();
|
65 |
+
$pincode = $order->getShippingAddress()->getPostcode();
|
66 |
+
$lastname = $order->getShippingAddress()->getLastname();
|
67 |
+
$Country = $order->getShippingAddress()->getCountry_id();
|
68 |
+
$State = $order->getShippingAddress()->getRegion();
|
69 |
+
|
70 |
+
$productinfo= $order->getShippingAddress()->getAddress_type();
|
71 |
+
|
72 |
+
$MERCHANT_KEY = Mage::getStoreConfig('magentomobileshop_payment/payucheckout_shared/payu_key');
|
73 |
+
$SALT = Mage::getStoreConfig('magentomobileshop_payment/payucheckout_shared/payu_salt');
|
74 |
+
|
75 |
+
|
76 |
+
if(Mage::getStoreConfig('magentomobileshop_payment/payucheckout_shared/payu_mode')):
|
77 |
+
$PAYU_BASE_URL = "https://secure.payu.in";
|
78 |
+
else:
|
79 |
+
$PAYU_BASE_URL = "https://test.payu.in";
|
80 |
+
endif;
|
81 |
+
|
82 |
+
$action = '';
|
83 |
+
$posted = array();
|
84 |
+
|
85 |
+
|
86 |
+
$posted['amount'] = $order->getBase_grand_total();
|
87 |
+
$posted['firstname'] = $order->getCustomer_firstname()?$order->getCustomer_firstname():$order->getBillingAddress()->getName();
|
88 |
+
$posted['email'] = $order->getCustomer_email();
|
89 |
+
$posted['phone'] = $order->getShippingAddress()->getTelephone();
|
90 |
+
$posted['productinfo'] = $order_id;
|
91 |
+
$posted['surl'] = $this->getUrl('payu/index/success');
|
92 |
+
$posted['furl'] = $this->getUrl('payu/index/failure');
|
93 |
+
$posted['service_provider'] = 'payu_paisa';
|
94 |
+
$posted['txnid'] = $order_id;
|
95 |
+
$posted['website'] = Mage::getBaseUrl();
|
96 |
+
$posted['lastname']= $order->getShippingAddress()->getLastname();
|
97 |
+
$posted['address1'] = $street;
|
98 |
+
$posted['address2'] = $street;
|
99 |
+
$posted['city'] = $order->getShippingAddress()->getCity();
|
100 |
+
$posted['state'] = $order->getShippingAddress()->getRegion();
|
101 |
+
$posted['country'] = $order->getShippingAddress()->getCountry_id();
|
102 |
+
$posted['zipcode'] = $order->getShippingAddress()->getPostcode();
|
103 |
+
|
104 |
+
|
105 |
+
if(!empty($_POST)):
|
106 |
+
|
107 |
+
foreach($_POST as $key => $value):
|
108 |
+
$posted[$key] = $value;
|
109 |
+
endforeach;
|
110 |
+
endif;
|
111 |
+
|
112 |
+
$formError = 0;
|
113 |
+
if(empty($posted['txnid'])):
|
114 |
+
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
|
115 |
+
else:
|
116 |
+
$txnid = $posted['txnid'];
|
117 |
+
endif;
|
118 |
+
$hash = '';
|
119 |
+
|
120 |
+
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
|
121 |
+
if(empty($posted['hash']) && sizeof($posted) > 0):
|
122 |
+
|
123 |
+
if( empty($posted['key'])
|
124 |
+
|| empty($posted['txnid'])
|
125 |
+
|| empty($posted['amount'])
|
126 |
+
|| empty($posted['firstname'])
|
127 |
+
|| empty($posted['email'])
|
128 |
+
|| empty($posted['phone'])
|
129 |
+
|| empty($posted['productinfo'])
|
130 |
+
|| empty($posted['surl'])
|
131 |
+
|| empty($posted['furl'])
|
132 |
+
|| empty($posted['service_provider'])
|
133 |
+
):
|
134 |
+
$formError = 1;
|
135 |
+
else:
|
136 |
+
|
137 |
+
$hashVarsSeq = explode('|', $hashSequence);
|
138 |
+
$hash_string = '';
|
139 |
+
foreach($hashVarsSeq as $hash_var):
|
140 |
+
$hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
|
141 |
+
$hash_string .= '|';
|
142 |
+
endforeach;
|
143 |
+
|
144 |
+
$hash_string .= $SALT;
|
145 |
+
$hash = strtolower(hash('sha512', $hash_string));
|
146 |
+
$action = $PAYU_BASE_URL . '/_payment.php';
|
147 |
+
endif;
|
148 |
+
elseif(!empty($posted['hash'])):
|
149 |
+
$hash = $posted['hash'];
|
150 |
+
$action = $PAYU_BASE_URL . '/_payment.php';
|
151 |
+
endif;
|
152 |
+
|
153 |
+
|
154 |
+
?>
|
155 |
+
|
156 |
+
|
157 |
+
<div id="container" style="display: none;" >
|
158 |
+
<h2>PayU Form</h2>
|
159 |
+
|
160 |
+
<form action="<?php echo $action; ?>" method="post" name="payuForm">
|
161 |
+
<input type="text" name="key" value="<?php echo $MERCHANT_KEY ?>" />
|
162 |
+
<input type="text" name="hash" value="<?php echo $hash ?>"/>
|
163 |
+
<input type="text" name="txnid" value="<?php echo $txnid ?>" />
|
164 |
+
<table>
|
165 |
+
<tr>
|
166 |
+
<td><b>Mandatory Parameters</b></td>
|
167 |
+
</tr>
|
168 |
+
<tr>
|
169 |
+
<td>Amount: </td>
|
170 |
+
<td><input name="amount" value="<?php echo (empty($posted['amount'])) ? '' : $posted['amount']; ?>" /></td>
|
171 |
+
<td>First Name: </td>
|
172 |
+
<td><input name="firstname" id="firstname" value="<?php echo (empty($posted['firstname'])) ? '' : $posted['firstname']; ?>" /></td>
|
173 |
+
</tr>
|
174 |
+
<tr>
|
175 |
+
<td>Email: </td>
|
176 |
+
<td><input name="email" id="email" value="<?php echo (empty($posted['email'])) ? '' : $posted['email']; ?>" /></td>
|
177 |
+
<td>Phone: </td>
|
178 |
+
<td><input name="phone" value="<?php echo (empty($posted['phone'])) ? '' : $posted['phone']; ?>" /></td>
|
179 |
+
</tr>
|
180 |
+
<tr>
|
181 |
+
<td>Product Info: </td>
|
182 |
+
<td colspan="3"><textarea name="productinfo"><?php echo (empty($posted['productinfo'])) ? '' : $posted['productinfo'] ?></textarea></td>
|
183 |
+
</tr>
|
184 |
+
<tr>
|
185 |
+
<td>Success URI: </td>
|
186 |
+
<td colspan="3"><input name="surl" value="<?php echo (empty($posted['surl'])) ? '' : $posted['surl'] ?>" size="64" /></td>
|
187 |
+
</tr>
|
188 |
+
<tr>
|
189 |
+
<td>Failure URI: </td>
|
190 |
+
<td colspan="3"><input name="furl" value="<?php echo (empty($posted['furl'])) ? '' : $posted['furl'] ?>" size="64" /></td>
|
191 |
+
</tr>
|
192 |
+
|
193 |
+
<tr>
|
194 |
+
<td>Service Provider: </td>
|
195 |
+
<td colspan="3"><input name="service_provider" value="<?php echo (empty($posted['service_provider'])) ? '' : $posted['service_provider'] ?>" size="64" /></td>
|
196 |
+
</tr>
|
197 |
+
|
198 |
+
|
199 |
+
<input name="service_provider" value="<?php echo (empty($posted['txnid'])) ? '' : $posted['txnid'] ?>" size="64" />
|
200 |
+
<input name="service_provider" value="<?php echo (empty($posted['website'])) ? '' : $posted['website'] ?>" size="64" />
|
201 |
+
|
202 |
+
|
203 |
+
|
204 |
+
<tr>
|
205 |
+
<td><b>Optional Parameters</b></td>
|
206 |
+
</tr>
|
207 |
+
<tr>
|
208 |
+
<td>Last Name: </td>
|
209 |
+
<td><input name="lastname" id="lastname" value="<?php echo (empty($posted['lastname'])) ? '' : $posted['lastname']; ?>" /></td>
|
210 |
+
<td>Cancel URI: </td>
|
211 |
+
<td><input name="curl" value="" /></td>
|
212 |
+
</tr>
|
213 |
+
<tr>
|
214 |
+
<td>Address1: </td>
|
215 |
+
<td><input name="address1" value="<?php echo (empty($posted['address1'])) ? '' : $posted['address1']; ?>" /></td>
|
216 |
+
<td>Address2: </td>
|
217 |
+
<td><input name="address2" value="<?php echo (empty($posted['address2'])) ? '' : $posted['address1']; ?>" /></td>
|
218 |
+
</tr>
|
219 |
+
<tr>
|
220 |
+
<td>City: </td>
|
221 |
+
<td><input name="city" value="<?php echo (empty($posted['city'])) ? '' : $posted['city']; ?>" /></td>
|
222 |
+
<td>State: </td>
|
223 |
+
<td><input name="state" value="<?php echo (empty($posted['state'])) ? '' : $posted['state']; ?>" /></td>
|
224 |
+
</tr>
|
225 |
+
<tr>
|
226 |
+
<td>Country: </td>
|
227 |
+
<td><input name="country" value="<?php echo (empty($posted['country'])) ? '' : $posted['country']; ?>" /></td>
|
228 |
+
<td>Zipcode: </td>
|
229 |
+
<td><input name="zipcode" value="<?php echo (empty($posted['zipcode'])) ? '' : $posted['zipcode']; ?>" /></td>
|
230 |
+
</tr>
|
231 |
+
<tr>
|
232 |
+
<td>UDF1: </td>
|
233 |
+
<td><input name="udf1" value="<?php echo (empty($posted['udf1'])) ? '' : $posted['udf1']; ?>" /></td>
|
234 |
+
<td>UDF2: </td>
|
235 |
+
<td><input name="udf2" value="<?php echo (empty($posted['udf2'])) ? '' : $posted['udf2']; ?>" /></td>
|
236 |
+
</tr>
|
237 |
+
<tr>
|
238 |
+
<td>UDF3: </td>
|
239 |
+
<td><input name="udf3" value="<?php echo (empty($posted['udf3'])) ? '' : $posted['udf3']; ?>" /></td>
|
240 |
+
<td>UDF4: </td>
|
241 |
+
<td><input name="udf4" value="<?php echo (empty($posted['udf4'])) ? '' : $posted['udf4']; ?>" /></td>
|
242 |
+
</tr>
|
243 |
+
<tr>
|
244 |
+
<td>UDF5: </td>
|
245 |
+
<td><input name="udf5" value="<?php echo (empty($posted['udf5'])) ? '' : $posted['udf5']; ?>" /></td>
|
246 |
+
<td>PG: </td>
|
247 |
+
<td><input name="pg" value="<?php echo (empty($posted['pg'])) ? '' : $posted['pg']; ?>" /></td>
|
248 |
+
</tr>
|
249 |
+
<tr>
|
250 |
+
|
251 |
+
<td colspan="4"><input type="submit" value="Submit" /></td>
|
252 |
+
|
253 |
+
</tr>
|
254 |
+
</table>
|
255 |
+
</form>
|
256 |
+
</div>
|
257 |
+
</body>
|
258 |
+
</html>
|
259 |
+
<?php
|
260 |
+
else:
|
261 |
+
echo "<script type='text/javascript'>location.href ='".
|
262 |
+
Mage::getBaseUrl()."payu/index/failure'</script>";
|
263 |
+
exit;
|
264 |
+
endif;
|
265 |
+
?>
|
app/design/frontend/base/default/template/payu/test.phtml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<SCRIPT LANGUAGE="JavaScript">
|
2 |
+
function fnSubmit() {
|
3 |
+
window.document.payuForm.submit();
|
4 |
+
return;
|
5 |
+
}
|
6 |
+
</SCRIPT>
|
7 |
+
<body LANGUAGE="javascript" onload="return fnSubmit()" style="display: none;">
|
8 |
+
<form action="<?php echo $this->getUrl('payu/index/success') ?>" method="post" name="payuForm">
|
9 |
+
</form>
|
10 |
+
</body>
|
app/etc/modules/Mss_Bannerslider.xml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Mss
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Mss.com license that is
|
9 |
+
* available through the world-wide-web at this URL:
|
10 |
+
* http://www.mss.com/license-agreement.html
|
11 |
+
*
|
12 |
+
* DISCLAIMER
|
13 |
+
*
|
14 |
+
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
15 |
+
* version in the future.
|
16 |
+
*
|
17 |
+
* @category Mss
|
18 |
+
* @package Mss_Bannerslider
|
19 |
+
* @copyright Copyright (c) 2012 Mss (http://www.mss.com/)
|
20 |
+
* @license http://www.mss.com/license-agreement.html
|
21 |
+
*/
|
22 |
+
-->
|
23 |
+
<config>
|
24 |
+
<modules>
|
25 |
+
<Mss_Bannerslider>
|
26 |
+
<active>true</active>
|
27 |
+
<codePool>local</codePool>
|
28 |
+
</Mss_Bannerslider>
|
29 |
+
</modules>
|
30 |
+
</config>
|
app/etc/modules/Mss_Connector.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version = "1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Connector>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
</Mss_Connector>
|
8 |
+
</modules>
|
9 |
+
</config>
|
app/etc/modules/Mss_Mpaypal.xml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Mpaypal>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
|
8 |
+
<depends>
|
9 |
+
<Mage_Payment />
|
10 |
+
</depends>
|
11 |
+
</Mss_Mpaypal>
|
12 |
+
</modules>
|
13 |
+
</config>
|
app/etc/modules/Mss_Payu.xml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Payu>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
<version>0.1.0</version>
|
8 |
+
</Mss_Payu>
|
9 |
+
</modules>
|
10 |
+
</config>
|
app/etc/modules/Mss_Pushnotification.xml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Pushnotification>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
<version>0.1.0</version>
|
8 |
+
</Mss_Pushnotification>
|
9 |
+
</modules>
|
10 |
+
</config>
|
app/etc/modules/Mss_Sociallogin.xml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Mss_Sociallogin>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
<version>0.1.0</version>
|
8 |
+
</Mss_Sociallogin>
|
9 |
+
</modules>
|
10 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Mss_Connector</name>
|
4 |
+
<version>1.4.5</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>OSL v1.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Mobile app for Android and Iphone</summary>
|
10 |
+
<description>Mobile app for Android and Iphone</description>
|
11 |
+
<notes>Product caching added to load product more faster.</notes>
|
12 |
+
<authors><author><name>mss</name><user>mss</user><email>mss.yogendra@gmail.com</email></author></authors>
|
13 |
+
<date>2016-03-16</date>
|
14 |
+
<time>13:51:11</time>
|
15 |
+
<contents><target name="magelocal"><dir name="Mss"><dir name="Bannerslider"><dir name="Block"><dir name="Adminhtml"><dir name="Bannerslider"><dir name="Edit"><file name="Form.php" hash="e3aac16542691916765e57238b3679a5"/><dir name="Tab"><file name="Form.php" hash="2aa3ba5ce44ad1ce15393b208008a4f4"/></dir><file name="Tabs.php" hash="d9421ac78bfe2f678b7514e6eea19ade"/></dir><file name="Edit.php" hash="9bca5bea62d4cedb8e458022fa683f92"/><file name="Grid.php" hash="8243e69694f860a3be9b4b2447b04843"/><dir name="Helper"><file name="Image.php" hash="f468b25e5344015483e0519da10bdd43"/></dir></dir><file name="Grid.php" hash="fbf2ede9f191ff040fa7b21e98ac440d"/><dir name="Renderer"><file name="Image.php" hash="451a2fc188826a8cbaee1ea6fc692435"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="5c691c3ae014305937e38418706c1c66"/></dir><dir name="Model"><file name="Bannerslider.php" hash="cd768d1bc28ed0a4c1d65d148252227d"/><dir name="Mysql4"><dir name="Bannerslider"><file name="Collection.php" hash="564694cc9b21e2e0a3c5202a6cc2eb99"/></dir><file name="Bannerslider.php" hash="46fc65447f3e41dbbe6194ddf9395e45"/></dir><file name="Observer.php" hash="b3bfac53fe96e0b10ddfeb8eed5bafd0"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="BannersliderController.php" hash="d06ad8e6fd2c82a6c483e0a7246f985e"/></dir><file name="BannerController.php" hash="c3f2cc84c3199eeb47b647b0f4e453d7"/></dir><dir name="etc"><file name="adminhtml.xml" hash="31787cf6a7b306a7fbc8522d8933473c"/><file name="config.xml" hash="34154e2434504e7c0769776199a2cc82"/></dir><dir name="sql"><dir name="bannerslider_setup"><file name="mysql4-install-0.1.0.php" hash="d668f47b50c8910ad91e802afc718ba7"/></dir></dir></dir><dir name="Connector"><dir name="Block"><dir name="Adminhtml"><file name="Notifications.php" hash="6f24014b5a24a4f56410e9754b8aa2d5"/></dir><dir name="System"><dir name="Config"><file name="About.php" hash="2e9dc040ee2d42a57d5c9411f0b999e4"/><file name="Authorizenet.php" hash="ed644e9814fef74147bdddf24cfd75c1"/><file name="Banktransfer.php" hash="77f6ebf2074462cdadf4bccbe2f0d19a"/><file name="Checkmo.php" hash="edfc0fc0b233cd349392e563eeac57ed"/><file name="Cod.php" hash="37d1757764340fd02b8be7ac32434967"/><file name="Mpaypal.php" hash="e69d6a2d58618cf741d4cf503ede70ca"/><file name="Payu.php" hash="d0307013bdf58700a29aa7838ee94e51"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="141759dea4d79d818c52231fe75f0686"/></dir><dir name="Model"><file name="Connector.php" hash="e9a927bc0a5974d092ab3af257ee7607"/><dir name="Mysql4"><dir name="Connector"><file name="Collection.php" hash="1f3bb37f160abdf974859f7419a19b65"/></dir><file name="Connector.php" hash="185189264d3275af813349e721ee46fb"/></dir><file name="Observer.php" hash="ae15112ec2d336596fdcce34932805b0"/></dir><dir name="controllers"><file name="CartController.php" hash="7a71fab75c3822c158090a8f44c54e95"/><file name="CreditController.php" hash="fb099f5c645b2008bf058b8e22f7b1ec"/><file name="CustomerController.php" hash="46351cd896aa3c983b681ba58312c7d8"/><file name="FeedbackController.php" hash="89517e40acba9d69cd15ff5ea304da79"/><file name="IndexController.php" hash="176b20d09b3001d26072369b7508a768"/><file name="ItemController.php" hash="698151aa101aec7e80e3f050ce51dc85"/><file name="ItemsController.php" hash="88e5703407cc970c98698419915393f2"/><file name="MenuController.php" hash="63a3ae898fa75e4755d06bd2ddb592e1"/><file name="ProductsController.php" hash="f693df70aa9071bd46ada0af96c61f48"/><file name="SearchController.php" hash="5d1d8975f7a3351d5833c6ad08ecf52b"/><file name="StaticpagesController.php" hash="2c593c6e2328512e2ee966119e18ba44"/><file name="StoreController.php" hash="86b038731080c68ae1e567958b36895c"/><file name="StoreinfoController.php" hash="f37535c137f93dbb8d2eaab9f2f67865"/><file name="TokenController.php" hash="5df87c80c3a9a4832d0ce3580d65dff8"/><file name="WishlistController.php" hash="9a72d73131b3ff380b53ca54fc8361f8"/><file name="_new_ProductsController.php" hash="08523bd31a97f2018cb08f31dfce005d"/></dir><dir name="etc"><file name="adminhtml.xml" hash="77dc75e2c5e73755764a79e08cc7c668"/><file name="config.xml" hash="4b0f127cd01463a6962ef751dd41c86b"/><file name="system.xml" hash="40b6555fa986d797ad206d674204e477"/></dir><dir name="sql"><dir name="connector_setup"><file name="mysql4-install-0.1.0.php" hash="4325ba30b21f9680b11d4b124b9e8181"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="eaa00e880b38ba41580b67785b33ed10"/></dir></dir></dir><dir name="Mpaypal"><dir name="Helper"><file name="Data.php" hash="c3ba57e7cc86210346b1b3f279083c0f"/></dir><dir name="Model"><file name="Mpaypal.php" hash="f49b32aad7d7bed49333534139fd07b7"/><file name="Observer.php" hash="4b92aaf547f0b080d8495cf064574d10"/></dir><dir name="controllers"><file name="IndexController.php" hash="4db5576f750fdf7b1b8b441ddaad9c8b"/></dir><dir name="etc"><file name="config.xml" hash="9ed76ff53b5e0232b4ea442a7e046b14"/><file name="system.xml" hash="2f51ad686858a69e07e8c21baf5d690e"/></dir></dir><dir name="Payu"><dir name="Block"><file name="Index.php" hash="db5ffd63f6cbb9f3320fde4829fcad35"/></dir><dir name="Helper"><file name="Data.php" hash="7800e0e58258b78d0f23a7fec482d120"/></dir><dir name="controllers"><file name="IndexController.php" hash="639ed0868e2a6b1bdbf6444f87565565"/></dir><dir name="etc"><file name="config.xml" hash="c6867fb0cc7efdde39c32a3ecbf62433"/></dir></dir><dir name="Pushnotification"><dir name="Block"><dir name="Adminhtml"><file name="Pushnotificationbackend.php" hash="6b9e143ee7b5fe4fc2642eee977b44bf"/></dir></dir><dir name="Helper"><file name="Data.php" hash="cad971167c1b59a1fdbd967132c61899"/></dir><dir name="Model"><dir name="Entity"><file name="Resource.php" hash="93b6a261762541433fa601aefb60d0a7"/></dir><dir name="Mysql4"><dir name="Pushnotification"><file name="Collection.php" hash="392612adedcb14ec5dcaaa4ea9858091"/></dir><file name="Pushnotification.php" hash="77f6cadb7682377a1de6b275310c1cf6"/></dir><file name="Pushnotification.php" hash="ad5fe0f74049c61402ff99fc32d8164a"/><dir name="System"><dir name="Config"><dir name="Backend"><file name="File.php" hash="d7c74e49b78bb9da3453bd5f414a445f"/><file name="Image.php" hash="e1d98dbf511fe16581b37a8b7b43f5b4"/><file name="Iosmode.php" hash="ff1794ef4844019b7af64192fbd4e122"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="PushnotificationbackendController.php" hash="ec4ebd0ad1cfee78d2e67a69698a14e5"/></dir></dir><dir name="etc"><file name="config.xml" hash="f62215f94167b81c5f73aea794a334c4"/><file name="system.xml" hash="a1c7c7ff8ba587ddafc61cd0fd798c7c"/></dir><dir name="sql"><dir name="pushnotification_setup"><file name="mysql4-upgrade-0.1.5-0.1.6.php" hash="418e997bb72afa725389593d4ca2f111"/></dir></dir></dir><dir name="Sociallogin"><dir name="Helper"><file name="Data.php" hash="c5da50448c589d47251ff4e731c7be26"/></dir><dir name="Model"><dir name="Mysql4"><file name="Sociallogin.php" hash="b881bc47c5ee70b1c4c02b59501ffbc5"/></dir><file name="Sociallogin.php" hash="0ba90dadb0f34528c2296704c5cea233"/></dir><dir name="etc"><file name="config.xml" hash="eac1dc2364bc283a9cd5326eb7e852a9"/></dir><dir name="sql"><dir name="sociallogin_setup"><file name="mysql4-install-0.1.0.php" hash="163332cb130dae297af332cbefde58f3"/></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="pushnotification"><file name="pushnotificationbackend.phtml" hash="138add7171fdd7fb326abc4a4f9dbe5a"/></dir><dir name="connector"><file name="notification.phtml" hash="164e5f9e7dcfc5c2d2451f0e77776d77"/></dir></dir><dir name="layout"><file name="bannerslider.xml" hash="a5a76f30bbedca5804646d53e783cdac"/><file name="pushnotification.xml" hash="f7fd974e63c4c7eb5ffac7b059470946"/><file name="connector.xml" hash="97cea6186b75948e6ed0d71da7b48710"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="payu.xml" hash="473595488f536cb588c5588a744915a3"/><file name="mpaypal.xml" hash="7b75c5bed6f3142c8bc9e4c1233bf1e9"/></dir><dir name="template"><dir name="payu"><file name="index.phtml" hash="5f54a8eb245364534e7695b1a8fcbf30"/><file name="test.phtml" hash="da4701ff5b2c64444a49f77571e8a00c"/></dir><dir name="mpaypal"><file name="index.phtml" hash="df077c063b2006b9321c96cd6744b19f"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Mss_Bannerslider.xml" hash="7d03ee71d8e860c51478aff5200b0deb"/><file name="Mss_Connector.xml" hash="ba8a5609c9c8c3636f183c5bfe04d664"/><file name="Mss_Payu.xml" hash="5feac03d698b481473223fbe6a8814b1"/><file name="Mss_Pushnotification.xml" hash="2e8e9bc56a5f0ff8bb42f43fb5a3a3db"/><file name="Mss_Sociallogin.xml" hash="8671199bdad3bdecbfe0c47ce9ff05e6"/><file name="Mss_Mpaypal.xml" hash="4d6a7f8d862de8c449b1366727ef0a6d"/></dir></dir></target><target name="mageskin"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="magentomobileshop"><file name="magentomobileshop_loader.gif" hash="453272c9cacd32efe6465961ea8a61dd"/></dir></dir></dir></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.3.0</min><max>7.0.5</max></php></required></dependencies>
|
18 |
+
</package>
|
skin/frontend/base/default/images/magentomobileshop/magentomobileshop_loader.gif
ADDED
Binary file
|