@@ -5,6 +5,19 @@ $baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
5
5
$ currentCurrencyCode = Mage::app ()->getStore ()->getCurrentCurrencyCode ();
6
6
$ currentCurrencySymbol = Mage::app ()->getLocale ()->currency ($ currentCurrencyCode )->getSymbol ();
7
7
$ rates = Mage::getModel ('directory/currency ' )->getCurrencyRates ($ baseCurrencyCode , $ currentCurrencyCode );
8
+
9
+ if (Mage::helper ('clerk ' )->getSetting ('clerk/general/collect_baskets ' , Mage::app ()->getStore ()->getId ()) == '1 ' ) {
10
+
11
+ $ cart_products = Mage::getModel ('checkout/cart ' )->getQuote ()->getAllVisibleItems ();
12
+ $ cart_product_ids = array ();
13
+ foreach ($ cart_products as $ product ) {
14
+ if (!in_array ($ product ->getProduct ()->getId (), $ cart_product_ids )) {
15
+ $ cart_product_ids [] = $ product ->getProduct ()->getId ();
16
+ }
17
+ }
18
+ }
19
+
20
+
8
21
?>
9
22
<script type="text/javascript">
10
23
(function(w,d){
@@ -38,4 +51,89 @@ $rates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCod
38
51
formkey: '<?php echo $ this ->getFormKey (); ?> '
39
52
}
40
53
});
54
+
55
+ <?php if (Mage::helper ('clerk ' )->getSetting ('clerk/general/collect_baskets ' , Mage::app ()->getStore ()->getId ()) == '1 ' ) : ?>
56
+
57
+ var clerk_productids = '<?php echo implode (', ' ,$ cart_product_ids ); ?> '.split(",") ;
58
+ clerk_productids = clerk_productids.map(Number);
59
+ var clerk_last_productids = [];
60
+ if( localStorage.getItem('clerk_productids') !== null ){
61
+ clerk_last_productids = localStorage.getItem('clerk_productids').split(",");
62
+ clerk_last_productids = clerk_last_productids.map(Number);
63
+ }
64
+ clerk_productids = clerk_productids.sort((a, b) => a - b);
65
+ clerk_last_productids = clerk_last_productids.sort((a, b) => a - b);
66
+ if(JSON.stringify(clerk_productids) == JSON.stringify(clerk_last_productids)){
67
+ // if equal - do nothing
68
+ }else{
69
+ // if not equal send cart to clerk
70
+ if(JSON.stringify(clerk_productids) === "[0]" ){
71
+ Clerk('cart', 'set', []);
72
+ }else{
73
+ Clerk('cart', 'set', clerk_productids);
74
+ }
75
+ }
76
+ localStorage.setItem("clerk_productids", clerk_productids);
77
+
78
+ let open = XMLHttpRequest.prototype.open;
79
+ XMLHttpRequest.prototype.open = function() {
80
+ this.addEventListener("load", function(){
81
+
82
+ if( this.responseURL.includes("/cart")){
83
+
84
+ data = "form_key='<?php echo Mage::getSingleton ('core/session ' )->getFormKey (); ?> '";
85
+
86
+ const request = new XMLHttpRequest();
87
+
88
+ request.addEventListener('load', function () {
89
+
90
+ if( this.responseURL.includes("/basket")){
91
+
92
+ if (this.readyState === 4 && this.status === 200) {
93
+
94
+ var response = this.responseText.replace('[', '').replace(']', '');
95
+ var clerk_productids = [];
96
+ clerk_productids = response.split(",")
97
+ clerk_productids = clerk_productids.map(Number);
98
+
99
+ var clerk_last_productids = [];
100
+ if( localStorage.getItem('clerk_productids') !== null ){
101
+ clerk_last_productids = localStorage.getItem('clerk_productids').split(",");
102
+ clerk_last_productids = clerk_last_productids.map(Number);
103
+ }
104
+ //sort
105
+ clerk_productids = clerk_productids.sort((a, b) => a - b);
106
+ clerk_last_productids = clerk_last_productids.sort((a, b) => a - b);
107
+ // compare
108
+ if(JSON.stringify(clerk_productids) == JSON.stringify(clerk_last_productids)){
109
+ // if equal - do nothing
110
+ // console.log('equal: ', clerk_productids, clerk_last_productids)
111
+ }else{
112
+ // if not equal send cart to clerk
113
+ // console.log('not equal: ', clerk_productids, clerk_last_productids)
114
+ if(JSON.stringify(clerk_productids) === "[0]" ){
115
+ Clerk('cart', 'set', []);
116
+ }else{
117
+ Clerk('cart', 'set', clerk_productids);
118
+ }
119
+
120
+ }
121
+ // save for next compare
122
+ localStorage.setItem("clerk_productids", clerk_productids);
123
+ }
124
+ }
125
+
126
+ });
127
+
128
+ request.open('POST', '<?php echo Mage::getUrl ('clerk/basket/basket ' ); ?> ', true);
129
+ request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
130
+ request.send(data);
131
+
132
+ }
133
+ }, false);
134
+ open.apply(this, arguments);
135
+ };
136
+
137
+ <?php endif ; ?>
138
+
41
139
</script>
0 commit comments