Jump to content

[SOLVED] Pack creation from module


Newls

Recommended Posts

It's an attribute of Product:

'type' => array(
'getter' => 'getWsType',
'setter' => 'setWsType',
),
 
Which can have three values:
const PTYPE_SIMPLE = 0;
const PTYPE_PACK = 1;
const PTYPE_VIRTUAL = 2;
 
 

You can check what type is is with this function:

public function getType()
{
if (!$this->id)
return Product::PTYPE_SIMPLE;
if (Pack::isPack($this->id))
return Product::PTYPE_PACK;
if ($this->is_virtual)
return Product::PTYPE_VIRTUAL;
 
return Product::PTYPE_SIMPLE;
}
 
If it's a pack, the product is registered in the table ps_pack as well, so you can also use this function to check if a product is a pack in Pack.php:
public static function isPack($id_product)
{
if (!Pack::isFeatureActive())
return false;
 
if (!$id_product)
return false;
 
if (!array_key_exists($id_product, self::$cacheIsPack))
{
$result = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.(int)$id_product);
self::$cacheIsPack[$id_product] = ($result > 0);
}
return self::$cacheIsPack[$id_product];
}
 

Hope this helps,

pascal

  • Like 1
Link to comment
Share on other sites

Thanks PascalVG !

 

This helped in fact !

Finally, I just create a new Product and ->save() it, then I call Pack::AddItem() giving the new product's (the pack freshly created) ID as first argument, and then what I want to add in it.

It automatically set the product as a pack because of the way Pack::isPack() is coded !

 

I set this topic on solved.

Thanks again !

Edited by Newls (see edit history)
  • Thanks 1
Link to comment
Share on other sites

  • 6 years 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...