3

I'm working with Magento CE 1.7.0.2. 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:

<magento_api>
    <store_id>7</store_id>
  <email>test@test.com</email>
    <addresses>
        <billing_address>
            <firstname>John</firstname>
            <lastname>Doe</lastname>
            <city>City</city>
            <region>Region</region>
            <postcode>1111</postcode>
            <country_id>FR</country_id>
            <telephone>123456</telephone>
            <street>Street 1</street>
        </billing_address>
        <shipping_address>
            <firstname>John</firstname>
            <lastname>Doe</lastname>
            <city>City</city>
            <region>Region</region>
            <postcode>1111</postcode>
            <country_id>FR</country_id>
            <telephone>123456</telephone>
            <street>Street 1</street>
        </shipping_address>
    </addresses>
    <items>
    <item>
            <sku>55032</sku>
            <qty_ordered>1</qty_ordered>                        
        </item>
    </items>
  <coupon_code>promotest</coupon_code>
</magento_api>

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.


EDIT 1:

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.


EDIT 2:

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)
{
    parent::collect($address);
    $quote = $address->getQuote();
    $store = Mage::app()->getStore($quote->getStoreId());
    $this->_calculator->reset($address);

    $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);

    $address->setDiscountDescription(array());

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?

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.