Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6700581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:49:54+00:00 2026-05-26T06:49:54+00:00

Hello i need to use magento to sell a product that will have custom

  • 0

Hello i need to use magento to sell a product that will have custom price rules.
the rule will depend by the quantity of this product sold.
I know that magento can make special rule, if a customer by ++ quantity of this product, but me i need to apply different rule and i cant find the way.
For example, product bought from customers first 100 times, price is :100$
product bought 200-500 times, price is 400$
500-1000times, product is 800$
1000 – > product is fixed price 1000$
is it possible for magento to do this?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:49:55+00:00Added an answer on May 26, 2026 at 6:49 am

    You can do this by creating a module that uses the checkout_cart_product_add_after and checkout_cart_update_items_after observers.

    Then inside your observer class you can put the following function in to set the price:

    public function yourAddToCartFunction($observer) {
    
        if ($p = $observer->getQuoteItem()->getParentItem()) {
            $discount_amount = $your_discount_logic;
            $p->setCustomPrice($discount_amount)->setOriginalCustomPrice($discount_amount); #configs
        } else  {
            $p = $observer->getQuoteItem();
            $discount_amount = $your_discount_logic;
            $p->setCustomPrice($discount_amount)->setOriginalCustomPrice($discount_amount); #simple products
        }
    }
    

    You will more than likely need a different function for the cart update observer call. The one above is for the cart_add_after event. The function for the cart update is nearly identical except you have to go through the cart object to get the logic.

    public function yourCartUpdateFunction($observer) {
        $cart = $observer->cart;
        $quote = $cart->getQuote();
    
        foreach($quote->getAllVisibleItems() as $item) {
            if ($p = $item->getParentItem()) {
                $discount_amount = $your_discount_logic;
                $p->setCustomPrice($discount_amount)->setOriginalCustomPrice($discount_amount); #configs
            } else {
                $discount_amount = $your_discount_logic;
                $item->setCustomPrice($discount_amount)->setOriginalCustomPrice($discount_amount); #simple products
            }
        }
    }
    

    The reason you would want the second function is if the logic needs to happen again if the cart is updated. If the price is going to stick forever no matter what happens once it is in the cart, you can probably exclude the second function.

    MASSIVE EDIT:

    Ok this is how I would do this. I am assuming you are starting with a basic, functional module.

    The first thing you want to do is setup your observers in your modules config.xml file. In this case you are going to use be using the checkout_cart_product_add_after and checkout_cart_update_items_after observers. You will set that up by adding the following to your config.xml file:

    <config>
        ...
        <global>
            ...
            <events>
                <checkout_cart_product_add_after>
                    <observers>
                        <call_this_something_unique>
                            <type>singleton</type>
                            <class>Ocaff_Custompricing_Model_Cart_Observer</class>
                            <method>calculateAddToCart</method>
                        </call_this_something_unique>
                    </observers>
                </checkout_cart_product_add_after>
    
                <checkout_cart_update_items_after>
                    <observers>
                        <call_this_something_unique_2>
                            <type>singleton</type>
                            <class>Ocaff_Custompricing_Model_Cart_Observer</class>
                            <method>calculateCartUpdate</method>
                        </call_this_something_unique_2>
                    </observers>
                </checkout_cart_update_items_after>
            </events>
            ...
        </global>
        ...
    </config>
    

    Basically what this does is it tells Magento that when the checkout_cart_product_add_after event is triggered, run the calculateAddToCart method of the Ocaff_Custompricing_Model_Cart_Observer class and also to run the calculateCartUpdate when the checkout_cart_update_items_after event is triggered.

    Ok now that you have your configuration put together you can create your model. In the case of this example the class would be located in the /app/code/local/Ocaff/Custompricing/Model/Cart/Observer.php file (however you will put the class that matches your module)

    Ok now in your Observer.php file you are going to put the following code:

    <?php
    
    class Ocaff_Custompricing_Model_Cart_Observer {
    
        public function calculateAddToCart($observer) {
            if ($p = $observer->getQuoteItem()->getParentItem()) {
            $discount_amount = Mage::helper('custompricing')->calculatePrice($p);
            $p->setCustomPrice($discount_amount)->setOriginalCustomPrice($discount_amount); #configs
        } else  {
            $p = $observer->getQuoteItem();
            $discount_amount = Mage::helper('custompricing')->calculatePrice($p);
            $p->setCustomPrice($discount_amount)->setOriginalCustomPrice($discount_amount); #simple products
        }
        }
    
        public function calculateCartUpdate($observer) {
            $cart = $observer->cart;
        $quote = $cart->getQuote();
    
        foreach($quote->getAllVisibleItems() as $item) {
            if ($p = $item->getParentItem()) {
                $discount_amount = Mage::helper('custompricing')->calculatePrice($prpoduct);
                $p->setCustomPrice($discount_amount)->setOriginalCustomPrice($discount_amount); #configs
            } else {
                $discount_amount = Mage::helper('custompricing')->calculatePrice($p);
                $item->setCustomPrice($discount_amount)->setOriginalCustomPrice($discount_amount); #simple products
            }
        }
        }
    
    }
    

    Ok a few notes here. both functions take a single paramater that I have called observer (and pretty much everywhere else calls it that too). This is a single variable that holds all the information that Magento passes along to all the functions that handle the event. In the case of the calculateAddToCart function we are only grabbing the Quote Item (which is confusing since in checkout with Magento there are quite a few different objects that kind of all represent the same thing if you are looking at it from 50,000 feet). What this function does is takes the quote item and determines if the product that was added to cart is a simple or configurable product and takes that appropiate action.

    The calculateCartUpdate function basically does the exact same thing, but it has to instead iterate through all the products in the cart since in Magento you update the entire cart all at once, not every line item.

    In both functions you will notice that I am updating the Custom Price and the Original Custom Price field. I am not 100% sure why you have to update both (and really why ask questions if it works :))

    Ok now you may or may not notice that I have done something a little less than conventional for figuring out the $discount_amount variable. I am calling a helper function to get the price that the product should be set to. I put this into a helper because you may want to access that logic elsewhere in the system and I generally prefer to put that kind of logic into a Helper (in fact I am pretty sure you are going to want to use this on the product and category pages since you are modifying the way pricing is working for some products and customers get mad when prices change up unexpectadly).

    Ok now onto the helper function. Since I am not 100% sure what logic you really want in the end, we are just going to keep this function simple and have it return $2. This will make everything that goes into the cart $2 no matter what its price actually is. This is going to be where you figure out your logic for pricing.

    <?php 
    
    class Ocaff_Custompricing_Helper_Data {
    
        public function calculatePrice($product=null) {
    
            // Your custom logic will go here. Whatever number you come up with and return will be the price that the item is set to
    
            return 2;
    
        }
    
    }
    

    For the most part this should get you about 90% of where you want to be. Try this out and post questions and I’ll do my best to help you.

    Another Edit: Activating Helpers in config.xml

    Put this code inside your config.xml file right after your observers block detailed above. This will tell Magento the location of the helper files for your module.

    <helpers>
        <custompricing>
        <class>Ocaff_Custompricing_Helper</class>
        </custompricing>
    </helpers>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HEllo, I have just installed xcode 3.2.3 and SDK4. I need to use ASIHttpRequest
Hello I need to have multiple language support of my django admin application.I can
Hello i am in desperate need of help on this i have an image
Hello i' need to use a pop-up menu, witch is created dynamically. OSErr err
Hello I have an array that looks like this, Array ( [cfi_title] => Mr
Hello i need to use writerreaderlock in my method. I want to know how
Hello I need use Cyrillic chars inside of UrlRewriting.config Does any one know how
Hello can anyone help me, i need to generate custom xml file from wordpress
hello guys i need to use pure SQL queries for my database project at
I have this BasicNode interface extending NSObject. At some point, I need to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.