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?

2
  • Are you sure that the API user has access to the coupon code resource? (set under the API role)
    – James
    Commented Apr 2, 2013 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
    Commented Apr 3, 2013 at 7:16

2 Answers 2

1

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

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.