Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在扩展Magento Rest API时启用多个端点/路由_Php_Api_Rest_Magento - Fatal编程技术网

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

Php 在扩展Magento Rest API时启用多个端点/路由,php,api,rest,magento,Php,Api,Rest,Magento,我希望我的自定义api有两个端点: 在magento购物车中创建自定义规则(URL=magento.com/coupondemo/generate) 为特定规则创建优惠券代码(URL=magento.com//coupondemo/rules/:rule\u id/code) 我已经按照教程学习了Magento中的优惠券代码,我也有可以在Magento中创建规则的代码。但是,我不知道如何在自定义RESTAPI中创建两个端点,因为我只能创建一个端点 我在api2.xml中有以下路径 <r

我希望我的自定义api有两个端点:

  • 在magento购物车中创建自定义规则(URL=
    magento.com/coupondemo/generate
  • 为特定规则创建优惠券代码(URL=
    magento.com//coupondemo/rules/:rule\u id/code
我已经按照教程学习了Magento中的优惠券代码,我也有可以在Magento中创建规则的代码。但是,我不知道如何在自定义RESTAPI中创建两个端点,因为我只能创建一个端点

我在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>

/coupondemo/generate
实体
/coupondemo/rules/:规则\u id/代码
收集
我的v1.php的框架如下

<?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)
    {

    }
}

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