zinc - Version 1.0.7

Version Notes

Fix Configurable product issues and fixed minor bugs

Download this release

Release Info

Developer ZincPlatform
Extension zinc
Version 1.0.7
Comparing to
See all releases


Code changes from version 1.0.4 to 1.0.7

Files changed (65) hide show
  1. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/Category.php +57 -8
  2. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/Manufacturer.php +31 -0
  3. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/Model.php +32 -0
  4. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/Subcategory.php +31 -0
  5. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Tab/Form.php +29 -3
  6. app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Grid.php +1 -1
  7. app/code/local/Zinc/Carebyzinc/Helper/Data.php +0 -6
  8. app/code/local/Zinc/Carebyzinc/Model/Carebyzinc.php +72 -64
  9. app/code/local/Zinc/Carebyzinc/Model/Checkout/Cart.php +61 -54
  10. app/code/local/Zinc/Carebyzinc/Model/Checkout/Multishipping.php +190 -0
  11. app/code/local/Zinc/Carebyzinc/Model/Entity/Subcategory.php +5 -3
  12. app/code/local/Zinc/Carebyzinc/Model/Observer.php +99 -11
  13. app/code/local/Zinc/Carebyzinc/Model/Order.php +16 -14
  14. app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/CarebyzincController.php +8 -9
  15. app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/ProductController.php +118 -71
  16. app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/Sales/Order/CreditmemoController.php +52 -0
  17. app/code/local/Zinc/Carebyzinc/controllers/CartController.php +159 -86
  18. app/code/local/Zinc/Carebyzinc/controllers/IndexController.php +46 -63
  19. app/code/local/Zinc/Carebyzinc/controllers/Sales/OrderController.php +53 -0
  20. app/code/local/Zinc/Carebyzinc/etc/config.xml +79 -25
  21. app/code/local/Zinc/Carebyzinc/etc/system.xml +11 -26
  22. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-1.0.4-1.0.5.php +23 -0
  23. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-1.0.5-1.0.6.php +23 -0
  24. app/code/local/Zinc/Carebyzinc/sql/carebyzinc_setup/mysql4-upgrade-1.0.6-1.0.7.php +104 -0
  25. app/design/adminhtml/default/default/layout/zinc_carebyzinc.xml +29 -23
  26. app/design/adminhtml/default/default/template/carebyzinc/carebyzinc_massaction.phtml +113 -0
  27. app/design/adminhtml/default/default/template/carebyzinc/order/creditmemo/create/items/renderer/default.phtml +3 -4
  28. app/design/adminhtml/default/default/template/carebyzinc/order/creditmemo/view/items/renderer/default.phtml +3 -4
  29. app/design/adminhtml/default/default/template/carebyzinc/order/invoice/create/items/renderer/default.phtml +3 -4
  30. app/design/adminhtml/default/default/template/carebyzinc/order/invoice/view/items/renderer/default.phtml +3 -4
  31. app/design/adminhtml/default/default/template/carebyzinc/order/shipment/create/items/renderer/default.phtml +3 -3
  32. app/design/adminhtml/default/default/template/carebyzinc/order/shipment/view/items/renderer/default.phtml +3 -3
  33. app/design/adminhtml/default/default/template/carebyzinc/order/view/items/renderer/default.phtml +1 -2
  34. app/design/frontend/base/default/layout/zinc_carebyzinc.xml +36 -50
  35. app/design/frontend/base/default/template/carebyzinc/carebyzinc.phtml +17 -4
  36. app/design/frontend/base/default/template/carebyzinc/checkout/cart.phtml +26 -6
  37. app/design/frontend/base/default/template/carebyzinc/checkout/cart/item/default.phtml +119 -131
  38. app/design/frontend/base/default/template/carebyzinc/checkout/cart/minicart/default.phtml +13 -6
  39. app/design/frontend/base/default/template/carebyzinc/checkout/multishipping/item/default.phtml +12 -2
  40. app/design/frontend/base/default/template/carebyzinc/checkout/onepage/review/info.phtml +97 -0
  41. app/design/frontend/base/default/template/carebyzinc/checkout/onepage/review/item.phtml +12 -4
  42. app/design/frontend/base/default/template/carebyzinc/email/order/items/creditmemo/default.phtml +2 -4
  43. app/design/frontend/base/default/template/carebyzinc/email/order/items/invoice/default.phtml +2 -4
  44. app/design/frontend/base/default/template/carebyzinc/email/order/items/order/default.phtml +2 -4
  45. app/design/frontend/base/default/template/carebyzinc/email/order/items/shipment/default.phtml +2 -4
  46. app/design/frontend/base/default/template/carebyzinc/options/cart.phtml +15 -4
  47. app/design/frontend/base/default/template/carebyzinc/options/default.phtml +22 -13
  48. app/design/frontend/base/default/template/carebyzinc/sales/order/creditmemo/items/renderer/default.phtml +2 -4
  49. app/design/frontend/base/default/template/carebyzinc/sales/order/invoice/items/renderer/default.phtml +2 -4
  50. app/design/frontend/base/default/template/carebyzinc/sales/order/items/renderer/default.phtml +2 -4
  51. app/design/frontend/base/default/template/carebyzinc/sales/order/shipment/items/renderer/default.phtml +0 -79
  52. js/carebyzinc/jquery.min.js +4 -0
  53. js/carebyzinc/noConflict.js +1 -0
  54. media/catalog/product/zinc/warranty.png +0 -0
  55. package.xml +9 -11
  56. skin/frontend/base/default/carebyzinc/css/carebyzinc.css +19 -11
  57. skin/frontend/rwd/default/carebyzinc/css/carebyzinc.css +109 -0
  58. skin/frontend/rwd/default/carebyzinc/css/colorbox.css +71 -0
  59. skin/frontend/rwd/default/carebyzinc/css/images/border.png +0 -0
  60. skin/frontend/rwd/default/carebyzinc/css/images/cancel.png +0 -0
  61. skin/frontend/rwd/default/carebyzinc/css/images/care-preloader.gif +0 -0
  62. skin/frontend/rwd/default/carebyzinc/css/images/controls.png +0 -0
  63. skin/frontend/rwd/default/carebyzinc/css/images/loading.gif +0 -0
  64. skin/frontend/rwd/default/carebyzinc/css/images/loading_background.png +0 -0
  65. skin/frontend/rwd/default/carebyzinc/css/images/overlay.png +0 -0
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/Category.php CHANGED
@@ -13,7 +13,36 @@ class Zinc_Carebyzinc_Block_Adminhtml_Catalog_Product_Renderer_Category extends
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')."';
@@ -21,18 +50,38 @@ class Zinc_Carebyzinc_Block_Adminhtml_Catalog_Product_Renderer_Category extends
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
}
13
$html = parent::getAfterElementHtml();
14
15
return $html."<script>
16
+
17
+ if(document.getElementById('carebyzinc').value != 1){
18
+ $('carebyzinc_category').hide();
19
+ jQuery('label[for=carebyzinc_category], input#carebyzinc_category').hide();
20
+
21
+ }else{
22
+ $('carebyzinc_category').show();
23
+ document.getElementById('carebyzinc_category').className += ' required-entry';
24
+ }
25
+ document.getElementById('carebyzinc_category').onchange = function() {
26
+ getSubcategories(this.value)
27
+ var category = this.value.toLowerCase();
28
+ var subarray = ['bicycle','electronics'];
29
+ if(subarray.indexOf(category) >= 0){
30
+ $('carebyzinc_manufacturer').show();
31
+ jQuery('label[for=carebyzinc_manufacturer], input#carebyzinc_manufacturer').show();
32
+ $('carebyzinc_model').show();
33
+ jQuery('label[for=carebyzinc_model], input#carebyzinc_model').show();
34
+ document.getElementById('carebyzinc_manufacturer').className += ' required-entry validate-length maximum-length-30 minimum-length-1';
35
+ document.getElementById('carebyzinc_model').className += ' required-entry validate-length maximum-length-30 minimum-length-1';
36
+ }else{
37
+ $('carebyzinc_manufacturer').hide();
38
+ jQuery('label[for=carebyzinc_manufacturer], input#carebyzinc_manufacturer').hide();
39
+ $('carebyzinc_model').hide();
40
+ jQuery('label[for=carebyzinc_model], input#carebyzinc_model').hide();
41
+
42
+ }
43
+
44
+
45
+ };
46
47
function getSubcategories(selectElement){
48
var reloadurl = '". Mage::getUrl('adminhtml/product/getSubcategories')."';
50
new Ajax.Request(reloadurl, {parameters: { cat: selectElement},
51
method: 'post',
52
onComplete: function(transport) {
53
+ var content = JSON.parse(transport.responseText);
54
+ var i = 0;
55
+ document.getElementById('carebyzinc_subcategory').options.length = 0;
56
+ for (var key in content) {
57
+ document.getElementById('carebyzinc_subcategory').options[i] = new Option(content[key],key);
58
+ i++;
59
+ }
60
61
}
62
});
63
}else
64
document.getElementById('carebyzinc_subcategory').innerHTML='';
65
+ }
66
+ document.getElementById('carebyzinc').onchange = function() {
67
+ if(this.value == 1){
68
+ $('carebyzinc_category').show();
69
+ $('carebyzinc_subcategory').show();
70
+ jQuery('label[for=carebyzinc_category], input#carebyzinc_category').show();
71
+ jQuery('label[for=carebyzinc_subcategory], input#carebyzinc_subcategory').show();
72
+ document.getElementById('carebyzinc_category').className += ' required-entry';
73
+ document.getElementById('carebyzinc_subcategory').className += ' required-entry';
74
+
75
+ }else{
76
+ $('carebyzinc_category').hide();
77
+ $('carebyzinc_subcategory').hide();
78
+ jQuery('label[for=carebyzinc_category], input#carebyzinc_category').hide();
79
+ jQuery('label[for=carebyzinc_subcategory], input#carebyzinc_subcategory').hide();
80
+ }
81
+ };
82
+
83
+
84
+ </script>";
85
86
}
87
}
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/Manufacturer.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
+
9
+ class Zinc_Carebyzinc_Block_Adminhtml_Catalog_Product_Renderer_Manufacturer extends Varien_Data_Form_Element_Text
10
+ {
11
+ public function getAfterElementHtml()
12
+ {
13
+ $html = parent::getAfterElementHtml();
14
+
15
+ return $html."<script>
16
+ var category = document.getElementById('carebyzinc_category').value.toLowerCase();
17
+ var subarray = ['bicycle','electronics'];
18
+ if((document.getElementById('carebyzinc').value == 1) && (subarray.indexOf(category) >= 0)){
19
+ $('carebyzinc_manufacturer').show();
20
+ jQuery('label[for=carebyzinc_manufacturer], input#carebyzinc_manufacturer').show();
21
+ document.getElementById('carebyzinc_manufacturer').className += ' required-entry validate-length maximum-length-30 minimum-length-1';
22
+
23
+ }else{
24
+ $('carebyzinc_manufacturer').hide();
25
+ jQuery('label[for=carebyzinc_manufacturer], input#carebyzinc_manufacturer').hide();
26
+ }
27
+
28
+ </script>";
29
+
30
+ }
31
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/Model.php ADDED
@@ -0,0 +1,32 @@
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_Model extends Varien_Data_Form_Element_Text
10
+ {
11
+ public function getAfterElementHtml()
12
+ {
13
+ $html = parent::getAfterElementHtml();
14
+
15
+ return $html."<script>
16
+
17
+ if((document.getElementById('carebyzinc').value == 1) && (subarray.indexOf(category) >= 0)){
18
+ var category = document.getElementById('carebyzinc_category').value.toLowerCase();
19
+ var subarray = ['bicycle','electronics'];
20
+ $('carebyzinc_model').show();
21
+ jQuery('label[for=carebyzinc_model], input#carebyzinc_model').show();
22
+ document.getElementById('carebyzinc_model').className += ' required-entry validate-length maximum-length-30 minimum-length-1';
23
+
24
+ }else{
25
+ $('carebyzinc_model').hide();
26
+ jQuery('label[for=carebyzinc_model], input#carebyzinc_model').hide();
27
+ }
28
+
29
+ </script>";
30
+
31
+ }
32
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Catalog/Product/Renderer/Subcategory.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
+
9
+ class Zinc_Carebyzinc_Block_Adminhtml_Catalog_Product_Renderer_Subcategory extends Varien_Data_Form_Element_Select
10
+ {
11
+ public function getAfterElementHtml()
12
+ {
13
+ $html = parent::getAfterElementHtml();
14
+
15
+ return $html."<script>
16
+
17
+ if(document.getElementById('carebyzinc').value != 1){
18
+ $('carebyzinc_subcategory').hide();
19
+ jQuery('label[for=carebyzinc_subcategory], input#carebyzinc_category').hide();
20
+
21
+
22
+ }else{
23
+ $('carebyzinc_subcategory').show();
24
+ jQuery('label[for=carebyzinc_subcategory], input#carebyzinc_category').show();
25
+ document.getElementById('carebyzinc_subcategory').className += ' required-entry';
26
+ }
27
+
28
+ </script>";
29
+
30
+ }
31
+ }
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Edit/Tab/Form.php CHANGED
@@ -44,10 +44,11 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Tab_Form extends Mage_Adminht
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
@@ -78,6 +79,31 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Edit_Tab_Form extends Mage_Adminht
78
79
80
}
81
82
if ( Mage::getSingleton('adminhtml/session')->getVendorData() )
83
{
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
+ document.getElementById('carebyzinc_subcategory').options.length = 0;
50
for (var key in content) {
51
+ document.getElementById('carebyzinc_subcategory').options[i] = new Option(content[key],key);
52
i++;
53
}
54
79
80
81
}
82
+ $fieldset->addField('carebyzinc_manufacturer', 'text', array(
83
+ 'label' => Mage::helper('carebyzinc')->__('Manufacturer'),
84
+ 'class' => 'required-entry validate-length maximum-length-30 ',
85
+ 'required' => true,
86
+ 'name' => 'carebyzinc_manufacturer',
87
+ ));
88
+ $fieldset->addField('carebyzinc_model', 'text', array(
89
+ 'label' => Mage::helper('carebyzinc')->__('Model'),
90
+ 'class' => 'required-entry validate-length maximum-length-30 ',
91
+ 'required' => true,
92
+ 'name' => 'carebyzinc_model',
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() )
109
{
app/code/local/Zinc/Carebyzinc/Block/Adminhtml/Product/Grid.php CHANGED
@@ -19,7 +19,7 @@ class Zinc_Carebyzinc_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_
19
public function setCollection($collection)
20
{
21
22
- $collection->addFieldToFilter('price',array('gteq' => 500));
23
$collection->addAttributeToSelect('carebyzinc');
24
$collection->addAttributeToSelect('carebyzinc_category');
25
//$collection->addAttributeToSelect('carebyzinc_subcategory');
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');
app/code/local/Zinc/Carebyzinc/Helper/Data.php CHANGED
@@ -36,13 +36,7 @@ class Zinc_Carebyzinc_Helper_Data extends Mage_Core_Helper_Abstract
36
return Mage::getUrl('carebyzinc/index/removeWarranty', array('id' => $itemId));
37
38
}
39
- public function validatePrice($price){
40
- if($price >=500)
41
- return true;
42
- else
43
- return false;
44
45
- }
46
public function callApi($url){
47
48
$ch = curl_init($url);
36
return Mage::getUrl('carebyzinc/index/removeWarranty', array('id' => $itemId));
37
38
}
39
40
public function callApi($url){
41
42
$ch = curl_init($url);
app/code/local/Zinc/Carebyzinc/Model/Carebyzinc.php CHANGED
@@ -31,8 +31,7 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
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(),
@@ -42,10 +41,18 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
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();
@@ -65,7 +72,7 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
65
}else{
66
$response = $outData['response'];
67
$response = (array)json_decode($response, true);
68
- return $response['errors'];
69
}
70
71
}
@@ -75,7 +82,6 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
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(),
@@ -86,9 +92,18 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
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();
@@ -98,16 +113,23 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
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
}
@@ -125,17 +147,8 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
125
$protocol = 'http://' ;
126
$url = $protocol.$path.'/'.$action;
127
return $url;
128
- }
129
130
- public function getUserId()
131
- {
132
-
133
- if((Mage::getStoreConfig('carebyzinc/api/testmode')) == 'live')
134
- $userId = Mage::getStoreConfig('carebyzinc/api/user_id');
135
- else
136
- $userId = Mage::getStoreConfig('carebyzinc/api/test_user_id');
137
- return $userId;
138
- }
139
public function getToken()
140
{
141
@@ -150,16 +163,15 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
150
$outData = array();
151
$values = json_encode($data);
152
$url = $this->getApiUrl($action);
153
- $uid = $this->getUserId();
154
$token = $this->getToken();
155
$email = Mage::getStoreConfig('carebyzinc/api/xuser_email');
156
if(($action =='price_quotes/generate') || ($action == 'policies' ))
157
- $header = array( "Content-Type: application/json","uid:$uid","X-User-Token:$token","X-User-Email:$email","token-type:Bearer");
158
elseif($action == 'token')
159
$header = array( "Content-Type: application/json","X-User-Token:$token","X-User-Email:$email","token-type:Bearer");
160
161
else
162
- $header = array( "Content-Type: application/json","uid:$uid","token-type:Bearer");
163
164
$ch = curl_init($url);
165
curl_setopt($ch, CURLOPT_URL, $url);
@@ -177,45 +189,30 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
177
return $outData;
178
}
179
180
- public function getwarrantyStatus( $item_id )
181
- {
182
if($item_id < 0){
183
return '';
184
}
185
- $cart = Mage::getSingleton('checkout/cart');
186
- $quoteItem = $cart->getQuote()->getItemById($item_id);
187
- $product = Mage::getModel('catalog/product')->load($quoteItem->getProductId());
188
- if(($product->getCarebyzinc() != 1) && ($quoteItem->getCarebyzincOption())){
189
- if ($additionalOption = $quoteItem->getOptionByCode('additional_options'))
190
- {
191
- $additionalOptions = (array) unserialize($additionalOption->getValue());
192
- }
193
- $additionalOptionsArray = array();
194
- foreach($additionalOptions as $option){
195
- if($option['label'] != 'carebyzinc')
196
- $additionalOptionsArray[] = $option;
197
- }
198
- $quoteItem->setCarebyzincOption('');
199
200
- if(! empty($additionalOptionsArray)){
201
- $quoteItem->addOption(array( 'product_id' => $quoteItem->getProductId(),
202
- 'code' => 'additional_options',
203
- 'value' => serialize($additionalOptionsArray)
204
- ));
205
- }else{
206
- $quoteItem->getOptionByCode('additional_options')->delete();
207
- }
208
- $productPrice = $quoteItem->getProduct()->getFinalPrice();
209
- $quoteItem->setCustomPrice($productPrice);
210
- $quoteItem->setOriginalCustomPrice($productPrice);
211
- $quoteItem->getProduct()->setIsSuperMode(true);
212
- $quoteItem->save();
213
- $cart->getQuote()->collectTotals()->save();
214
-
215
- }
216
return true;
217
- }
218
- public function getCategoryArray()
219
{
220
221
@@ -231,7 +228,7 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
231
{
232
if($category)
233
$dataArray = $this->getCategoryJson();
234
- $subcategory = array();
235
foreach($dataArray as $key => $value){
236
if($key == $category){
237
foreach($value as $val){
@@ -255,5 +252,16 @@ class Zinc_Carebyzinc_Model_Carebyzinc extends Mage_Core_Model_Abstract
255
256
}
257
258
259
}
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(),
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();
72
}else{
73
$response = $outData['response'];
74
$response = (array)json_decode($response, true);
75
+ return 'No Quotes Available';
76
}
77
78
}
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(),
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();
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
}
147
$protocol = 'http://' ;
148
$url = $protocol.$path.'/'.$action;
149
return $url;
150
+ }
151
152
public function getToken()
153
{
154
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);
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
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){
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
}
app/code/local/Zinc/Carebyzinc/Model/Checkout/Cart.php CHANGED
@@ -17,14 +17,15 @@ class Zinc_Carebyzinc_Model_Checkout_Cart extends Mage_Checkout_Model_Cart
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()) {
@@ -36,63 +37,68 @@ class Zinc_Carebyzinc_Model_Checkout_Cart extends Mage_Checkout_Model_Cart
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();
@@ -119,6 +125,7 @@ class Zinc_Carebyzinc_Model_Checkout_Cart extends Mage_Checkout_Model_Cart
119
120
Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));
121
$this->getCheckoutSession()->setLastAddedProductId($productId);
122
}else{
123
if ($productId) {
124
try {
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()) {
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();
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 {
app/code/local/Zinc/Carebyzinc/Model/Checkout/Multishipping.php ADDED
@@ -0,0 +1,190 @@
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_Multishipping extends Mage_Checkout_Model_Type_Multishipping
9
+ {
10
+
11
+ /**
12
+ * Assign quote items to addresses and specify items qty
13
+ *
14
+ * array structure:
15
+ * array(
16
+ * $quoteItemId => array(
17
+ * 'qty' => $qty,
18
+ * 'address' => $customerAddressId
19
+ * )
20
+ * )
21
+ *
22
+ * @param array $info
23
+ * @return Mage_Checkout_Model_Type_Multishipping
24
+ */
25
+ public function setShippingItemsInformation($info)
26
+ {
27
+ if (is_array($info)) {
28
+ $allQty = 0;
29
+ $itemsInfo = array();
30
+ foreach ($info as $itemData) {
31
+ foreach ($itemData as $quoteItemId => $data) {
32
+ $allQty += $data['qty'];
33
+ $itemsInfo[$quoteItemId] = $data;
34
+ }
35
+ }
36
+
37
+ $maxQty = (int)Mage::getStoreConfig('shipping/option/checkout_multiple_maximum_qty');
38
+ if ($allQty > $maxQty) {
39
+ Mage::throwException(Mage::helper('checkout')->__('Maximum qty allowed for Shipping to multiple addresses is %s', $maxQty));
40
+ }
41
+ $quote = $this->getQuote();
42
+ $addresses = $quote->getAllShippingAddresses();
43
+ foreach ($addresses as $address) {
44
+ $quote->removeAddress($address->getId());
45
+ }
46
+
47
+ foreach ($info as $itemData) {
48
+ foreach ($itemData as $quoteItemId => $data) {
49
+ $this->_addShippingItem($quoteItemId, $data);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Delete all not virtual quote items which are not added to shipping address
55
+ * MultishippingQty should be defined for each quote item when it processed with _addShippingItem
56
+ */
57
+ foreach ($quote->getAllItems() as $_item) {
58
+ if (!$_item->getProduct()->getIsVirtual() &&
59
+ !$_item->getParentItem() &&
60
+ !$_item->getMultishippingQty()
61
+ ) {
62
+ $quote->removeItem($_item->getId());
63
+ }
64
+ }
65
+
66
+ if ($billingAddress = $quote->getBillingAddress()) {
67
+ $quote->removeAddress($billingAddress->getId());
68
+ }
69
+
70
+ if ($customerDefaultBilling = $this->getCustomerDefaultBillingAddress()) {
71
+ $quote->getBillingAddress()->importCustomerAddress($customerDefaultBilling);
72
+ }
73
+
74
+ foreach ($quote->getAllItems() as $_item) {
75
+ if (!$_item->getProduct()->getIsVirtual()) {
76
+ continue;
77
+ }
78
+
79
+ if (isset($itemsInfo[$_item->getId()]['qty'])) {
80
+ if ($qty = (int)$itemsInfo[$_item->getId()]['qty']) {
81
+ if(Mage::getStoreConfig('carebyzinc/general/enabled')){
82
+ $qty = 1;
83
+ $itemsInfo[$_item->getId()]['qty'] = 1;
84
+ }
85
+ $_item->setQty($qty);
86
+ $quote->getBillingAddress()->addItem($_item);
87
+ } else {
88
+ $_item->setQty(0);
89
+ $quote->removeItem($_item->getId());
90
+ }
91
+ }
92
+
93
+ }
94
+
95
+ $this->save();
96
+ Mage::dispatchEvent('checkout_type_multishipping_set_shipping_items', array('quote'=>$quote));
97
+ }
98
+ return $this;
99
+ }
100
+
101
+ protected function _addShippingItem($quoteItemId, $data)
102
+ {
103
+
104
+ $qty = isset($data['qty']) ? (int) $data['qty'] : 1;
105
+ //$qty = $qty > 0 ? $qty : 1;
106
+ $addressId = isset($data['address']) ? $data['address'] : false;
107
+ $quoteItem = $this->getQuote()->getItemById($quoteItemId);
108
+ if(Mage::getStoreConfig('carebyzinc/general/enabled')){
109
+ if($qty>1){
110
+ $limit = $qty;
111
+ $qty = 1;
112
+ if($quoteItem->getProductId() != Mage::getStoreConfig('carebyzinc/general/warranty_product')){
113
+ for($i =1; $i<$limit;$i++){
114
+ $product = Mage::getModel('catalog/product')->load($quoteItem->getProductId());
115
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
116
+ $result = $quote->addProduct($product, $quoteItem->getBuyRequest());
117
+ $quote->collectTotals()->save();
118
+
119
+ if ($addressId && $result) {
120
+ /**
121
+ * Skip item processing if qty 0
122
+ */
123
+ if ($qty === 0) {
124
+ return $this;
125
+ }
126
+ $quoteItem->setMultishippingQty((int)$result->getMultishippingQty());
127
+ $quoteItem->setQty($result->getMultishippingQty());
128
+ $address = $this->getCustomer()->getAddressById($addressId);
129
+ if ($address->getId()) {
130
+ if (!$quoteAddress = $this->getQuote()->getShippingAddressByCustomerAddressId($address->getId())) {
131
+ $quoteAddress = Mage::getModel('sales/quote_address')->importCustomerAddress($address);
132
+ $this->getQuote()->addShippingAddress($quoteAddress);
133
+ if ($couponCode = $this->getCheckoutSession()->getCartCouponCode()) {
134
+ $this->getQuote()->setCouponCode($couponCode);
135
+ }
136
+ }
137
+
138
+ $quoteAddress = $this->getQuote()->getShippingAddressByCustomerAddressId($address->getId());
139
+ if ($quoteAddressItem = $quoteAddress->getItemByQuoteItemId($result->getId())) {
140
+ $quoteAddressItem->setQty((int)($quoteAddressItem->getQty()));
141
+ } else {
142
+ $quoteAddress->addItem($result, $qty);
143
+ }
144
+ /**
145
+ * Require shiping rate recollect
146
+ */
147
+ $quoteAddress->setCollectShippingRates((boolean) $this->getCollectRatesFlag());
148
+ }
149
+ }
150
+
151
+ }
152
+
153
+ }
154
+
155
+ }
156
+ }
157
+ if ($addressId && $quoteItem) {
158
+ /**
159
+ * Skip item processing if qty 0
160
+ */
161
+ if ($qty === 0) {
162
+ return $this;
163
+ }
164
+ $quoteItem->setMultishippingQty((int)$quoteItem->getMultishippingQty()+$qty);
165
+ $quoteItem->setQty($quoteItem->getMultishippingQty());
166
+ $address = $this->getCustomer()->getAddressById($addressId);
167
+ if ($address->getId()) {
168
+ if (!$quoteAddress = $this->getQuote()->getShippingAddressByCustomerAddressId($address->getId())) {
169
+ $quoteAddress = Mage::getModel('sales/quote_address')->importCustomerAddress($address);
170
+ $this->getQuote()->addShippingAddress($quoteAddress);
171
+ if ($couponCode = $this->getCheckoutSession()->getCartCouponCode()) {
172
+ $this->getQuote()->setCouponCode($couponCode);
173
+ }
174
+ }
175
+
176
+ $quoteAddress = $this->getQuote()->getShippingAddressByCustomerAddressId($address->getId());
177
+ if ($quoteAddressItem = $quoteAddress->getItemByQuoteItemId($quoteItemId)) {
178
+ $quoteAddressItem->setQty((int)($quoteAddressItem->getQty()+$qty));
179
+ } else {
180
+ $quoteAddress->addItem($quoteItem, $qty);
181
+ }
182
+ /**
183
+ * Require shiping rate recollect
184
+ */
185
+ $quoteAddress->setCollectShippingRates((boolean) $this->getCollectRatesFlag());
186
+ }
187
+ }
188
+ return $this;
189
+ }
190
+ }
app/code/local/Zinc/Carebyzinc/Model/Entity/Subcategory.php CHANGED
@@ -10,9 +10,11 @@ class Zinc_Carebyzinc_Model_Entity_Subcategory extends Mage_Eav_Model_Entity_Att
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
}
10
{
11
public function getAllOptions()
12
{
13
+ $this->_options = array();
14
+ if(Mage::registry('current_product')){
15
+ if($category = Mage::registry('current_product')->getCarebyzincCategory())
16
+ $this->_options = Mage::getModel('carebyzinc/carebyzinc')->getSubcategoryArray($category);
17
+ }
18
return $this->_options;
19
}
20
}
app/code/local/Zinc/Carebyzinc/Model/Observer.php CHANGED
@@ -19,29 +19,117 @@ class Zinc_Carebyzinc_Model_Observer{
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
}
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)
86
+ {
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
}
app/code/local/Zinc/Carebyzinc/Model/Order.php CHANGED
@@ -21,10 +21,9 @@ class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
21
{
22
$data = array();
23
$currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
24
- $data['user_id'] = $this->getUserId();
25
$data['customer'] = $this->getUserAddress($order);
26
$carebyItem = 0;$policyKeyArray = array();
27
- $orderItems = $order->getAllVisibleItems();
28
$fromname = Mage::getStoreConfig('trans_email/ident_general/name');
29
$fromemail = Mage::getStoreConfig('trans_email/ident_general/email');
30
$translate = Mage::getSingleton('core/translate');
@@ -37,11 +36,19 @@ class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
37
$mode = 1;
38
else
39
$mode = 0;
40
foreach($orderItems as $item){
41
- if($item->getCarebyzincOption()){
42
-
43
- $policyNo = '';
44
- $carebyzincAry = (array) unserialize($item->getCarebyzincOption()) ;
45
$product = Mage::getModel('catalog/product')->load($item->getProductId());
46
$data['price_quote_id'] = $carebyzincAry['id'];
47
$data['sku_id'] = $carebyzincAry['sku_id'];
@@ -63,8 +70,7 @@ class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
63
$careOrder->setOrderIncId($order->getIncrementId());
64
$careOrder->setItemId($item->getId());
65
$careOrder->setWarrentyPrice($carebyzincAry['price_per_year']);
66
- $price = $item->getPrice() - $carebyzincAry['price_per_year'];
67
- $careOrder->setProductPrice($price);
68
$careOrder->setCarebyzincProvider($carebyzincAry['provider']);
69
$name = $order->getCustomerFirstname(). ' '. $order->getCustomerLastname();
70
$careOrder->setCustomerName($name);
@@ -88,7 +94,7 @@ class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
88
$anyDate = $order->getCreatedAt();
89
$dateTimestamp = Mage::getModel('core/date')->timestamp(strtotime($anyDate));
90
$date = date("Y-m-d",$dateTimestamp);
91
- $subject = $this->getUserId().'_'.$policyKeyArray[$i].'_'.$storeObj->getFrontendName().'_'.$date;
92
$emailTemplate = Mage::getModel('core/email_template')->loadDefault('sales_email_order_template');
93
$emailTemplateVariables = array();
94
$emailTemplateVariables['order'] = $order;
@@ -105,11 +111,7 @@ class Zinc_Carebyzinc_Model_Order extends Mage_Core_Model_Abstract
105
}
106
}
107
108
- private function getUserId()
109
- {
110
- $userId = Mage::getStoreConfig('carebyzinc/api/user_id');
111
- return $userId;
112
- }
113
114
public function getUserAddress($order)
115
{
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');
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'];
70
$careOrder->setOrderIncId($order->getIncrementId());
71
$careOrder->setItemId($item->getId());
72
$careOrder->setWarrentyPrice($carebyzincAry['price_per_year']);
73
+ $careOrder->setProductPrice($item->getPrice());
74
$careOrder->setCarebyzincProvider($carebyzincAry['provider']);
75
$name = $order->getCustomerFirstname(). ' '. $order->getCustomerLastname();
76
$careOrder->setCustomerName($name);
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;
111
}
112
}
113
114
+
115
116
public function getUserAddress($order)
117
{
app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/CarebyzincController.php CHANGED
@@ -9,18 +9,17 @@ class Zinc_Carebyzinc_Adminhtml_CarebyzincController extends Mage_Adminhtml_Cont
9
{
10
public function validateAction()
11
{
12
- $model = Mage::getModel('carebyzinc/carebyzinc');
13
- $data['uid'] = $model->getUserId();
14
$data['X-User-Token'] = $model->getToken();
15
$data['X-User-Email'] = Mage::getStoreConfig('carebyzinc/api/xuser_email');
16
17
18
- $result = $model->callApi($data,'token','post');
19
- if($result['code'] == 200)
20
- $response = 'Success';
21
- else
22
- $response = 'Error';
23
- Mage::app()->getResponse()->setBody($response);
24
- }
25
26
}
9
{
10
public function validateAction()
11
{
12
+ $model = Mage::getModel('carebyzinc/carebyzinc');
13
$data['X-User-Token'] = $model->getToken();
14
$data['X-User-Email'] = Mage::getStoreConfig('carebyzinc/api/xuser_email');
15
16
17
+ $result = $model->callApi($data,'token','post');
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/ProductController.php CHANGED
@@ -64,13 +64,15 @@ class Zinc_Carebyzinc_Adminhtml_ProductController extends Mage_Adminhtml_Control
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
@@ -81,29 +83,39 @@ class Zinc_Carebyzinc_Adminhtml_ProductController extends Mage_Adminhtml_Control
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
/**
@@ -115,44 +127,42 @@ class Zinc_Carebyzinc_Adminhtml_ProductController extends Mage_Adminhtml_Control
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)
@@ -161,14 +171,51 @@ class Zinc_Carebyzinc_Adminhtml_ProductController extends Mage_Adminhtml_Control
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
}
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->setCarebyzincManufacturer($post['carebyzinc_manufacturer']);
71
+ $model->setCarebyzincModel($post['carebyzinc_model']);
72
+ $model->setCarebyzinc($post['carebyzinc']);
73
+ $model->save();
74
+ $this->_redirect('*/*/');
75
+ return;
76
77
}
78
83
public function massCarebyzincAction()
84
{
85
$productIds = (array)$this->getRequest()->getParam('product');
86
+ $carebyzinc = (int)$this->getRequest()->getParam('zinc_carebyzinc');
87
+ $this->_validateMassCarebyzinc($productIds, $carebyzinc);
88
+ if($carebyzinc == 1){
89
+ $this->loadLayout();
90
+ $this->_setActiveMenu('carebyzinc/products');
91
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
92
+ $block = $this->getLayout()->getBlock('carebyzinc_massaction');
93
+ $block->setProductIds(implode(',',$productIds));
94
+ $this->renderLayout();
95
+ }else{
96
+
97
+ try {
98
99
+ Mage::getSingleton('catalog/product_action')
100
+ ->updateAttributes($productIds, array('carebyzinc' => $carebyzinc));
101
+
102
+ $this->_getSession()->addSuccess(
103
+ $this->__('Total of %d record(s) have been updated.', count($productIds))
104
+ );
105
+ }
106
+ catch (Mage_Core_Model_Exception $e) {
107
+ $this->_getSession()->addError($e->getMessage());
108
+ } catch (Mage_Core_Exception $e) {
109
+ $this->_getSession()->addError($e->getMessage());
110
+ } catch (Exception $e) {
111
+ $this->_getSession()
112
+ ->addException($e, $this->__('An error occurred while updating the product(s)'));
113
+ }
114
+ if($this->getRequest()->getParam('pid'))
115
+ $this->_redirect('*/*/');
116
+ else
117
+ $this->_redirect('adminhtml/catalog_product/index');
118
+ }
119
}
120
121
/**
127
$productIds = (array)$this->getRequest()->getParam('product');
128
$category = $this->getRequest()->getParam('carebyzinc_category');
129
$subCat = 'Other';
130
+ if(!is_array($productIds)) {
131
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('carebyzinc')->__('Please select Product(s).'));
132
+ }else{
133
+ try {
134
+ $this->_validateMassCarebyzinc($productIds, $category);
135
+ $subCategories = Mage::getModel('carebyzinc/carebyzinc')->getSubCategoryArray($category);
136
+ foreach ($productIds as $product_id) {
137
+ $productModel = Mage::getModel('catalog/product')->load($product_id);
138
+ $name = $productModel->getName();
139
+ foreach($subCategories as $subcat){
140
+ if (stripos($name, $subcat) !== false) {
141
+ $subCat = $subcat;
142
+ break;
143
+ }
144
+ }
145
+ $productModel->setCarebyzincCategory($category);
146
+ $productModel->setCarebyzincSubcategory($subCat);
147
+ $productModel->save();
148
+
149
+ }
150
+ $this->_getSession()->addSuccess(
151
+ $this->__('Total of %d record(s) have been updated.', count($productIds))
152
+ );
153
}
154
+ catch (Mage_Core_Model_Exception $e) {
155
+ $this->_getSession()->addError($e->getMessage());
156
+ } catch (Mage_Core_Exception $e) {
157
+ $this->_getSession()->addError($e->getMessage());
158
+ } catch (Exception $e) {
159
+ $this->_getSession()->addException($e, $this->__('An error occurred while updating the product(s)'));
160
+ }
161
+ }
162
+ if($this->getRequest()->getParam('pid'))
163
+ $this->_redirect('*/*/');
164
+ else
165
+ $this->_redirect('adminhtml/catalog_product/index');
166
}
167
168
public function _validateMassCarebyzinc(array $productIds, $carebyzinc)
171
throw new Mage_Core_Exception(
172
$this->__('Some of the processed products have no SKU value defined. Please fill it prior to performing operations on these products.')
173
);
174
+ }
175
}
176
177
public function getSubcategoriesAction()
178
{
179
+ $cid = $this->getRequest()->getParam('cat');
180
+ $subCategories = Mage::getModel('carebyzinc/carebyzinc')->getSubCategoryArray($cid);
181
+ return $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($subCategories));
182
+
183
+ }
184
+ public function saveCarebyzincCategoryAction()
185
+ {
186
+ $post = $this->getRequest()->getPost();
187
+ $subCategory = '';
188
+ if($post['carebyzinc_subcategory']){
189
+ $subCategory = $post['carebyzinc_subcategory'];
190
+ }
191
+ $category = $post['carebyzinc_category'];
192
+ $productIds = explode(',',$post['product_ids']);
193
+ $subCategories = Mage::getModel('carebyzinc/carebyzinc')->getSubCategoryArray($category);
194
+ foreach ($productIds as $product_id) {
195
+ $productModel = Mage::getModel('catalog/product')->load($product_id);
196
+ $name = $productModel->getName();
197
+ if(! $subCategory){
198
+ foreach($subCategories as $subcat){
199
+ if (stripos($name, $subcat) !== false) {
200
+ $subCategory = $subcat;
201
+ break;
202
+ }
203
+ }
204
+ }
205
+ if(! $subCategory){
206
+ $subCategory = 'Other';
207
+ }
208
+ $productModel->setCarebyzincCategory($category);
209
+ $productModel->setCarebyzincSubcategory($subCategory);
210
+ $productModel->setCarebyzinc(1);
211
+ $productModel->setCarebyzincManufacturer($post['carebyzinc_manufacturer']);
212
+ $productModel->setCarebyzincModel($post['carebyzinc_model']);
213
+ $productModel->save();
214
+ }
215
+ $this->_getSession()->addSuccess(
216
+ $this->__('Total of %d record(s) have been updated.', count($productIds))
217
+ );
218
+ $this->_redirect('*/*/');
219
+
220
}
221
}
app/code/local/Zinc/Carebyzinc/controllers/Adminhtml/Sales/Order/CreditmemoController.php ADDED
@@ -0,0 +1,52 @@
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
+ * Adminhtml sales order creditmemo controller
11
+ */
12
+
13
+
14
+ require_once(Mage::getModuleDir('controllers','Mage_Adminhtml').DS.'Sales/Order'. DS.'CreditmemoController.php');
15
+
16
+ class Zinc_Carebyzinc_Adminhtml_Sales_Order_CreditmemoController extends Mage_Adminhtml_Sales_Order_CreditmemoController
17
+ {
18
+ /**
19
+ * Get requested items qtys and return to stock flags
20
+ */
21
+ protected function _getItemData()
22
+ {
23
+ $data = $this->getRequest()->getParam('creditmemo');
24
+ if (!$data) {
25
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
26
+ }
27
+
28
+ if (isset($data['items'])) {
29
+
30
+ if(Mage::getStoreConfig('carebyzinc/general/enabled')){
31
+ foreach($data['items'] as $key=>$value){
32
+ $orderItem = Mage::getModel('sales/order_item')->load($key);
33
+ if($orderItem->getProductId() == Mage::getStoreConfig('carebyzinc/general/warranty_product')){
34
+ if($data['items'][$key]['qty']==0){
35
+ if($data['items'][$orderItem->getCarebyzincParentid()]['qty'] == 0){}
36
+ else{
37
+ $data['items'][$key]['qty'] = 1;
38
+ }
39
+
40
+ }
41
+ }
42
+ }
43
+ }
44
+ $qtys = $data['items'];
45
+
46
+ } else {
47
+ $qtys = array();
48
+ }
49
+ return $qtys;
50
+ }
51
+
52
+ }
app/code/local/Zinc/Carebyzinc/controllers/CartController.php CHANGED
@@ -16,9 +16,10 @@ class Zinc_Carebyzinc_CartController extends Mage_Checkout_CartController
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();
@@ -32,88 +33,39 @@ class Zinc_Carebyzinc_CartController extends Mage_Checkout_CartController
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
@@ -180,7 +132,7 @@ class Zinc_Carebyzinc_CartController extends Mage_Checkout_CartController
180
$filter = new Zend_Filter_LocalizedToNormalized(
181
array('locale' => Mage::app()->getLocale()->getLocaleCode())
182
);
183
- $cart = $this->_getCart();
184
foreach ($cartData as $index => $data) {
185
$quote = Mage::getSingleton('checkout/session')->getQuote();
186
$oldQuoteItem = $quote->getItemById($index);
@@ -190,42 +142,34 @@ class Zinc_Carebyzinc_CartController extends Mage_Checkout_CartController
190
->setStoreId(Mage::app()->getStore()->getId())
191
->load($oldQuoteItem->getProductId());
192
$productType = $product->getTypeId();
193
- $newPrice = 0;$price = 0;$additionalOptions = array();
194
if(($productType == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE || $productType == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) && ($product->getCarebyzinc() == 1))
195
- {
196
- $additionalOption = $oldQuoteItem->getOptionByCode('additional_options');
197
- $newPrice = $oldQuoteItem->getPrice();
198
- $price = $oldQuoteItem->getCarebyzincPrice();
199
$qty = 1;
200
- $flag = 1;
201
- if ($additionalOption = $oldQuoteItem->getOptionByCode('additional_options'))
202
- {
203
- $additionalOptions = (array) unserialize($additionalOption->getValue());
204
- }
205
}
206
if (isset($data['qty'])) {
207
if($flag){
208
$qty = $data['qty'];
209
- $data['qty'] = 1;
210
}
211
$cartData[$index]['qty'] = $filter->filter(trim($data['qty']));
212
}
213
if($flag){
214
if($qty >1){
215
for($i = 1;$i<=($qty-1);$i++){
216
217
$result = $quote->addProduct($product, $oldQuoteItem->getBuyRequest());
218
- $result = ( $result->getParentItem() ? $result->getParentItem() : $result );
219
- $result->setCarebyzincOption($oldQuoteItem->getCarebyzincOption());
220
- $result->setCarebyzincPrice($price);
221
- $result->addOption(array(
222
- 'product_id' => $result->getProductId(),
223
- 'code' => 'additional_options',
224
- 'value' => serialize($additionalOptions)
225
- ));
226
-
227
- $result->setCustomPrice($newPrice);
228
- $result->setOriginalCustomPrice($newPrice);
229
}
230
}
231
}
@@ -247,5 +191,134 @@ class Zinc_Carebyzinc_CartController extends Mage_Checkout_CartController
247
Mage::logException($e);
248
}
249
}
250
251
}
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
+
23
$params = $this->getRequest()->getParams();
24
if (!isset($params['options'])) {
25
$params['options'] = array();
33
34
$product = Mage::getModel('catalog/product')->load($quoteItem->getProductId());
35
$productType = $product->getTypeId();
36
+ $flag = 0;
37
if(($productType == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE || $productType == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) && ($product->getCarebyzinc() == 1))
38
{
39
$qty = 1;
40
$flag = 1;
41
}
42
+ if($product->getId() == Mage::getStoreConfig('carebyzinc/general/warranty_product')){
43
+ $flag = 0;
44
+ if($qty >1){
45
+ $params['qty'] = 1;
46
+ $qty = 1;
47
+ }
48
+ }
49
if (isset($params['qty'])) {
50
if($flag){
51
$qty = $params['qty'];
52
+ if($qty >1)
53
+ $params['qty'] = 1;
54
}
55
$filter = new Zend_Filter_LocalizedToNormalized(
56
array('locale' => Mage::app()->getLocale()->getLocaleCode())
57
);
58
$params['qty'] = $filter->filter($params['qty']);
59
+ }
60
+
61
$item = $cart->updateItem($id, new Varien_Object($params));
62
63
if($flag){
64
if($qty >1){
65
$quote = Mage::getSingleton('checkout/session')->getQuote();
66
for($i = 1;$i<=($qty-1);$i++){
67
$result = $quote->addProduct($product, $item->getBuyRequest());
68
+ $result = ( $result->getParentItem() ? $result->getParentItem() : $result );
69
}
70
}
71
132
$filter = new Zend_Filter_LocalizedToNormalized(
133
array('locale' => Mage::app()->getLocale()->getLocaleCode())
134
);
135
+ $cart = $this->_getCart();
136
foreach ($cartData as $index => $data) {
137
$quote = Mage::getSingleton('checkout/session')->getQuote();
138
$oldQuoteItem = $quote->getItemById($index);
142
->setStoreId(Mage::app()->getStore()->getId())
143
->load($oldQuoteItem->getProductId());
144
$productType = $product->getTypeId();
145
if(($productType == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE || $productType == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) && ($product->getCarebyzinc() == 1))
146
+ {
147
$qty = 1;
148
+ $flag = 1;
149
}
150
+
151
if (isset($data['qty'])) {
152
if($flag){
153
$qty = $data['qty'];
154
+ if($qty >1)
155
+ $data['qty'] = 1;
156
+ }
157
+ if($product->getId() == Mage::getStoreConfig('carebyzinc/general/warranty_product')){
158
+ $flag = 0;
159
+ if($data['qty'] >1){
160
+ $data['qty'] = 1;
161
+ $qty = 1;
162
+ }
163
}
164
$cartData[$index]['qty'] = $filter->filter(trim($data['qty']));
165
}
166
+
167
if($flag){
168
if($qty >1){
169
for($i = 1;$i<=($qty-1);$i++){
170
171
$result = $quote->addProduct($product, $oldQuoteItem->getBuyRequest());
172
+ $result = ( $result->getParentItem() ? $result->getParentItem() : $result );
173
}
174
}
175
}
191
Mage::logException($e);
192
}
193
}
194
+
195
+
196
+ /**
197
+ * Minicart delete action
198
+ */
199
+ public function ajaxDeleteAction()
200
+ {
201
+ if (!$this->_validateFormKey()) {
202
+ Mage::throwException('Invalid form key');
203
+ }
204
+ $id = (int) $this->getRequest()->getParam('id');
205
+ $result = array();
206
+ if ($id) {
207
+ try {
208
+
209
+ if(Mage::getStoreConfig('carebyzinc/general/enabled')){
210
+ $cartHelper = Mage::helper('checkout/cart');
211
+ $cart = Mage::getSingleton('checkout/cart');
212
+ $_item = $cart->getQuote()->getItemById($id);
213
+ $itemId = $_item->getId();
214
+ $productId = $_item->getProductId();
215
+ if($_item->getCarebyzincVariantid()){
216
+ $cart = Mage::getModel('checkout/cart')->getQuote();
217
+ foreach ($cart->getAllItems() as $item) {
218
+ if($item->getCarebyzincParentid() == $itemId)
219
+ $cartHelper->getCart()->removeItem($item->getId())->save();
220
+
221
+ }
222
+ }else{
223
+ if($productId == Mage::getStoreConfig('carebyzinc/general/warranty_product')){
224
+ $itemId = $_item->getCarebyzincParentid();
225
+ $cart = Mage::getSingleton('checkout/cart');
226
+ $item = $cart->getQuote()->getItemById($itemId);
227
+ $item->setCarebyzincVariantid(NULL);
228
+ $item->save();
229
+ }
230
+ }
231
+
232
+ }
233
+
234
+ $this->_getCart()->removeItem($id)->save();
235
+
236
+ $result['qty'] = $this->_getCart()->getSummaryQty();
237
+
238
+ $this->loadLayout();
239
+ $result['content'] = $this->getLayout()->getBlock('minicart_content')->toHtml();
240
+
241
+ $result['success'] = 1;
242
+ $result['message'] = $this->__('Item was removed successfully.');
243
+ Mage::dispatchEvent('ajax_cart_remove_item_success', array('id' => $id));
244
+ } catch (Exception $e) {
245
+ $result['success'] = 0;
246
+ $result['error'] = $this->__('Can not remove the item.');
247
+ }
248
+ }
249
+
250
+ $this->getResponse()->setHeader('Content-type', 'application/json');
251
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
252
+ }
253
+
254
+
255
+ /**
256
+ * Minicart ajax update qty action
257
+ */
258
+ public function ajaxUpdateAction()
259
+ {
260
+ if (!$this->_validateFormKey()) {
261
+ Mage::throwException('Invalid form key');
262
+ }
263
+ $id = (int)$this->getRequest()->getParam('id');
264
+ $qty = $this->getRequest()->getParam('qty');
265
+ $result = array();
266
+ if ($id) {
267
+ try {
268
+ $cart = $this->_getCart();
269
+ $quoteItem = $cart->getQuote()->getItemById($id);
270
+ if (!$quoteItem) {
271
+ Mage::throwException($this->__('Quote item is not found.'));
272
+ }
273
+ $product = Mage::getModel('catalog/product')
274
+ ->setStoreId(Mage::app()->getStore()->getId())
275
+ ->load($quoteItem->getProductId());
276
+ if($product->getCarebyzinc() == 1)
277
+ {
278
+ $qty = 1;
279
+ $flag = 1;
280
+ }
281
+ if($product->getId() == Mage::getStoreConfig('carebyzinc/general/warranty_product')){
282
+ $flag = 0;
283
+ if($qty >1){
284
+ $qty = 1;
285
+ }
286
+ }
287
+ if (isset($qty)) {
288
+ $filter = new Zend_Filter_LocalizedToNormalized(
289
+ array('locale' => Mage::app()->getLocale()->getLocaleCode())
290
+ );
291
+ $qty = $filter->filter($qty);
292
+ }
293
+
294
+
295
+ if ($qty == 0) {
296
+ $cart->removeItem($id);
297
+ } else {
298
+ $quoteItem->setQty($qty)->save();
299
+ }
300
+ $this->_getCart()->save();
301
+
302
+ $this->loadLayout();
303
+ $result['content'] = $this->getLayout()->getBlock('minicart_content')->toHtml();
304
+
305
+ $result['qty'] = $this->_getCart()->getSummaryQty();
306
+
307
+ if (!$quoteItem->getHasError()) {
308
+ $result['message'] = $this->__('Item was updated successfully.');
309
+ } else {
310
+ $result['notice'] = $quoteItem->getMessage();
311
+ }
312
+ $result['success'] = 1;
313
+ } catch (Exception $e) {
314
+ $result['success'] = 0;
315
+ $result['error'] = $this->__('Can not save item.');
316
+ }
317
+ }
318
+
319
+ $this->getResponse()->setHeader('Content-type', 'application/json');
320
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
321
+ }
322
+
323
324
}
app/code/local/Zinc/Carebyzinc/controllers/IndexController.php CHANGED
@@ -27,6 +27,7 @@ class Zinc_Carebyzinc_IndexController extends Mage_Core_Controller_Front_Action
27
$response = '';
28
$this->loadLayout();
29
$product = Mage::getModel('catalog/product')->load($product_id);
30
if(! empty($configOptionsArray)){
31
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
32
$priceVal = 0;
@@ -58,6 +59,8 @@ class Zinc_Carebyzinc_IndexController extends Mage_Core_Controller_Front_Action
58
$response = is_array($response[$itemId])?$response[$itemId]:$response;
59
$quoteBlock->setTemplate('carebyzinc/options/cart.phtml');
60
$quoteBlock->setItemId($itemId);
61
62
} else {
63
$response = $model->getPriceQuote($product,$zip,$customoptionPrice);
@@ -70,80 +73,60 @@ class Zinc_Carebyzinc_IndexController extends Mage_Core_Controller_Front_Action
70
}
71
72
public function updatePriceQuoteinCartAction()
73
- {
74
$carebyzincId = $this->getRequest()->getParam('carebyzinc');
75
$itemId = $this->getRequest()->getParam('itemId');
76
$priceQuoteSession = Mage::getSingleton('core/session')->getCareByZincQuote();
77
$priceQuote = $priceQuoteSession[$itemId];
78
-
79
if($carebyzincItem = $priceQuote[$carebyzincId]){
80
- $additionalOptions[] = array(
81
- 'label' => 'carebyzinc',
82
- 'value' => $carebyzincId,
83
- );
84
-
85
$cart = Mage::getSingleton('checkout/cart');
86
- $item = $cart->getQuote()->getItemById($itemId);
87
- $item->getProduct()->setIsSuperMode(true);
88
- if($price = $carebyzincItem['price_per_year']){
89
- $product = Mage::getModel('catalog/product')->load($item->getProductId());
90
- $productPrice = $item->getProduct()->getFinalPrice();
91
- $newPrice = $productPrice + $price;
92
- $item->setCarebyzincPrice($price);
93
- $item->setCustomPrice($newPrice);
94
- $item->setOriginalCustomPrice($newPrice);
95
- }
96
- if ($additionalOption = $item->getOptionByCode('additional_options'))
97
- {
98
- $additionalOptions = (array) unserialize($additionalOption->getValue());
99
- }
100
- $item->setCarebyzincOption(serialize($priceQuote[$carebyzincId]));
101
- $item->addOption(array(
102
- 'product_id' => $item->getProductId(),
103
'code' => 'additional_options',
104
'value' => serialize($additionalOptions)
105
));
106
- $item->save();
107
- $cart->save();
108
Mage::getSingleton('core/session')->unsCareByZincQuote();
109
}
110
echo 'success';
111
}
112
- public function removeWarrantyAction()
113
- {
114
- $item_id = $this->getRequest()->getParam('id');
115
- if($item_id < 0){
116
- return '';
117
- }
118
- $cart = Mage::getSingleton('checkout/cart');
119
- $quoteItem = $cart->getQuote()->getItemById($item_id);
120
- if ($additionalOption = $quoteItem->getOptionByCode('additional_options'))
121
- {
122
- $additionalOptions = (array) unserialize($additionalOption->getValue());
123
- }
124
- $additionalOptionsArray = array();
125
- foreach($additionalOptions as $option){
126
- if($option['label'] != 'carebyzinc')
127
- $additionalOptionsArray[] = $option;
128
- }
129
- $quoteItem->setCarebyzincOption('');
130
- $productPrice = $quoteItem->getProduct()->getFinalPrice();
131
- if(! empty($additionalOptionsArray)){
132
- $quoteItem->addOption(array( 'product_id' => $quoteItem->getProductId(),
133
- 'code' => 'additional_options',
134
- 'value' => serialize($additionalOptionsArray)
135
- ));
136
- }else{
137
- $quoteItem->getOptionByCode('additional_options')->delete();
138
-
139
- }
140
- $quoteItem->setCarebyzincPrice(0);
141
- $quoteItem->setCustomPrice($productPrice);
142
- $quoteItem->setOriginalCustomPrice($productPrice);
143
- $quoteItem->getProduct()->setIsSuperMode(true);
144
- $quoteItem->save();
145
- $cart->getQuote()->collectTotals()->save();
146
- $this->_redirect('checkout/cart/');
147
- }
148
-
149
}
27
$response = '';
28
$this->loadLayout();
29
$product = Mage::getModel('catalog/product')->load($product_id);
30
+ $basePrice = $product->getPrice();
31
if(! empty($configOptionsArray)){
32
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
33
$priceVal = 0;
59
$response = is_array($response[$itemId])?$response[$itemId]:$response;
60
$quoteBlock->setTemplate('carebyzinc/options/cart.phtml');
61
$quoteBlock->setItemId($itemId);
62
+ $quoteBlock->setZipData($zip);
63
+ $quoteBlock->setPId($product->getId());
64
65
} else {
66
$response = $model->getPriceQuote($product,$zip,$customoptionPrice);
73
}
74
75
public function updatePriceQuoteinCartAction()
76
+ {
77
+
78
$carebyzincId = $this->getRequest()->getParam('carebyzinc');
79
$itemId = $this->getRequest()->getParam('itemId');
80
$priceQuoteSession = Mage::getSingleton('core/session')->getCareByZincQuote();
81
$priceQuote = $priceQuoteSession[$itemId];
82
+ $additionalOptions = array();
83
if($carebyzincItem = $priceQuote[$carebyzincId]){
84
+
85
$cart = Mage::getSingleton('checkout/cart');
86
+ $item = $cart->getQuote()->getItemById($itemId);
87
+ $item->setCarebyzincVariantid($carebyzincId);
88
+ $item->save();
89
+ $warrantPrdctId = Mage::getStoreConfig('carebyzinc/general/warranty_product');
90
+ if($warrantPrdctId){
91
+
92
+ $req = array('qty'=>1);
93
+ $careParentId = $itemId;
94
+ $warrantyProduct = Mage::getModel('catalog/product')->load($warrantPrdctId);
95
+ $productPrice = $warrantyProduct->getPrice();
96
+
97
+ if($price = $carebyzincItem['price_per_year'])
98
+ $newPrice = $productPrice + $price;
99
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
100
+
101
+ $quoteItem = $quote->addProduct($warrantyProduct,1);
102
+ $quoteItem->setCustomPrice($newPrice);
103
+ $quoteItem->setOriginalCustomPrice($newPrice);
104
+ $quoteItem->setCarebyzincPrice($price);
105
+ $quoteItem->setCarebyzincParentid((int)$careParentId);
106
+ $quoteItem->getProduct()->setIsSuperMode(true);
107
+
108
+ if( $item = $priceQuote[$carebyzincId]){
109
+ $additionalOptions[] = array(
110
+ 'label' => 'carebyzinc',
111
+ 'value' => $carebyzincId,
112
+ );
113
+ $quoteItem->setCarebyzincOption(serialize($priceQuote[$carebyzincId]));
114
+
115
+ }
116
+ $quoteItem->addOption(array(
117
+ 'product_id' => $quoteItem->getProductId(),
118
'code' => 'additional_options',
119
'value' => serialize($additionalOptions)
120
));
121
+
122
+ $quote->collectTotals()->save();
123
+
124
+ }
125
+
126
Mage::getSingleton('core/session')->unsCareByZincQuote();
127
}
128
echo 'success';
129
}
130
+
131
+
132
}
app/code/local/Zinc/Carebyzinc/controllers/Sales/OrderController.php ADDED
@@ -0,0 +1,53 @@
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
+ require_once 'Mage/Sales/controllers/OrderController.php';
11
+ class Zinc_Carebyzinc_Sales_OrderController extends Mage_Sales_OrderController
12
+ {
13
+
14
+ /**
15
+ * Action for reorder
16
+ */
17
+ public function reorderAction()
18
+ {
19
+ if (!$this->_loadValidOrder()) {
20
+ return;
21
+ }
22
+ $order = Mage::registry('current_order');
23
+
24
+ $cart = Mage::getSingleton('checkout/cart');
25
+ $cartTruncated = false;
26
+ /* @var $cart Mage_Checkout_Model_Cart */
27
+
28
+ $items = $order->getItemsCollection();
29
+ foreach ($items as $item) {
30
+ try {
31
+ if($item->getProductId() != Mage::getStoreConfig('carebyzinc/general/warranty_product'))
32
+ $cart->addOrderItem($item);
33
+ } catch (Mage_Core_Exception $e){
34
+ if (Mage::getSingleton('checkout/session')->getUseNotice(true)) {
35
+ Mage::getSingleton('checkout/session')->addNotice($e->getMessage());
36
+ }
37
+ else {
38
+ Mage::getSingleton('checkout/session')->addError($e->getMessage());
39
+ }
40
+ $this->_redirect('*/*/history');
41
+ } catch (Exception $e) {
42
+ Mage::getSingleton('checkout/session')->addException($e,
43
+ Mage::helper('checkout')->__('Cannot add the item to shopping cart.')
44
+ );
45
+ $this->_redirect('checkout/cart');
46
+ }
47
+ }
48
+
49
+ $cart->save();
50
+ $this->_redirect('checkout/cart');
51
+ }
52
+
53
+ }
app/code/local/Zinc/Carebyzinc/etc/config.xml CHANGED
@@ -10,7 +10,7 @@
10
<config>
11
<modules>
12
<Zinc_Carebyzinc>
13
- <version>1.0.4</version>
14
</Zinc_Carebyzinc>
15
</modules>
16
<frontend>
@@ -32,16 +32,16 @@
32
</layout>
33
</frontend>
34
35
- <admin>
36
- <routers>
37
- <adminhtml>
38
- <args>
39
- <modules>
40
- <carebyzinc after="Mage_Adminhtml">Zinc_Carebyzinc_Adminhtml</carebyzinc>
41
- </modules>
42
</args>
43
- </adminhtml>
44
- </routers>
45
</admin>
46
<adminhtml>
47