Skip to content

Commit

Permalink
Merge pull request #11 from BKWLD/optional-current-publication-filtering
Browse files Browse the repository at this point in the history
Add config option for disabling the publishedOnCurrentPublication check
  • Loading branch information
weotch authored Aug 9, 2023
2 parents f98c4cd + 37e13bd commit 0ff968e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Bkwld\ImportableShopifyFeeds;

use craft\base\Model;

class Plugin extends \craft\base\Plugin
{
public function init()
Expand All @@ -11,4 +13,9 @@ public function init()
'shopifyAdminApi' => services\ShopifyAdminApi::class,
]);
}

protected function createSettingsModel(): ?Model
{
return new models\Settings();
}
}
10 changes: 10 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Bkwld\ImportableShopifyFeeds\models;

use craft\base\Model;

class Settings extends Model
{
public $disablePublishedCheck = false;
}
10 changes: 8 additions & 2 deletions src/services/ShopifyAdminApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Bkwld\ImportableShopifyFeeds\services;

use Bkwld\ImportableShopifyFeeds\Plugin;
use Craft;
use yii\base\Component;
use Exception;
Expand All @@ -14,6 +15,7 @@
class ShopifyAdminApi extends Component
{
private $client;
private $disablePublishedCheck;

/**
* Make Guzzle instance
Expand All @@ -27,6 +29,8 @@ public function __construct()
'X-Shopify-Access-Token' => $token,
],
]);
$this->disablePublishedCheck = Plugin::getInstance()
->settings->disablePublishedCheck;
}

/**
Expand Down Expand Up @@ -166,8 +170,10 @@ public function getVariants(): Collection
// Custom App whose credentials are being used to query the API. This
// can be used to filter out products not intended for the public store,
// like wholesale only products.
->filter(function($variant) {
return $variant['product']['publishedOnCurrentPublication'];
->when(!$this->disablePublishedCheck, function($variants) {
return $variants->filter(function($variant) {
return $variant['product']['publishedOnCurrentPublication'];
});
})

// Dedupe by SKU, prefering active variants. Shopify allows you to
Expand Down

0 comments on commit 0ff968e

Please sign in to comment.