6

I am trying something for a social cause website where there are trying to provide a user choice price for a NGO's product which can be any price. this is for promotional activity where user can set the any price for product.

3

Yes, it is possible, this blog post (German) uses exactly this as a simplified example for dynamic pricing: http://www.avs-webentwicklung.de/nc/blog/artikel/magento-umsetzung-von-flexiblen-preisen.html

Summary:

  1. Add an input field "price" to the form on the product page.
  2. Create a custom module with an observer for catalog_product_get_final_price:

    <events>
        <catalog_product_get_final_price>
            <observers>
                <modulename_catalog_product_get_final_price>
                    <type>singleton</type>
                    <class>Namespace_Modulename_Model_Observer</class>
                    <method>getFinalPrice</method>
                </modulename_catalog_product_get_final_price>
            </observers>
        </catalog_product_get_final_price>
    </events>
    
  3. In the observer, set the final price based on the request:

    /**
     * Update price for product items
     *
     * @param Varien_Event_Observer $observer
     */
    public function getFinalPrice($observer) {
    
        /* @var Mage_Catalog_Model_Product $product */
        $product = $observer->getEvent()->getProduct();
    
        if ($buyRequest = $product->getCustomOption('info_buyRequest')) {
    
            $buyRequest = unserialize($buyRequest->getValue());
    
            if (is_array($buyRequest) && isset($buyRequest['price'])) {
    
                $product->setFinalPrice(floatval($buyRequest['price']));
            }
        }
    }
    

(this example does not validate the price to be greater than zero, I'll leave that part as an exercise to the reader)

1

You even don't need coding. Depending on the range of chooseable prices, you can just use custom options with a price.

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