zinc - Version 1.0.3

Version Notes

Zinc allows merchants to display warranty and product protection quotes next to the product being sold. Customers can add those policies to their purchases at point of sale, and Zinc follow up to complete the sale. Merchants earn additional margin while Zinc takes care of all the heavy lifting to execute the contract and handle the claims.

Download this release

Release Info

Developer ZincPlatform
Extension zinc
Version 1.0.3
Comparing to
See all releases


Version 1.0.3

Files changed (77) hide show
  1. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Grid.php +88 -0
  2. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/Category.php +38 -0
  3. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Order.php +18 -0
  4. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Order/Grid.php +102 -0
  5. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product.php +18 -0
  6. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit.php +29 -0
  7. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Form.php +24 -0
  8. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Tab/Form.php +91 -0
  9. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Tabs.php +29 -0
  10. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Grid.php +144 -0
  11. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/System/Config/Tokenvalidate.php +56 -0
  12. app/code/local/Zinc/Carebyzinc/Block/Carebyzinc.php +23 -0
  13. app/code/local/Zinc/Carebyzinc/Helper/Data.php +60 -0
  14. app/code/local/Zinc/Carebyzinc/Model/Carebyzinc.php +235 -0
  15. app/code/local/Zinc/Carebyzinc/Model/Checkout/Cart.php +158 -0
  16. app/code/local/Zinc/Carebyzinc/Model/Entity/Category.php +17 -0
  17. app/code/local/Zinc/Carebyzinc/Model/Entity/Subcategory.php +18 -0
  18. app/code/local/Zinc/Carebyzinc/Model/Mysql4/Order.php +14 -0
  19. app/code/local/Zinc/Carebyzinc/Model/Mysql4/Order/Collection.php +15 -0
  20. app/code/local/Zinc/Carebyzinc/Model/Observer.php +47 -0
  21. app/code/local/Zinc/Carebyzinc/Model/Order.php +114 -0
  22. app/code/local/Zinc/Carebyzinc/Model/Sales/Quote.php +31 -0
  23. app/code/local/Zinc/Carebyzinc/Model/System/Config/Source.php +23 -0
  24. app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/CarebyzincController.php +25 -0
  25. app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/OrderController.php +25 -0
  26. app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/ProductController.php +174 -0
  27. app/code/local/Zinc/Carebyzinc/controllers/CartController.php +251 -0
  28. app/code/local/Zinc/Carebyzinc/controllers/IndexController.php +152 -0
  29. app/code/local/Zinc/Carebyzinc/etc/adminhtml.xml +59 -0
  30. app/code/local/Zinc/Carebyzinc/etc/config.xml +173 -0
  31. app/code/local/Zinc/Carebyzinc/etc/system.xml +141 -0
  32. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-install-0.1.0.php +32 -0
  33. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-0.1.0-0.2.0.php +30 -0
  34. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-0.2.0-1.0.0.php +23 -0
  35. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-1.0.0-1.0.1.php +34 -0
  36. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-1.0.1-1.0.2.php +23 -0
  37. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-1.0.2-1.0.3.php +49 -0
  38. app/design/adminhtml/default/default/layout/zinc_carebyzinc.xml +107 -0
  39. app/design/adminhtml/default/default/template/carebyzinc/order/creditmemo/create/items/renderer/default.phtml +261 -0
  40. app/design/adminhtml/default/default/template/carebyzinc/order/creditmemo/view/items/renderer/default.phtml +262 -0
  41. app/design/adminhtml/default/default/template/carebyzinc/order/invoice/create/items/renderer/default.phtml +257 -0
  42. app/design/adminhtml/default/default/template/carebyzinc/order/invoice/view/items/renderer/default.phtml +249 -0
  43. app/design/adminhtml/default/default/template/carebyzinc/order/shipment/create/items/renderer/default.phtml +62 -0
  44. app/design/adminhtml/default/default/template/carebyzinc/order/shipment/view/items/renderer/default.phtml +48 -0
  45. app/design/adminhtml/default/default/template/carebyzinc/order/view/items/renderer/default.phtml +256 -0
  46. app/design/adminhtml/default/default/template/carebyzinc/system/tokenvalidate.phtml +18 -0
  47. app/design/frontend/base/default/layout/zinc_carebyzinc.xml +346 -0
  48. app/design/frontend/base/default/template/carebyzinc/carebyzinc.phtml +86 -0
  49. app/design/frontend/base/default/template/carebyzinc/checkout/cart.phtml +246 -0
  50. app/design/frontend/base/default/template/carebyzinc/checkout/cart/item/default.phtml +418 -0
  51. app/design/frontend/base/default/template/carebyzinc/checkout/cart/item/default.phtml-10-08-2016 +415 -0
  52. app/design/frontend/base/default/template/carebyzinc/checkout/cart/minicart/default.phtml +220 -0
  53. app/design/frontend/base/default/template/carebyzinc/checkout/multishipping/item/default.phtml +62 -0
  54. app/design/frontend/base/default/template/carebyzinc/checkout/onepage/review/item.phtml +260 -0
  55. app/design/frontend/base/default/template/carebyzinc/email/order/items/creditmemo/default.phtml +137 -0
  56. app/design/frontend/base/default/template/carebyzinc/email/order/items/invoice/default.phtml +138 -0
  57. app/design/frontend/base/default/template/carebyzinc/email/order/items/order/default.phtml +150 -0
  58. app/design/frontend/base/default/template/carebyzinc/email/order/items/shipment/default.phtml +60 -0
  59. app/design/frontend/base/default/template/carebyzinc/options/cart.phtml +31 -0
  60. app/design/frontend/base/default/template/carebyzinc/options/default.phtml +39 -0
  61. app/design/frontend/base/default/template/carebyzinc/sales/order/creditmemo/items/renderer/default.phtml +346 -0
  62. app/design/frontend/base/default/template/carebyzinc/sales/order/invoice/items/renderer/default.phtml +347 -0
  63. app/design/frontend/base/default/template/carebyzinc/sales/order/items/renderer/default.phtml +341 -0
  64. app/design/frontend/base/default/template/carebyzinc/sales/order/shipment/items/renderer/default.phtml +79 -0
  65. app/etc/modules/Zinc_Carebyzinc.xml +9 -0
  66. js/carebyzinc/jquery.colorbox.js +1105 -0
  67. js/carebyzinc/product.js +812 -0
  68. package.xml +18 -0
  69. skin/frontend/base/default/carebyzinc/css/carebyzinc.css +101 -0
  70. skin/frontend/base/default/carebyzinc/css/colorbox.css +71 -0
  71. skin/frontend/base/default/carebyzinc/css/images/border.png +0 -0
  72. skin/frontend/base/default/carebyzinc/css/images/cancel.png +0 -0
  73. skin/frontend/base/default/carebyzinc/css/images/care-preloader.gif +0 -0
  74. skin/frontend/base/default/carebyzinc/css/images/controls.png +0 -0
  75. skin/frontend/base/default/carebyzinc/css/images/loading.gif +0 -0
  76. skin/frontend/base/default/carebyzinc/css/images/loading_background.png +0 -0
  77. skin/frontend/base/default/carebyzinc/css/images/overlay.png +0 -0
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Grid.php ADDED
@@ -0,0 +1,88 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
9
+ {
10
+
11
+ public function setCollection($collection)
12
+ {
13
+ //$collection->addAttributeToSelect('carebyzinc');
14
+ $collection->addExpressionAttributeToSelect('carebyzinc','round({{carebyzinc}},0)','carebyzinc');
15
+ parent::setCollection($collection);
16
+ }
17
+
18
+ protected function _prepareColumns()
19
+ {
20
+
21
+ $this->addColumnAfter('carebyzinc',
22
+ array(
23
+ 'header'=> Mage::helper('catalog')->__('Care by Zinc'),
24
+ 'width' => '70px',
25
+ 'index' => 'carebyzinc',
26
+ 'type' => 'options',
27
+ 'options' => array('1' => 'Enabled', '0' => 'Disabled'),
28
+ ), 'visibility');
29
+
30
+ return parent::_prepareColumns();
31
+ }
32
+
33
+ protected function _prepareMassaction()
34
+ {
35
+ $this->setMassactionIdField('entity_id');
36
+ $this->getMassactionBlock()->setFormFieldName('product');
37
+
38
+ $this->getMassactionBlock()->addItem('delete', array(
39
+ 'label'=> Mage::helper('catalog')->__('Delete'),
40
+ 'url' => $this->getUrl('*/*/massDelete'),
41
+ 'confirm' => Mage::helper('catalog')->__('Are you sure?')
42
+ ));
43
+
44
+ $statuses = Mage::getSingleton('catalog/product_status')->getOptionArray();
45
+
46
+ array_unshift($statuses, array('label'=>'', 'value'=>''));
47
+ $this->getMassactionBlock()->addItem('status', array(
48
+ 'label'=> Mage::helper('catalog')->__('Change status'),
49
+ 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
50
+ 'additional' => array(
51
+ 'visibility' => array(
52
+ 'name' => 'status',
53
+ 'type' => 'select',
54
+ 'class' => 'required-entry',
55
+ 'label' => Mage::helper('catalog')->__('Status'),
56
+ 'values' => $statuses
57
+ )
58
+ )
59
+ ));
60
+
61
+ $carebyzinc = Mage::getSingleton('carebyzinc/carebyzinc')->getOptionArray();
62
+
63
+ $this->getMassactionBlock()->addItem('zinc_carebyzinc', array(
64
+ 'label'=> Mage::helper('carebyzinc')->__('Change Carebyzinc'),
65
+ 'url' => $this->getUrl('adminhtml/product/massCarebyzinc', array('_current'=>true)),
66
+ 'additional' => array(
67
+ 'visibility' => array(
68
+ 'name' => 'zinc_carebyzinc',
69
+ 'type' => 'select',
70
+ 'class' => 'required-entry',
71
+ 'label' => Mage::helper('carebyzinc')->__('Care by Zinc'),
72
+ 'values' => $carebyzinc
73
+ )
74
+ )
75
+ ));
76
+
77
+ if (Mage::getSingleton('admin/session')->isAllowed('catalog/update_attributes')){
78
+ $this->getMassactionBlock()->addItem('attributes', array(
79
+ 'label' => Mage::helper('catalog')->__('Update Attributes'),
80
+ 'url' => $this->getUrl('*/catalog_product_action_attribute/edit', array('_current'=>true))
81
+ ));
82
+ }
83
+
84
+ Mage::dispatchEvent('adminhtml_catalog_product_grid_prepare_massaction', array('block' => $this));
85
+ return $this;
86
+ }
87
+
88
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/Category.php ADDED
@@ -0,0 +1,38 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ class Zinc_Carebyzinc_Block_Adminhtml_Catalog_Product_Renderer_Category extends Varien_Data_Form_Element_Select
10
+ {
11
+ public function getAfterElementHtml()
12
+ {
13
+ $html = parent::getAfterElementHtml();
14
+
15
+ return $html."<script>
16
+ document.getElementById('carebyzinc_category').onchange = function() {getSubcategories(this.value)};
17
+
18
+ function getSubcategories(selectElement){
19
+ var reloadurl = '". Mage::getUrl('adminhtml/product/getSubcategories')."';
20
+ if(selectElement){
21
+ new Ajax.Request(reloadurl, {parameters: { cat: selectElement},
22
+ method: 'post',
23
+ onComplete: function(transport) {
24
+ var content = JSON.parse(transport.responseText);
25
+ var i = 0;
26
+ for (var key in content) {
27
+ document.getElementById('carebyzinc_subcategory').options[i] = new Option(content[key],content[key]);
28
+ i++;
29
+ }
30
+
31
+ }
32
+ });
33
+ }else
34
+ document.getElementById('carebyzinc_subcategory').innerHTML='';
35
+ }</script>";
36
+
37
+ }
38
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Order.php ADDED
@@ -0,0 +1,18 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Adminhtml_Order extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ $this->_controller = 'adminhtml_order';
13
+ $this->_blockGroup = 'carebyzinc';
14
+ $this->_headerText = Mage::helper('carebyzinc')->__('Care by Zinc Orders');
15
+ parent::__construct();
16
+ $this->_removeButton('add');
17
+ }
18
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Order/Grid.php ADDED
@@ -0,0 +1,102 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
9
+ {
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+ $this->setId('orderGrid');
15
+ $this->setDefaultSort('id');
16
+ $this->setDefaultDir('DESC');
17
+ $this->setSaveParametersInSession(true);
18
+ }
19
+
20
+ protected function _prepareCollection()
21
+ {
22
+ $collection = Mage::getModel('carebyzinc/order')->getCollection();
23
+ $this->setCollection($collection);
24
+ return parent::_prepareCollection();
25
+ }
26
+
27
+ protected function _prepareColumns()
28
+ {
29
+ $this->addColumn('id', array(
30
+ 'header' => Mage::helper('carebyzinc')->__('ID'),
31
+ 'align' =>'right',
32
+ 'width' => '50px',
33
+ 'index' => 'id',
34
+ ));
35
+
36
+ $this->addColumn('order_id', array(
37
+ 'header' => Mage::helper('carebyzinc')->__('Order ID'),
38
+ 'align' =>'right',
39
+ 'width' => '50px',
40
+ 'index' => 'order_inc_id',
41
+ ));
42
+
43
+ $this->addColumn('product_id', array(
44
+ 'header' => Mage::helper('carebyzinc')->__('Product ID'),
45
+ 'align' =>'right',
46
+ 'width' => '50px',
47
+ 'index' => 'product_id',
48
+ ));
49
+
50
+ $this->addColumn('product_name', array(
51
+ 'header' => Mage::helper('carebyzinc')->__('Product'),
52
+ 'align' =>'left',
53
+ 'index' => 'product_name',
54
+ ));
55
+ $this->addColumn('price', array(
56
+ 'header' => Mage::helper('carebyzinc')->__('Price'),
57
+ 'align' =>'left',
58
+ 'index' => 'product_price',
59
+ ));
60
+ $this->addColumn('warrenty_price', array(
61
+ 'header' => Mage::helper('carebyzinc')->__('Warrenty Price'),
62
+ 'align' =>'left',
63
+ 'index' => 'warrenty_price',
64
+ ));
65
+
66
+ $this->addColumn('customer_name', array(
67
+ 'header' => Mage::helper('carebyzinc')->__('Customer Name'),
68
+ 'align' =>'left',
69
+ 'index' => 'customer_name',
70
+ ));
71
+
72
+ $this->addColumn('customer_email', array(
73
+ 'header' => Mage::helper('carebyzinc')->__('Email'),
74
+ 'align' =>'left',
75
+ 'index' => 'customer_email',
76
+ ));
77
+
78
+ $this->addColumn('carebyzinc_key', array(
79
+ 'header' => Mage::helper('carebyzinc')->__('Care by Zinc Key'),
80
+ 'align' =>'right',
81
+ 'index' => 'carebyzinc_key',
82
+ ));
83
+
84
+ $this->addColumn('carebyzinc_provider', array(
85
+ 'header' => Mage::helper('carebyzinc')->__('Provider'),
86
+ 'align' =>'left',
87
+ 'index' => 'carebyzinc_provider',
88
+ ));
89
+
90
+ return parent::_prepareColumns();
91
+ }
92
+
93
+ public function getRowUrl($row)
94
+ {
95
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
96
+ return $this->getUrl('*/sales_order/view', array('order_id' => $row->getOrderId()));
97
+ }
98
+ return false;
99
+ }
100
+
101
+
102
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product.php ADDED
@@ -0,0 +1,18 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Adminhtml_Product extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ $this->_controller = 'adminhtml_product';
13
+ $this->_blockGroup = 'carebyzinc';
14
+ $this->_headerText = Mage::helper('carebyzinc')->__('Care by Zinc Manager');
15
+ parent::__construct();
16
+ $this->_removeButton('add');
17
+ }
18
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit.php ADDED
@@ -0,0 +1,29 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ $this->_objectId = 'id';
15
+ $this->_blockGroup = 'carebyzinc';
16
+ $this->_controller = 'adminhtml_product';
17
+ $this->_updateButton('save', 'label', Mage::helper('carebyzinc')->__('Save'));
18
+ }
19
+
20
+ public function getHeaderText()
21
+ {
22
+ if( Mage::registry('carebyzinc_data') && Mage::registry('carebyzinc_data')->getId() ) {
23
+ return Mage::helper('carebyzinc')->__("Edit Care by Zinc of '".'%s'."'", $this->htmlEscape(Mage::registry('carebyzinc_data')->getName()));
24
+ }
25
+ else
26
+ return Mage::helper('carebyzinc')->__("Edit Care by Zinc");
27
+
28
+ }
29
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Form.php ADDED
@@ -0,0 +1,24 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
9
+ {
10
+ protected function _prepareForm()
11
+ {
12
+ $form = new Varien_Data_Form(array(
13
+ 'id' => 'edit_form',
14
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
15
+ 'method' => 'post',
16
+ 'enctype' => 'multipart/form-data'
17
+ )
18
+ );
19
+
20
+ $form->setUseContainer(true);
21
+ $this->setForm($form);
22
+ return parent::_prepareForm();
23
+ }
24
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Tab/Form.php ADDED
@@ -0,0 +1,91 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
9
+ {
10
+ protected function _prepareForm()
11
+ {
12
+ $form = new Varien_Data_Form();
13
+ $this->setForm($form);
14
+ $fieldset = $form->addFieldset('carebyzinc_form', array('legend'=>Mage::helper('carebyzinc')->__('Care By Zinc')));
15
+ $fieldset->addField('carebyzinc', 'select', array(
16
+ 'label' => Mage::helper('carebyzinc')->__('Care by Zinc'),
17
+ 'class' => 'required-entry',
18
+ 'required' => true,
19
+ 'name' => 'carebyzinc',
20
+ 'values' => array(
21
+
22
+ array(
23
+ 'value' => 0,
24
+ 'label' => Mage::helper('carebyzinc')->__('Disable'),
25
+
26
+ ),
27
+ array(
28
+ 'value' => 1,
29
+ 'label' => Mage::helper('carebyzinc')->__('Enable'),
30
+ ),
31
+ ),
32
+
33
+ ));
34
+ $fieldset->addField('carebyzinc_category', 'select', array(
35
+ 'label' => Mage::helper('carebyzinc')->__('Category'),
36
+ 'class' => 'required-entry',
37
+ 'required' => true,
38
+ 'name' => 'category',
39
+
40
+ 'values' => Mage::getModel('carebyzinc/carebyzinc')->getCategoryArray(),
41
+ 'onchange' => "getSubcategories(this.value); function getSubcategories(selectElement){
42
+ var reloadurl = '". $this->getUrl('*/product/getSubcategories')."';
43
+ if(selectElement){
44
+ new Ajax.Request(reloadurl, {parameters: { cat: selectElement},
45
+ method: 'post',
46
+ onComplete: function(transport) {
47
+ var content = JSON.parse(transport.responseText);
48
+ var i = 0;
49
+ for (var key in content) {
50
+ document.getElementById('carebyzinc_subcategory').options[i] = new Option(content[key],content[key]);
51
+ i++;
52
+ }
53
+
54
+ }
55
+ });
56
+ }else
57
+ document.getElementById('carebyzinc_subcategory').innerHTML='';
58
+ }",
59
+ ));
60
+ $category = Mage::registry('carebyzinc_data')->getData('carebyzinc_category');
61
+ if(($this->getRequest()->getParam('id')) && ($category)) {
62
+ $fieldset->addField('carebyzinc_subcategory', 'select', array(
63
+ 'label' => Mage::helper('carebyzinc')->__('Sub Category'),
64
+ 'class' => 'required-entry',
65
+ 'required' => true,
66
+ 'name' => 'subcategory',
67
+ 'values' => Mage::getModel('carebyzinc/carebyzinc')->getSubCategoryArray($category),
68
+ ));
69
+ }else{
70
+
71
+ $fieldset->addField('carebyzinc_subcategory', 'select', array(
72
+ 'label' => Mage::helper('carebyzinc')->__('Sub Category'),
73
+ 'class' => 'required-entry',
74
+ 'required' => true,
75
+ 'name' => 'subcategory',
76
+ 'values' => array(''=>'Please Select'),
77
+ ));
78
+
79
+
80
+ }
81
+
82
+ if ( Mage::getSingleton('adminhtml/session')->getVendorData() )
83
+ {
84
+ $form->setValues(Mage::getSingleton('adminhtml/session')->getCarebyzincData());
85
+ Mage::getSingleton('adminhtml/session')->setCarebyzincData(null);
86
+ } elseif ( Mage::registry('carebyzinc_data') ) {
87
+ $form->setValues( Mage::registry('carebyzinc_data')->getData());
88
+ }
89
+ return parent::_prepareForm();
90
+ }
91
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Tabs.php ADDED
@@ -0,0 +1,29 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
9
+ {
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+ $this->setId('product_tabs');
15
+ $this->setDestElementId('edit_form');
16
+ $this->setTitle(Mage::helper('carebyzinc')->__('Care by Zinc'));
17
+ }
18
+
19
+ protected function _beforeToHtml()
20
+ {
21
+ $this->addTab('form_section', array(
22
+ 'label' => Mage::helper('carebyzinc')->__('Care by Zinc'),
23
+ 'title' => Mage::helper('carebyzinc')->__('Care by Zinc'),
24
+ 'content' => $this->getLayout()->createBlock('carebyzinc/adminhtml_product_edit_tab_form')->toHtml(),
25
+ ));
26
+
27
+ return parent::_beforeToHtml();
28
+ }
29
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Grid.php ADDED
@@ -0,0 +1,144 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+ $this->setId('listGrid');
14
+ $this->setDefaultSort('entity_id');
15
+ $this->setDefaultDir('DESC');
16
+ $this->setSaveParametersInSession(true);
17
+ }
18
+
19
+ public function setCollection($collection)
20
+ {
21
+
22
+ //$collection->addAttributeToSelect('carebyzinc');
23
+ $collection->addFieldToFilter('price',array('gteq' => 500));
24
+ $collection->addAttributeToSelect('carebyzinc');
25
+ $collection->addExpressionAttributeToSelect('carebyzinc','round({{carebyzinc}},0)','carebyzinc');
26
+ parent::setCollection($collection);
27
+
28
+ }
29
+
30
+ protected function _prepareColumns()
31
+ {
32
+ $this->addColumn('entity_id',
33
+ array(
34
+ 'header'=> Mage::helper('catalog')->__('ID'),
35
+ 'width' => '50px',
36
+ 'type' => 'number',
37
+ 'index' => 'entity_id',
38
+ ));
39
+ $this->addColumn('name',
40
+ array(
41
+ 'header'=> Mage::helper('catalog')->__('Name'),
42
+ 'index' => 'name',
43
+ ));
44
+
45
+ $store = $this->_getStore();
46
+ if ($store->getId()) {
47
+ $this->addColumn('custom_name',
48
+ array(
49
+ 'header'=> Mage::helper('catalog')->__('Name in %s', $store->getName()),
50
+ 'index' => 'custom_name',
51
+ ));
52
+ }
53
+
54
+ $this->addColumn('sku',
55
+ array(
56
+ 'header'=> Mage::helper('catalog')->__('SKU'),
57
+ 'width' => '80px',
58
+ 'index' => 'sku',
59
+ ));
60
+
61
+ $store = $this->_getStore();
62
+ $this->addColumn('price',
63
+ array(
64
+ 'header'=> Mage::helper('catalog')->__('Price'),
65
+ 'type' => 'price',
66
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
67
+ 'index' => 'price',
68
+ ));
69
+
70
+ $this->addColumn('carebyzinc',
71
+ array(
72
+ 'header'=> Mage::helper('catalog')->__('Care by Zinc'),
73
+ 'width' => '150px',
74
+ 'index' => 'carebyzinc',
75
+ 'type' => 'options',
76
+ 'options' => array('1' => 'Enable', '0' => 'Disable')
77
+ ));
78
+ $this->addColumn('action', array(
79
+ 'header' => Mage::helper('carebyzinc')->__('Action'),
80
+ 'width' => '100',
81
+ 'type' => 'action',
82
+ 'getter' => 'getId',
83
+ 'actions' => array(
84
+ array(
85
+ 'caption' => Mage::helper('carebyzinc')->__('Edit'),
86
+ 'url' => array('base'=> '*/*/edit'),
87
+ 'title' => 'Edit',
88
+ 'field' => 'id'
89
+ )
90
+ ),
91
+ 'filter' => false,
92
+ 'sortable' => false,
93
+ 'index' => 'stores',
94
+ 'is_system' => true,
95
+ ));
96
+ return $this;
97
+ }
98
+
99
+ protected function _prepareMassaction()
100
+ {
101
+ $this->setMassactionIdField('entity_id');
102
+ $this->getMassactionBlock()->setFormFieldName('product');
103
+
104
+ $carebyzinc = Mage::getSingleton('carebyzinc/carebyzinc')->getOptionArray();
105
+
106
+ $this->getMassactionBlock()->addItem('zinc_carebyzinc', array(
107
+ 'label'=> Mage::helper('carebyzinc')->__('Change Care by Zinc'),
108
+ 'url' => $this->getUrl('adminhtml/product/massCarebyzinc', array('_current'=>true,'pid'=>1)),
109
+ 'additional' => array(
110
+ 'visibility' => array(
111
+ 'name' => 'zinc_carebyzinc',
112
+ 'type' => 'select',
113
+ 'class' => 'required-entry',
114
+ 'values' => $carebyzinc
115
+ )
116
+ )
117
+ ));
118
+ $this->getMassactionBlock()->addItem('carebyzinc_category', array(
119
+ 'label'=> Mage::helper('carebyzinc')->__('Change Category'),
120
+ 'url' => $this->getUrl('adminhtml/product/massCategory', array('_current'=>true,'pid'=>1)),
121
+ 'additional' => array(
122
+ 'visibility' => array(
123
+ 'name' => 'carebyzinc_category',
124
+ 'type' => 'select',
125
+ 'class' => 'required-entry',
126
+ 'values' => Mage::getModel('carebyzinc/carebyzinc')->getCategoryArray()
127
+ )
128
+ )
129
+ ));
130
+
131
+
132
+
133
+ return $this;
134
+ }
135
+
136
+ public function getRowUrl($row)
137
+ {
138
+ return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
139
+ }
140
+ public function getGridUrl(){
141
+ return $this->getUrl('*/*/grid', array('_current'=>true));
142
+ }
143
+
144
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/System/Config/Tokenvalidate.php ADDED
@@ -0,0 +1,56 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Adminhtml_System_Config_Tokenvalidate extends Mage_Adminhtml_Block_System_Config_Form_Field
9
+ {
10
+ /*
11
+ * Set template
12
+ */
13
+ protected function _construct()
14
+ {
15
+ parent::_construct();
16
+ $this->setTemplate('carebyzinc/system/tokenvalidate.phtml');
17
+ }
18
+
19
+ /**
20
+ * Return element html
21
+ *
22
+ * @param Varien_Data_Form_Element_Abstract $element
23
+ * @return string
24
+ */
25
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
26
+ {
27
+ return $this->_toHtml();
28
+ }
29
+
30
+ /**
31
+ * Return ajax url for button
32
+ *
33
+ * @return string
34
+ */
35
+ public function getAjaxCheckUrl()
36
+ {
37
+ return Mage::helper('adminhtml')->getUrl('adminhtml/carebyzinc/validate');
38
+ }
39
+
40
+ /**
41
+ * Generate button html
42
+ *
43
+ * @return string
44
+ */
45
+ public function getButtonHtml()
46
+ {
47
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
48
+ ->setData(array(
49
+ 'id' => 'validate_button',
50
+ 'label' => $this->helper('adminhtml')->__('Validate Token'),
51
+ 'onclick' => 'javascript:validate(); return false;'
52
+ ));
53
+
54
+ return $button->toHtml();
55
+ }
56
+ }
app/code/local/Zinc/Carebyzinc/Block/Carebyzinc.php ADDED
@@ -0,0 +1,23 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Block_Carebyzinc extends Mage_Core_Block_Template
9
+ {
10
+ public function _prepareLayout()
11
+ {
12
+ return parent::_prepareLayout();
13
+ }
14
+
15
+ public function getCarebyzinc()
16
+ {
17
+ if (!$this->hasData('carebyzinc')) {
18
+ $this->setData('carebyzinc', Mage::registry('carebyzinc'));
19
+ }
20
+ return $this->getData('carebyzinc');
21
+
22
+ }
23
+ }
app/code/local/Zinc/Carebyzinc/Helper/Data.php ADDED
@@ -0,0 +1,60 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Helper_Data extends Mage_Core_Helper_Abstract
9
+ {
10
+ public function getTitle(){
11
+ $config = Mage::getStoreConfig('carebyzinc/general/carebytitle');
12
+ return $config;
13
+ }
14
+ public function getZipCode(){
15
+
16
+ $zip = '';
17
+ if(Mage::getSingleton('customer/session')->isLoggedIn()){
18
+ $primaryAddress = Mage::getSingleton('customer/session')->getCustomer()->getPrimaryShippingAddress();
19
+ if($primaryAddress->getPostcode()){
20
+ $zip = $primaryAddress->getPostcode();
21
+ }
22
+ }
23
+ if(! $zip){
24
+ $url = 'http://freegeoip.net/json/'.$_SERVER['REMOTE_ADDR'];
25
+ $response = $this->callApi($url);
26
+ $responseArray = (array)json_decode($response);
27
+ $zip = $responseArray['zip_code'];
28
+ if(! $zip)
29
+ $zip = Mage::getStoreConfig('carebyzinc/general/defaultzip');
30
+ }
31
+ return $zip;
32
+ }
33
+ public function getDeleteUrl($itemId){
34
+
35
+ return Mage::getUrl('carebyzinc/index/removeWarranty', array('id' => $itemId));
36
+
37
+ }
38
+ public function validatePrice($price){
39
+ if($price >=500)
40
+ return true;
41
+ else
42
+ return false;
43
+
44
+ }
45
+ public function callApi($url){
46
+
47
+ $ch = curl_init($url);
48
+ curl_setopt($ch, CURLOPT_URL, $url);
49
+ curl_setopt($ch, CURLOPT_HEADER ,FALSE);
50
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json"));
51
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER ,TRUE);
52
+ $result = curl_exec($ch);
53
+ curl_close($ch);
54
+ return $result;
55
+ }
56
+ public function checkQuoteVisibility(){
57
+ return Mage::getStoreConfig('carebyzinc/general/showquote');
58
+
59
+ }
60
+ }
app/code/local/Zinc/Carebyzinc/Model/Carebyzinc.php ADDED
@@ -0,0 +1,235 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
9
+ {
10
+ const WARRANTY_ENABLED = 1;
11
+ const WARRANTY_DISABLED = 0;
12
+
13
+ public function _construct()
14
+ {
15
+ parent::_construct();
16
+ $this->_init('carebyzinc/carebyzinc');
17
+ }
18
+
19
+ static public function getOptionArray()
20
+ {
21
+ return array(
22
+ self::WARRANTY_ENABLED => Mage::helper('carebyzinc')->__('Enabled'),
23
+ self::WARRANTY_DISABLED => Mage::helper('carebyzinc')->__('Disabled')
24
+ );
25
+ }
26
+
27
+
28
+ public function getPriceQuote($product,$zip,$optionPrice)
29
+ {
30
+ $currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
31
+ $price = $product->getFinalPrice();
32
+ if($optionPrice)
33
+ $price += $optionPrice;
34
+ $userId = $this->getUserId();
35
+ $data = array();
36
+ $data['sku'] = array(
37
+ 'merchant_sku_id' => $product->getId(),
38
+ 'sku_name' => $product->getName(),
39
+ 'variant_id' => '',
40
+ 'category' => $product->getCarebyzincCategory(),
41
+ 'subcategory' => $product->getCarebyzincSubcategory(),
42
+ 'subcategory2' => '',
43
+ 'description' => $product->getShortDescription(),
44
+ 'price' => $price,
45
+ 'currency' => $currencyCode,
46
+ 'user_id' => $userId
47
+ );
48
+
49
+ if(! $zip){
50
+ $helper = Mage::helper('carebyzinc');
51
+ $zip = $helper->getZipCode();
52
+ }
53
+ $data['zip_code'] = $zip;
54
+ $outData = $this->callApi($data, 'price_quotes/generate');
55
+ if($outData['code'] == '200'){
56
+ $response = $outData['response'];
57
+ $quoteData = json_decode($response, true);
58
+ $priceQuote = array();
59
+ foreach($quoteData['price_quotes'] as $item):
60
+ $priceQuote[$item['id']] = $item;
61
+ endforeach;
62
+ Mage::getSingleton('core/session')->setCareQuote($priceQuote);
63
+ return $priceQuote;
64
+
65
+ }else{
66
+ $response = $outData['response'];
67
+ $response = (array)json_decode($response, true);
68
+ return $response['errors'];
69
+ }
70
+
71
+ }
72
+
73
+ public function getPriceQuoteinCart($product,$itemId,$zip)
74
+ {
75
+
76
+ $currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
77
+ $_item = Mage::getModel('sales/quote_item')->load($itemId);
78
+ $userId = $this->getUserId();
79
+ $data = array();
80
+ $data['sku'] = array(
81
+ 'merchant_sku_id' => $product->getId(),
82
+ 'sku_name' => $product->getName(),
83
+ 'variant_id' => '',
84
+ 'category' => $product->getCarebyzincCategory(),
85
+ 'subcategory' => $product->getCarebyzincSubcategory(),
86
+ 'subcategory2' => '',
87
+ 'description' => $product->getShortDescription(),
88
+ 'price' => $_item->getPrice(),
89
+ 'currency' => $currencyCode,
90
+ 'user_id' => $userId
91
+ );
92
+ if(! $zip){
93
+ $helper = Mage::helper('carebyzinc');
94
+ $zip = $helper->getZipCode();
95
+ }
96
+ $data['zip_code'] = $zip;
97
+ $outData = $this->callApi($data, 'price_quotes/generate');
98
+ if($outData['code'] == '200'){
99
+ $response = $outData['response'];
100
+ $quoteData = json_decode($response, true);
101
+ $priceQuote = array();
102
+ foreach($quoteData['price_quotes'] as $item):
103
+ $priceQuote[$itemId][$item['id']] = $item;
104
+ endforeach;
105
+ Mage::getSingleton('core/session')->setCareByZincQuote($priceQuote);
106
+ return $priceQuote;
107
+ }else{
108
+ $response = $outData['response'];
109
+ $response = (array)json_decode($response, true);
110
+ return $response['errors'];
111
+ }
112
+
113
+ }
114
+
115
+ public function getApiUrl($action)
116
+ {
117
+ $path = Mage::getStoreConfig('carebyzinc/api/url');
118
+ if((Mage::getStoreConfig('carebyzinc/api/testmode')) == 'live')
119
+ $path = Mage::getStoreConfig('carebyzinc/api/url');
120
+ else
121
+ $path = Mage::getStoreConfig('carebyzinc/api/test_url');
122
+
123
+ $url = $path.'/'.$action;
124
+ return $url;
125
+ }
126
+
127
+ private function getUserId()
128
+ {
129
+ $userId = Mage::getStoreConfig('carebyzinc/api/user_id');
130
+ return $userId;
131
+ }
132
+
133
+ public function callApi($data, $action, $method = 'post'){
134
+ $outData = array();
135
+ $values = json_encode($data);
136
+ $url = $this->getApiUrl($action);
137
+ $uid = $this->getUserId();
138
+ $token = Mage::getStoreConfig('carebyzinc/api/access_token');
139
+ $client = Mage::getStoreConfig('carebyzinc/api/client');
140
+ $header = array( "Content-Type: application/json","uid:$uid","access-token:$token","client:$client","token-type:Bearer");
141
+ $ch = curl_init($url);
142
+ curl_setopt($ch, CURLOPT_URL, $url);
143
+ if($method == 'post'){
144
+ curl_setopt($ch, CURLOPT_POST,TRUE);
145
+ curl_setopt($ch, CURLOPT_POSTFIELDS,$values);
146
+ }
147
+ curl_setopt($ch, CURLOPT_HEADER ,FALSE);
148
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
149
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER ,TRUE);
150
+ $outData['response'] = curl_exec($ch);
151
+ $outData['code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
152
+ curl_close($ch);
153
+ return $outData;
154
+ }
155
+
156
+ public function getwarrantyStatus( $item_id )
157
+ {
158
+ if($item_id < 0){
159
+ return '';
160
+ }
161
+ $cart = Mage::getSingleton('checkout/cart');
162
+ $quoteItem = $cart->getQuote()->getItemById($item_id);
163
+ $product = Mage::getModel('catalog/product')->load($quoteItem->getProductId());
164
+ if(($product->getCarebyzinc() != 1) && ($quoteItem->getCarebyzincOption())){
165
+ if ($additionalOption = $quoteItem->getOptionByCode('additional_options'))
166
+ {
167
+ $additionalOptions = (array) unserialize($additionalOption->getValue());
168
+ }
169
+ $additionalOptionsArray = array();
170
+ foreach($additionalOptions as $option){
171
+ if($option['label'] != 'carebyzinc')
172
+ $additionalOptionsArray[] = $option;
173
+ }
174
+ $quoteItem->setCarebyzincOption('');
175
+
176
+ if(! empty($additionalOptionsArray)){
177
+ $quoteItem->addOption(array( 'product_id' => $quoteItem->getProductId(),
178
+ 'code' => 'additional_options',
179
+ 'value' => serialize($additionalOptionsArray)
180
+ ));
181
+ }else{
182
+ $quoteItem->getOptionByCode('additional_options')->delete();
183
+ }
184
+ $productPrice = $quoteItem->getProduct()->getFinalPrice();
185
+ $quoteItem->setCustomPrice($productPrice);
186
+ $quoteItem->setOriginalCustomPrice($productPrice);
187
+ $quoteItem->getProduct()->setIsSuperMode(true);
188
+ $quoteItem->save();
189
+ $cart->getQuote()->collectTotals()->save();
190
+
191
+ }
192
+ return true;
193
+ }
194
+ public function getCategoryArray()
195
+ {
196
+
197
+
198
+ $dataArray = $this->getCategoryJson();
199
+ $category = array(''=>'Please Select');
200
+ foreach($dataArray as $key => $value){
201
+ $category[$key] = $key;
202
+ }
203
+ return $category;
204
+
205
+ }
206
+ public function getSubCategoryArray($category)
207
+ {
208
+ if($category)
209
+ $dataArray = $this->getCategoryJson();
210
+ $subcategory = array();
211
+ foreach($dataArray as $key => $value){
212
+ if($key == $category){
213
+ foreach($value as $val){
214
+ $subcategory[$val] = $val;
215
+ }
216
+ }
217
+ }
218
+ return $subcategory;
219
+
220
+ }
221
+ public function getCategoryJson()
222
+ {
223
+
224
+ $outData = $this->callApi('','categories','get');
225
+ if($outData['code'] == '200')
226
+ $response = $outData['response'];
227
+ else
228
+ $response = '{"Jewelry": ["Bracelet", "Necklace","Pendant","Brooch","Engagement Ring","Wedding Ring","Other Ring","Other"]}';
229
+ $dataArray = json_decode($response);
230
+ return $dataArray;
231
+
232
+ }
233
+
234
+
235
+ }
app/code/local/Zinc/Carebyzinc/Model/Checkout/Cart.php ADDED
@@ -0,0 +1,158 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Model_Checkout_Cart extends Mage_Checkout_Model_Cart
9
+ {
10
+ /**
11
+ * Add product to shopping cart (quote)
12
+ *
13
+ * @param int|Mage_Catalog_Model_Product $productInfo
14
+ * @param mixed $requestInfo
15
+ * @return Mage_Checkout_Model_Cart
16
+ */
17
+ public function addProduct($productInfo, $requestInfo=null)
18
+ {
19
+ $product = $this->_getProduct($productInfo);
20
+ $request = $this->_getProductRequest($requestInfo);
21
+ $productId = $product->getId();
22
+ $flag = 0;$qty = 0;
23
+ $productType = $product->getTypeId();
24
+ if(($productType == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE || $productType == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) && ($product->getCarebyzinc() == 1))
25
+ {
26
+ $flag = 1;
27
+ $qty = $request->getQty();
28
+ $request['qty'] = 1;
29
+ }
30
+ if ($product->getStockItem()) {
31
+ $minimumQty = $product->getStockItem()->getMinSaleQty();
32
+ //If product was not found in cart and there is set minimal qty for it
33
+ if ($minimumQty && $minimumQty > 0 && $request->getQty() < $minimumQty
34
+ && !$this->getQuote()->hasProductId($productId)
35
+ ){
36
+ $request->setQty($minimumQty);
37
+ }
38
+ }
39
+ if($flag){
40
+ $helper = Mage::helper('carebyzinc');
41
+
42
+
43
+ if ($productId) {
44
+ try {
45
+ for($i= 0;$i<$qty;$i++){
46
+ $additionalOptions = array();
47
+ $product = Mage::getModel('catalog/product')
48
+ ->setStoreId(Mage::app()->getStore()->getId())
49
+ ->load($productId);
50
+ $result = $this->getQuote()->addProduct($product, $request);
51
+ if(is_object($result)){
52
+ $result = ( $result->getParentItem() ? $result->getParentItem() : $result );
53
+ $carebyzincId = $request->getCarebyzincOption();
54
+ $priceQuote = Mage::getSingleton('core/session')->getCareQuote();
55
+ $carebyzincAry = $priceQuote[$carebyzincId];
56
+ $productPrice = $result->getProduct()->getFinalPrice();
57
+ $valid = $helper->validatePrice($productPrice);
58
+ if($valid){
59
+ if($price = $carebyzincAry['price_per_year']){
60
+ $newPrice = $productPrice + $price;
61
+ $result->setCustomPrice($newPrice);
62
+ $result->setOriginalCustomPrice($newPrice);
63
+ $result->setCarebyzincPrice($price);
64
+ $result->getProduct()->setIsSuperMode(true);
65
+ }
66
+ if ($additionalOption = $result->getOptionByCode('additional_options'))
67
+ {
68
+ $additionalOptions = (array) unserialize($additionalOption->getValue());
69
+ }
70
+
71
+ if( $item = $priceQuote[$carebyzincId]){
72
+ $additionalOptions[] = array(
73
+ 'label' => 'carebyzinc',
74
+ 'value' => $carebyzincId,
75
+ );
76
+ $result->setCarebyzincOption(serialize($priceQuote[$carebyzincId]));
77
+
78
+
79
+ }else{
80
+ $additionalOptions[] = array(
81
+ 'label' => 'carebyzinc',
82
+ 'value' => '',
83
+ );
84
+
85
+
86
+
87
+ }
88
+ $result->addOption(array(
89
+ 'product_id' => $result->getProductId(),
90
+ 'code' => 'additional_options',
91
+ 'value' => serialize($additionalOptions)
92
+ ));
93
+ $this->getQuote()->save();
94
+ }
95
+ }}
96
+ } catch (Mage_Core_Exception $e) {
97
+ $this->getCheckoutSession()->setUseNotice(false);
98
+ $result = $e->getMessage();
99
+ }
100
+ /**
101
+ * String we can get if prepare process has error
102
+ */
103
+ if (is_string($result)) {
104
+ $redirectUrl = ($product->hasOptionsValidationFail())
105
+ ? $product->getUrlModel()->getUrl(
106
+ $product,
107
+ array('_query' => array('startcustomization' => 1))
108
+ )
109
+ : $product->getProductUrl();
110
+ $this->getCheckoutSession()->setRedirectUrl($redirectUrl);
111
+ if ($this->getCheckoutSession()->getUseNotice() === null) {
112
+ $this->getCheckoutSession()->setUseNotice(true);
113
+ }
114
+ Mage::throwException($result);
115
+ }
116
+ } else {
117
+ Mage::throwException(Mage::helper('checkout')->__('The product does not exist.'));
118
+ }
119
+
120
+ Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));
121
+ $this->getCheckoutSession()->setLastAddedProductId($productId);
122
+ //}Mage::getSingleton('core/session')->unsCareQuote();
123
+ }else{
124
+ if ($productId) {
125
+ try {
126
+ $result = $this->getQuote()->addProduct($product, $request);
127
+
128
+ } catch (Mage_Core_Exception $e) {
129
+ $this->getCheckoutSession()->setUseNotice(false);
130
+ $result = $e->getMessage();
131
+ }
132
+ /**
133
+ * String we can get if prepare process has error
134
+ */
135
+ if (is_string($result)) {
136
+ $redirectUrl = ($product->hasOptionsValidationFail())
137
+ ? $product->getUrlModel()->getUrl(
138
+ $product,
139
+ array('_query' => array('startcustomization' => 1))
140
+ )
141
+ : $product->getProductUrl();
142
+ $this->getCheckoutSession()->setRedirectUrl($redirectUrl);
143
+ if ($this->getCheckoutSession()->getUseNotice() === null) {
144
+ $this->getCheckoutSession()->setUseNotice(true);
145
+ }
146
+ Mage::throwException($result);
147
+ }
148
+ }else {
149
+ Mage::throwException(Mage::helper('checkout')->__('The product does not exist.'));
150
+ }
151
+
152
+ Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));
153
+ $this->getCheckoutSession()->setLastAddedProductId($productId);
154
+ }
155
+
156
+ return $this;
157
+ }
158
+ }
app/code/local/Zinc/Carebyzinc/Model/Entity/Category.php ADDED
@@ -0,0 +1,17 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ class Zinc_Carebyzinc_Model_Entity_Category extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
10
+ {
11
+ public function getAllOptions()
12
+ {
13
+ $this->_options = array();
14
+ $this->_options = Mage::getModel('carebyzinc/carebyzinc')->getCategoryArray();
15
+ return $this->_options;
16
+ }
17
+ }
app/code/local/Zinc/Carebyzinc/Model/Entity/Subcategory.php ADDED
@@ -0,0 +1,18 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ class Zinc_Carebyzinc_Model_Entity_Subcategory extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
10
+ {
11
+ public function getAllOptions()
12
+ {
13
+ $this->_options = array();
14
+ if($category = Mage::registry('current_product')->getCarebyzincCategory())
15
+ $this->_options = Mage::getModel('carebyzinc/carebyzinc')->getSubcategoryArray($category);
16
+ return $this->_options;
17
+ }
18
+ }
app/code/local/Zinc/Carebyzinc/Model/Mysql4/Order.php ADDED
@@ -0,0 +1,14 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Model_Mysql4_Order extends Mage_Core_Model_Mysql4_Abstract
9
+ {
10
+ public function _construct()
11
+ {
12
+ $this->_init('carebyzinc/order', 'id');
13
+ }
14
+ }
app/code/local/Zinc/Carebyzinc/Model/Mysql4/Order/Collection.php ADDED
@@ -0,0 +1,15 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Model_Mysql4_Order_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
9
+ {
10
+ public function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->_init('carebyzinc/order');
14
+ }
15
+ }
app/code/local/Zinc/Carebyzinc/Model/Observer.php ADDED
@@ -0,0 +1,47 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Model_Observer{
9
+
10
+
11
+
12
+ public function saveCarebyzinc($observer)
13
+ {
14
+ if(!Mage::registry('carebyzinc_save')):
15
+ $order = $observer->getEvent()->getOrder();
16
+ $model = Mage::getModel('carebyzinc/order');
17
+ $model->savePolicy($order);
18
+ Mage::register('carebyzinc_save',true);
19
+ endif;
20
+
21
+ }
22
+ public function cartLoad($observer)
23
+ {
24
+ if( ! Mage::getStoreConfig('carebyzinc/general/enabled')){
25
+ $cartHelper = Mage::helper('checkout/cart');
26
+ $cart = Mage::getModel('checkout/cart')->getQuote();
27
+ foreach ($cart->getAllItems() as $item) {
28
+ if($item->getCarebyzincOption()){
29
+ $cartHelper->getCart()->removeItem($item->getId())->save();
30
+ }
31
+ $additionalOptions = array();
32
+ $item->addOption(array(
33
+ 'product_id' => $item->getProductId(),
34
+ 'code' => 'additional_options',
35
+ 'value' => serialize($additionalOptions)
36
+ ));
37
+ $item->save();
38
+ }
39
+
40
+
41
+ }
42
+
43
+ }
44
+
45
+
46
+
47
+ }
app/code/local/Zinc/Carebyzinc/Model/Order.php ADDED
@@ -0,0 +1,114 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
9
+ {
10
+ public function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->_init('carebyzinc/order');
14
+ }
15
+
16
+
17
+ public function savePolicy($order)
18
+ {
19
+ $data = array();
20
+ $currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
21
+ $data['user_id'] = $this->getUserId();
22
+ $data['customer'] = $this->getUserAddress($order);
23
+ $carebyItem = 0;
24
+ $orderItems = $order->getAllVisibleItems();
25
+ $model = Mage::getModel('carebyzinc/carebyzinc');
26
+ foreach($orderItems as $item){
27
+ if($item->getCarebyzincOption()){
28
+ $carebyItem++;
29
+ $policyNo = '';
30
+ $carebyzincAry = (array) unserialize($item->getCarebyzincOption()) ;
31
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
32
+ $data['price_quote_id'] = $carebyzincAry['id'];
33
+ $data['sku_id'] = $carebyzincAry['sku_id'];
34
+ $result = $model->callApi($data, 'policies');
35
+ $policyAry = $result['response'];
36
+ if($result['code'] == 200){
37
+ $policyArray = (array) json_decode($policyAry);
38
+ $policyNo = $policyArray['policy_id'];
39
+ }
40
+ $careOrder = Mage::getModel('carebyzinc/order');
41
+ $careOrder->setOrderId($order->getId());
42
+ $careOrder->setProductId($item->getProductId());
43
+ $careOrder->setCustomerId($order->getCustomerId());
44
+ $careOrder->setProductName($product->getName());
45
+ $careOrder->setProductSku($product->getSku());
46
+ $careOrder->setCarebyzincKey($policyNo);
47
+ $careOrder->setOrderIncId($order->getIncrementId());
48
+ $careOrder->setItemId($item->getId());
49
+ $careOrder->setWarrentyPrice($carebyzincAry['price_per_year']);
50
+ $price = $item->getPrice() - $carebyzincAry['price_per_year'];
51
+ $careOrder->setProductPrice($price);
52
+ $careOrder->setCarebyzincProvider($carebyzincAry['provider']);
53
+ $name = $order->getCustomerFirstname(). ' '. $order->getCustomerLastname();
54
+ $careOrder->setCustomerName($name);
55
+ $careOrder->setCustomerEmail($order->getCustomerEmail());
56
+ $careOrder->setCreatedTime(now());
57
+ $careOrder->save();
58
+ }
59
+ }
60
+ if($carebyItem){
61
+ $fromname = Mage::getStoreConfig('trans_email/ident_general/name');
62
+ $fromemail = Mage::getStoreConfig('trans_email/ident_general/email');
63
+ $translate = Mage::getSingleton('core/translate');
64
+ $email = 'support@zincplatform.com';
65
+ $name = 'Zinc';
66
+ $templateId = Mage::getStoreConfig('sales_email/order/template');
67
+ if($email){
68
+ $storeObj = Mage::getModel('core/store')->load($order->getStoreId());
69
+ $anyDate = $order->getCreatedAt();
70
+ $dateTimestamp = Mage::getModel('core/date')->timestamp(strtotime($anyDate));
71
+ $date = date("Y-m-d",$dateTimestamp);
72
+ $subject = $this->getUserId().'_policyid_'.$storeObj->getFrontendName().'_'.$date;
73
+ $emailTemplate = Mage::getModel('core/email_template')->loadDefault('sales_email_order_template');
74
+ $emailTemplateVariables = array();
75
+ $emailTemplateVariables['order'] = $order;
76
+ $emailTemplateVariables['store'] = $storeObj;
77
+ $emailTemplate->setSenderName($fromname);
78
+ $emailTemplate->setSenderEmail($fromemail);
79
+ $emailTemplate->setType('html');
80
+ $emailTemplate->setTemplateSubject($subject);
81
+ $emailTemplate->send($email, $name, $emailTemplateVariables);
82
+
83
+
84
+ }
85
+
86
+ }
87
+ }
88
+
89
+ private function getUserId()
90
+ {
91
+ $userId = Mage::getStoreConfig('carebyzinc/api/user_id');
92
+ return $userId;
93
+ }
94
+
95
+ public function getUserAddress($order)
96
+ {
97
+ $address ['first_name'] = $order->getCustomerFirstname();
98
+ $address ['last_name'] = $order->getCustomerLastname();
99
+ $address ['transaction_currency'] = $order->getOrderCurrencyCode();
100
+ $address ['email'] = $order->getCustomerEmail();
101
+ $billingAddress = $order->getBillingAddress();
102
+ $address ['main_phone_number'] = $billingAddress->getTelephone();
103
+ $address ['country'] = $billingAddress->getCountryId();
104
+ $address ['address'] = array(
105
+ "billing_city" => $billingAddress->getCity(),
106
+ "billing_zip_code" => $billingAddress->getPostcode(),
107
+ "billing_state" => $billingAddress->getRegion(),
108
+ "billing_address1" => $billingAddress->getStreet(),
109
+ );
110
+
111
+ return $address;
112
+
113
+ }
114
+ }
app/code/local/Zinc/Carebyzinc/Model/Sales/Quote.php ADDED
@@ -0,0 +1,31 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Model_Sales_Quote extends Mage_Sales_Model_Quote
9
+ {
10
+ /**
11
+ * Retrieve quote item by product id
12
+ *
13
+ * @param Mage_Catalog_Model_Product $product
14
+ * @return Mage_Sales_Model_Quote_Item || false
15
+ */
16
+ public function getItemByProduct($product)
17
+ {
18
+ $product = Mage::getModel('catalog/product')->load($product);
19
+ $productType = $product->getTypeId();
20
+ if(($productType == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE || $productType == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) && ($product->getCarebyzinc() == 1))
21
+ return false;
22
+ else{
23
+ foreach ($this->getAllItems() as $item) {
24
+ if ($item->representProduct($product)) {
25
+ return $item;
26
+ }
27
+ }
28
+ }
29
+ return false;
30
+ }
31
+ }
app/code/local/Zinc/Carebyzinc/Model/System/Config/Source.php ADDED
@@ -0,0 +1,23 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Model_System_Config_Source
9
+ {
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array(
14
+ 'value' => 'test',
15
+ 'label' => 'Test Mode',
16
+ ),
17
+ array(
18
+ 'value' => 'live',
19
+ 'label' => 'Production Mode',
20
+ ),
21
+ );
22
+ }
23
+ }
app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/CarebyzincController.php ADDED
@@ -0,0 +1,25 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Adminhtml_CarebyzincController extends Mage_Adminhtml_Controller_action
9
+ {
10
+ public function validateAction()
11
+ {
12
+ $data['uid'] = Mage::getStoreConfig('carebyzinc/api/user_id');
13
+ $data['access-token'] = Mage::getStoreConfig('carebyzinc/api/access_token');
14
+ $data['client'] = Mage::getStoreConfig('carebyzinc/api/client');
15
+
16
+ $model = Mage::getModel('carebyzinc/carebyzinc');
17
+ $result = $model->callApi($data,'auth/validate_token','get');
18
+ if($result['code'] == 200)
19
+ $response = 'Success';
20
+ else
21
+ $response = 'Error';
22
+ Mage::app()->getResponse()->setBody($response);
23
+ }
24
+
25
+ }
app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/OrderController.php ADDED
@@ -0,0 +1,25 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Adminhtml_OrderController extends Mage_Adminhtml_Controller_action
9
+ {
10
+
11
+ protected function _initAction() {
12
+ $this->loadLayout()
13
+ ->_setActiveMenu('carebyzinc/order')
14
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Carebyzinc Orders'), Mage::helper('adminhtml')->__('Carebyzinc Orders'));
15
+
16
+ return $this;
17
+ }
18
+
19
+ public function indexAction() {
20
+ $this->_initAction()
21
+ ->renderLayout();
22
+ }
23
+
24
+
25
+ }
app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/ProductController.php ADDED
@@ -0,0 +1,174 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Zinc_Carebyzinc_Adminhtml_ProductController extends Mage_Adminhtml_Controller_action
9
+ {
10
+
11
+ protected function _initAction() {
12
+ $this->loadLayout()
13
+ ->_setActiveMenu('carebyzinc/product')
14
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Care by Zinc'), Mage::helper('adminhtml')->__('Care by Zinc'));
15
+
16
+ return $this;
17
+ }
18
+
19
+ public function indexAction() {
20
+ $this->_initAction()
21
+ ->renderLayout();
22
+ }
23
+
24
+
25
+ public function orderAction() {
26
+ $this->_initAction()
27
+ ->renderLayout();
28
+ }
29
+ public function gridAction()
30
+ {
31
+ $this->loadLayout();
32
+ $this->renderLayout();
33
+ }
34
+ /**
35
+ * Edit Carebyzinc status action
36
+ *
37
+ */
38
+ public function editAction() {
39
+ $id = $this->getRequest()->getParam('id');
40
+ $model = Mage::getModel('catalog/product')->load($id);
41
+ if ($model->getId() || $id == 0) {
42
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
43
+ if (!empty($data)) {
44
+ $model->setData($data);
45
+ }
46
+
47
+ Mage::register('carebyzinc_data', $model);
48
+ $this->loadLayout();
49
+ $this->_setActiveMenu('carebyzinc/products');
50
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
51
+ $this->_addContent($this->getLayout()->createBlock('carebyzinc/adminhtml_product_edit'))
52
+ ->_addLeft($this->getLayout()->createBlock('carebyzinc/adminhtml_product_edit_tabs'));
53
+ $this->renderLayout();
54
+ } else {
55
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('carebyzinc')->__('Item does not exist'));
56
+ $this->_redirect('*/*/');
57
+ }
58
+ }
59
+ /**
60
+ * Update product(s) status action
61
+ *
62
+ */
63
+ public function saveAction()
64
+ {
65
+ $post = $this->getRequest()->getPost();
66
+ $id = $this->getRequest()->getParam('id');
67
+ $model = Mage::getModel('catalog/product')->load($id);
68
+ $model->setCarebyzincCategory($post['category']);
69
+ $model->setCarebyzincSubcategory($post['subcategory']);
70
+ $model->setCarebyzinc($post['carebyzinc']);
71
+ $model->save();
72
+ $this->_redirect('*/*/');
73
+ return;
74
+
75
+ }
76
+
77
+ /**
78
+ * Update product(s) status action
79
+ *
80
+ */
81
+ public function massCarebyzincAction()
82
+ {
83
+ $productIds = (array)$this->getRequest()->getParam('product');
84
+ $carebyzinc = (int)$this->getRequest()->getParam('zinc_carebyzinc');
85
+
86
+ try {
87
+ $this->_validateMassCarebyzinc($productIds, $carebyzinc);
88
+ Mage::getSingleton('catalog/product_action')
89
+ ->updateAttributes($productIds, array('carebyzinc' => $carebyzinc));
90
+
91
+ $this->_getSession()->addSuccess(
92
+ $this->__('Total of %d record(s) have been updated.', count($productIds))
93
+ );
94
+ }
95
+ catch (Mage_Core_Model_Exception $e) {
96
+ $this->_getSession()->addError($e->getMessage());
97
+ } catch (Mage_Core_Exception $e) {
98
+ $this->_getSession()->addError($e->getMessage());
99
+ } catch (Exception $e) {
100
+ $this->_getSession()
101
+ ->addException($e, $this->__('An error occurred while updating the product(s)'));
102
+ }
103
+ if($this->getRequest()->getParam('pid'))
104
+ $this->_redirect('*/*/');
105
+ else
106
+ $this->_redirect('adminhtml/catalog_product/index');
107
+ }
108
+
109
+ /**
110
+ * Update product(s) category action
111
+ *
112
+ */
113
+ public function massCategoryAction()
114
+ {
115
+ $productIds = (array)$this->getRequest()->getParam('product');
116
+ $category = $this->getRequest()->getParam('carebyzinc_category');
117
+ $subCat = 'Other';
118
+ if(!is_array($productIds)) {
119
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('carebyzinc')->__('Please select Product(s).'));
120
+ }else {
121
+ try {
122
+ $this->_validateMassCarebyzinc($productIds, $category);
123
+ $subCategories = Mage::getModel('carebyzinc/carebyzinc')->getSubCategoryArray($category);
124
+ foreach ($productIds as $product_id) {
125
+ $productModel = Mage::getModel('catalog/product')->load($product_id);
126
+ $name = $productModel->getName();
127
+ foreach($subCategories as $subcat){
128
+ if (stripos($name, $subcat) !== false) {
129
+ $subCat = $subcat;
130
+ break;
131
+ }
132
+ }
133
+ $productModel->setCarebyzincCategory($category);
134
+ $productModel->setCarebyzincSubcategory($subCat);
135
+ $productModel->save();
136
+
137
+ }
138
+
139
+ $this->_getSession()->addSuccess(
140
+ $this->__('Total of %d record(s) have been updated.', count($productIds))
141
+ );
142
+ }
143
+ catch (Mage_Core_Model_Exception $e) {
144
+ $this->_getSession()->addError($e->getMessage());
145
+ } catch (Mage_Core_Exception $e) {
146
+ $this->_getSession()->addError($e->getMessage());
147
+ } catch (Exception $e) {
148
+ $this->_getSession()
149
+ ->addException($e, $this->__('An error occurred while updating the product(s)'));
150
+ }
151
+ }
152
+ if($this->getRequest()->getParam('pid'))
153
+ $this->_redirect('*/*/');
154
+ else
155
+ $this->_redirect('adminhtml/catalog_product/index');
156
+ }
157
+
158
+ public function _validateMassCarebyzinc(array $productIds, $carebyzinc)
159
+ {
160
+ if (!Mage::getModel('catalog/product')->isProductsHasSku($productIds)) {
161
+ throw new Mage_Core_Exception(
162
+ $this->__('Some of the processed products have no SKU value defined. Please fill it prior to performing operations on these products.')
163
+ );
164
+ }
165
+ }
166
+
167
+ public function getSubcategoriesAction()
168
+ {
169
+ $cid = $this->getRequest()->getParam('cat');
170
+ $subCategories = Mage::getModel('carebyzinc/carebyzinc')->getSubCategoryArray($cid);
171
+ return $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($subCategories));
172
+
173
+ }
174
+ }
app/code/local/Zinc/Carebyzinc/controllers/CartController.php ADDED
@@ -0,0 +1,251 @@
1
+ <?php
2
+ /**
3
+ * ZincPlatform
4
+ * @package Zinc_Carebyzinc
5
+ * @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ /**
10
+ * Shopping cart controller
11
+ */
12
+ require_once 'Mage/Checkout/controllers/CartController.php';
13
+ class Zinc_Carebyzinc_CartController extends Mage_Checkout_CartController
14
+ {
15
+ /**
16
+ * Update product configuration for a cart item
17
+ */
18
+ public function updateItemOptionsAction()
19
+ {
20
+ $cart = $this->_getCart();
21
+ $id = (int) $this->getRequest()->getParam('id');
22
+ $params = $this->getRequest()->getParams();
23
+ if (!isset($params['options'])) {
24
+ $params['options'] = array();
25
+ }
26
+
27
+ try {
28
+ $quoteItem = $cart->getQuote()->getItemById($id);
29
+ if (!$quoteItem) {
30
+ Mage::throwException($this->__('Quote item is not found.'));
31
+ }
32
+
33
+ $product = Mage::getModel('catalog/product')->load($quoteItem->getProductId());
34
+ $productType = $product->getTypeId();
35
+ $carebyzinc = '';
36
+ $flag = 0;$price = 0;
37
+ $additionalOptions = array();
38
+ if(($productType == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE || $productType == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) && ($product->getCarebyzinc() == 1))
39
+ {
40
+ $newPrice = $quoteItem->getPrice();
41
+ $qty = 1;
42
+ $flag = 1;
43
+ }
44
+
45
+ if (isset($params['qty'])) {
46
+ if($flag){
47
+ $qty = $params['qty'];
48
+ $params['qty'] = 1;
49
+ }
50
+ $filter = new Zend_Filter_LocalizedToNormalized(
51
+ array('locale' => Mage::app()->getLocale()->getLocaleCode())
52
+ );
53
+ $params['qty'] = $filter->filter($params['qty']);
54
+ }
55
+
56
+ if($flag)
57
+ {
58
+ $carebyzincOption = $params['carebyzinc_option'];
59
+ if ($additionalOption = $quoteItem->getOptionByCode('additional_options'))
60
+ {
61
+ $additionalOptions = (array) unserialize($additionalOption->getValue());
62
+ }
63
+ if($carebyzincOption){
64
+ $priceQuote = Mage::getSingleton('core/session')->getCareQuote();
65
+ $carebyzincAry = $priceQuote[$carebyzincOption];
66
+ $price = $carebyzincAry['price_per_year']?$carebyzincAry['price_per_year']:0;
67
+ $carebyzinc = serialize($priceQuote[$carebyzincOption]);
68
+ foreach($additionalOptions as $option){
69
+ if($option['label'] == 'carebyzinc'){
70
+ $option['value'] = $carebyzincOption;
71
+ break;
72
+ }
73
+ }
74
+
75
+ Mage::getSingleton('core/session')->unsCareQuote();
76
+
77
+ }else{
78
+ $carebyzinc = $quoteItem->getCarebyzincOption();
79
+ $price = $quoteItem->getCarebyzincPrice();
80
+ }
81
+
82
+ }
83
+ $item = $cart->updateItem($id, new Varien_Object($params));
84
+
85
+ if($flag){
86
+ $productPrice = $item->getProduct()->getFinalPrice();
87
+ $newPrice = $productPrice + $price;
88
+ if($carebyzinc){
89
+ $item->setCarebyzincOption($carebyzinc);
90
+ $item->addOption(array(
91
+ 'product_id' => $item->getProductId(),
92
+ 'code' => 'additional_options',
93
+ 'value' => serialize($additionalOptions)
94
+ ));
95
+ $item->setCarebyzincPrice($price);
96
+ $item->setCustomPrice($newPrice);
97
+ $item->setOriginalCustomPrice($newPrice);
98
+ $item->getProduct()->setIsSuperMode(true);
99
+ }
100
+ if($qty >1){
101
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
102
+ for($i = 1;$i<=($qty-1);$i++){
103
+ $result = $quote->addProduct($product, $item->getBuyRequest());
104
+ $result = ( $result->getParentItem() ? $result->getParentItem() : $result );
105
+ if($carebyzinc){
106
+ $result->setCarebyzincOption($carebyzinc);
107
+ $result->setCarebyzincPrice($price);
108
+ $result->addOption(array(
109
+ 'product_id' => $item->getProductId(),
110
+ 'code' => 'additional_options',
111
+ 'value' => serialize($additionalOptions)
112
+ ));
113
+
114
+ $result->setCustomPrice($newPrice);
115
+ $result->setOriginalCustomPrice($newPrice);
116
+ }
117
+ }
118
+ }
119
+
120
+ }
121
+
122
+ if (is_string($item)) {
123
+ Mage::throwException($item);
124
+ }
125
+ if ($item->getHasError()) {
126
+ Mage::throwException($item->getMessage());
127
+ }
128
+
129
+ $related = $this->getRequest()->getParam('related_product');
130
+ if (!empty($related)) {
131
+ $cart->addProductsByIds(explode(',', $related));
132
+ }
133
+
134
+ $cart->save();
135
+
136
+ $this->_getSession()->setCartWasUpdated(true);
137
+
138
+ Mage::dispatchEvent('checkout_cart_update_item_complete',
139
+ array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())
140
+ );
141
+ if (!$this->_getSession()->getNoCartRedirect(true)) {
142
+ if (!$cart->getQuote()->getHasError()) {
143
+ $message = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->escapeHtml($item->getProduct()->getName()));
144
+ $this->_getSession()->addSuccess($message);
145
+ }
146
+ $this->_goBack();
147
+ }
148
+ } catch (Mage_Core_Exception $e) {
149
+ if ($this->_getSession()->getUseNotice(true)) {
150
+ $this->_getSession()->addNotice($e->getMessage());
151
+ } else {
152
+ $messages = array_unique(explode("\n", $e->getMessage()));
153
+ foreach ($messages as $message) {
154
+ $this->_getSession()->addError($message);
155
+ }