craftcms / shopify

Synchronize and extend product data from your Shopify storefront.
MIT License
45 stars 25 forks source link

Issue Importing Certain Products Based on a Custom Meta Data Field #108

Closed sm9 closed 6 months ago

sm9 commented 6 months ago

Description

Hi there, we're trying to follow the guide in the readme here, so that we can only import certain products based on a custom meta data field. Perhaps we've misunderstood how this works, but we tried to change the conditional from:

if ($event->metafields['do_not_sync'] ?? false) {

to

if ($event->metafields['custom.sync_to_craft']) {

But we're seeing this error:

Exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: craft\shopify\events\ShopifyProductSyncEvent::metafields'

in ../vendor/yiisoft/yii2/base/BaseObject.php:141

Stack trace:
#0 ../modules/base/Module.php(77): yii\base\BaseObject->__get('metafields')
#1 [internal function]: modules\base\Module->modules\base\{closure}(Object(craft\shopify\events\ShopifyProductSyncEvent))
#2 ../vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\shopify\events\ShopifyProductSyncEvent))
#3 ../vendor/yiisoft/yii2/base/Component.php(642): yii\base\Event::trigger('craft\\shopify\\s...', 'beforeSynchroni...', Object(craft\shopify\events\ShopifyProductSyncEvent))
#4 ../vendor/craftcms/shopify/src/services/Products.php(193): yii\base\Component->trigger('beforeSynchroni...', Object(craft\shopify\events\ShopifyProductSyncEvent))
#5 ../vendor/craftcms/shopify/src/services/Products.php(76): craft\shopify\services\Products->createOrUpdateProduct(Object(Shopify\Rest\Admin2023_10\Product), Array, Array)
#6 ../vendor/craftcms/shopify/src/services/Products.php(90): craft\shopify\services\Products->_updateProduct(Object(Shopify\Rest\Admin2023_10\Product))
#7 ../vendor/craftcms/shopify/src/console/controllers/SyncController.php(50): craft\shopify\services\Products->syncAllProducts()
#8 ../vendor/craftcms/shopify/src/console/controllers/SyncController.php(32): craft\shopify\console\controllers\SyncController->_syncProducts()
#9 [internal function]: craft\shopify\console\controllers\SyncController->actionAll()
#10 ../vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#11 ../vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#12 ../vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('all', Array)
#13 ../vendor/craftcms/cms/src/console/ControllerTrait.php(90): yii\console\Controller->runAction('all', Array)
#14 ../vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('all', Array)
#15 ../vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('all', Array)
#16 ../vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('shopify/sync/al...', Array)
#17 ../vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('shopify/sync/al...', Array)
#18 ../vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('shopify/sync/al...', Array)
#19 ../vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#20 ../vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#21 ../craft(13): yii\base\Application->run()
#22 {main}

Do you have any ideas where we might be going wrong, or have we hit a bug?

Thanks in advance for any help or advice!

Stephen

Additional info

linear[bot] commented 6 months ago

PT-1647 Issue Importing Certain Products Based on a Custom Meta Data Field

lukeholder commented 6 months ago

Hi Stephen,

The documentation looks wrong, sorry. The event no longer has a metafields array property, you would need to look at the elements meta fields.

Like this:

$metaFields = $event->element->getMetaFields();

We will fix the documentation. Hope that helps.