Jump to content

I don't want combinations to override the basic product quantity


Roggie

Recommended Posts

For example

Suppose I have a theatre with 40 seats

Each seat can be sold for either £10, £15 or £20, the price selected depending on whether they are for child, student or adult.

If I enter these as a price group and add them as combinations then the basic 40 seats is overwritten and I have to input the quantities in the combinations. This makes it impossible to manage my stock of 40 seats because I have no idea how many tickets I will sell at each price point.

Anyone know a workaround?

Failing that, is there another way I can add different price levels for the same product and successfully manage my stock levels?

Link to comment
Share on other sites

  • 1 month later...

Can anyone help on this please?

I've tried to find a solution but failed. I'm not a programmer but I imagine that there is a flag set that forces combination quantities to override the base product quantity. I just need a check box in the admin that reverses this and uses the quantity in the product information page as the default.

I evaluated Zen Cart before switching to Prestashop and the only thing I miss is that Zen Cart allows me to do this.

Any modules out there that do it or programmers prepared to have a go?

Link to comment
Share on other sites

I understand that your product.php code:

Decreases the quantity of every combination when any one of the combinations is selected.

Includes logic based on the product location field on the products page. If this is set to 1 than the special stock management is implemented else it uses the the Prestashop default.

I was going to do a cut and paste but the code for the function is different in my version of Prestashop.

Your version:

public static function updateQuantity($product)
   {
       if (!is_array($product))
           die (Tools::displayError());

       if (Pack::isPack(intval($product['id_product'])))
       {
           $products_pack = Pack::getItems(intval($product['id_product']), intval(Configuration::get('PS_LANG_DEFAULT')));
           foreach($products_pack AS $product_pack)
           {
               $tab_product_pack['id_product'] = intval($product_pack->id);
               $tab_product_pack['id_product_attribute'] = self::getDefaultAttribute($tab_product_pack['id_product'], 1);
               $tab_product_pack['cart_quantity'] = intval($product_pack->pack_quantity * $product['cart_quantity']);
               self::updateQuantity($tab_product_pack);
           }
       }

       $result = Db::getInstance()->getRow('
       SELECT `quantity`
       FROM `'._DB_PREFIX_.($product['id_product_attribute'] ? 'product_attribute' : 'product').'`
       WHERE `id_product` = '.intval($product['id_product']).($product['id_product_attribute'] ?
       ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : ''));

       if (!Configuration::get('PS_STOCK_MANAGEMENT'))
           return true;
       if (self::isAvailableWhenOutOfStock($product['out_of_stock']) AND intval($result['quantity']) == 0)
           return -1;

       if ($result['quantity'] < $product['cart_quantity'])
       {
           Db::getInstance()->Execute('
           UPDATE `'._DB_PREFIX_.($product['id_product_attribute'] ? 'product_attribute' : 'product').'`
           SET `quantity` = 0
           WHERE `id_product` = '.intval($product['id_product']).($product['location'] == 1 && $product['id_product_attribute'] ?
           ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : ''));
           return false;
       }

       Db::getInstance()->Execute('
       UPDATE `'._DB_PREFIX_.'product'.($product['id_product_attribute'] ? '_attribute' : '').'`
       SET `quantity` = `quantity`-'.intval($product['cart_quantity']).'
       WHERE `id_product` = '.intval($product['id_product']).
       ($product['location'] == 1 && $product['id_product_attribute'] ? ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : ''));
       return true;
   } 



The version I'm using (1.3.2.3) has extra code tagged on to the end of the function (the if statement with a db update) and I don't understand the code well enough to go in and start editing. I would really appreciate your help.

1.3.2.3 code:

public static function updateQuantity($product)
   {
       if (!is_array($product))
           die (Tools::displayError());

       if (Pack::isPack(intval($product['id_product'])))
       {
           $products_pack = Pack::getItems(intval($product['id_product']), intval(Configuration::get('PS_LANG_DEFAULT')));
           foreach($products_pack AS $product_pack)
           {
               $tab_product_pack['id_product'] = intval($product_pack->id);
               $tab_product_pack['id_product_attribute'] = self::getDefaultAttribute($tab_product_pack['id_product'], 1);
               $tab_product_pack['cart_quantity'] = intval($product_pack->pack_quantity * $product['cart_quantity']);
               self::updateQuantity($tab_product_pack);
           }
       }

       $result = Db::getInstance()->getRow('
       SELECT `quantity`
       FROM `'._DB_PREFIX_.($product['id_product_attribute'] ? 'product_attribute' : 'product').'`
       WHERE `id_product` = '.intval($product['id_product']).($product['id_product_attribute'] ?
       ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : ''));

       if (!Configuration::get('PS_STOCK_MANAGEMENT'))
           return true;
       if (self::isAvailableWhenOutOfStock($product['out_of_stock']) AND intval($result['quantity']) == 0)
           return -1;

       if ($result['quantity'] < $product['cart_quantity'])
       {
           Db::getInstance()->Execute('
           UPDATE `'._DB_PREFIX_.($product['id_product_attribute'] ? 'product_attribute' : 'product').'`
           SET `quantity` = 0
           WHERE `id_product` = '.intval($product['id_product']).($product['id_product_attribute'] ?
           ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : ''));
           return false;
       }

       Db::getInstance()->Execute('
       UPDATE `'._DB_PREFIX_.'product'.($product['id_product_attribute'] ? '_attribute' : '').'`
       SET `quantity` = `quantity`-'.intval($product['cart_quantity']).'
       WHERE `id_product` = '.intval($product['id_product']).
       ($product['id_product_attribute'] ? ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : ''));
       if ($product['id_product_attribute'])
           Db::getInstance()->Execute('
           UPDATE `'._DB_PREFIX_.'product` 
           SET `quantity` = 
               (
               SELECT SUM(`quantity`)
               FROM `'._DB_PREFIX_.'product_attribute`
               WHERE `id_product` = '.intval($product['id_product']).'
               )
           WHERE `id_product` = '.intval($product['id_product']));
       return true;
   }

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