包括Laravel中的Woocommerce API库



我试图将这个Woocommerce API库包含到我的项目中。这不是Laravel特有的包。但是,在我的项目中包括这个时,我遇到了麻烦。

autoload-classmap.php

'WC_API_Client' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/class-wc-api-client.php',
'WC_API_Client_Authentication' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/class-wc-api-client-authentication.php',
'WC_API_Client_Exception' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/exceptions/class-wc-api-client-exception.php',
'WC_API_Client_HTTP_Exception' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/exceptions/class-wc-api-client-http-exception.php',
'WC_API_Client_HTTP_Request' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/class-wc-api-client-http-request.php',
'WC_API_Client_Resource' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/abstract-wc-api-client-resource.php',
'WC_API_Client_Resource_Coupons' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/class-wc-api-client-resource-coupons.php',
'WC_API_Client_Resource_Custom' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/class-wc-api-client-resource-custom.php',
'WC_API_Client_Resource_Customers' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/class-wc-api-client-resource-customers.php',
'WC_API_Client_Resource_Index' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/class-wc-api-client-resource-index.php',
'WC_API_Client_Resource_Order_Notes' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/class-wc-api-client-resource-order-notes.php',
'WC_API_Client_Resource_Order_Refunds' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/class-wc-api-client-resource-order-refunds.php',
'WC_API_Client_Resource_Orders' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/class-wc-api-client-resource-orders.php',
'WC_API_Client_Resource_Products' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php',
'WC_API_Client_Resource_Reports' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/class-wc-api-client-resource-reports.php',
'WC_API_Client_Resource_Webhooks' => $vendorDir . '/woothemes/woocommerce-api/lib/woocommerce-api/resources/class-wc-api-client-resource-webhooks.php',

我想知道,因为这不是一个Laravel包,我是否需要在控制器中包含这个文件以及我如何做到这一点?

"require": {
    "woothemes/woocommerce-api": "dev-master"
     },
"require-dev": {
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "app\": "app/"
    },
    "files":[
    "vendor/woothemes/woocommerce-api/lib/woocommerce-api.php"
    ]
},

所以需要woocommerce api,然后将主require文件添加到composer的files数组中。然后你可以使用composer dump- autolload,这样你就可以使用这个库了。

我打电话给

composer require automattic/woocommerce

然后在我的PHP文件:

use AutomatticWooCommerceClient;
$woocommerce = new Client(
    'http://example.com', 
    'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 
    'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
);

和它工作没有问题

https://github.com/woocommerce/wc-api-php

相关内容

  • 没有找到相关文章

最新更新