Jump to content

$cart->updateQty() add twice the quantity


files___

Recommended Posts

Hi folks, here my code to update a cart and add (if the product doesn't exist in the cart) or update(if the product is in the cart) a product.

<?php

$useSSL = true;

include './config/config.inc.php';
include './header.php';

global $params;
$errors = array();

if ($cookie->isLogged())
{
    /*Cart already exists*/
    if ((int)$cookie->id_cart)
    {
        $cart = new Cart((int)$cookie->id_cart);
    }
    $product = new Product(2);
    /*print_r($cart);*/

    /*If needed to create new cart*/
    if (!isset($cart) or !$cart->id)
    {
        $cart = new Cart();
        $cart->id_customer = (int)($cookie->id_customer);
        $cart->id_address_delivery = (int)  (Address::getFirstCustomerAddressId($cart->id_customer));
        $cart->id_address_invoice = $cart->id_address_delivery;
        $cart->id_lang = (int)($cookie->id_lang);
        $cart->id_currency = (int)($cookie->id_currency);
        $cart->id_carrier = 1;
        $cart->recyclable = 0;
        $cart->gift = 0;
        $cart->add();
        $cookie->id_cart = (int)($cart->id);   
    }

    $productID = $product->id;
    $productAttributeID = Product::getDefaultAttribute($productID);
    $cartID = $cart->id;
    $addressDeliveryID = $cart->id_address_delivery;
    $shopID = (int)Context::getContext()->shop->id;
    $qty = 1;

    $cart->updateQty((int)($qty), (int)($productID), (int)($productAttributeID));
    $cart->update();

    Tools::redirect('order');

}
    
include './footer.php';
?>

The problem here is that it adds in my cart twice the quantity I choose in updateQty(). So if in this function I choose to set $qty = 1, it adds 2, if I set $qty = 10, it adds 20 quantity of the product.

Why?! Can anyone help me?!

UPDATE: It seems this behaviour happens only with Safari. Chrome and Firefox seem to act normally.

Edited by files___ (see edit history)
Link to comment
Share on other sites

  • 6 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...