简体   繁体   English

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

[英]Magento API gives Access Denied when trying to add a coupon

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

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. $ sessionId和$ cartId肯定有效。 The $couponCode if entered directly on the magento frontend works. $ couponCode如果直接输入magento前端工作。

Can anyone advise me how I might be able to solve this? 任何人都可以告诉我如何解决这个问题?

Thanks to John I got an answer on the magento.stackexchange.com site. 感谢John,我在magento.stackexchange.com网站上得到了答案。

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

The problem was that the api roles did not include access for coupons. 问题是api角色不包括优惠券的访问权限。 However the reason I did not see this was due to it not showing on the backend. 然而,我没有看到这个的原因是由于它没有显示在后端。

Editing the api_role table directly I was able to set the 4 records for cart coupons to allowed. 直接编辑api_role表我能够将购物车优惠券的4条记录设置为允许。

To build upon @Hyarion's answer, the problem for me in Magento v1.7 with receiving Access Denied was that the Coupon permissions do not appear in the Admin > System > Web Services > xxx Roles > (select Role) > Role Resources so I could not enable them for my API user. 基于@ Hyarion的回答,Magento v1.7中接收Access Denied权限的问题是,优惠券权限没有出现在Admin > System > Web Services > xxx Roles > (select Role) > Role Resources所以我可以不为我的API用户启用它们。

The fix that worked for me was to run this database query, which should affect 3 records (per role): 对我有用的修复是运行此数据库查询,这将影响3个记录(每个角色):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM