zinc - Version 1.0.8

Version Notes

Code refactoring and bug fixing.

Download this release

Release Info

Developer ZincPlatform
Extension zinc
Version 1.0.8
Comparing to
See all releases


Code changes from version 1.0.7 to 1.0.8

Files changed (46) hide show
  1. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Grid.php +21 -21
  2. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/List.php +33 -0
  3. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Form.php +5 -5
  4. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Tab/Form.php +14 -14
  5. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Grid.php +150 -82
  6. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/System/Config/Importorders.php +56 -0
  7. app/code/local/Zinc/Carebyzinc/Block/Carebyzinc.php +7 -8
  8. app/code/local/Zinc/Carebyzinc/Helper/Data.php +67 -47
  9. app/code/local/Zinc/Carebyzinc/Model/Carebyzinc.php +426 -241
  10. app/code/local/Zinc/Carebyzinc/Model/Checkout/Cart.php +128 -138
  11. app/code/local/Zinc/Carebyzinc/Model/Observer.php +57 -65
  12. app/code/local/Zinc/Carebyzinc/Model/Order.php +285 -52
  13. app/code/local/Zinc/Carebyzinc/Model/System/Config/Protocol.php +0 -23
  14. app/code/local/Zinc/Carebyzinc/Model/System/Config/Source.php +11 -3
  15. app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/CarebyzincController.php +30 -16
  16. app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/ProductController.php +143 -100
  17. app/code/local/Zinc/Carebyzinc/controllers/CartController.php +185 -3
  18. app/code/local/Zinc/Carebyzinc/controllers/Checkout/OnepageController.php +46 -0
  19. app/code/local/Zinc/Carebyzinc/controllers/IndexController.php +115 -115
  20. app/code/local/Zinc/Carebyzinc/etc/adminhtml.xml +5 -0
  21. app/code/local/Zinc/Carebyzinc/etc/config.xml +170 -155
  22. app/code/local/Zinc/Carebyzinc/etc/system.xml +157 -80
  23. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-1.0.0-1.0.1.php +0 -12
  24. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-1.0.6-1.0.7.php +4 -4
  25. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-1.0.7-1.0.8.php +23 -0
  26. app/design/adminhtml/default/default/layout/zinc_carebyzinc.xml +11 -1
  27. app/design/adminhtml/default/default/template/carebyzinc/carebyzinc_massaction.phtml +122 -105
  28. app/design/adminhtml/default/default/template/carebyzinc/system/importorders.phtml +19 -0
  29. app/design/frontend/base/default/layout/zinc_carebyzinc.xml +336 -312
  30. app/design/frontend/base/default/template/carebyzinc/carebyzinc.phtml +161 -92
  31. app/design/frontend/base/default/template/carebyzinc/checkout/cart.phtml +122 -120
  32. app/design/frontend/base/default/template/carebyzinc/checkout/cart/item/default.phtml +306 -294
  33. app/design/frontend/base/default/template/carebyzinc/checkout/cart/minicart/default.phtml +84 -91
  34. app/design/frontend/base/default/template/carebyzinc/checkout/multishipping/item/default.phtml +1 -1
  35. app/design/frontend/base/default/template/carebyzinc/checkout/onepage/review/item.phtml +1 -1
  36. app/design/frontend/base/default/template/carebyzinc/checkout/success.phtml +85 -0
  37. app/design/frontend/base/default/template/carebyzinc/options/cart.phtml +34 -39
  38. app/design/frontend/base/default/template/carebyzinc/options/default.phtml +38 -46
  39. app/design/frontend/base/default/template/carebyzinc/sales/order/shipment/items/renderer/default.phtml +79 -0
  40. js/carebyzinc/functions.js +3 -0
  41. media/catalog/product/zinc/warranty.png +0 -0
  42. package.xml +8 -8
  43. skin/adminhtml/default/default/carebyzinc/carebyzinc.css +3 -0
  44. skin/frontend/base/default/carebyzinc/css/carebyzinc.css +355 -89
  45. skin/frontend/rwd/default/carebyzinc/css/carebyzinc.css +355 -89
  46. skin/frontend/rwd/default/carebyzinc/css/colorbox.css +29 -30
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Grid.php CHANGED
@@ -17,14 +17,14 @@ class Zinc_Carebyzinc_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtm
17
protected function _prepareColumns()
18
{
19
20
- $this->addColumnAfter('carebyzinc',
21
- array(
22
- 'header'=> Mage::helper('catalog')->__('Care by Zinc'),
23
- 'width' => '70px',
24
- 'index' => 'carebyzinc',
25
- 'type' => 'options',
26
- 'options' => array('1' => 'Enabled', '0' => 'Disabled'),
27
- ), 'visibility');
28
29
return parent::_prepareColumns();
30
}
@@ -59,19 +59,19 @@ class Zinc_Carebyzinc_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtm
59
60
$carebyzinc = Mage::getSingleton('carebyzinc/carebyzinc')->getOptionArray();
61
62
- $this->getMassactionBlock()->addItem('zinc_carebyzinc', array(
63
- 'label'=> Mage::helper('carebyzinc')->__('Change Carebyzinc'),
64
- 'url' => $this->getUrl('adminhtml/product/massCarebyzinc', array('_current'=>true)),
65
- 'additional' => array(
66
- 'visibility' => array(
67
- 'name' => 'zinc_carebyzinc',
68
- 'type' => 'select',
69
- 'class' => 'required-entry',
70
- 'label' => Mage::helper('carebyzinc')->__('Care by Zinc'),
71
- 'values' => $carebyzinc
72
- )
73
- )
74
- ));
75
76
if (Mage::getSingleton('admin/session')->isAllowed('catalog/update_attributes')){
77
$this->getMassactionBlock()->addItem('attributes', array(
17
protected function _prepareColumns()
18
{
19
20
+ // $this->addColumnAfter('carebyzinc',
21
+ // array(
22
+ // 'header'=> Mage::helper('catalog')->__('Care by Zinc'),
23
+ // 'width' => '70px',
24
+ // 'index' => 'carebyzinc',
25
+ // 'type' => 'options',
26
+ // 'options' => array('1' => 'Enabled', '0' => 'Disabled'),
27
+ // ), 'visibility');
28
29
return parent::_prepareColumns();
30
}
59
60
$carebyzinc = Mage::getSingleton('carebyzinc/carebyzinc')->getOptionArray();
61
62
+ // $this->getMassactionBlock()->addItem('zinc_carebyzinc', array(
63
+ // 'label'=> Mage::helper('carebyzinc')->__('Change Carebyzinc'),
64
+ // 'url' => $this->getUrl('adminhtml/product/massCarebyzinc', array('_current'=>true)),
65
+ // 'additional' => array(
66
+ // 'visibility' => array(
67
+ // 'name' => 'zinc_carebyzinc',
68
+ // 'type' => 'select',
69
+ // 'class' => 'required-entry',
70
+ // 'label' => Mage::helper('carebyzinc')->__('Care by Zinc'),
71
+ // 'values' => $carebyzinc
72
+ // )
73
+ // )
74
+ // ));
75
76
if (Mage::getSingleton('admin/session')->isAllowed('catalog/update_attributes')){
77
$this->getMassactionBlock()->addItem('attributes', array(
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/List.php ADDED
@@ -0,0 +1,33 @@
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_List extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
10
+ {
11
+ public function render(Varien_Object $row)
12
+ {
13
+ $result = '';
14
+ $categoryCache = array();
15
+
16
+ $value = $row->getData($this->getColumn()->getIndex());
17
+ if(!empty($value)) {
18
+ $value = explode(",", $value);
19
+ foreach($value as $val) {
20
+ if(in_array($val, $categoryCache)) {
21
+ $result .= $categoryCache[$val] . '<br />';
22
+ } else {
23
+ $_category = Mage::getModel('catalog/category')->load($val);
24
+ $categoryName = $_category->getName();
25
+ $categoryCache[$val] = $_category->getName();
26
+ $result .= $categoryName . '<br />';
27
+ }
28
+ }
29
+ }
30
+
31
+ return $result;
32
+ }
33
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Form.php CHANGED
@@ -10,11 +10,11 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Form extends Mage_Adminhtml_B
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);
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);
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Tab/Form.php CHANGED
@@ -13,7 +13,7 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Tab_Form extends Mage_Adminht
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',
@@ -32,7 +32,7 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Tab_Form extends Mage_Adminht
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',
@@ -61,7 +61,7 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Tab_Form extends Mage_Adminht
61
$category = Mage::registry('carebyzinc_data')->getData('carebyzinc_category');
62
if(($this->getRequest()->getParam('id')) && ($category)) {
63
$fieldset->addField('carebyzinc_subcategory', 'select', array(
64
- 'label' => Mage::helper('carebyzinc')->__('Sub Category'),
65
'class' => 'required-entry',
66
'required' => true,
67
'name' => 'subcategory',
@@ -70,7 +70,7 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Tab_Form extends Mage_Adminht
70
}else{
71
72
$fieldset->addField('carebyzinc_subcategory', 'select', array(
73
- 'label' => Mage::helper('carebyzinc')->__('Sub Category'),
74
'class' => 'required-entry',
75
'required' => true,
76
'name' => 'subcategory',
@@ -93,16 +93,16 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Tab_Form extends Mage_Adminht
93
));
94
95
$this->setChild('form_after', $this->getLayout()
96
- ->createBlock('adminhtml/widget_form_element_dependence')
97
- ->addFieldMap('carebyzinc', 'carebyzinc')
98
- ->addFieldMap('carebyzinc_category', 'carebyzinc_category')
99
- ->addFieldMap('carebyzinc_manufacturer', 'carebyzinc_manufacturer')
100
- ->addFieldMap('carebyzinc_model', 'carebyzinc_model')
101
- ->addFieldMap('carebyzinc_subcategory', 'carebyzinc_subcategory')
102
- ->addFieldDependence('carebyzinc_category', 'carebyzinc', 1)
103
- ->addFieldDependence('carebyzinc_subcategory', 'carebyzinc', 1)
104
- ->addFieldDependence('carebyzinc_model', 'carebyzinc_category', array((string)'Bicycle',(string)'Electronics'))
105
- ->addFieldDependence('carebyzinc_manufacturer', 'carebyzinc_category', array((string)'Bicycle',(string)'Electronics'))
106
);
107
108
if ( Mage::getSingleton('adminhtml/session')->getVendorData() )
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')->__('Enable Zinc Quote'),
17
'class' => 'required-entry',
18
'required' => true,
19
'name' => 'carebyzinc',
32
33
));
34
$fieldset->addField('carebyzinc_category', 'select', array(
35
+ 'label' => Mage::helper('carebyzinc')->__('Zinc Category'),
36
'class' => 'required-entry',
37
'required' => true,
38
'name' => 'category',
61
$category = Mage::registry('carebyzinc_data')->getData('carebyzinc_category');
62
if(($this->getRequest()->getParam('id')) && ($category)) {
63
$fieldset->addField('carebyzinc_subcategory', 'select', array(
64
+ 'label' => Mage::helper('carebyzinc')->__('Zinc Subcategory'),
65
'class' => 'required-entry',
66
'required' => true,
67
'name' => 'subcategory',
70
}else{
71
72
$fieldset->addField('carebyzinc_subcategory', 'select', array(
73
+ 'label' => Mage::helper('carebyzinc')->__('Zinc Subcategory'),
74
'class' => 'required-entry',
75
'required' => true,
76
'name' => 'subcategory',
93
));
94
95
$this->setChild('form_after', $this->getLayout()
96
+ ->createBlock('adminhtml/widget_form_element_dependence')
97
+ ->addFieldMap('carebyzinc', 'carebyzinc')
98
+ ->addFieldMap('carebyzinc_category', 'carebyzinc_category')
99
+ ->addFieldMap('carebyzinc_manufacturer', 'carebyzinc_manufacturer')
100
+ ->addFieldMap('carebyzinc_model', 'carebyzinc_model')
101
+ ->addFieldMap('carebyzinc_subcategory', 'carebyzinc_subcategory')
102
+ ->addFieldDependence('carebyzinc_category', 'carebyzinc', 1)
103
+ ->addFieldDependence('carebyzinc_subcategory', 'carebyzinc', 1)
104
+ ->addFieldDependence('carebyzinc_model', 'carebyzinc_category', array((string)'Bicycle',(string)'Electronics'))
105
+ ->addFieldDependence('carebyzinc_manufacturer', 'carebyzinc_category', array((string)'Bicycle',(string)'Electronics'))
106
);
107
108
if ( Mage::getSingleton('adminhtml/session')->getVendorData() )
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Grid.php CHANGED
@@ -8,103 +8,145 @@
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->addAttributeToFilter('visibility',array('neq'=>1));
23
$collection->addAttributeToSelect('carebyzinc');
24
- $collection->addAttributeToSelect('carebyzinc_category');
25
- //$collection->addAttributeToSelect('carebyzinc_subcategory');
26
$collection->addExpressionAttributeToSelect('carebyzinc','round({{carebyzinc}},0)','carebyzinc');
27
- parent::setCollection($collection);
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
79
- $this->addColumn('carebyzinc_category',
80
- array(
81
- 'header'=> Mage::helper('catalog')->__('Category'),
82
- 'index' => 'carebyzinc_category',
83
));
84
- /* $this->addColumn('carebyzinc_subcategory',
85
- array(
86
- 'header'=> Mage::helper('catalog')->__('Subcategory'),
87
- 'index' => 'carebyzinc_subcategory',
88
- ));*/
89
90
$this->addColumn('action', array(
91
- 'header' => Mage::helper('carebyzinc')->__('Action'),
92
- 'width' => '100',
93
- 'type' => 'action',
94
- 'getter' => 'getId',
95
- 'actions' => array(
96
- array(
97
- 'caption' => Mage::helper('carebyzinc')->__('Edit'),
98
- 'url' => array('base'=> '*/*/edit'),
99
- 'title' => 'Edit',
100
- 'field' => 'id'
101
- )
102
- ),
103
- 'filter' => false,
104
- 'sortable' => false,
105
- 'index' => 'stores',
106
- 'is_system' => true,
107
));
108
return $this;
109
}
110
@@ -113,10 +155,10 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_
113
$this->setMassactionIdField('entity_id');
114
$this->getMassactionBlock()->setFormFieldName('product');
115
116
- $carebyzinc = Mage::getSingleton('carebyzinc/carebyzinc')->getOptionArray();
117
118
$this->getMassactionBlock()->addItem('zinc_carebyzinc', array(
119
- 'label'=> Mage::helper('carebyzinc')->__('Change Care by Zinc'),
120
'url' => $this->getUrl('adminhtml/product/massCarebyzinc', array('_current'=>true,'pid'=>1)),
121
'additional' => array(
122
'visibility' => array(
@@ -127,8 +169,8 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_
127
)
128
)
129
));
130
- $this->getMassactionBlock()->addItem('carebyzinc_category', array(
131
- 'label'=> Mage::helper('carebyzinc')->__('Change Category'),
132
'url' => $this->getUrl('adminhtml/product/massCategory', array('_current'=>true,'pid'=>1)),
133
'additional' => array(
134
'visibility' => array(
@@ -145,12 +187,38 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_
145
return $this;
146
}
147
148
- public function getRowUrl($row)
149
- {
150
- return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
151
- }
152
- public function getGridUrl(){
153
- return $this->getUrl('*/*/grid', array('_current'=>true));
154
- }
155
156
}
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
+ $collection->addAttributeToFilter('visibility',array('neq'=>1));
22
$collection->addAttributeToSelect('carebyzinc');
23
+ $collection->addAttributeToSelect('carebyzinc_category');
24
+ $collection->addAttributeToSelect('carebyzinc_subcategory');
25
$collection->addExpressionAttributeToSelect('carebyzinc','round({{carebyzinc}},0)','carebyzinc');
26
+
27
+ $select = $collection->getSelect();
28
+ $aliasCategory = 'catalog_category_product';
29
+
30
+ $subselect = $collection->getConnection()->select();
31
+ $subselect->from(
32
+ array(
33
+ 'main_table' => $collection->getTable('catalog/category_product'),
34
+ ),
35
+ array(
36
+ 'product_id',
37
+ )
38
+ );
39
+ $subselect->columns(array(
40
+ 'category_ids' => new Zend_Db_Expr("GROUP_CONCAT(`main_table`.`category_id`)")
41
+ ));
42
+ $subselect->group('main_table.product_id');
43
+
44
+ $select->joinLeft(
45
+ array($aliasCategory => $subselect),
46
+ "`e`.`entity_id` = `{$aliasCategory}`.`product_id`",
47
+ array('category_ids')
48
+ );
49
+
50
+ parent::setCollection($collection);
51
}
52
53
+ protected function _prepareColumns()
54
{
55
+ $this->addColumn('entity_id', array(
56
+ 'header'=> Mage::helper('catalog')->__('ID'),
57
+ 'width' => '30px',
58
+ 'type' => 'number',
59
+ 'index' => 'entity_id',
60
));
61
+
62
+ $this->addColumn('name', array(
63
+ 'header'=> Mage::helper('catalog')->__('Name'),
64
+ 'index' => 'name',
65
+ 'width' => '400px'
66
));
67
68
$store = $this->_getStore();
69
if ($store->getId()) {
70
+ $this->addColumn('custom_name', array(
71
+ 'header'=> Mage::helper('catalog')->__('Name in %s', $store->getName()),
72
+ 'index' => 'custom_name',
73
));
74
}
75
76
+ $this->addColumn('sku', array(
77
+ 'header'=> Mage::helper('catalog')->__('SKU'),
78
+ 'width' => '80px',
79
+ 'index' => 'sku',
80
));
81
82
+ $this->addColumn('price', array(
83
+ 'header'=> Mage::helper('catalog')->__('Price'),
84
+ 'type' => 'price',
85
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
86
+ 'index' => 'price',
87
+ ));
88
+
89
+ $this->addColumn('category_ids', array(
90
+ 'header'=> Mage::helper('catalog')->__('Category'),
91
+ 'type' => 'text',
92
+ 'width' => '150px',
93
+ 'index' => 'category_ids',
94
+ 'filter_index' => 'catalog_category_product.category_ids',
95
+ 'renderer' => 'Zinc_Carebyzinc_Block_Adminhtml_Catalog_Product_Renderer_List',
96
+ 'filter_condition_callback' => array($this, '_categoryFilterCallback')
97
));
98
+
99
+ $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
100
+ ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
101
+ ->load()
102
+ ->toOptionHash();
103
+ $this->addColumnAfter('set_name', array(
104
+ 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
105
+ 'width' => '120px',
106
+ 'index' => 'attribute_set_id',
107
+ 'type' => 'options',
108
+ 'options' => $sets,
109
+ ), 'name');
110
111
+ $this->addColumn('carebyzinc', array(
112
+ 'header'=> Mage::helper('catalog')->__('Enable Zinc Quote'),
113
+ 'width' => '120px',
114
+ 'index' => 'carebyzinc',
115
+ 'type' => 'options',
116
+ 'options' => array('1' => 'Enable', '0' => 'Disable')
117
));
118
119
+ $this->addColumn('carebyzinc_category', array(
120
+ 'header'=> Mage::helper('catalog')->__('Zinc Category'),
121
+ 'index' => 'carebyzinc_category',
122
+ 'width' => '120px'
123
+ ));
124
+
125
+ $this->addColumn('carebyzinc_subcategory', array(
126
+ 'header'=> Mage::helper('catalog')->__('Zinc Subcategory'),
127
+ 'index' => 'carebyzinc_subcategory',
128
+ 'width' => '120px'
129
));
130
131
$this->addColumn('action', array(
132
+ 'header' => Mage::helper('carebyzinc')->__('Action'),
133
+ 'width' => '100',
134
+ 'type' => 'action',
135
+ 'getter' => 'getId',
136
+ 'actions' => array(
137
+ array(
138
+ 'caption' => Mage::helper('carebyzinc')->__('Edit'),
139
+ 'url' => array('base'=> '*/*/edit'),
140
+ 'title' => 'Edit',
141
+ 'field' => 'id'
142
+ )
143
+ ),
144
+ 'filter' => false,
145
+ 'sortable' => false,
146
+ 'index' => 'stores',
147
+ 'is_system' => true,
148
));
149
+
150
return $this;
151
}
152
155
$this->setMassactionIdField('entity_id');
156
$this->getMassactionBlock()->setFormFieldName('product');
157
158
+ $carebyzinc = Mage::getSingleton('carebyzinc/carebyzinc')->getOptionArray();
159
160
$this->getMassactionBlock()->addItem('zinc_carebyzinc', array(
161
+ 'label'=> Mage::helper('carebyzinc')->__('Update Zinc Enablement'),
162
'url' => $this->getUrl('adminhtml/product/massCarebyzinc', array('_current'=>true,'pid'=>1)),
163
'additional' => array(
164
'visibility' => array(
169
)
170
)
171
));
172
+ $this->getMassactionBlock()->addItem('carebyzinc_category', array(
173
+ 'label'=> Mage::helper('carebyzinc')->__('Update Zinc Category'),
174
'url' => $this->getUrl('adminhtml/product/massCategory', array('_current'=>true,'pid'=>1)),
175
'additional' => array(
176
'visibility' => array(
187
return $this;
188
}
189
190
+ public function getRowUrl($row)
191
+ {
192
+ return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
193
+ }
194
195
+ public function getGridUrl()
196
+ {
197
+ return $this->getUrl('*/*/grid', array('_current'=>true));
198
+ }
199
+
200
+ protected function _categoryFilterCallback($collection, $column)
201
+ {
202
+ if (!$value = $column->getFilter()->getValue()) {
203
+ return $this;
204
+ }
205
+
206
+ $categories = Mage::getResourceModel('catalog/category_collection');
207
+
208
+ $categories->addAttributeToFilter('name', array('like' => '%' . $value . '%'));
209
+
210
+ $select = $categories->getSelect();
211
+
212
+ $select->reset(Zend_Db_Select::COLUMNS);
213
+
214
+ $select->joinLeft(
215
+ array('catalog_category_product' => $collection->getTable('catalog/category_product')),
216
+ 'e.entity_id = catalog_category_product.category_id',
217
+ array('product_id')
218
+ );
219
+
220
+ $collection->addAttributeToFilter($collection->getResource()->getIdFieldName(), array('in' => $select));
221
+
222
+ return $this;
223
+ }
224
}
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/System/Config/Importorders.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_Importorders 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/importorders.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/importorders');
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' => 'import_button',
50
+ 'label' => $this->helper('adminhtml')->__('Import Orders'),
51
+ 'onclick' => 'javascript:importOrders(); return false;'
52
+ ));
53
+
54
+ return $button->toHtml();
55
+ }
56
+ }
app/code/local/Zinc/Carebyzinc/Block/Carebyzinc.php CHANGED
@@ -1,23 +1,22 @@
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
}
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
}
app/code/local/Zinc/Carebyzinc/Helper/Data.php CHANGED
@@ -1,55 +1,75 @@
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){
20
- if($primaryAddress->getPostcode())
21
- $zip = $primaryAddress->getPostcode();
22
- }
23
- }
24
- if(! $zip){
25
- $url = 'http://freegeoip.net/json/'.$_SERVER['REMOTE_ADDR'];
26
- $response = $this->callApi($url);
27
- $responseArray = (array)json_decode($response);
28
- $zip = $responseArray['zip_code'];
29
- if(! $zip)
30
- $zip = Mage::getStoreConfig('carebyzinc/general/defaultzip');
31
- }
32
- return $zip;
33
- }
34
- public function getDeleteUrl($itemId){
35
-
36
- return Mage::getUrl('carebyzinc/index/removeWarranty', array('id' => $itemId));
37
-
38
- }
39
-
40
- public function callApi($url){
41
-
42
- $ch = curl_init($url);
43
- curl_setopt($ch, CURLOPT_URL, $url);
44
- curl_setopt($ch, CURLOPT_HEADER ,FALSE);
45
- curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json"));
46
- curl_setopt($ch, CURLOPT_RETURNTRANSFER ,TRUE);
47
- $result = curl_exec($ch);
48
- curl_close($ch);
49
- return $result;
50
- }
51
- public function checkQuoteVisibility(){
52
- return Mage::getStoreConfig('carebyzinc/general/showquote');
53
-
54
- }
55
}
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 getZipCode()
11
+ {
12
+ $zip = '';
13
+ if(Mage::getSingleton('customer/session')->isLoggedIn()) {
14
+ $primaryAddress = Mage::getSingleton('customer/session')->getCustomer()->getPrimaryShippingAddress();
15
+ if($primaryAddress) {
16
+ if($primaryAddress->getPostcode()) {
17
+ $zip = $primaryAddress->getPostcode();
18
+ }
19
+ }
20
+ }
21
+
22
+ if(!$zip) {
23
+ $url = 'http://freegeoip.net/json/' . $_SERVER['REMOTE_ADDR'];
24
+ $response = $this->callApi($url);
25
+ $responseArray = (array) json_decode($response);
26
+ $zip = $responseArray['zip_code'];
27
+ if (!$zip) {
28
+ $zip = Mage::getStoreConfig('carebyzinc/general/defaultzip');
29
+ }
30
+ }
31
+
32
+ return $zip;
33
+ }
34
+
35
+ public function getDeleteUrl($itemId)
36
+ {
37
+ return Mage::getUrl('carebyzinc/index/removeWarranty', array('id' => $itemId));
38
+ }
39
+
40
+ public function callApi($url)
41
+ {
42
+ $ch = curl_init($url);
43
+ curl_setopt($ch, CURLOPT_URL, $url);
44
+ curl_setopt($ch, CURLOPT_HEADER, FALSE);
45
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
46
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
47
+ $result = curl_exec($ch);
48
+ curl_close($ch);
49
+ return $result;
50
+ }
51
+
52
+ /**
53
+ * Check quote visability on frontend (for product and cart pages)
54
+ *
55
+ * @param string $type - page type
56
+ * @return boolean $result - show/hide care by zinc section
57
+ */
58
+ public function checkQuoteVisibility($type = 'product')
59
+ {
60
+ $result = false;
61
+ switch($type) {
62
+ case 'cart':
63
+ $result = Mage::getStoreConfig('carebyzinc/display/quotecart');
64
+ break;
65
+ case 'product':
66
+ $result = Mage::getStoreConfig('carebyzinc/display/quoteproduct');
67
+ break;
68
+ default:
69
+ break;
70
+ }
71
+
72
+ return $result;
73
+ }
74
+
75
}
app/code/local/Zinc/Carebyzinc/Model/Carebyzinc.php CHANGED
@@ -1,267 +1,452 @@
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
- $data = array();
35
- $data['sku'] = array(
36
- 'merchant_sku_id' => $product->getId(),
37
- 'sku_name' => $product->getName(),
38
- 'variant_id' => '',
39
- 'category' => $product->getCarebyzincCategory(),
40
- 'subcategory' => $product->getCarebyzincSubcategory(),
41
- 'subcategory2' => '',
42
- 'description' => $product->getShortDescription(),
43
- 'price' => $price,
44
- 'currency' => $currencyCode
45
- );
46
- $catArray = array('bicycle','electronics');
47
- if(in_array(strtolower($product->getCarebyzincCategory()),$catArray)){
48
-
49
- if(($product->getCarebyzincModel()) && ($product->getCarebyzincManufacturer())){
50
- $additional = array('model'=>$product->getCarebyzincModel());
51
- $data['sku']['additional_info'] = json_encode($additional);
52
- $data['sku']['brand'] = $product->getCarebyzincManufacturer();
53
- }
54
55
- }
56
- if(! $zip){
57
- $helper = Mage::helper('carebyzinc');
58
- $zip = $helper->getZipCode();
59
- }
60
- $data['zip_code'] = $zip;
61
- $outData = $this->callApi($data, 'price_quotes/generate');
62
- if($outData['code'] == '200'){
63
- $response = $outData['response'];
64
- $quoteData = json_decode($response, true);
65
- $priceQuote = array();
66
- foreach($quoteData['price_quotes'] as $item):
67
- $priceQuote[$item['id']] = $item;
68
- endforeach;
69
- Mage::getSingleton('core/session')->setCareQuote($priceQuote);
70
- return $priceQuote;
71
72
- }else{
73
- $response = $outData['response'];
74
- $response = (array)json_decode($response, true);
75
- return 'No Quotes Available';
76
- }
77
-
78
- }
79
-
80
- public function getPriceQuoteinCart($product,$itemId,$zip)
81
- {
82
-
83
- $currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
84
- $_item = Mage::getModel('sales/quote_item')->load($itemId);
85
- $data = array();
86
- $data['sku'] = array(
87
- 'merchant_sku_id' => $product->getId(),
88
- 'sku_name' => $product->getName(),
89
- 'variant_id' => '',
90
- 'category' => $product->getCarebyzincCategory(),
91
- 'subcategory' => $product->getCarebyzincSubcategory(),
92
- 'subcategory2' => '',
93
- 'description' => $product->getShortDescription(),
94
- 'price' => $_item->getPrice(),
95
- 'currency' => $currencyCode
96
- );
97
- $catArray = array('bicycle','electronics');
98
- if(in_array(strtolower($product->getCarebyzincCategory()),$catArray)){
99
-
100
- if(($product->getCarebyzincModel()) && ($product->getCarebyzincManufacturer())){
101
- $additional = array('model'=>$product->getCarebyzincModel());
102
- $data['sku']['additional_info'] = json_encode($additional);
103
- $data['sku']['brand'] = $product->getCarebyzincManufacturer();
104
- }
105
106
- }
107
- if(! $zip){
108
- $helper = Mage::helper('carebyzinc');
109
- $zip = $helper->getZipCode();
110
- }
111
- $data['zip_code'] = $zip;
112
- $outData = $this->callApi($data, 'price_quotes/generate');
113
- if($outData['code'] == '200'){
114
- $response = $outData['response'];
115
- $quoteData = json_decode($response, true);
116
- $priceQuote = array();
117
- if(! empty($quoteData['price_quotes'])){
118
- $priceQuote = Mage::getSingleton('core/session')->getCareByZincQuote();
119
- foreach($quoteData['price_quotes'] as $item):
120
- if($priceQuote[$itemId])
121
- unset($priceQuote[$itemId]);
122
- $priceQuote[$itemId][$item['id']] = $item;
123
- endforeach;
124
- Mage::getSingleton('core/session')->setCareByZincQuote($priceQuote);
125
- return $priceQuote;
126
- }else{
127
- return 'No Quotes Available';
128
- }
129
- }else{
130
- $response = $outData['response'];
131
- $response = (array)json_decode($response, true);
132
- return 'No Quotes Available';//return $response['errors'];
133
- }
134
-
135
- }
136
-
137
- public function getApiUrl($action)
138
- {
139
- $path = Mage::getStoreConfig('carebyzinc/api/url');
140
- if((Mage::getStoreConfig('carebyzinc/api/testmode')) == 'live')
141
- $path = Mage::getStoreConfig('carebyzinc/api/url');
142
- else
143
- $path = Mage::getStoreConfig('carebyzinc/api/test_url');
144
- if(Mage::getStoreConfig('carebyzinc/api/protocol') == 'https')
145
- $protocol = 'https://' ;
146
- else
147
- $protocol = 'http://' ;
148
- $url = $protocol.$path.'/'.$action;
149
- return $url;
150
- }
151
-
152
- public function getToken()
153
- {
154
-
155
- if((Mage::getStoreConfig('carebyzinc/api/testmode')) == 'live')
156
- $token = Mage::getStoreConfig('carebyzinc/api/xuser_token');
157
- else
158
- $token = Mage::getStoreConfig('carebyzinc/api/test_xuser_token');
159
- return $token;
160
- }
161
-
162
- public function callApi($data, $action, $method = 'post'){
163
- $outData = array();
164
- $values = json_encode($data);
165
- $url = $this->getApiUrl($action);
166
- $token = $this->getToken();
167
- $email = Mage::getStoreConfig('carebyzinc/api/xuser_email');
168
- if(($action =='price_quotes/generate') || ($action == 'policies' ))
169
- $header = array( "Content-Type: application/json","X-User-Token:$token","X-User-Email:$email","token-type:Bearer");
170
- elseif($action == 'token')
171
- $header = array( "Content-Type: application/json","X-User-Token:$token","X-User-Email:$email","token-type:Bearer");
172
173
- else
174
- $header = array( "Content-Type: application/json","token-type:Bearer");
175
-
176
- $ch = curl_init($url);
177
- curl_setopt($ch, CURLOPT_URL, $url);
178
- if($method == 'post'){
179
- curl_setopt($ch, CURLOPT_POST,TRUE);
180
- curl_setopt($ch, CURLOPT_POSTFIELDS,$values);
181
- }
182
- curl_setopt($ch, CURLOPT_HEADER ,FALSE);
183
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
184
- curl_setopt($ch, CURLOPT_RETURNTRANSFER ,TRUE);
185
- curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
186
- $outData['response'] = curl_exec($ch);
187
- $outData['code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
188
- curl_close($ch);
189
- return $outData;
190
- }
191
-
192
- public function getwarrantyStatus( $item_id,$warrentyitem )
193
- {
194
- if($item_id < 0){
195
- return '';
196
- }
197
- $cart = Mage::getModel('checkout/cart');
198
- $quoteItem = $cart->getQuote()->getItemById($item_id);
199
- if($quoteItem){
200
- $product = Mage::getModel('catalog/product')->load($quoteItem->getProductId());
201
- if(($product->getCarebyzinc() != 1) && ($quoteItem->getCarebyzincVariantid())){
202
-
203
- $quoteItem->setCarebyzincVariantid(NULL);
204
- $quoteItem->save();
205
- $cartHelper = Mage::helper('checkout/cart');
206
- $cartHelper->getCart()->removeItem($warrentyitem)->save();
207
- $cart->getQuote()->collectTotals()->save();
208
-
209
- }
210
- }
211
- return true;
212
}
213
214
-
215
public function getCategoryArray()
216
- {
217
-
218
-
219
- $dataArray = $this->getCategoryJson();
220
- $category = array(''=>'Please Select');
221
- foreach($dataArray as $key => $value){
222
- $category[$key] = $key;
223
- }
224
- return $category;
225
226
- }
227
- public function getSubCategoryArray($category)
228
- {
229
- if($category)
230
- $dataArray = $this->getCategoryJson();
231
- $subcategory = array(''=>'Please Select');
232
- foreach($dataArray as $key => $value){
233
- if($key == $category){
234
- foreach($value as $val){
235
- $subcategory[$val] = $val;
236
- }
237
- }
238
- }
239
- return $subcategory;
240
241
- }
242
- public function getCategoryJson()
243
- {
244
-
245
- $outData = $this->callApi('','categories','get');
246
- if($outData['code'] == '200')
247
- $response = $outData['response'];
248
- else
249
- $response = '{"Jewelry": ["Bracelet", "Necklace","Pendant","Brooch","Engagement Ring","Wedding Ring","Other Ring","Other"]}';
250
- $dataArray = json_decode($response);
251
- return $dataArray;
252
-
253
- }
254
-
255
- public function getWarrentyName($itemId)
256
- {
257
- $name = '';
258
- $orderItem = Mage::getModel('sales/quote_item')->load($itemId);
259
- $product = Mage::getModel('catalog/product')->load($orderItem->getProductId());
260
- if($product)
261
- $name = ' for '. $product->getName();
262
- return $name;
263
-
264
- }
265
-
266
267
}
1
<?php
2
+
3
+ /**
4
* ZincPlatform
5
* @package Zinc_Carebyzinc
6
* @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
10
{
11
+
12
+ const WARRANTY_ENABLED = 1;
13
+ const WARRANTY_DISABLED = 0;
14
+
15
+ const QUOTE_ADDITIONAL_PARAMS_SOURCE_PRODUCT = 'PRODUCT_PROFILE';
16
+ const QUOTE_ADDITIONAL_PARAMS_SOURCE_CART = 'CART';
17
+
18
+ public function _construct()
19
{
20
parent::_construct();
21
$this->_init('carebyzinc/carebyzinc');
22
}
23
+
24
+ /**
25
+ * Get Zinc Plugin enablement status
26
+ *
27
+ * @return string Enabled/Disabled
28
+ */
29
+ static public function getOptionArray()
30
{
31
return array(
32
+ self::WARRANTY_ENABLED => Mage::helper('carebyzinc')->__('Enabled'),
33
+ self::WARRANTY_DISABLED => Mage::helper('carebyzinc')->__('Disabled')
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Get Zinc Quote for product page
39
+ *
40
+ * @param object $product
41
+ * @param string $zip
42
+ * @param string $optionPrice
43
+ *
44
+ * @return mixed $result - price quoite / error message
45
+ */
46
+ public function getPriceQuote($product, $zip, $optionPrice)
47
+ {
48
+ $result = false;
49
+
50
+ $currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
51
+ $price = $product->getFinalPrice();
52
+ if ($optionPrice) {
53
+ $price += $optionPrice;
54
+ }
55
+
56
+ $data = array();
57
+ $data['sku'] = array(
58
+ 'merchant_sku_id' => $product->getId(),
59
+ 'sku_name' => $product->getName(),
60
+ 'variant_id' => '',
61
+ 'category' => $product->getCarebyzincCategory(),
62
+ 'subcategory' => $product->getCarebyzincSubcategory(),
63
+ 'subcategory2' => '',
64
+ 'description' => $product->getShortDescription(),
65
+ 'price' => $price,
66
+ 'currency' => $currencyCode,
67
+ 'remote_image_url' => Mage::getUrl('media') . 'catalog/product' . $product->getImage()
68
+ );
69
+
70
+ $data['additional_params'] = array(
71
+ 'source' => self::QUOTE_ADDITIONAL_PARAMS_SOURCE_PRODUCT
72
+ );
73
+
74
+ $catArray = array('bicycle', 'electronics');
75
+ if (in_array(strtolower($product->getCarebyzincCategory()), $catArray)) {
76
+
77
+ if (($product->getCarebyzincModel()) && ($product->getCarebyzincManufacturer())) {
78
+ $additional = array('model' => $product->getCarebyzincModel());
79
+ $data['sku']['additional_info'] = json_encode($additional);
80
+ $data['sku']['brand'] = $product->getCarebyzincManufacturer();
81
+ }
82
+ }
83
+
84
+ if (!$zip) {
85
+ $helper = Mage::helper('carebyzinc');
86
+ $zip = $helper->getZipCode();
87
+ }
88
+
89
+ $data['zip_code'] = $zip;
90
+
91
+ $outData = $this->callApi($data, 'price_quotes/generate');
92
+ $response = $outData['response'];
93
+
94
+ switch($outData['code']) {
95
+ case '200':
96
+ $quoteData = json_decode($response, true);
97
+ $priceQuote = array();
98
+ foreach ($quoteData['price_quotes'] as $item) {
99
+ $priceQuote[$item['id']] = $item;
100
+ }
101
+ Mage::getSingleton('core/session')->setCareQuote($priceQuote);
102
+ $result['code'] = '200';
103
+ $result['price'] = $priceQuote;
104
+ break;
105
+ case '400':
106
+ $quoteData = (array) json_decode($response, true);
107
+ $result['code'] = '400';
108
+ if(isset($quoteData['errors'])) {
109
+ $result['title'] = $quoteData['errors'][0]['title'];
110
+ $result['details'] = $quoteData['errors'][0]['details'];
111
+ } else {
112
+ $result = 'No Quotes Available';
113
+ }
114
+ break;
115
+ }
116
+
117
+ return $result;
118
+ }
119
+
120
+ /**
121
+ * Get Zinc Quote for cart page
122
+ *
123
+ * @param object $product
124
+ * @param string $zip
125
+ * @param string $optionPrice
126
+ *
127
+ * @return mixed $result - price quoite / error message
128
+ */
129
+ public function getPriceQuoteinCart($product, $itemId, $zip)
130
+ {
131
+ $result = false;
132
+
133
+ $currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
134
+ $_item = Mage::getModel('sales/quote_item')->load($itemId);
135
+
136
+ $data = array();
137
+ $data['sku'] = array(
138
+ 'merchant_sku_id' => $product->getId(),
139
+ 'sku_name' => $product->getName(),
140
+ 'variant_id' => '',
141
+ 'category' => $product->getCarebyzincCategory(),
142
+ 'subcategory' => $product->getCarebyzincSubcategory(),
143
+ 'subcategory2' => '',
144
+ 'description' => $product->getShortDescription(),
145
+ 'price' => $_item->getPrice(),
146
+ 'currency' => $currencyCode,
147
+ 'remote_image_url' => Mage::getUrl('media') . 'catalog/product' . $product->getImage()
148
+ );
149
+
150
+ $data['additional_params'] = array(
151
+ 'source' => self::QUOTE_ADDITIONAL_PARAMS_SOURCE_CART
152
);
153
+
154
+ $catArray = array('bicycle', 'electronics');
155
+ if (in_array(strtolower($product->getCarebyzincCategory()), $catArray)) {
156
+ if (($product->getCarebyzincModel()) && ($product->getCarebyzincManufacturer())) {
157
+ $additional = array('model' => $product->getCarebyzincModel());
158
+ $data['sku']['additional_info'] = json_encode($additional);
159
+ $data['sku']['brand'] = $product->getCarebyzincManufacturer();
160
+ }
161
+ }
162
+
163
+ if (!$zip) {
164
+ $helper = Mage::helper('carebyzinc');
165
+ $zip = $helper->getZipCode();
166
+ }
167
+
168
+ $data['zip_code'] = $zip;
169
+
170
+ $outData = $this->callApi($data, 'price_quotes/generate');
171
+ $response = $outData['response'];
172
+
173
+ switch($outData['code']) {
174
+ case '200':
175
+ $quoteData = json_decode($response, true);
176
+ $priceQuote = array();
177
+ if (!empty($quoteData['price_quotes'])) {
178
+ $priceQuote = Mage::getSingleton('core/session')->getCareByZincQuote();
179
+ foreach ($quoteData['price_quotes'] as $item) {
180
+ if ($priceQuote[$itemId]) {
181
+ unset($priceQuote[$itemId]);
182
+ }
183
+ $priceQuote[$itemId][$item['id']] = $item;
184
+ }
185
+
186
+ Mage::getSingleton('core/session')->setCareByZincQuote($priceQuote);
187
+ $result['code'] = '200';
188
+ $result['price'] = $priceQuote;
189
+ } else {
190
+ return 'No Quotes Available';
191
+ }
192
+ break;
193
+ case '400':
194
+ $quoteData = (array) json_decode($response, true);
195
+ $result['code'] = '400';
196
+ if(isset($quoteData['errors'])) {
197
+ $result['title'] = $quoteData['errors'][0]['title'];
198
+ $result['details'] = $quoteData['errors'][0]['details'];
199
+ } else {
200
+ $result = 'No Quotes Available';
201
+ }
202
+ break;
203
+ }
204
+
205
+ return $result;
206
+ }
207
208
+ /**
209
+ * Get API URL based on selected application mode
210
+ *
211
+ * @param type $action
212
+ *
213
+ * @return string API URL
214
+ */
215
+ public function getApiUrl($action, $params = false)
216
+ {
217
+ $path = Mage::getStoreConfig('carebyzinc/api/url');
218
219
+ switch (Mage::getStoreConfig('carebyzinc/api/testmode')) {
220
+ case 'live':
221
+ $path = Mage::getStoreConfig('carebyzinc/api/url');
222
+ break;
223
+ case 'sandbox':
224
+ $path = Mage::getStoreConfig('carebyzinc/api/sandbox_url');
225
+ break;
226
+ case 'staging':
227
+ $path = Mage::getStoreConfig('carebyzinc/api/staging_url');
228
+ break;
229
+ case 'test':
230
+ default:
231
+ $path = Mage::getStoreConfig('carebyzinc/api/test_url');
232
+ break;
233
+ }
234
235
+ $protocol = 'https://';
236
+ $url = $protocol . $path . '/' . $action;
237
+
238
+ if($params) {
239
+ $url .= '/' . $params;
240
+ }
241
+
242
+ return $url;
243
+ }
244
245
+ /*
246
+ * Get Token based on selected application mode
247
+ *
248
+ * @return string User Token
249
+ */
250
+ public function getToken()
251
+ {
252
+ $token = false;
253
+ switch (Mage::getStoreConfig('carebyzinc/api/testmode')) {
254
+ case 'live':
255
+ $token = Mage::getStoreConfig('carebyzinc/api/xuser_token');
256
+ break;
257
+ case 'sandbox':
258
+ $token = Mage::getStoreConfig('carebyzinc/api/sandbox_xuser_token');
259
+ break;
260
+ case 'staging':
261
+ $token = Mage::getStoreConfig('carebyzinc/api/staging_xuser_token');
262
+ break;
263
+ case 'test':
264
+ default:
265
+ $token = Mage::getStoreConfig('carebyzinc/api/test_xuser_token');
266
+ break;
267
+ }
268
269
+ return $token;
270
}
271
272
+ /**
273
+ * Call Zinc API
274
+ *
275
+ * @param array $data - input data
276
+ * @param string $action
277
+ * @param string $method
278
+ *
279
+ * @return json $result - API response
280
+ */
281
+ public function callApi($data, $action, $method = 'post')
282
+ {
283
+ $result = array();
284
+ $urlParams = false;
285
+
286
+ if($action == 'interstitials') {
287
+ $urlParams = $data;
288
+ } else {
289
+ $values = json_encode($data);
290
+ }
291
+
292
+ $url = $this->getApiUrl($action, $urlParams);
293
+
294
+ $token = $this->getToken();
295
+ $email = Mage::getStoreConfig('carebyzinc/api/xuser_email');
296
+
297
+ if (($action == 'price_quotes/generate') || ($action == 'policies' ) || ($action == 'retarget/flow') || ($action == 'orders') || ($action == 'interstitials')) {
298
+ $header = array("Content-Type: application/json", "X-User-Token:$token", "X-User-Email:$email", "token-type:Bearer");
299
+ } elseif ($action == 'token') {
300
+ $header = array("Content-Type: application/json", "X-User-Token:$token", "X-User-Email:$email", "token-type:Bearer");
301
+ } else {
302
+ $header = array("Content-Type: application/json", "token-type:Bearer");
303
+ }
304
+
305
+ $ch = curl_init($url);
306
+ curl_setopt($ch, CURLOPT_URL, $url);
307
+ if ($method == 'post') {
308
+ curl_setopt($ch, CURLOPT_POST, TRUE);
309
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $values);
310
+ }
311
+ curl_setopt($ch, CURLOPT_HEADER, FALSE);
312
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
313
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
314
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
315
+
316
+ $result['response'] = curl_exec($ch);
317
+ $result['code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
318
+ curl_close($ch);
319
+
320
+ return $result;
321
+ }
322
+
323
+ /**
324
+ * Get warranty status
325
+ *
326
+ * @param type $itemId
327
+ * @param type $warrentyitem
328
+ * @return boolean|string
329
+ */
330
+ public function getwarrantyStatus($itemId, $warrantyItem)
331
+ {
332
+ if ($item_id < 0) {
333
+ return '';
334
+ }
335
+
336
+ $cart = Mage::getModel('checkout/cart');
337
+ $quoteItem = $cart->getQuote()->getItemById($itemId);
338
+ if ($quoteItem) {
339
+ $product = Mage::getModel('catalog/product')->load($quoteItem->getProductId());
340
+ if (($product->getCarebyzinc() != 1) && ($quoteItem->getCarebyzincVariantid())) {
341
+
342
+ $quoteItem->setCarebyzincVariantid(NULL);
343
+ $quoteItem->save();
344
+ $cartHelper = Mage::helper('checkout/cart');
345
+ $cartHelper->getCart()->removeItem($warrantyItem)->save();
346
+ $cart->getQuote()->collectTotals()->save();
347
+ }
348
+ }
349
+
350
+ return true;
351
+ }
352
+
353
+ /**
354
+ * Get Category list
355
+ *
356
+ * @return array $result - category list
357
+ */
358
public function getCategoryArray()
359
+ {
360
+ $dataArray = $this->getCategoryJson();
361
+ $category = array('' => 'Please Select');
362
+ foreach ($dataArray as $key => $value) {
363
+ $category[$key] = $key;
364
+ }
365
+
366
+ return $category;
367
+ }
368
369
+ /**
370
+ * Get Subcategory list
371
+ *
372
+ * @return array $result - subcategory list
373
+ */
374
+ public function getSubCategoryArray($category)
375
+ {
376
+ if ($category)
377
+ $dataArray = $this->getCategoryJson();
378
+ $subcategory = array('' => 'Please Select');
379
+ foreach ($dataArray as $key => $value) {
380
+ if ($key == $category) {
381
+ foreach ($value as $val) {
382
+ $subcategory[$val] = $val;
383
+ }
384
+ }
385
+ }
386
+ return $subcategory;
387
+ }
388
+
389
+ /**
390
+ * Get Subcategory in json
391
+ *
392
+ * @return array $result - category list
393
+ */
394
+ public function getCategoryJson()
395
+ {
396
+ $result = false;
397
+
398
+ $outData = $this->callApi('', 'categories', 'get');
399
+ if ($outData['code'] == '200') {
400
+ $response = $outData['response'];
401
+ } else {
402
+ $response = '{"Jewelry": ["Bracelet", "Necklace","Pendant","Brooch","Engagement Ring","Wedding Ring","Other Ring","Other"]}';
403
+ }
404
+ $result = json_decode($response);
405
+
406
+ return $result;
407
+ }
408
+
409
+ /**
410
+ * Get subcategory suggestions
411
+ *
412
+ * @param string $category - category name
413
+ * @return array $result -subcategories suggestion
414
+ */
415
+ public function getSubCategorySuggestions($category)
416
+ {
417
+ $result = false;
418
+
419
+ $outData = $this->callApi('', 'category_suggestions', 'get');
420
+ if ($outData['code'] == '200'){
421
+ $response = $outData['response'];
422
+ $decode = json_decode($response);
423
+ $result = $decode->$category;
424
+ }
425
+
426
+ return $result;
427
+ }
428
+
429
+ /**
430
+ * Get warranty name
431
+ *
432
+ * @param int $itemId
433
+ * @return string $result - warranty name
434
+ */
435
+ public function getWarrantyName($itemId)
436
+ {
437
+ $result = '';
438
439
+ $orderItem = Mage::getModel('sales/quote_item')->load($itemId);
440
+ $product = Mage::getModel('catalog/product')->load($orderItem->getProductId());
441
+ if ($product) {
442
+ $result = ' for ' . $product->getName();
443
+ }
444
+
445
+ return $result;
446
+ }
447
448
+ public function prepareZincQuoteLayer($product)
449
+ {
450
+
451
+ }
452
}
app/code/local/Zinc/Carebyzinc/Model/Checkout/Cart.php CHANGED
@@ -1,12 +1,13 @@
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
*
@@ -14,151 +15,140 @@ class Zinc_Carebyzinc_Model_Checkout_Cart extends Mage_Checkout_Model_Cart
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
-
22
$productId = $product->getId();
23
- $flag = 0;$qty = 0;
24
$productType = $product->getTypeId();
25
- if(($productType == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE || $productType == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) && ($product->getCarebyzinc() == 1))
26
- {
27
- $flag = 1;
28
- $qty = $request->getQty()?$request->getQty():1;
29
- $request['qty'] = 1;
30
- }
31
if ($product->getStockItem()) {
32
$minimumQty = $product->getStockItem()->getMinSaleQty();
33
//If product was not found in cart and there is set minimal qty for it
34
- if ($minimumQty && $minimumQty > 0 && $request->getQty() < $minimumQty
35
- && !$this->getQuote()->hasProductId($productId)
36
- ){
37
$request->setQty($minimumQty);
38
}
39
}
40
- if($flag){
41
-
42
- if ($productId) {
43
- try {
44
- for($i= 0;$i<$qty;$i++){
45
-
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
-
53
- $result = ( $result->getParentItem() ? $result->getParentItem() : $result );
54
-
55
- $carebyzincId = $request->getCarebyzincOption();
56
- $priceQuote = Mage::getSingleton('core/session')->getCareQuote();
57
- $carebyzincAry = $priceQuote[$carebyzincId];
58
- if(! empty($carebyzincAry)){
59
-
60
- $productPrice = $result->getProduct()->getFinalPrice();
61
-
62
- if($carebyzincId){
63
- $result->setCarebyzincVariantid($carebyzincId);
64
- $warrantPrdctId = Mage::getStoreConfig('carebyzinc/general/warranty_product');
65
- if($warrantPrdctId){
66
- $req = $this->_getProductRequest(array('product'=>$warrantPrdctId,'qty'=>1,'form_key'=>$request['form_key']));
67
-
68
- $this->getQuote()->save();
69
- $careParentId = $result->getId();
70
-
71
- $warrantyProduct = Mage::getModel('catalog/product')->load($warrantPrdctId);
72
- $productPrice = $warrantyProduct->getPrice();
73
- if($price = $carebyzincAry['price_per_year'])
74
- $newPrice = $productPrice + $price;
75
- $resultItem = $this->getQuote()->addProduct($warrantyProduct, $req);
76
- $resultItem->setCustomPrice($newPrice);
77
- $resultItem->setOriginalCustomPrice($newPrice);
78
- $resultItem->setCarebyzincPrice($price);
79
- $resultItem->setCarebyzincParentid((int)$careParentId);
80
- $resultItem->getProduct()->setIsSuperMode(true);
81
- if( $item = $priceQuote[$carebyzincId]){
82
- $additionalOptions[] = array(
83
- 'label' => 'carebyzinc',
84
- 'value' => $carebyzincId,
85
- );
86
- $resultItem->setCarebyzincOption(serialize($priceQuote[$carebyzincId]));
87
-
88
- }
89
- $resultItem->addOption(array(
90
- 'product_id' => $resultItem->getProductId(),
91
- 'code' => 'additional_options',
92
- 'value' => serialize($additionalOptions)
93
- ));
94
- $this->getQuote()->save();
95
- }
96
- }
97
-
98
99
- }
100
- }
101
- }
102
- } catch (Mage_Core_Exception $e) {
103
- $this->getCheckoutSession()->setUseNotice(false);
104
- $result = $e->getMessage();
105
- }
106
- /**
107
- * String we can get if prepare process has error
108
- */
109
- if (is_string($result)) {
110
- $redirectUrl = ($product->hasOptionsValidationFail())
111
- ? $product->getUrlModel()->getUrl(
112
- $product,
113
- array('_query' => array('startcustomization' => 1))
114
- )
115
- : $product->getProductUrl();
116
- $this->getCheckoutSession()->setRedirectUrl($redirectUrl);
117
- if ($this->getCheckoutSession()->getUseNotice() === null) {
118
- $this->getCheckoutSession()->setUseNotice(true);
119
- }
120
- Mage::throwException($result);
121
- }
122
- } else {
123
- Mage::throwException(Mage::helper('checkout')->__('The product does not exist.'));
124
- }
125
126
- Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));
127
- $this->getCheckoutSession()->setLastAddedProductId($productId);
128
- Mage::getSingleton('core/session')->unsCareQuote();
129
- }else{
130
- if ($productId) {
131
- try {
132
- $result = $this->getQuote()->addProduct($product, $request);
133
-
134
- } catch (Mage_Core_Exception $e) {
135
- $this->getCheckoutSession()->setUseNotice(false);
136
- $result = $e->getMessage();
137
- }
138
- /**
139
- * String we can get if prepare process has error
140
- */
141
- if (is_string($result)) {
142
- $redirectUrl = ($product->hasOptionsValidationFail())
143
- ? $product->getUrlModel()->getUrl(
144
- $product,
145
- array('_query' => array('startcustomization' => 1))
146
- )
147
- : $product->getProductUrl();
148
- $this->getCheckoutSession()->setRedirectUrl($redirectUrl);
149
- if ($this->getCheckoutSession()->getUseNotice() === null) {
150
- $this->getCheckoutSession()->setUseNotice(true);
151
- }
152
- Mage::throwException($result);
153
- }
154
- }else {
155
- Mage::throwException(Mage::helper('checkout')->__('The product does not exist.'));
156
- }
157
158
- Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));
159
- $this->getCheckoutSession()->setLastAddedProductId($productId);
160
- }
161
-
162
return $this;
163
- }
164
}
1
<?php
2
+
3
+ /**
4
* ZincPlatform
5
* @package Zinc_Carebyzinc
6
* @copyright Copyright (c) 2016-2017 Zinplatform (http://www.zincplatform.com/)
7
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ class Zinc_Carebyzinc_Model_Checkout_Cart extends Mage_Checkout_Model_Cart {
10
+
11
/**
12
* Add product to shopping cart (quote)
13
*
15
* @param mixed $requestInfo
16
* @return Mage_Checkout_Model_Cart
17
*/
18
+ public function addProduct($productInfo, $requestInfo = null) {
19
$product = $this->_getProduct($productInfo);
20
+ $request = $this->_getProductRequest($requestInfo);
21
+
22
$productId = $product->getId();
23
+ $flag = 0;
24
+ $qty = 0;
25
$productType = $product->getTypeId();
26
+
27
+ if (($productType == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE || $productType == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) && ($product->getCarebyzinc() == 1)) {
28
+ $flag = 1;
29
+ $qty = $request->getQty() ? $request->getQty() : 1;
30
+ $request['qty'] = 1;
31
+ }
32
if ($product->getStockItem()) {
33
$minimumQty = $product->getStockItem()->getMinSaleQty();
34
//If product was not found in cart and there is set minimal qty for it
35
+ if ($minimumQty && $minimumQty > 0 && $request->getQty() < $minimumQty && !$this->getQuote()->hasProductId($productId)
36
+ ) {
37
$request->setQty($minimumQty);
38
}
39
}
40
+ if ($flag) {
41
42
+ if ($productId) {
43
+ try {
44
+ for ($i = 0; $i < $qty; $i++) {
45
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
+
53
+ $result = ( $result->getParentItem() ? $result->getParentItem() : $result );
54
+
55
+ $carebyzincId = $request->getCarebyzincOption();
56
+ $priceQuote = Mage::getSingleton('core/session')->getCareQuote();
57
+ $carebyzincAry = $priceQuote[$carebyzincId];
58
+ if (!empty($carebyzincAry)) {
59
+
60
+ $productPrice = $result->getProduct()->getFinalPrice();
61
+ if ($carebyzincId) {
62
+ $result->setCarebyzincVariantid($carebyzincId);
63
+ $warrantPrdctId = Mage::getStoreConfig('carebyzinc/general/warranty_product');
64
+ if ($warrantPrdctId) {
65
+ $req = $this->_getProductRequest(array('product' => $warrantPrdctId, 'qty' => 1, 'form_key' => $request['form_key']));
66
+
67
+ $this->getQuote()->save();
68
+ $careParentId = $result->getId();
69
+
70
+ $warrantyProduct = Mage::getModel('catalog/product')->load($warrantPrdctId);
71
+ $productPrice = $warrantyProduct->getPrice();
72
+ if ($price = $carebyzincAry['price_per_year'])
73
+ $newPrice = $productPrice + $price;
74
+ $resultItem = $this->getQuote()->addProduct($warrantyProduct, $req);
75
+ $resultItem->setCustomPrice($newPrice);
76
+ $resultItem->setOriginalCustomPrice($newPrice);
77
+ $resultItem->setCarebyzincPrice($price);
78
+ $resultItem->setCarebyzincParentid((int) $careParentId);
79
+ $resultItem->getProduct()->setIsSuperMode(true);
80
+ if ($item = $priceQuote[$carebyzincId]) {
81
+ $additionalOptions[] = array(
82
+ 'label' => 'carebyzinc',
83
+ 'value' => $carebyzincId,
84
+ );
85
+ $resultItem->setCarebyzincOption(serialize($priceQuote[$carebyzincId]));
86
+ }
87
+ $resultItem->addOption(array(
88
+ 'product_id' => $resultItem->getProductId(),
89
+ 'code' => 'additional_options',
90
+ 'value' => serialize($additionalOptions)
91
+ ));
92
+ $this->getQuote()->save();
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ } catch (Mage_Core_Exception $e) {
99
+ $this->getCheckoutSession()->setUseNotice(false);
100
+ $result = $e->getMessage();
101
+ }
102
+ /**
103
+ * String we can get if prepare process has error
104
+ */
105
+ if (is_string($result)) {
106
+ $redirectUrl = ($product->hasOptionsValidationFail()) ? $product->getUrlModel()->getUrl(
107
+ $product, array('_query' => array('startcustomization' => 1))
108
+ ) : $product->getProductUrl();
109
+ $this->getCheckoutSession()->setRedirectUrl($redirectUrl);
110
+ if ($this->getCheckoutSession()->getUseNotice() === null) {
111
+ $this->getCheckoutSession()->setUseNotice(true);
112
+ }
113
+ Mage::throwException($result);
114
+ }
115
+ } else {
116
+ Mage::throwException(Mage::helper('checkout')->__('The product does not exist.'));
117
+ }
118
+
119
+ Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));
120
+ $this->getCheckoutSession()->setLastAddedProductId($productId);
121
+ Mage::getSingleton('core/session')->unsCareQuote();
122
+ } else {
123
+ if ($productId) {
124
+ try {
125
+ $result = $this->getQuote()->addProduct($product, $request);
126
+ } catch (Mage_Core_Exception $e) {
127
+ $this->getCheckoutSession()->setUseNotice(false);
128
+ $result = $e->getMessage();
129
+ }
130
+ /**
131
+ * String we can get if prepare process has error
132
+ */
133
+ if (is_string($result)) {
134
+ $redirectUrl = ($product->hasOptionsValidationFail()) ? $product->getUrlModel()->getUrl(
135
+ $product, array('_query' => array('startcustomization' => 1))
136
+ ) : $product->getProductUrl();
137
+ $this->getCheckoutSession()->setRedirectUrl($redirectUrl);
138
+ if ($this->getCheckoutSession()->getUseNotice() === null) {
139
+ $this->getCheckoutSession()->setUseNotice(true);
140
+ }
141
+ Mage::throwException($result);
142
+ }
143
+ } else {
144
+ Mage::throwException(Mage::helper('checkout')->__('The product does not exist.'));
145
+ }
146
+
147
+ Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));
148
+ $this->getCheckoutSession()->setLastAddedProductId($productId);
149
+ }
150
151
return $this;
152
+ }
153
+
154
}
app/code/local/Zinc/Carebyzinc/Model/Observer.php CHANGED
@@ -5,81 +5,72 @@
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
23
public function setCarebyzinc($observer)
24
- {
25
- if(Mage::getStoreConfig('carebyzinc/general/enabled')){
26
- $order = $observer->getEvent()->getOrder();
27
- $orderId = $order->getId();
28
- $orderItems = $order->getAllItems();
29
- foreach($orderItems as $item){
30
- if(($item->getCarebyzincParentid()) && ($item->getCarebyzincOption())){
31
-
32
- $careParentId = 0;
33
- $orderItemCollection = Mage::getModel('sales/order_item')->getCollection()
34
- ->addFieldToFilter('quote_item_id', $item->getCarebyzincParentid())
35
- ->addFieldToFilter('order_id', $orderId);
36
- foreach($orderItemCollection as $col){
37
- $careParentId = $col->getItemId();
38
- }
39
- if($careParentId){
40
- $item->setCarebyzincParentid((int)$careParentId);
41
- $item->save();
42
- }
43
-
44
-
45
-
46
- }
47
-
48
- }
49
- }
50
-
51
}
52
53
public function cartLoad($observer)
54
{
55
- if( ! Mage::getStoreConfig('carebyzinc/general/enabled')){
56
$cartHelper = Mage::helper('checkout/cart');
57
$cart = Mage::getModel('checkout/cart')->getQuote();
58
$idArray = array();
59
foreach ($cart->getAllItems() as $item) {
60
- if($item->getCarebyzincVariantid()){
61
$item->setCarebyzincVariantid(NULL);
62
$item->save();
63
$idArray[] = $item->getId();
64
- }else{
65
if(($item->getProductId() == Mage::getStoreConfig('carebyzinc/general/warranty_product')) || (in_array($item->getCarebyzincParentid(),$idArray)) ){
66
$cartHelper->getCart()->removeItem($item->getId())->save();
67
}
68
}
69
-
70
-
71
}
72
- }else{
73
$cart = Mage::getModel('checkout/cart')->getQuote();
74
foreach ($cart->getAllItems() as $item) {
75
- if($item->getProductId() == Mage::getStoreConfig('carebyzinc/general/warranty_product')){
76
$model = Mage::getModel('carebyzinc/carebyzinc');
77
$carebyStatus = $model->getwarrantyStatus($item->getCarebyzincParentid(),$item->getId());
78
}
79
}
80
-
81
}
82
-
83
}
84
85
public function warrantyDelete($observer)
@@ -87,49 +78,50 @@ class Zinc_Carebyzinc_Model_Observer{
87
$_item = $observer->getEvent()->getQuoteItem();
88
$itemId = $_item->getId();
89
$productId = $_item->getProductId();
90
- if(Mage::getStoreConfig('carebyzinc/general/enabled')){
91
$cartHelper = Mage::helper('checkout/cart');
92
- if($_item->getCarebyzincVariantid()){
93
$cart = Mage::getModel('checkout/cart')->getQuote();
94
foreach ($cart->getAllItems() as $item) {
95
- if($item->getCarebyzincParentid() == $itemId)
96
- $cartHelper->getCart()->removeItem($item->getId())->save();
97
-
98
}
99
- }else{
100
- if($productId == Mage::getStoreConfig('carebyzinc/general/warranty_product')){
101
$itemId = $_item->getCarebyzincParentid();
102
$cart = Mage::getSingleton('checkout/cart');
103
- $item = $cart->getQuote()->getItemById($itemId);
104
- if($item){
105
$item->setCarebyzincVariantid(NULL);
106
$item->save();
107
}
108
}
109
}
110
-
111
}
112
-
113
}
114
- public function salesQuoteItemSetProduct(Varien_Event_Observer $observer)
115
{
116
/* @var $item Mage_Sales_Model_Quote_Item */
117
$item = $observer->getQuoteItem();
118
$name = '';
119
120
- if($item->getProductId() == Mage::getStoreConfig('carebyzinc/general/warranty_product')){
121
$quoteItem = Mage::getModel('sales/quote_item')->load($item->getCarebyzincParentid());
122
$carebyzincAry = (array) unserialize($item->getCarebyzincOption());
123
124
- if($quoteItem)
125
- $name = $item->getName().' for '.$quoteItem->getName();
126
- if($name)
127
- $item->setName($name);
128
- if($carebyzincAry['quote_type'])
129
- $item->setSku($carebyzincAry['quote_type']);
130
}
131
return $this;
132
}
133
-
134
-
135
}
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
public function saveCarebyzinc($observer)
11
{
12
+ if(!Mage::registry('carebyzinc_save')) {
13
+ $order = $observer->getEvent()->getOrder();
14
$model = Mage::getModel('carebyzinc/order');
15
$model->savePolicy($order);
16
Mage::register('carebyzinc_save',true);
17
+
18
+ $model->recordOrderToZinc($order);
19
+ }
20
}
21
22
public function setCarebyzinc($observer)
23
+ {
24
+ if(Mage::getStoreConfig('carebyzinc/general/enabled')) {
25
+ $order = $observer->getEvent()->getOrder();
26
+ $orderId = $order->getId();
27
+ $orderItems = $order->getAllItems();
28
+ foreach($orderItems as $item) {
29
+ if(($item->getCarebyzincParentid()) && ($item->getCarebyzincOption())) {
30
+ $careParentId = 0;
31
+ $orderItemCollection = Mage::getModel('sales/order_item')->getCollection()
32
+ ->addFieldToFilter('quote_item_id', $item->getCarebyzincParentid())
33
+ ->addFieldToFilter('order_id', $orderId);
34
+
35
+ foreach($orderItemCollection as $col) {
36
+ $careParentId = $col->getItemId();
37
+ }
38
+
39
+ if($careParentId){
40
+ $item->setCarebyzincParentid((int)$careParentId);
41
+ $item->save();
42
+ }
43
+ }
44
+ }
45
+ }
46
}
47
48
public function cartLoad($observer)
49
{
50
+ if(!Mage::getStoreConfig('carebyzinc/general/enabled')){
51
$cartHelper = Mage::helper('checkout/cart');
52
$cart = Mage::getModel('checkout/cart')->getQuote();
53
$idArray = array();
54
foreach ($cart->getAllItems() as $item) {
55
+ if($item->getCarebyzincVariantid()) {
56
$item->setCarebyzincVariantid(NULL);
57
$item->save();
58
$idArray[] = $item->getId();
59
+ } else {
60
if(($item->getProductId() == Mage::getStoreConfig('carebyzinc/general/warranty_product')) || (in_array($item->getCarebyzincParentid(),$idArray)) ){
61
$cartHelper->getCart()->removeItem($item->getId())->save();
62
}
63
}
64
}
65
+ } else {
66
$cart = Mage::getModel('checkout/cart')->getQuote();
67
foreach ($cart->getAllItems() as $item) {
68
+ if($item->getProductId() == Mage::getStoreConfig('carebyzinc/general/warranty_product')) {
69
$model = Mage::getModel('carebyzinc/carebyzinc');
70
$carebyStatus = $model->getwarrantyStatus($item->getCarebyzincParentid(),$item->getId());
71
}
72
}
73
}
74
}
75
76
public function warrantyDelete($observer)
78
$_item = $observer->getEvent()->getQuoteItem();
79
$itemId = $_item->getId();
80
$productId = $_item->getProductId();
81
+ if(Mage::getStoreConfig('carebyzinc/general/enabled')) {
82
$cartHelper = Mage::helper('checkout/cart');
83
+ if($_item->getCarebyzincVariantid()) {
84
$cart = Mage::getModel('checkout/cart')->getQuote();
85
foreach ($cart->getAllItems() as $item) {
86
+ if($item->getCarebyzincParentid() == $itemId) {
87
+ $cartHelper->getCart()->removeItem($item->getId())->save();
88
+ }
89
}
90
+ } else {
91
+ if($productId == Mage::getStoreConfig('carebyzinc/general/warranty_product')) {
92
$itemId = $_item->getCarebyzincParentid();
93
$cart = Mage::getSingleton('checkout/cart');
94
+ $item = $cart->getQuote()->getItemById($itemId);
95
+ if($item) {
96
$item->setCarebyzincVariantid(NULL);
97
$item->save();
98
}
99
}
100
}
101
}
102
}
103
+
104
+ public function salesQuoteItemSetProduct(Varien_Event_Observer $observer)
105
{
106
/* @var $item Mage_Sales_Model_Quote_Item */
107
$item = $observer->getQuoteItem();
108
$name = '';
109
110
+ if($item->getProductId() == Mage::getStoreConfig('carebyzinc/general/warranty_product')) {
111
$quoteItem = Mage::getModel('sales/quote_item')->load($item->getCarebyzincParentid());
112
$carebyzincAry = (array) unserialize($item->getCarebyzincOption());
113
114
+ if($quoteItem) {
115
+ $name = $item->getName().' for '.$quoteItem->getName();
116
+ }
117
+ if($name) {
118
+ $item->setName($name);
119
+ }
120
+ if($carebyzincAry['quote_type']) {
121
+ $item->setSku($carebyzincAry['quote_type']);
122
+ }
123
}
124
+
125
return $this;
126
}
127
}
app/code/local/Zinc/Carebyzinc/Model/Order.php CHANGED
@@ -7,23 +7,22 @@
7
*/
8
class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
9
{
10
-
11
const PRODUCTION = 1;
12
const SANDBOX = 0;
13
public function _construct()
14
{
15
parent::_construct();
16
$this->_init('carebyzinc/order');
17
}
18
19
-
20
public function savePolicy($order)
21
{
22
$data = array();
23
$currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
24
$data['customer'] = $this->getUserAddress($order);
25
$carebyItem = 0;$policyKeyArray = array();
26
- $orderItems = $order->getAllVisibleItems();
27
$fromname = Mage::getStoreConfig('trans_email/ident_general/name');
28
$fromemail = Mage::getStoreConfig('trans_email/ident_general/email');
29
$translate = Mage::getSingleton('core/translate');
@@ -32,30 +31,33 @@ class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
32
$templateId = Mage::getStoreConfig('sales_email/order/template');
33
34
$model = Mage::getModel('carebyzinc/carebyzinc');
35
- if((Mage::getStoreConfig('carebyzinc/api/testmode')) == 'live')
36
- $mode = 1;
37
- else
38
- $mode = 0;
39
$orderId = $order->getId();
40
- foreach($orderItems as $item){
41
-
42
- if($item->getCarebyzincVariantid()){
43
- $policyNo = ''; $carezincOption = '';
44
$orderItemCollection = Mage::getModel('sales/order_item')->getCollection()
45
- ->addFieldToFilter('carebyzinc_parentid', $item->getQuoteItemId())
46
- ->addFieldToFilter('order_id', $orderId);
47
48
- foreach($orderItemCollection as $col){
49
- $carezincOption = $col->getCarebyzincOption();
50
- }
51
- $carebyzincAry = (array) unserialize($carezincOption) ;
52
- $product = Mage::getModel('catalog/product')->load($item->getProductId());
53
$data['price_quote_id'] = $carebyzincAry['id'];
54
$data['sku_id'] = $carebyzincAry['sku_id'];
55
$result = $model->callApi($data, 'policies');
56
$policyAry = $result['response'];
57
if($result['code'] == 200){
58
- $policyArray = (array) json_decode($policyAry);
59
$policyNo = $policyArray['policy_id'];
60
}
61
$policyKeyArray[] = $policyNo;
@@ -78,41 +80,36 @@ class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
78
$careOrder->setCreatedTime(now());
79
$careOrder->setOrderCreatedMode($mode);
80
$careOrder->save();
81
-
82
}
83
}
84
- if($carebyItem){
85
$fromname = Mage::getStoreConfig('trans_email/ident_general/name');
86
$fromemail = Mage::getStoreConfig('trans_email/ident_general/email');
87
$translate = Mage::getSingleton('core/translate');
88
$email = 'support@zincplatform.com';
89
$name = 'Zinc';
90
$templateId = Mage::getStoreConfig('sales_email/order/template');
91
- if($email){
92
- for($i =0;$i<count($policyKeyArray);$i++){
93
- $storeObj = Mage::getModel('core/store')->load($order->getStoreId());
94
- $anyDate = $order->getCreatedAt();
95
$dateTimestamp = Mage::getModel('core/date')->timestamp(strtotime($anyDate));
96
$date = date("Y-m-d",$dateTimestamp);
97
$subject = $policyKeyArray[$i].'_'.$storeObj->getFrontendName().'_'.$date;
98
- $emailTemplate = Mage::getModel('core/email_template')->loadDefault('sales_email_order_template');
99
- $emailTemplateVariables = array();
100
- $emailTemplateVariables['order'] = $order;
101
- $emailTemplateVariables['store'] = $storeObj;
102
- $emailTemplate->setSenderName($fromname);
103
- $emailTemplate->setSenderEmail($fromemail);
104
- $emailTemplate->setType('html');
105
- $emailTemplate->setTemplateSubject($subject);
106
- $emailTemplate->send($email, $name, $emailTemplateVariables);
107
}
108
-
109
}
110
-
111
}
112
}
113
114
-
115
-
116
public function getUserAddress($order)
117
{
118
$address ['first_name'] = $order->getCustomerFirstname();
@@ -123,24 +120,260 @@ class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
123
$address ['main_phone_number'] = $billingAddress->getTelephone();
124
$address ['country'] = $billingAddress->getCountryId();
125
$address ['address'] = array(
126
- "billing_city" => $billingAddress->getCity(),
127
- "billing_zip_code" => $billingAddress->getPostcode(),
128
- "billing_state" => $billingAddress->getRegion(),
129
- "billing_address1" => $billingAddress->getStreet(),
130
- );
131
-
132
return $address;
133
-
134
}
135
-
136
-
137
-
138
-
139
- static public function getOptionArray()
140
{
141
return array(
142
- self::PRODUCTION => Mage::helper('carebyzinc')->__('Production'),
143
- self::SANDBOX => Mage::helper('carebyzinc')->__('Sandbox')
144
);
145
}
146
}
7
*/
8
class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
9
{
10
const PRODUCTION = 1;
11
const SANDBOX = 0;
12
+
13
public function _construct()
14
{
15
parent::_construct();
16
$this->_init('carebyzinc/order');
17
}
18
19
public function savePolicy($order)
20
{
21
$data = array();
22
$currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
23
$data['customer'] = $this->getUserAddress($order);
24
$carebyItem = 0;$policyKeyArray = array();
25
+ $orderItems = $order->getAllVisibleItems();
26
$fromname = Mage::getStoreConfig('trans_email/ident_general/name');
27
$fromemail = Mage::getStoreConfig('trans_email/ident_general/email');
28
$translate = Mage::getSingleton('core/translate');
31
$templateId = Mage::getStoreConfig('sales_email/order/template');
32
33
$model = Mage::getModel('carebyzinc/carebyzinc');
34
+ if((Mage::getStoreConfig('carebyzinc/api/testmode')) == 'live') {
35
+ $mode = 1;
36
+ } else {
37
+ $mode = 0;
38
+ }
39
+
40
$orderId = $order->getId();
41
+ foreach($orderItems as $item) {
42
+ if($item->getCarebyzincVariantid()) {
43
+ $policyNo = '';
44
+ $carezincOption = '';
45
$orderItemCollection = Mage::getModel('sales/order_item')->getCollection()
46
+ ->addFieldToFilter('carebyzinc_parentid', $item->getQuoteItemId())
47
+ ->addFieldToFilter('order_id', $orderId);
48
49
+ foreach($orderItemCollection as $col) {
50
+ $carezincOption = $col->getCarebyzincOption();
51
+ }
52
+
53
+ $carebyzincAry = (array) unserialize($carezincOption);
54
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
55
$data['price_quote_id'] = $carebyzincAry['id'];
56
$data['sku_id'] = $carebyzincAry['sku_id'];
57
$result = $model->callApi($data, 'policies');
58
$policyAry = $result['response'];
59
if($result['code'] == 200){
60
+ $policyArray = (array) json_decode($policyAry);
61
$policyNo = $policyArray['policy_id'];
62
}
63
$policyKeyArray[] = $policyNo;
80
$careOrder->setCreatedTime(now());
81
$careOrder->setOrderCreatedMode($mode);
82
$careOrder->save();
83
}
84
}
85
+ if($carebyItem) {
86
$fromname = Mage::getStoreConfig('trans_email/ident_general/name');
87
$fromemail = Mage::getStoreConfig('trans_email/ident_general/email');
88
$translate = Mage::getSingleton('core/translate');
89
$email = 'support@zincplatform.com';
90
$name = 'Zinc';
91
$templateId = Mage::getStoreConfig('sales_email/order/template');
92
+ if($email) {
93
+ for($i =0;$i<count($policyKeyArray);$i++) {
94
+ $storeObj = Mage::getModel('core/store')->load($order->getStoreId());
95
+ $anyDate = $order->getCreatedAt();
96
$dateTimestamp = Mage::getModel('core/date')->timestamp(strtotime($anyDate));
97
$date = date("Y-m-d",$dateTimestamp);
98
$subject = $policyKeyArray[$i].'_'.$storeObj->getFrontendName().'_'.$date;
99
+ $emailTemplate = Mage::getModel('core/email_template')->loadDefault('sales_email_order_template');
100
+ $emailTemplateVariables = array();
101
+ $emailTemplateVariables['order'] = $order;
102
+ $emailTemplateVariables['store'] = $storeObj;
103
+ $emailTemplate->setSenderName($fromname);
104
+ $emailTemplate->setSenderEmail($fromemail);
105
+ $emailTemplate->setType('html');
106
+ $emailTemplate->setTemplateSubject($subject);
107
+ $emailTemplate->send($email, $name, $emailTemplateVariables);
108
}
109
}
110
}
111
}
112
113
public function getUserAddress($order)
114
{
115
$address ['