2

In my custom product type model, I have:

public function prepareForCartAdvanced(Varien_Object $buyRequest, $product = null, $processMode) {
    $product->setMyProperty(500);
    return parent::prepareForCartAdvanced($buyRequest, $product, $processMode);
}

In my product type's price model, I have:

public function getPrice($product) {
    // This displays 500
    echo $product->getMyProperty();
    exit;
    // This does not return 500 - the product's price in cart is 0.00
    return $product->getMyProperty();
    // This does return 500 - the product's price in cart is 500.00
    return 500;
}

Why can I not return $product->getMyProperty() even though the value I have set is properly echoed?

No matter what I do, I am only able to set the return price if I key a number in directly. I cannot set any value in the price model based on something passed through $product.

1

Suggesting to you create Custom attribute of type price name as my_property from Backend as getPrice() is always return a numeric value.

Also, don't use prepareForCartAdvanced() for this case.If want to change the price of product basic of an attribute then

use magento event/observer. Basically there are two events,by which you can change the cart price of that products:

  1. checkout_cart_product_add_after
  2. checkout_cart_update_items_after
  3. checkout_cart_product_update_after

As per as magento system, a cart item price change using setter functions setCustomPrice(), setOriginalCustomPrice of cart item Object.

Just like:

$EachCartitem->setCustomPrice($price);
$EachCartitem->setOriginalCustomPrice($price);
// Enable super mode on the product.
$EachCartitem->getProduct()->setIsSuperMode(true);

An example: Custom options operations

  • The reason I have a custom product type in the first place is because a price attribute cannot be used (decimal precision is not sufficient). Why do I need to use an observer to set the price of a custom product type? Isn't that precisely what a custom price model is for? – pspahn Jun 2 '15 at 16:05
  • You could enhance the decimal precision of prices throughout your DB. It is a painful process (trust me, I've done it), and you'd have to override lots of Magento models to get it working, but it's feasible. – Julien Lachal Oct 19 '15 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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