0

I have created an attribute price_used and the type is price. I know how to display this price in frontend, i use this method and it works ok:

<?php echo Mage::helper('core')->currency($_product->getPriceUsed(),true,false); ?>

I need to create a separate addtocart for this price, i have tried many things for example overide observer but it will affect also normal price.

What would be the correct method to make this work for my custom price and also not affect the normal price?

I do not want to use magento's custom options for products.

0

You can use the original_custom_price and custom_price attributes of Mage_Sales_Quote_Item.

You could use an observer attaching the checkout_cart_product_add_after:

...
<events>
    <checkout_cart_product_add_after>
        <observers>
            <my_module>
                <class>my_module/observer</class>
                <method>checkoutCartProductAddAfter</method>
            </my_module>
        </observers>
    </checkout_cart_product_add_after>
</events>
...

And, in your observer:

...
public function checkoutCartProductAddAfter(Varient_Event_Observer $observer) {
    $item = $observer->getQuoteItem();
    $product = $item->getProduct();

    $item->setCustomPrice($product->getUsedPrice());
    $item->setOriginalCustomPrice($product->getUsedPrice());
    $item->getProduct()->setIsSuperMode(true);
}
...

This will set used_price as price in the cart, but will leave the product price unvaried.

I did not test the code, but should work. Hope it helps.

  • Thank you @RiccardoT , @Senthil for your answers, now i understand clear that i need to go with the observer method. I know that it might sound stupid, but how i add the product to the cart using the custom function?I tried <a href="<?php echo $_product->getcheckoutCartProductAddAfter(); ?>">add to cart custom </a> – spanakorizo Mar 7 '16 at 5:03
  • You could use a parameter in the querystring and intercept that in the observer. – Phoenix128_RiccardoT Mar 7 '16 at 7:29
  • thanks, can you please give me an example for the query string?From what i understand i need new function in observer like Mage::app()->getRequest()->getParam('price_used') == '1') and then encode it in the addtocart querystring url – spanakorizo Mar 9 '16 at 3:03
0

You can use catalog_product_get_final_price observer. Observer function would be some thing like this.


public function setFinalPrice(Varien_Object $observer){   
$product->$observer->getEvent()->get product();
$price = $product->getCustomPrice();$product->setFinalPrice ($price);
}

Then have your definition in the config.xml

  • This will affect the standard price, he does not want – Phoenix128_RiccardoT Mar 7 '16 at 7:30
  • Thanks Riccardo. He can have a conditional statement in there to check that. That way this can be skipped. – Senthil Kumar Muppidathi Mar 7 '16 at 9:07

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.