How to add custom qty field to custom option of simple product magento
By default in magento there is no qty field of simple product for custom option. If you want to add qty as per your custom option you can add now using this post.
Suppose you have custom option 'Color: Red, Blue, White' of your simple product and you want to add different qty option for your color option you can do it now.
1. go to app\design\adminhtml\default\default\template\catalog\product\edit\options\type\select.phtml
Find the below code:
2. go to app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Options\Option.php
Find the below code:
Find the below code:
'sku' => $this->htmlEscape($_value->getSku()),
3. Add field in “catalog_product_option_type_value” table
Suppose you have custom option 'Color: Red, Blue, White' of your simple product and you want to add different qty option for your color option you can do it now.
1. go to app\design\adminhtml\default\default\template\catalog\product\edit\options\type\select.phtml
Find the below code:
'<th class="type-sku"><?php echo Mage::helper('catalog')->__('SKU') ?></th>'+
Now add following code just after above code.
'<th class="type-qty"><?php echo Mage::helper('catalog')->__('Qty') ?></th>'+
Find the below code:
'<td><input type="text" class="input-text" name="product[options][{{id}}][values][{{select_id}}][sku]" value="{{sku}}"></td>'+
Now add following code just after above code.
'<td><input type="text" class="input-text" name="product[options][{{id}}][values][{{select_id}}][qty]" value="{{qty}}"></td>'+
$value['sku'] = $this->htmlEscape($option->getSku());
Now add following code just after above code.
$value['qty'] = $this->htmlEscape($option->getQty());'sku' => $this->htmlEscape($_value->getSku()),
Now add following code just after above code.
'qty' => $this->htmlEscape($_value->getQty()),
`qty` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Qty',
Now clear your cache and check in you magento admin. You can hit below if post is help full for you.
Please support us, Like us on Facebook.
Subscribe to:
Post Comments (Atom)
Works fantastic.
ReplyDeleteHowever might need a fix as csv files do not have the 'qty'. instead the values seems to go under '_custom_option_row_sku' in the csv file.
Nice! But....
ReplyDeleteis it combine the calculation?
I mean lets say we have 4 t-shirts in stock and customer wants to buy two black
both in XL size.
The stock has the following combination: 2 red XL; 1 black XL; 1 black XXL;
The above code suggests me that it's possible to the customer selecting two black
XL t-shirts, however you have only one in stock, because the simple product qty is
4, the size option qty for XL is 3, the color option qty for black is 2.
In short, I don't see the connection in your code between the different options.
Or do I miss something?
You need to add some code to check this all.
DeleteIt's working in the admin, but I can place orders with a higer QTY then what is have added in the admin.
ReplyDeleteFor that you need to make some validation before adding item in the cart. You can validate this on your product details page.
DeleteHi. Where do I find catalog_product_option_type_value ?
ReplyDeleteThanks
Open your database and find catalog_product_option_type_value table in it.
DeleteHi
ReplyDeleteDo you have sample code to validate the quantity before adding item to the cart?
Thanks
Your help is highly appreciated
hi
ReplyDeletehow can i maintain stock for custom option for configurable product.
please i am stuck with manage stock for packages
please help me out
contact me swzvikas@gmail.com
Helo I am having trouble : In admin a new field qty is added but when i pdate it , it is not saved. Please help
ReplyDeleteMay i know which magento version you are using? and please make sure you have added all steps.
Deletehi,
ReplyDeleteYour blog helped me to bring the qty option in custom option.
If you have the sample code to validate the qty in the front end, pls share it.
Help needed urgently
how to add price during option change . add price to ad to cart
ReplyDeleteNo sense how it will WORK on frontend store? price * qty in basket?
ReplyDeleteHi,
ReplyDeleteQty text box can see in the admin panel. But when I save the qty is always set to zero, that means not saving.
Also how can i display how many qty is exist in the that custom option drop down box ?
like color 1 => 10 qty like that.
Im using Magento ver. 1.9.0.1.
Thanks
Hi,
ReplyDeleteThanks for the code update. I have successfully added the qty code, but but when customer purchased the product but qty is not reducing(Size M has 3 after the purchase 2 M products still the Size M has 3). Let me how to make this work
Hi,
ReplyDeleteThanks for the code. When we buy a product of size M 2 out of 4, but still the quantity didn't reduced it was still 4. Kindly help to fix this issue. (I am Using Magento 1.9.2)
Hi Ramesh,
DeleteYou need to add observer event to change option quantity after order is placed.
Thanks
Dear Author,
ReplyDeleteCan you guide me to Add Observer event for this operation,
Thank You.
what code i have to add for quantity validation in product detail page please share with me.
ReplyDeleteHardik g can you provide the solution with validation code and stock
ReplyDeleteAsslam O Alikum, Nice work bro great article keep it up.
ReplyDeleteMe face miner problem when i add back-end product custom quantity, when i add to cart product custom quantity not decrease from back-end. Please help me.
http://www.rivaj-uk.com
Hello,
DeleteYou need to use observer to decrease qty when you add product to cart.
What is observer n where i can apply?
DeleteI think you are not aware with magento code customization.
DeleteRead this answer for how to create observer event in magento https://magento.stackexchange.com/a/41280
For further discussion you can contact me via contact us page.
https://hkpatel201.blogspot.in/p/contact-us.html
Thanks,
hi hardik, how to Change weight based on custom option. I did'nt find any solution even in stackoverflow.
ReplyDeleteI need weight field in custom option so that shipping will calculate on the basis of weight of custom option.
I have create the custom field weight & weight is successfully added to DB. but now i want to replace the general weight attribute value to selected custom weight value so that correct shipping will calculate on the basis of weight of custom option.
ReplyDeletefor that i have create observer.
getQuoteItem();
$product = $item->getProduct();
$productOptions = $product->getTypeInstance(true)->getOrderOptions($product);
$weight = '';
foreach ($productOptions['options'] as $key => $value) {
$product = Mage::getModel("catalog/product")->load($product->getId());
foreach ($product->getOptions() as $o) {
$values = $o->getValues();
foreach ($values as $v) {
if ($value['option_value'] == $v->getOptionTypeId()) {
$weight = $v->getWeight();
}
}
}
}
if(!empty($weight)){
return $item->getProduct()->setWeight($weight);
}else{
return;
}
}
}
//echo $weight; display the selected weight in the observer
& I am getting the selected custom field weight but when check the shopping cart page. using the below code.
getQuote()
->getShippingAddress()
->getWeight();
echo $weight; die;
?>
it print the general attribute weight instead of selected custom option weight.
pls help
Hi Pankaj,
DeleteFirst of all try this simple thing before adding custom option value.
$item = $observer->getQuoteItem();
$item->setWeight(10);
and check if its working or not.
Thanks,