@@ -464,6 +464,48 @@ public function imports_product_when_in_sales_channel_and_filter_enabled()
464464 $ this ->assertSame ($ entry ->product_id , '108828309 ' );
465465 }
466466
467+ #[Test]
468+ public function uses_shopify_inventory_policy_when_variant_is_tracked ()
469+ {
470+ Facades \Collection::make (config ('shopify.collection_handle ' , 'products ' ))->save ();
471+ Facades \Collection::make ('variants ' )->save ();
472+ Facades \Taxonomy::make ()->handle ('collections ' )->save ();
473+ Facades \Taxonomy::make ()->handle ('tags ' )->save ();
474+ Facades \Taxonomy::make ()->handle ('type ' )->save ();
475+ Facades \Taxonomy::make ()->handle ('vendor ' )->save ();
476+
477+ $ this ->mock (Graphql::class, function (MockInterface $ mock ) {
478+ $ mock ->shouldReceive ('query ' )->andReturn (new HttpResponse (status: 200 , body: $ this ->getProductJson ()));
479+ });
480+
481+ Jobs \ImportSingleProductJob::dispatch (1 );
482+
483+ $ variant = Facades \Entry::whereCollection ('variants ' )->first ();
484+ $ this ->assertSame ('DENY ' , $ variant ->get ('inventory_policy ' ));
485+ }
486+
487+ #[Test]
488+ public function sets_inventory_policy_to_continue_when_variant_is_not_tracked ()
489+ {
490+ Facades \Collection::make (config ('shopify.collection_handle ' , 'products ' ))->save ();
491+ Facades \Collection::make ('variants ' )->save ();
492+ Facades \Taxonomy::make ()->handle ('collections ' )->save ();
493+ Facades \Taxonomy::make ()->handle ('tags ' )->save ();
494+ Facades \Taxonomy::make ()->handle ('type ' )->save ();
495+ Facades \Taxonomy::make ()->handle ('vendor ' )->save ();
496+
497+ $ json = str_replace ('"tracked": true ' , '"tracked": false ' , $ this ->getProductJson ());
498+
499+ $ this ->mock (Graphql::class, function (MockInterface $ mock ) use ($ json ) {
500+ $ mock ->shouldReceive ('query ' )->andReturn (new HttpResponse (status: 200 , body: $ json ));
501+ });
502+
503+ Jobs \ImportSingleProductJob::dispatch (1 );
504+
505+ $ variant = Facades \Entry::whereCollection ('variants ' )->first ();
506+ $ this ->assertSame ('CONTINUE ' , $ variant ->get ('inventory_policy ' ));
507+ }
508+
467509 private function getProductJson (): string
468510 {
469511 return '{
@@ -602,7 +644,8 @@ private function getProductJson(): string
602644 "value": 0
603645 }
604646 },
605- "requiresShipping": true
647+ "requiresShipping": true,
648+ "tracked": true
606649 },
607650 "inventoryPolicy": "DENY",
608651 "inventoryQuantity": 0,
0 commit comments