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 7677015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:19:43+00:00 2026-05-31T17:19:43+00:00

I am currently adding products programatically to the cart, to create a ‘free sample’

  • 0

I am currently adding products programatically to the cart, to create a ‘free sample’ aspect to my site.

Currently, all of these products are $0 and you can add a maximum of 15. Once you have 5 ‘free sample’ products in the cart, I need to add $20 to the subtotal.

I know I can get the grandtotal using:

Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal();

But how do I access the subtotal and also add $20 to it?

I’m guessing I’ll need to write an observer, as I’ll need to check when products are added/removed from the cart in order to either add the $20 or not.

Has anyone done this before or could point me in the right direction of how I could do this?

Many thanks

Thanks

  • 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-31T17:19:45+00:00Added an answer on May 31, 2026 at 5:19 pm

    I actually answered this question recently here is a basic idea of what needs to be done, let me know if you need more specific details:
    Add an observer which looks for this event ‘sales_quote_add_item’:

    <events>
        <sales_quote_add_item>
            <observers>
                <priceupdate_observer>
                    <type>singleton</type>
                    <class>mymodule/observer</class>
                    <method>updatePrice</method>
                </priceupdate_observer>
            </observers>
        </sales_quote_add_item>
    

    The observer should have a method which does something like this:

    public function updatePrice($observer) {
        $event = $observer->getEvent();
        $quote_item = $event->getQuoteItem();
        if(sample etc...) $new_price = <insert logic>
        $quote_item->setOriginalCustomPrice($new_price);
        $quote_item->save();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently am adding some features to our logging-library. One of these is the
I'm currently adding a div to use as a slider programmatically, but when I
I'm currently adding transposition tables in my chess engine, and I'm having issues with
I'm adding a toolbar to my application and currently I'm adding some toggle buttons
Currently in my controller, when adding new data, I validate the inputs, and if
I'm currently evaluating options for adding sub-domain support to a new Ruby on Rails
Currently I have a loop that tries to find an unused filename by adding
The code I'm currently working on requires adding an NSNumber object to an array.
I'm currently in the process of adding JNI functionality into a legacy delphi app.
I am currently adding Oracle 10.2.0. as a viable database to a product. The

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.