Heresis Posted January 21, 2013 Share Posted January 21, 2013 (edited) Bonjour à tous. Je suis actuellement sur le développement d'un module pour Prestashop. Une des fonctions de ce dernier est de dupliquer une commande. Pour faire ça proprement, je duplique également le panier afin que les stocks soient affectés par la création d'une nouvelle commande. Bref, j'ai besoin d'un coup de main au niveau de la duplication du panier car avec mon code actuel, ça fonctionne mais j'obtiens une erreur: [PrestaShop] Fatal error in module Cart: Trying to get property of non-object Pour l'instant, ma fonction de duplication de panier est comme ceci: public function duplicateCart($subscription){ // Recuperer la commande initiale $order = new OrderCore ( $subscription ['id_order'] ); // Recuperer le module qui a servi au paiement de cet abonnement $oldcart = new CartCore ( $order->id_cart ); // Dupliquer l'ancien panier $result = $oldcart->duplicate(); // Si le nouveau panier a ete valide et est correct if ($result ['success'] == TRUE) { return $result; } } J'ai donc fouillé dans la fonction duplicate de la classe Cart et l'erreur survient après la ligne 3140 foreach ($products as $product) $success &= $cart->updateQty( $product['quantity'], (int)$product['id_product'], (int)$product['id_product_attribute'], null, 'up', (int)$product['id_address_delivery'], new Shop($cart->id_shop) ); J'aimerais savoir pourquoi j'ai une erreur et surtout s'il y a un moyen plus "propre" de faire ce dont j'ai besoin. D'avance merci Bonne journée. Max. Edited January 22, 2013 by Heresis (see edit history) Link to comment Share on other sites More sharing options...
NikosKos Posted January 21, 2013 Share Posted January 21, 2013 Bonjour, D'apres ce que je vois, il faut que tu vérifies que l'objet $oldcart que tu as chargé est bien rempli. Fais un var_dump($oldcart) apres la ligne $oldcart = new CartCore ( $order->id_cart ); D'autre part, es-tu certain qu'il faille dupliquer le panier lors de la duplication d'une commande pour affecter les stocks ? Ca me semble curieux. Link to comment Share on other sites More sharing options...
Heresis Posted January 22, 2013 Author Share Posted January 22, 2013 D'après les tests que j'ai déjà fait. Si je duplique la commande sans dupliquer le panier. La nouvelle commande est liée au même panier que la commande originale. Du coup les stocks ne bougent pas, mais dans le doute je vais essayer à nouveau. J'ai fait un var_dump de $oldcart et c'est bien un objet rempli... object(Cart)#51 (39) { ["id"]=> int(213) ["id_shop_group"]=> string(1) "1" ["id_shop"]=> string(1) "1" ["id_address_delivery"]=> string(1) "5" ["id_address_invoice"]=> string(1) "5" ["id_currency"]=> string(1) "1" ["id_customer"]=> string(1) "2" ["id_guest"]=> string(1) "4" ["id_lang"]=> string(1) "5" ["recyclable"]=> string(1) "0" ["gift"]=> string(1) "0" ["gift_message"]=> string(0) "" ["date_add"]=> string(19) "2013-01-22 09:46:06" ["secure_key"]=> string(32) "77e21f3e53abb0b505f72927870c7a7a" ["id_carrier"]=> string(1) "3" ["date_upd"]=> string(19) "2013-01-22 09:46:06" ["checkedTos"]=> bool(false) ["pictures"]=> NULL ["textFields"]=> NULL ["delivery_option"]=> string(19) "a:1:{i:5;s:2:"3,";}" ["allow_seperated_package"]=> string(1) "0" ["_products":protected]=> NULL ["_taxCalculationMethod":protected]=> string(1) "0" ["webserviceParameters":protected]=> array(2) { ["fields"]=> array(6) { ["id_address_delivery"]=> array(1) { ["xlink_resource"]=> string(9) "addresses" } ["id_address_invoice"]=> array(1) { ["xlink_resource"]=> string(9) "addresses" } ["id_currency"]=> array(1) { ["xlink_resource"]=> string(10) "currencies" } ["id_customer"]=> array(1) { ["xlink_resource"]=> string(9) "customers" } ["id_guest"]=> array(1) { ["xlink_resource"]=> string(6) "guests" } ["id_lang"]=> array(1) { ["xlink_resource"]=> string(9) "languages" } } ["associations"]=> array(1) { ["cart_rows"]=> array(3) { ["resource"]=> string(8) "cart_row" ["virtual_entity"]=> bool(true) ["fields"]=> array(3) { ["id_product"]=> array(2) { ["required"]=> bool(true) ["xlink_resource"]=> string(8) "products" } ["id_product_attribute"]=> array(2) { ["required"]=> bool(true) ["xlink_resource"]=> string(12) "combinations" } ["quantity"]=> array(1) { ["required"]=> bool(true) } } } } } ["id_shop_list"]=> NULL ["get_shop_from_context":protected]=> bool(true) ["table":protected]=> string(4) "cart" ["identifier":protected]=> string(7) "id_cart" ["fieldsRequired":protected]=> array(2) { [0]=> string(11) "id_currency" [1]=> string(7) "id_lang" } ["fieldsSize":protected]=> array(1) { ["secure_key"]=> int(32) } ["fieldsValidate":protected]=> array(15) { ["id_shop_group"]=> string(12) "isUnsignedId" ["id_shop"]=> string(12) "isUnsignedId" ["id_address_delivery"]=> string(12) "isUnsignedId" ["id_address_invoice"]=> string(12) "isUnsignedId" ["id_carrier"]=> string(12) "isUnsignedId" ["id_currency"]=> string(12) "isUnsignedId" ["id_customer"]=> string(12) "isUnsignedId" ["id_guest"]=> string(12) "isUnsignedId" ["id_lang"]=> string(12) "isUnsignedId" ["recyclable"]=> string(6) "isBool" ["gift"]=> string(6) "isBool" ["gift_message"]=> string(9) "isMessage" ["allow_seperated_package"]=> string(6) "isBool" ["date_add"]=> string(12) "isDateFormat" ["date_upd"]=> string(12) "isDateFormat" } ["fieldsRequiredLang":protected]=> array(0) { } ["fieldsSizeLang":protected]=> array(0) { } ["fieldsValidateLang":protected]=> array(0) { } ["tables":protected]=> array(0) { } ["image_dir":protected]=> NULL ["image_format":protected]=> string(3) "jpg" ["def":protected]=> array(4) { ["table"]=> string(4) "cart" ["primary"]=> string(7) "id_cart" ["fields"]=> array(17) { ["id_shop_group"]=> array(2) { ["type"]=> int(1) ["validate"]=> string(12) "isUnsignedId" } ["id_shop"]=> array(2) { ["type"]=> int(1) ["validate"]=> string(12) "isUnsignedId" } ["id_address_delivery"]=> array(2) { ["type"]=> int(1) ["validate"]=> string(12) "isUnsignedId" } ["id_address_invoice"]=> array(2) { ["type"]=> int(1) ["validate"]=> string(12) "isUnsignedId" } ["id_carrier"]=> array(2) { ["type"]=> int(1) ["validate"]=> string(12) "isUnsignedId" } ["id_currency"]=> array(3) { ["type"]=> int(1) ["validate"]=> string(12) "isUnsignedId" ["required"]=> bool(true) } ["id_customer"]=> array(2) { ["type"]=> int(1) ["validate"]=> string(12) "isUnsignedId" } ["id_guest"]=> array(2) { ["type"]=> int(1) ["validate"]=> string(12) "isUnsignedId" } ["id_lang"]=> array(3) { ["type"]=> int(1) ["validate"]=> string(12) "isUnsignedId" ["required"]=> bool(true) } ["recyclable"]=> array(2) { ["type"]=> int(2) ["validate"]=> string(6) "isBool" } ["gift"]=> array(2) { ["type"]=> int(2) ["validate"]=> string(6) "isBool" } ["gift_message"]=> array(2) { ["type"]=> int(3) ["validate"]=> string(9) "isMessage" } ["delivery_option"]=> array(1) { ["type"]=> int(3) } ["secure_key"]=> array(2) { ["type"]=> int(3) ["size"]=> int(32) } ["allow_seperated_package"]=> array(2) { ["type"]=> int(2) ["validate"]=> string(6) "isBool" } ["date_add"]=> array(2) { ["type"]=> int(5) ["validate"]=> string(12) "isDateFormat" } ["date_upd"]=> array(2) { ["type"]=> int(5) ["validate"]=> string(12) "isDateFormat" } } ["classname"]=> string(4) "Cart" } ["update_fields":protected]=> NULL } Le pire c'est que c'est une fatal error et pourtant cela fonctionne... Je vais continuer de fouiller mais honnêtement je ne comprend pas, surtout que Prestashop duplique son panier de la même manière (ParentOrderController ligne 75) et je ne vois aucune error dans les logs... $oldCart = new Cart(Order::getCartIdStatic((int)$id_order, (int)self::$cookie->id_customer)); $duplication = $oldCart->duplicate(); Je suis peut-être maudit ou mauvais ^^ Link to comment Share on other sites More sharing options...
Heresis Posted January 22, 2013 Author Share Posted January 22, 2013 j'ai oublié de préciser que je suis en Prestashop 1.5.3 et je crois qu'il faut utiliser le "context" mais j'ai quand même du mal à comprendre comment dupliquer un panier avec cette nouvelle méthode. Si quelqu'un à un tuyau, je suis preneur Merci. Link to comment Share on other sites More sharing options...
Heresis Posted January 22, 2013 Author Share Posted January 22, 2013 C'est bon J'ai trouvé d'où venait le problème. Il fallait que je définisse le client a qui va être lié le panier et la commande. $this->context->customer = new Customer($customer['id_customer']); Merci NikosKos de ton aide Bonne journée. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now