Jump to content

cart->updateQty Fatal Error


Alessandro Cimino

Recommended Posts

Hi guys,

I've a problem. I'm trying to add a product into a cart programmatically. Every thing it's ok until I try to add the product to the cart.

 

This is my code:

include('config/config.inc.php');

global $params;
$errors = array();

$product = new Product(282);
$cart = new Cart();

$cart->id_customer = (int)(7);
$cart->id_address_delivery = (int) (Address::getFirstCustomerAddressId($cart->id_customer));
$cart->id_address_invoice = $cart->id_address_delivery;
$cart->id_lang = (int)(1);
$cart->id_currency = (int)(1);
$cart->id_shop_group = 1;
$cart->mobile_theme = 0;
$cart->secure_key = md5(uniqid(rand(), true));
$cart->id_guest = 7406;
///$cart->id_carrier = 17;
$cart->recyclable = 0;
$cart->gift = 0;
$cart->add();
$id_cart = (int)($cart->id);    
 

$productID = $product->id;
$productAttributeID = Product::getDefaultAttribute($productID);
$cartID = $cart->id;
$addressDeliveryID = $cart->id_address_delivery;
$shopID = 2;
$qty = 1;
$cart->updateQty((int)($qty), (int)($productID), (int)($productAttributeID), false, 'up', 8);
$cart->update();

print_r($cart);
die;

Everything is ok, but when I call 

$cart->updateQty((int)($qty), (int)($productID), (int)($productAttributeID), false, 'up', 8);

The script return "Fatal Error".

The strange thing is that if i show cart table i can see the new cart and cart_product too have the new product inside but the script stops and i cant to confirm the order.

Anyone can help me  please? :-)

Link to comment
Share on other sites

Why productAttributeId uses $productAttributeID = Product::getDefaultAttribute($productID); instead of real product id_product_attribute or combination id?

And you have in code 

$cart->id_address_delivery = (int) (Address::getFirstCustomerAddressId($cart->id_customer));

 a space beetwen (int) (Adress)

Link to comment
Share on other sites

On 20/6/2018 at 2:31 PM, hakeryk2 said:

Why productAttributeId uses $productAttributeID = Product::getDefaultAttribute($productID); instead of real product id_product_attribute or combination id?

And you have in code 


$cart->id_address_delivery = (int) (Address::getFirstCustomerAddressId($cart->id_customer));

 a space beetwen (int) (Adress)

2

 

I checked Product::getDefaultAttribute and return the correct id_product_attribute.

I tried to set specific id but the result is the same.

About the space i removed but nothing changed.

I receive everything "Fatal Error" output.

How i can check prestashop internal errors?

Link to comment
Share on other sites

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...