Skip to content

Commit

Permalink
Merge branch 'release/3.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Jan 20, 2023
2 parents ac87f26 + 3d827b2 commit aed7f69
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Add issues to project

on:
issues:
types:
- opened
- transferred

jobs:
add-to-project:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/craftcms/projects/16
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes for Shopify

## 3.1.1 - 2023-01-20

- Fixed a SQL error that occurred when syncing products with several tags. ([#54](https://github.com/craftcms/shopify/issues/54))
- Product metadata is now synced via a queue job to avoid the Shopify API rate limiting.

## 3.1.0 - 2022-12-14

- Added the `resave/shopify-products` console command. ([#47](https://github.com/craftcms/shopify/issues/47))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ Once you have a reference to a variant, you can output its properties:
```twig
{% set defaultVariant = product.getDefaultVariant() %}
{{ variant.price|currency }}
{{ defaultVariant.price|currency }}
```

> **Note**
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Plugin extends BasePlugin
/**
* @var string
*/
public string $schemaVersion = '4.0.5'; // For some reason the 2.2+ version of the plugin was at 4.0 schema version
public string $schemaVersion = '4.0.6'; // For some reason the 2.2+ version of the plugin was at 4.0 schema version

/**
* @inheritdoc
Expand Down
39 changes: 39 additions & 0 deletions src/jobs/UpdateProductMetadata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace craft\shopify\jobs;

use Craft;
use craft\queue\BaseJob;
use craft\shopify\elements\Product;
use craft\shopify\Plugin;

/**
* Updates the metadata for a Shopify product.
*/
class UpdateProductMetadata extends BaseJob
{
public int $shopifyProductId;

/**
* @inheritdoc
*/
public function execute($queue): void
{
$api = Plugin::getInstance()->getApi();
$product = Product::find()->shopifyId($this->shopifyProductId)->one();
if ($product) {
$metaFields = $api->getMetafieldsByProductId($this->shopifyProductId);
$product->setMetafields($metaFields);
Craft::$app->elements->saveElement($product);
sleep(1); // Avoid rate limiting
}
}

/**
* @inheritdoc
*/
protected function defaultDescription(): ?string
{
return null;
}
}
2 changes: 1 addition & 1 deletion src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function createTables(): void
'publishedAt' => $this->dateTime(),
'publishedScope' => $this->string(),
'shopifyStatus' => $this->string(),
'tags' => $this->string(),
'tags' => $this->text(),
'templateSuffix' => $this->string(),
'updatedAt' => $this->string(),
'variants' => $this->text(),
Expand Down
30 changes: 30 additions & 0 deletions src/migrations/m230118_062557_increase_tag_column_size.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace craft\shopify\migrations;

use craft\db\Migration;

/**
* m230118_062557_increase_tag_column_size migration.
*/
class m230118_062557_increase_tag_column_size extends Migration
{
/**
* @inheritdoc
*/
public function safeUp(): bool
{
$this->alterColumn('{{%shopify_productdata}}', 'tags', $this->text());

return true;
}

/**
* @inheritdoc
*/
public function safeDown(): bool
{
echo "m230118_062557_increase_tag_column_size cannot be reverted.\n";
return false;
}
}
10 changes: 8 additions & 2 deletions src/services/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use craft\shopify\elements\Product as ProductElement;
use craft\shopify\events\ShopifyProductSyncEvent;
use craft\shopify\helpers\Metafields as MetafieldsHelper;
use craft\shopify\jobs\UpdateProductMetadata;
use craft\shopify\Plugin;
use craft\shopify\records\ProductData as ProductDataRecord;
use Shopify\Rest\Admin2022_10\Metafield as ShopifyMetafield;
Expand Down Expand Up @@ -59,8 +60,13 @@ public function syncAllProducts(): void
$products = $api->getAllProducts();

foreach ($products as $product) {
$metafields = $api->getMetafieldsByProductId($product->id);
$this->createOrUpdateProduct($product, $metafields);
$this->createOrUpdateProduct($product);
Craft::$app->getQueue()->push(new UpdateProductMetadata([
'description' => Craft::t('shopify', 'Updating product metadata for “{title}”', [
'title' => $product->title,
]),
'shopifyProductId' => $product->id,
]));
}

// Remove any products that are no longer in Shopify just in case.
Expand Down

0 comments on commit aed7f69

Please sign in to comment.