1

I am using the SOAP API for Magento (v1.5.1.0) and have managed to get the entire process of creating a cart, adding user, adding billing/shipping addresses, payment methods, etc. working, however I cannot get Coupons to work.

The code I'm using is as follows:

if ($couponCode != '') {
    try {
        $result = $this->magentoservice->shoppingCartCouponAdd($sessionId, $cartId, $couponCode);                
    } catch (Exception $err) {
        return $this->returnError($err->getMessage());
    }
}

I've tried with both a guest user and a registered user and I keep getting the same exception thrown - "Access denied.". As far as I can see from the limited documentation and forums posts this isn't even an expected error.

$sessionId and $cartId are definately valid. The $couponCode if entered directly on the magento frontend works.

Can anyone advise me how I might be able to solve this?

Hyarion
  • 113
  • 5
  • Are you sure that the API user has access to the coupon code resource? (set under the API role) – James Apr 02 '13 at 16:17
  • Thank you so much! So it turns out that the role was set to deny for coupon resources. However this seems to be because the coupon resources are not listed under the selectable items in the admin section. I had to manually allow them in the database (table is api_rule). Please add your comment as an answer so I can accept it :) – Hyarion Apr 03 '13 at 07:16

2 Answers2

1

Make sure that the API user has access to the coupon code resource (set under the API role)

Ben Lessani
  • 17,630
  • 4
  • 44
  • 68
James
  • 26
  • 1
0

It seems that ACL for coupons is not defined. Please merge the following snippet into ../Mage/Checkout/etc/api.xml. It should make proper ACL item available in the the admin panel.

<config>
    <api>
        <resources>
            <cart_coupon translate="title" module="checkout">
                <acl>cart/coupon</acl>
                <methods>
                    <add translate="title" module="checkout">
                        <title>Add coupon code for shopping cart</title>
                        <method>add</method>
                        <acl>cart/coupon/add</acl>
                    </add>
                </methods>
            </cart_coupon>
        </resources>
        <acl>
            <resources>
                <cart translate="title" module="checkout">
                    <title>Shopping Cart</title>
                    <coupon>
                        <title>Shopping cart ability to set coupon code</title>
                        <add>
                            <title>Add coupon code for shopping cart</title>
                        </add>
                    </coupon>
                </cart>
            </resources>
        </acl>
    </api>
</config>
Raphael at Digital Pianism
  • 70,385
  • 34
  • 188
  • 352
Alex Paliarush
  • 13,751
  • 5
  • 51
  • 55