0

First I am developing an extension for custom price and I have an input on product page, this is an image describes what I've done :

enter image description here

when a customer enters the price he wants and clicks add to cart, the product must be added with that price added by him.

I know that can be coded in the controller but I don't know how?

this is the controller empty class :

<?php

class WebDirect_CustomPrice_savePriceController extends Mage_Core_Controller_Front_Action{
    //put your code here
}

anyone knows how that add to cart button works(code)

3
  • Please post the rest of your code, when a customer clicks add to basket what method in your controller is being called and what values do you have access too? (i.e. Custom price). It's possible to do what you want, but get the basics working first (i.e. So a product actually gets added to cart with normal price first). Once you have got that bit working look at this post where I have explained how to do this before: stackoverflow.com/questions/20949796/… Mar 25, 2014 at 11:20
  • Also, I would try doing this with an observer maybe instead of a whole new custom controller and changing a lot of magento default behaviour. Think of future upgrades :-) Mar 25, 2014 at 11:21
  • @AshleySwatton if that so how to do that with observer ? the extension doesn't modify the core and that's what i want ?
    – Souf
    Mar 25, 2014 at 11:55

2 Answers 2

6

You need to call final_price observer for it. Need to follow bellow steps:

1 add Observer in etc/config.xml

<events>
  <catalog_product_get_final_price>
    <observers>
      <xyz_catalog_price_observer>
        <type>singleton</type>
        <class>Xyz_Catalog_Model_Price_Observer</class>
        <method>apply_customprice</method>
      </xyz_catalog_price_observer>
    </observers>
  </catalog_product_get_final_price>     
</events>
  1. Add method in you model apply_customprice()

     public function apply_customprice($observer)
     {
         $event = $observer->getEvent();
         $product = $event->getProduct();
     // ADDD LOGIC HERE to get price added by customer
        $product->setFinalPrice($specialPrice); // set the product final price
        return $this;
     }
    

Click on below like where you can find how to set custom price when product added in cart.

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method

5
  • by the way Xyz is what namespace or module name?
    – Souf
    Mar 25, 2014 at 15:09
  • the price changed but i don't wanna draw regular price
    – Souf
    Mar 25, 2014 at 15:25
  • i've tried this one first magentotutorial.org/… but didn't work
    – Souf
    Mar 25, 2014 at 15:28
  • Do you have knowledge event observer in magento so you can easily understand it. It you have still issue email me I am happy to resolve it. Mar 26, 2014 at 8:11
  • no i know how observers work but u can see this 2nd question stackoverflow.com/questions/22638328/…
    – Souf
    Mar 26, 2014 at 9:15
1

As a starting point you can start at:

class Mage_Checkout_CartController extends Mage_Core_Controller_Front_Action
{

 /**
 * Add product to shopping cart action
 *
 * @return Mage_Core_Controller_Varien_Action
 * @throws Exception
 */
public function addAction()
{

Make sure you overwrite the add to cart route to point to yours (the new one that overwrites the Core route described above).

Also getting the price from a user's input will affect the checkout process as well, specifically the quote and everything that results from it (the cart, the order and so on).

Also, regarding onepage checkout be careful as the BE logic and the opcheckout.js are very tight together.

Chears

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.