@@ -40,27 +40,15 @@ public function initCart()
40
40
}
41
41
42
42
if (!isset ($ this ->context ->cookie ->id_cart )) {
43
- // create a new cart
44
- $ objCart = new Cart ();
45
- $ objCart ->recyclable = 0 ;
46
- $ objCart ->gift = 0 ;
47
- $ objCart ->id_shop = (int ) $ this ->context ->shop ->id ;
48
- $ objCart ->id_lang = (($ id_lang = (int ) Tools::getValue ('id_lang ' )) ? $ id_lang : (int ) Configuration::get ('PS_LANG_DEFAULT ' ));
49
- $ objCart ->id_currency = (($ id_currency = (int ) Tools::getValue ('id_currency ' )) ? $ id_currency : (int ) Configuration::get ('PS_CURRENCY_DEFAULT ' ));
50
- $ objCart ->id_address_delivery = 0 ;
51
- $ objCart ->id_address_invoice = 0 ;
52
- $ objCart ->id_currency = (int ) Configuration::get ('PS_CURRENCY_DEFAULT ' );
53
- $ objCart ->id_guest = (int ) $ this ->context ->cookie ->id_guest ;
54
- $ objCart ->setNoMultishipping ();
55
-
56
- $ this ->context ->cart = $ objCart ;
57
- $ this ->context ->cart ->save ();
58
-
43
+ $ objCart = $ this ->createNewCart ();
59
44
$ this ->context ->cookie ->id_cart = (int ) $ objCart ->id ;
60
45
} else {
61
46
// use previous cart
62
- $ this ->context ->cart = new Cart ($ this ->context ->cookie ->id_cart );
47
+ if (!validate::isLoadedObject ($ objCart = new Cart ($ this ->context ->cookie ->id_cart ))) {
48
+ $ objCart = $ this ->createNewCart ();
49
+ }
63
50
}
51
+ $ this ->context ->cart = $ objCart ;
64
52
65
53
$ objCustomer = new Customer ();
66
54
$ objCustomer ->id_gender = 0 ;
@@ -77,6 +65,26 @@ public function initCart()
77
65
$ this ->context ->customer = $ objCustomer ;
78
66
}
79
67
68
+ protected function createNewCart ()
69
+ {
70
+ // create a new cart
71
+ $ objCart = new Cart ();
72
+ $ objCart ->recyclable = 0 ;
73
+ $ objCart ->gift = 0 ;
74
+ $ objCart ->id_shop = (int ) $ this ->context ->shop ->id ;
75
+ $ objCart ->id_lang = (($ id_lang = (int ) Tools::getValue ('id_lang ' )) ? $ id_lang : (int ) Configuration::get ('PS_LANG_DEFAULT ' ));
76
+ $ objCart ->id_currency = (($ id_currency = (int ) Tools::getValue ('id_currency ' )) ? $ id_currency : (int ) Configuration::get ('PS_CURRENCY_DEFAULT ' ));
77
+ $ objCart ->id_address_delivery = 0 ;
78
+ $ objCart ->id_address_invoice = 0 ;
79
+ $ objCart ->id_currency = (int ) Configuration::get ('PS_CURRENCY_DEFAULT ' );
80
+ $ objCart ->id_guest = (int ) $ this ->context ->cookie ->id_guest ;
81
+ $ objCart ->setNoMultishipping ();
82
+
83
+ $ objCart ->save ();
84
+ return $ objCart ;
85
+ }
86
+
87
+
80
88
public function postProcess ()
81
89
{
82
90
if (Tools::getValue ('date_from ' )) {
0 commit comments