Jump to content

Limit Product Quantity on cart base on Manufacturer


gejrot

Recommended Posts

I try to limit customer that can buy a product from certain manufacturer.

Example :

Product A from Manufacturer B

Product C from Manufacturer D

I want to limit that the customer can only buy 10 pcs product A and 5 pcs product C. I have been using this example code that provide in this  link

as follow and change the $id_product with $id_manufacturer and it's not working, any idea how to do this since i am new in prestashop,

any idea how to recall the id_manufacturer from product in cart.php ?

Quote

if ((int)$quantity <= 0)

  return $this->deleteProduct($id_product, $id_product_attribute, (int)$id_customization);

elseif (!$product->available_for_order || Configuration::get('PS_CATALOG_MODE'))

  return false;

elseif ($quantity > 4 && $id_product =='XXX') { // Where XXX is the product id. For example, 4 max per same product/product-combination allowed

  return false;

}

else

{

  /* Check if the product is already in the cart */

  $result = $this->containsProduct($id_product, $id_product_attribute, (int)$id_customization,

      (int)$id_address_delivery);

 

  /* Update quantity if product already exist */

  if ($result)

  {

    if ($operator == 'up')

    {

      $sql = 'SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity

          FROM '._DB_PREFIX_.'product p

          '.Product::sqlStock('p', $id_product_attribute, true, $shop).'

          WHERE p.id_product = '.$id_product;

 

      $result2 = Db::getInstance()->getRow($sql);

      $product_qty = (int)$result2['quantity'];

      // Quantity for product pack

      if (Pack::isPack($id_product))

        $product_qty = Pack::getQuantity($id_product, $id_product_attribute);

      $new_qty = (int)$result['quantity'] + (int)$quantity;

      if ($new_qty > 4 && $id_product =='XXX') { // Where XXX is the product id. For example, 4 max per same product/product-combination allowed

        return false;

      }

Any suggestion would help me to understand the code. really appreciate it. Thanks

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