From 2783f7ee7ba57b02f902edd4ceb106fb9423a80a Mon Sep 17 00:00:00 2001 From: Josh Angell Date: Thu, 20 May 2021 12:08:34 +0100 Subject: [PATCH] =?UTF-8?q?Added=20current=20product=20emabled=20status=20?= =?UTF-8?q?to=20import=20controller=20=E2=80=A6=E2=80=A6..=20n+1=20problem?= =?UTF-8?q?=20created=20but=20no=20way=20around=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProductsController.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/controllers/ProductsController.php b/src/controllers/ProductsController.php index 1101f9f..19caeb0 100644 --- a/src/controllers/ProductsController.php +++ b/src/controllers/ProductsController.php @@ -13,6 +13,7 @@ use angellco\vend\models\Settings; use angellco\vend\Vend; use Craft; +use craft\commerce\elements\Product; use craft\db\Paginator; use craft\elements\Entry; use craft\helpers\DateTimeHelper; @@ -241,9 +242,16 @@ public function actionImport(): Response } } + // Get the current product if there is one + $productQuery = Product::find(); + $productQuery->status = null; + $productQuery->vendProductId = $rawProduct->vendProductId; + $commerceProduct = $productQuery->one(); + $products[] = [ 'id' => $rawProduct->vendProductId, 'name' => $rawProduct->title, + 'enabled' => $commerceProduct ? $commerceProduct->enabled : false, 'variants' => $variants ]; }