0

Goodnight, I updated the model Price.phtml that handles the prices of the bundled products. My need is to add a surplus price on regular prices based on a custom attribute (supplementoprezzo). The bundle is Dynamic. This is the function interested:

public function getSelectionFinalTotalPrice ($bundleProduct, $selectionProduct, $bundleQty, $selectionQty, $multiplyQty = true, $takeTierPrice = true)
{

$attribute = $bundleProduct->getResource()->getAttribute('supplementoprezzo');
$supplementoprezzo = $attribute_value = $attribute ->getFrontend()->getValue($bundleProduct); 

if (is_null($selectionQty)) {
    $selectionQty = $selectionProduct->getSelectionQty();
}

if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) {

    $price = $selectionProduct->getFinalPrice($takeTierPrice ? $selectionQty : 1);

} else {
    if ($selectionProduct->getSelectionPriceType()) { // percent
        $product = clone $bundleProduct;
        $product->setFinalPrice($this->getPrice($product));
        Mage::dispatchEvent(
            'catalog_product_get_final_price',
            array('product' => $product, 'qty' => $bundleQty)
        );
        $price = ($product->getData('final_price')) * ($selectionProduct->getSelectionPriceValue() / 100);



    } else { // fixed
        $price = $selectionProduct->getSelectionPriceValue();
    }
}
$price = $this->getLowestPrice($bundleProduct, $price, $bundleQty);

if ($multiplyQty) {
    $price *= $selectionQty;
}

$price += $supplementoprezzo;
return $price;
}

The last two lines are the lines affected: the variable $supplementoprezzo is a float number. The problem (and the odd thing) is that if I enter a number like this:

$price += 2.50;
return $price;

everythink works like a charme.. Instead summing the variable (which also is a number)

$price += $supplementoprezzo;
return $price;

the final price of the bundle is not updated with the surplus value. I tried with various casting for the variable (float, floatval number_format, etc) .... nothing. Any suggestions?

Thank you

Save

1 Answer 1

0

Solved, the problem was that retrivieng attribute "supplementoprezzo" this way:

$attribute = $bundleProduct->getResource()->getAttribute('supplementoprezzo');
$supplementoprezzo = $attribute_value = $attribute ->getFrontend()->getValue($bundleProduct); 

was not recognized in cart controller.

This is the right way:

$productId = $bundleProduct->getId();
$bundleProduct = Mage::getModel('catalog/product')->load($productId);
$supplementoprezzo =  $bundleProduct->getData('supplementoprezzo');
$_bcbbMaxQty =  $bundleProduct->getData('bcbb_maximum_qty');
$supplementoprezzo = ($supplementoprezzo/$_bcbbMaxQty);
$supplementoprezzo = number_format($supplementoprezzo, 2, '.', '');

Then this at the end made the magic:

if ($supplementoprezzo>0) {
    $price = $supplementoprezzo + $price;
    $selectionProduct->setCustomPrice($price);
    $selectionProduct->setOriginalCustomPrice($price);
}

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.