0
votes

We want to update product custom option quantity in our magento website using php script.

If we used code for showing custom option quanity then it is showing fine with following code :

$product = Mage::getModel("catalog/product")->load($productId); $attVal = $product->getOptions();

if($attVal){
    $values = array();
    foreach($attVal as $optionKey => $optionVal) {
        foreach($optionVal->getValues() as $valuesKey => $valuesVal) {

                echo $valuesVal->getCustomoptionsQty();

            }
        }
    }
}

Under this when we used setCustomoptionQty(10) function then it is not working with this code :

$product = Mage::getModel("catalog/product")->load($productId); $attVal = $product->getOptions();

    if($attVal){
        $values = array();
        foreach($attVal as $optionKey => $optionVal) {
            foreach($optionVal->getValues() as $valuesKey => $valuesVal) {
                    $valuesVal->setCustomoptionsQty(10);
                    $valuesVal->save();
                }
            }
        }
    }

    try {
        $product->save();
    }
    catch(Exception $ex) {
        echo $ex->getMessage();
    }

Please provide me some solution for this, we want to update product custom options quanity value for using this function.

1
what is the complete name of you attibute ? - Christophe Ferreboeuf
@ChristopheFerreboeuf it's not attribute, this is custom option quantity (customoptions_qty) - Kapil Gupta
Im not shure but you putting the value to the values object $valuesVal->setCustomoptionsQty(10). You should put the value to the product class $product->setCustomoptionsQty(10) (id the attribute name is customoptions_qty) or somewhere put the $valuesVal to $product. In the code you create $valuesVal and save it, save product, but product will not be changed? - Martin
customoptions_qty souds like attribute with ID "customoptions_qty". Make sure if is numeric (if you save numbers in it), active, assigned to the product group. - Martin

1 Answers

0
votes

It should be:

$product = Mage::getModel( 'catalog/product' )->load( $productId );
$product->setCustomoptionsQty(10)->save();