Open kahmra opened 1 year ago
@kahmra Below is the code I am using, I am currently using the 2023-04 version, this code works, If you find some bugs, please point it out, thanks.
Or you can refer #283
static function create_order_fulfillment_new($order_id, $notify_customer, $tracking_number, $tracking_company) {
$config = array(
'ShopUrl' => self::MYSHOPIFY_DOMAIN,
'ApiKey' => self::API_KEY,
'Password' => self::PASSWORD,
'ApiVersion' => '2023-04',
// The following must be added, refer to https://github.com/phpclassic/php-shopify/issues/187
'AccessToken' => self::PASSWORD,
'Curl' => array(
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_TIMEOUT => 10,
)
);
$sp= new PHPShopify\ShopifySDK($config);
// Only get the FulfillmentOrder when declare the shipping order.
$list = $sp->Order($order_id)->FulfillmentOrder()->get();
$fulfillmentorder_id = $list[0]['id'];
$params = array(
'notify_customer'=> $notify_customer,
'tracking_info' => [
'number' => $tracking_number,
'company' => $tracking_company
],
'line_items_by_fulfillment_order' => [
array('fulfillment_order_id' => $fulfillmentorder_id)
]
);
$ret = $sp->Fulfillment()->post($params);
print_r($ret);
}
I googled or referred to many other online methods, but none of them succeeded, or I felt that it was not easy to use. Finally, directly refer to the official https://shopify.dev/docs/api/admin-rest/2023-04/resources/fulfillment#post-fulfillments, and then construct the corresponding parameters. Of course, thanks to the SDK library php-shopify.
Hi! i use the same method hahaha but this not works if an order have a delete item
A possible workaround by adding the 'Fulfillment' item in the ShopifySDK.php $resources array .
In this way you can use this method as standalone method without passing for orders, accordly with the official documentation https://shopify.dev/docs/api/admin-rest/2023-04/resources/fulfillment#post-fulfillments .
After that the resulting working code is something like that :
$FulfillmentOrder = $shopify->Order('123456789')->FulfillmentOrder->get();
$location = 123456789;
$fulfillment = [
"location_id" => $location,
"notify_customer" => true,
"tracking_info" => [
"number" => '123456789',
"url" => 'https://www.ship.it&id=434324234234234234',
],
"line_items_by_fulfillment_order" => [
[
"fulfillment_order_id" => $FulfillmentOrder[0]['id']
]
]
];
$fulfill = $shopify->Fulfillment()->post($fulfillment);
The last API changelog explain what is removed from fulfillment endpoint .
If needed i can make a PR to fix this .
@fr00ller this still dont work :( i have this function
function fulfill_order_by_id($order_id,$tracking_number){
$config=connection();
$shopify = new PHPShopify\ShopifySDK($config);
$list = $shopify->Order($order_id)->FulfillmentOrder()->get();
$fulfillmentorder_id = $list[0]['id'];
try{
$params = array(
'location_id' =>'****',
'notify_customer'=> true,
'tracking_info' => [
'number' => $tracking_number,
'company' => "Other",
'url' => "https://www.starken.cl/seguimiento",
],
'line_items_by_fulfillment_order' => [
array('fulfillment_order_id' => $fulfillmentorder_id)
]
);
$ret = $shopify->Fulfillment()->post($params);
}catch(Exception $e) {
echo 'Caught exception ' . $e->getMessage(), "\n";
}
}
and dont fulfill orders dont have delete items
@kahmra
Have you try to remove company field from "tracking_info" array ?
Accordly with official documentation https://shopify.dev/docs/api/admin-rest/2023-04/resources/fulfillment#post-fulfillments the company field it must exactly match one of the items in the list that Shopify provides .
In your example it seems that it is not correct .
@kahmra
Have you try to remove company field from "tracking_info" array ?
Accordly with official documentation https://shopify.dev/docs/api/admin-rest/2023-04/resources/fulfillment#post-fulfillments the company field it must exactly match one of the items in the list that Shopify provides .
In your example it seems that it is not correct .
yes but dont work if you have a delete item in the order you can't fullfit a order
Use this way to update the fulfillment .Its works for me ` $oms_order_id = $request->get('order_id'); $oms_line_item_id = $request->get('line_item_id'); $oms_tracking_number = $request->get('tracking_number'); $oms_tracking_url = $request->get('tracking_url'); $oms_tracking_company = $request->get('tracking_company'); // Set your API credentials $shopify = ShopifySDK::config([ 'ShopUrl' => $shopifyStoreUrl, 'AccessToken' => $AccessToken, 'ApiVersion' => $version, ]);
$FulfillmentOrder = $shopify->Order($oms_order_id)->FulfillmentOrder->get();
$line_item_id = null;
$quantity = 1;
$order_id = null;
if (count($FulfillmentOrder) && !empty($FulfillmentOrder[0]['line_items']) && count($FulfillmentOrder[0].
['line_items'])) {
foreach ($FulfillmentOrder[0]['line_items'] as $line_item) {
if ($oms_line_item_id == $line_item['line_item_id']) {
$order_id = $line_item['fulfillment_order_id'];
$line_item_id = $line_item['id'];
$quantity = $line_item['quantity'];
break;
}
}
}
if (!empty($order_id) && !empty($line_item_id)) {
// for specific line item fulfillment
$fulfillment = [
"notify_customer" => false,
"tracking_info" => [
'company' => $oms_tracking_company,
"number" => $oms_tracking_number,
"url" => $oms_tracking_url
],
"line_items_by_fulfillment_order" => [
[
"fulfillment_order_id" => $order_id,
"fulfillment_order_line_items" => [
[
"id" => $line_item_id,
"quantity" => $quantity
]
]
],
],
];
$fulfill = $shopify->Fulfillment()->post($fulfillment);
dd(fulfill)
`
Hi! I have an app made in php and it no longer allows me to fulfill orders, this is giving me a 404 error.
this is what i have
i try to update everyting cause i create this app on 2020 i update the api to 2023-07 and i make this.
but its giving me this error Caught exception No action named save is defined for Fulfillment
please help