How can we create a package product in magento. For eg. A product is having 1g weight and base price = 10$ But when same product is purchased at a smaller quantity say 1 g * 10 pouch its price is not 10*10 = 100, but will be 90. Similarly if I have a new package under the same product of say 2g*10 its price will be 150 and not 200. I hope my question is understandable. Please comment if anything is unclear.

Think in a way, that i need a product something related to pharmaceuticals. And I have pouches with different weights of tablets. And a user can add both the pouches which are associate to a same product. Please help me in this condition Thanks

  • Maybe this fits your needs: magento.stackexchange.com/a/10488/146
    – Marius
    Jun 5, 2014 at 7:57
  • @Marius : Thanks for the comment, i guess I should make my question more clear.
    – Ami Kamboj
    Jun 5, 2014 at 8:00
  • In this case I think you should have the same product in different quantities as separate products with their own SKU. If you have separate products you can use configurable products, where the configurable product is the "box size" or something like that.
    – Marius
    Jun 5, 2014 at 8:05
  • This is the exact approach i tried. But i also need to show all the packages on the product details page. So basically i will have one product, say paracetamol, and underneath that many packages of that. with different prices, weights quantities. And all can be individually added to cart
    – Ami Kamboj
    Jun 5, 2014 at 8:11
  • 1
    Then maybe the grouped product is the way to go. Have one grouped product named "Some product" and have child products named "Some product 10g", "Some product 20g", .. and each one will have it's own qty box and you can add it to cart separately.
    – Marius
    Jun 5, 2014 at 8:20

2 Answers 2


Really good link, But its Always better to share the code:

$productA = Mage::getModel('catalog/product')->load(Mage::app()->getRequest()->getParam('a_id'));

 $productB = Mage::getModel('catalog/product')->load(Mage::app()->getRequest()->getParam('b_id')); 
 $productA_price = ($productA->getPackageprice() > 0 ? $productA->getPackagePrice() : $productA->getFinalPrice());
 $productB_price = ($productB->getPackageprice() > 0 ? $productB->getPackagePrice() : $productB->getFinalPrice());

2) Check if package product already exists, if not create it!

Now load the package product based on the SKU that I know I’m going to make, if it doesn’t exist I will create the product and save.


 if (!$package_product) { 4
 $package_product = Mage::getModel('catalog/product');
 ->setWebsiteIds(array(1, 2))
 ->setName("PACKAGE DEAL: ".$productA->getName().' & '.$productB->getName())
 ->setPrice($productA_price + $productB_price)

3) Set stock data for package product

    $stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->setData('is_in_stock', 1);
$stockItem->setData('stock_id', 1);
$stockItem->setData('store_id', 1);
$stockItem->setData('manage_stock', 0);
$stockItem->setData('use_config_manage_stock', 0);
$stockItem->setData('min_sale_qty', 0);
$stockItem->setData('use_config_min_sale_qty', 1);
$stockItem->setData('max_sale_qty', 1000);
$stockItem->setData('use_config_max_sale_qty', 1);

4) If package does exists, update the price

} else {

$package_product->setPrice($productA_price + $productB_price)->save();

5) Add package product to cart

    $cart = Mage::getModel('checkout/cart')->init();
$cart->addProduct($package_product, array('qty' => 1));

6) Decrease individual product stock

 class Creare_Productpackages_Model_Observer
public function packageDecreaseStock($observer) {

$order = $observer['order'];

$items = $order->getAllVisibleItems();
foreach ($items as $itemid => $item){

$product = Mage::getModel('catalog/product')->load($item->getProductId());
if ($product->getAttributeSetId() == 15)
$qty = $item->getQtyToInvoice();
$skus = explode('__', $product->getSku());

foreach ($skus as $sku)
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
$stocklevel = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
$newlevel = $stocklevel-($qty);
if ($newlevel > 0) { $instock = 1; } else { $instock = 0; }
$stockItem = Mage::getModel('cataloginventory/stock_item')->assignProduct($_product);
$stockItem->setData('is_in_stock', $instock);
$stockItem->setData('qty', $newlevel);


As per your requriment please go to link:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.