在尝试添加优惠券时,Magento API会拒绝访问

时间:2013-04-02 14:11:25

标签: php magento-1.5

我正在使用SOAP API for Magento(v1.5.1.0),并设法获得创建购物车,添加用户,添加帐单/送货地址,付款方式等工作的整个过程,但我不能获得优惠券。

我正在使用的代码如下:

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

我已经尝试过访客用户和注册用户,并且我不断得到同样的异常 - “访问被拒绝。”。据我所知,从有限的文档和论坛帖子来看,这甚至都不是预期的错误。

$ sessionId和$ cartId肯定有效。 $ couponCode如果直接输入magento前端,则可以使用。

有人可以告诉我如何解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

感谢John,我在magento.stackexchange.com网站上得到了答案。

https://magento.stackexchange.com/questions/2729/magento-api-gives-access-denied-when-trying-to-add-a-coupon

问题是api角色不包括优惠券的访问权限。然而,我没有看到这个原因是因为它没有显示在后端。

直接编辑api_role表我可以将购物车优惠券的4条记录设置为允许。

答案 1 :(得分:1)

根据@ Hyarion的回答,Magento v1.7中接收Access Denied的问题是,优惠券权限没有出现在Admin > System > Web Services > xxx Roles > (select Role) > Role Resources中,所以我无法启用它们是我的API用户。

对我有用的修复是运行此数据库查询,该查询应影响3条记录(每个角色):

update api_rule set api_permission='allow' where role_id=1 -- Replace with your desired role id and resource_id like 'cart/coupon%'