doushi3715 2014-09-04 18:50
浏览 46

在扩展Magento Rest API的同时启用多个端点/路由

I want two endpoints for my custom api which are

  • Create custom rules in a magento cart (URL= magento.com/coupondemo/generate)
  • Create coupon codes for a particular rule (URL= magento.com//coupondemo/rules/:rule_id/codes)

I've followed this tutorial to and coupon codes in Magento and I have code that can create a rule in Magento too. However, I've no clue how to create the two endpoints in my custom rest api as I am only able to create one.

I have the following routes in api2.xml

<routes>
    <route_collection>
        <route>/coupondemo/generate</route>
        <action_type>entity</action_type>
    </route_collection>
    <route_collection>
        <route>/coupondemo/rules/:rule_id/codes</route>
        <action_type>collection</action_type>
    </route_collection>
</routes>

my v1.php's skeleton is as follows

<?php
/* Coupon AutoGen REST API
*
* @category CouponDemo
* @package CouponDemo_AutoGen
* @author Chuck Hudson (used with permission). For more recipes, see Chuck's book http://shop.oreilly.com/product/0636920023968.do
*/

class CouponDemo_AutoGen_Model_Api2_Coupon_Rest_Admin_V1 extends CouponDemo_AutoGen_Model_Api2_Coupon
{
    /**
     * Generate one or more coupon codes using the Generate Coupons rule defined in Magento.
     * Expected parameters are:
     * {
     *    'qty': int, - number of coupon codes to instruct Magento to generate
     *    'length': int, - length of each generated coupon code
     *    'format': string, - alphanum (for alphanumeric codes), alpha (for alphabetical codes), and num (for numeric codes)
     * }
     *
     * @param array $couponData
     * @return string|void
     */
    protected function _create($couponData)
    {

    }

    protected function _retrieveCollection()
    {        

    }

    protected function _retrieve($couponDatas)
    {

    }
}

The problem is that both the routes call the _create methods in my v1.php. I want to have the first route call a custom method with an array as a parameter. So how can I do that?

I tried using this route

<!-- Call For V1.php _retrieve() -->
<route_entity_count>
    <route>/coupondemo/generate</route>
    <action_type>entity</action_type>
</route_entity_count>

which calls the _retrieve method but it doesn't allow the parameter to be passed in. How should I handle the first route then?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题