Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 3
Add weight to a product when a custom option is selected? 
 
aureh12
Jr. Member
 
Total Posts:  8
Joined:  2010-04-23
 

I added Weight: the admin form can save the value of the option
I added Volume.the admin form can NOT save the value of the option

Any new field can be retrieve from DB but can NOT be saved.

Do you know how to make this Save work ?

Thanks for your help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
szotyi
Sr. Member
 
Total Posts:  153
Joined:  2008-11-29
 

3. add the weight to the array
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php
after this line:

'price_type' => $_value->getPriceType(),
insert:
'weight' => $_value->getWeight(),

change the Weight to Volume

if does not work, then do all steps as Weight, but change the Weight word to Volume

 
Magento Community Magento Community
Magento Community
Magento Community
 
aureh12
Jr. Member
 
Total Posts:  8
Joined:  2010-04-23
 

Thanks, this part works perfectly: the Volume value is retrieved from the database
‘volume’ => $_value->getVolume(),

The problem is that if you modify the value on the admin, it is NOT saved in the database.

For testing purpose:
- modify the field name in DB = weightA
- modify all the weight by weightA in Option.php and select.phtml

the data will not be updated in the database anymore ...

 
Magento Community Magento Community
Magento Community
Magento Community
 
aureh12
Jr. Member
 
Total Posts:  8
Joined:  2010-04-23
 

Anybody has the answer for this ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
rrroulio
Sr. Member
 
Avatar
Total Posts:  88
Joined:  2008-03-26
france moselle
 

Perhaps A in lowercase ? Are you sure to change Weight to Volume and weight to volume (case sensitive) ?
working with cache disabled.
i think you have error in code because i add “qty” (duplicate everything with “weight” in other line) and everything works. I have now, my two fields in database and in backoffice custom options.

with small modification, i can disabled a custom option on front end (hide checkbox or radio) and show text : not available for one custom option for qty 0.
So, i can’t decrease stock for custom option because code is too hard for me (lot of files, classes and function) but if someone wants…

 
Magento Community Magento Community
Magento Community
Magento Community
 
aureh12
Jr. Member
 
Total Posts:  8
Joined:  2010-04-23
 

It’s working !

I had to Flush the Cache Storage to make it work.

Thank you again !

 
Magento Community Magento Community
Magento Community
Magento Community
 
Giannis-M-
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2010-06-24
Greece
 

Thank you so much for this szotyi and ale.sm. You sold my problem smile

Update: I just noticed that the weight is beeing added only for the first product that is beeing selected (by checking a checkbox). Any product selected after that is not beeing added to the overal product’s weight. Can you please help?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vantages Media
Jr. Member
 
Total Posts:  3
Joined:  2010-10-04
 

For those having the “cannot add item” error when your options include file uploads and text input, change the Item.php modifications to:

foreach ($options as $option{
$valueofoption 
$option->getValue();
if (
$valueofoption && is_numeric($valueofoption)) {
$temp 
$read->fetchRow("SELECT * FROM catalog_product_option_type_value WHERE option_type_id = ".$valueofoption." LIMIT 0, 1");
$optionsWeight += $temp['weight']
}          
}

Also, note that your tables might have the “mage_” prefix, like “mage_catalog_product_option_type_value”. You need to change the table name above if that is the case. Most “cannot add item” errors seem to relate to a bad SQL query in the Item.php page.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rrroulio
Sr. Member
 
Avatar
Total Posts:  88
Joined:  2008-03-26
france moselle
 

Thanks it works fine with checkbox, no errors

 
Magento Community Magento Community
Magento Community
Magento Community
 
fusionxx
Jr. Member
 
Total Posts:  4
Joined:  2010-09-02
 

How could you post this weight beside the custom option on the product page?

 
Magento Community Magento Community
Magento Community
Magento Community
 
richardlapes
Member
 
Avatar
Total Posts:  43
Joined:  2011-07-04
 

The code works.

But I want to accomplish a different thing.

I want to add option quantity and update it whenever an order has been successful.

So far I am able to update it when added to the cart using the following codes

$options $this->getOptions();
        if (
is_array($options)) {
            
unset($options[0]);unset($options[1]); 
            
            
$read Mage::getSingleton('core/resource')->getConnection('core_read');
            foreach (
$options as $option{
                
                  $temp 
$read->fetchRow('SELECT * FROM `catalog_product_option_type_value` WHERE `option_type_id` = '.$option->getValue().' LIMIT 0, 1');
                  
                  
$tempQty = ($temp['qty']>0)?$temp['qty']-1:0;
                  
                  
$write =  Mage::getSingleton('core/resource')->getConnection('core_write');
                  
                  
$updateQuery  'UPDATE `catalog_product_option_type_value` SET qty = '.$tempQty.' WHERE `option_type_id` = '.$option->getValue();
                  
                  
$write->query($updateQuery); 
                
}
        }

But the problem is that, although I added 5 the qty is just subtracted by 1, sometimes 2 >.< .
I’m still finding the codes for cancelling the order and update the quantity as well.
I hope some people seek the same and will help me accomplish this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
richardlapes
Member
 
Avatar
Total Posts:  43
Joined:  2011-07-04
 

repost

 
Magento Community Magento Community
Magento Community
Magento Community
 
lurebeauty
Sr. Member
 
Avatar
Total Posts:  229
Joined:  2009-07-06
 

I installed this and it works for drop downs but now we’re getting errors if we have pages with checkboxes or text boxes - customers keep getting error “cannot add to shopping cart” and i even added the fix above.  for the checkboxes, we only get the error if they choose more than one option.  any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
lurebeauty
Sr. Member
 
Avatar
Total Posts:  229
Joined:  2009-07-06
 

This coding is causing so many problems so im removing it.  if a customer orders two products of the same item, its charging the same price, even if one costs more money.

 
Magento Community Magento Community
Magento Community
Magento Community
 
venz
Jr. Member
 
Total Posts:  19
Joined:  2009-02-04
 

Hi,

I’m trying to send this custom option weight to a shipping company. So I have a module which sends the order once it’s completed.

My code looks like this(it’s in the observer of my module):

$optionsArr $item->getProductOptions();
                    
foreach (
$optionsArr['options'as $option{
    
if($option['label'!='' && $option['value'!=''{

        $optionValue 
$option['value']// OK
        
$optionId $option['option_id']// OK
        
$optionWeight $option['weight']// NOT WORKING
            
    
}
}

Getting option ID and Value is just fine. But I can’t get the weight field.

Any help will be appreciated. Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 3