I'm working with Magento CE I create order by sending REST Api request (working fine) but when I'm adding coupon code to my XML (or JSON) request, the discount is not applying and the amounts are not re-calculated (mean discount_amount, base_discount_amount, etc).

fyi, my XML request:

            <street>Street 1</street>
            <street>Street 1</street>

What is tested and confirmed:

  • my shopping cart price rule is correctly applied on frontend & when creating an order from backend.
  • my coupon code is correctly added to the quote & sales_flat_order when creating order by REST.

It seems this is the collectTotals() method that is not correctly fired or bypassed the promotion stuff application.

Any help/suggestion will be appreciate. Thx in advance.


After some investigations, it seems a potential problem could be the fact that I'm creating a GUEST order.

After some debugs, when creating guest order by rest, the value of $this->getWebsiteId() is 0 at Mage_SalesRule_Model_Validator::process() method.

When I create a guest order by Magento backend, the websiteId is 1.

I guess the problem is here. I'm still analysing how to fix. I'll keep this post updated as soon as I get the response.


At Mage_SalesRule_Model_Quote_Discount::collect(), the weird thing is $quote->getStoreId() returns 0 when creating order by REST but returns the correct store_id when creating order from admin backend.

public function collect(Mage_Sales_Model_Quote_Address $address)
    $quote = $address->getQuote();
    $store = Mage::app()->getStore($quote->getStoreId());

    $items = $this->_getAddressItems($address);
    if (!count($items)) {
        return $this;

    $eventArgs = array(
        'website_id'        => $store->getWebsiteId(),
        'customer_group_id' => $quote->getCustomerGroupId(),
        'coupon_code'       => $quote->getCouponCode(),

    $this->_calculator->init($store->getWebsiteId(), $quote->getCustomerGroupId(), $quote->getCouponCode());
    $this->_calculator->initTotals($items, $address);


Important: in the db table sales_flat_quote, the store_id is always saved and correct for the related quote (by both REST & admin processes).

Any idea why?

  • have you got any solutoin for this ?
    – jpk
    Mar 23 at 16:21


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.