mirkos90 Posted July 15, 2014 Share Posted July 15, 2014 Hi to all! I've a little problem, i've writed this class for decrease the quantity of a product and make an order in prestashop: $context = Context::getContext(); $id_cart = $context->cookie->__get('id_cart'); $cart = new Cart($id_cart); $cart->id_currency = $context->cookie->id_currency; $cart->id_carrier = 1; $cart->recyclable = 0; $cart->gift = 0; $cart->id_customer = 92; $cart->id_lang = $context->cookie->id_lang; $cart->add(); $cart->updateQty(1,$id_product); $total = (float)($cart->getOrderTotal(true, Cart::BOTH)); $currency = $this->context->currency; $customer = new Customer($cart->id_customer); //($cart->id, Configuration::get('PS_OS_BANKWIRE'), $total, $this->module->displayName, NULL, $mailVars, (int)$currency->id, false, $customer->secure_key); $prodotti = $cart->getProducts(); PaymentModule::validateOrder($cart->id,'7',$total); Now I need to write a similar function for make an order and increase the quantity of the selected product, how I can do it? I tried to change the sign of the quantity in the function updateQty, but it did not work. How I can do it? Thank you! Link to comment Share on other sites More sharing options...
PascalVG Posted July 15, 2014 Share Posted July 15, 2014 Hi Mirkos, Looking at file classes/Cart.php you have the function updateQty defined: /** * Update product quantity * * @param integer $quantity Quantity to add (or substract) * @param integer $id_product Product ID * @param integer $id_product_attribute Attribute ID if needed * @param string $operator Indicate if quantity must be increased or decreased */ public function updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, Shop $shop = null, $auto_add_cart_rule = true) { ... So instead of using -1 or so for the first parameter, try to use and combined with 'up' or 'down' like: $cart->updateQty(1,$id_product, null, false, 'up'); and $cart->updateQty(1,$id_product, null, false, 'down'); I think that's what you need. Let me know if it works, pascal. Link to comment Share on other sites More sharing options...
mirkos90 Posted July 16, 2014 Author Share Posted July 16, 2014 Hi Pascal! Thanks for your answer! I've tried with your solution, now my code is: $context = Context::getContext(); $id_cart = $context->cookie->__get('id_cart'); $cart = new Cart($id_cart); $cart->id_currency = $context->cookie->id_currency; $cart->id_carrier = 1; $cart->recyclable = 0; $cart->gift = 0; $cart->id_customer = 92; $cart->id_lang = $context->cookie->id_lang; $cart->add(); $cart->updateQty(1,$id_product,null,false,'down'); $total = (float)($cart->getOrderTotal(true, Cart::BOTH)); $currency = $this->context->currency; $customer = new Customer($cart->id_customer); $prodotti = $cart->getProducts(); PaymentModule::validateOrder($cart->id,'2',$total); If I set the id of the status to 7 nothing happens, no order is created and no quantity is increased. But if i go to set the status to 2, prestashop give me an exception: [PrestaShop] Fatal error in module PaymentModule: Call to a member function addOrderPayment() on a non-object Why there is this error? Thanks! Link to comment Share on other sites More sharing options...
mirkos90 Posted July 18, 2014 Author Share Posted July 18, 2014 Bump, please help me guys :S Thanks! Link to comment Share on other sites More sharing options...
mirkos90 Posted July 20, 2014 Author Share Posted July 20, 2014 Upupup² :S Mirko 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