1. Go to this page and download the library: Download craftcms/shopify library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
craftcms / shopify example snippets
use craft\shopify\events\ShopifyProductSyncEvent;
use craft\shopify\services\Products;
use yii\base\Event;
Event::on(
Products::class,
Products::EVENT_BEFORE_SYNCHRONIZE_PRODUCT,
function(ShopifyProductSyncEvent $event) {
// Example 1: Cancel the sync if a flag is set via a Shopify metafield:
$metafields = $event->element->getMetaFields();
if (metafields['do_not_sync'] ?? false) {
$event->isValid = false;
}
// Example 2: Set a field value from metafield data:
$event->element->setFieldValue('myNumberFieldHandle', $metafields['cool_factor']);
}
);