Skip to content

Commit c3bf2a1

Browse files
committed
Fixed #176 PHP error on saving product drafts
1 parent eb5863b commit c3bf2a1

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Fixed a PHP error that occurred when setting the Shopify host name to a non `myshopify` domain. ([#168](https://github.com/craftcms/shopify/issues/168))
6+
- Fixed a PHP error that occurred when creating product drafts. ([#176](https://github.com/craftcms/shopify/issues/176))
67

78
## 6.0.3 - 2025-05-27
89

src/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Plugin extends BasePlugin
6767
/**
6868
* @var string
6969
*/
70-
public string $schemaVersion = '6.0.3.1';
70+
public string $schemaVersion = '6.0.4.0';
7171

7272
/**
7373
* @inheritdoc

src/elements/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ public function afterSave(bool $isNew): void
752752
public function afterDelete(): void
753753
{
754754
// Remove all the product shopify data
755-
if ($this->shopifyGid) {
755+
if ($this->shopifyGid && $this->getIsCanonical()) {
756756
Plugin::getInstance()->getProducts()->deleteShopifyDataByShopifyId($this->shopifyGid);
757757
}
758758

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace craft\shopify\migrations;
4+
5+
use Craft;
6+
use craft\db\Migration;
7+
use craft\shopify\db\Table;
8+
9+
/**
10+
* m250808_100206_update_shopify_product_indexes migration.
11+
*/
12+
class m250808_100206_update_shopify_product_indexes extends Migration
13+
{
14+
/**
15+
* @inheritdoc
16+
*/
17+
public function safeUp(): bool
18+
{
19+
$this->dropIndexIfExists(Table::PRODUCTS, ['shopifyId'], true);
20+
$this->dropIndexIfExists(Table::PRODUCTS, ['shopifyGid'], true);
21+
22+
$this->createIndexIfMissing(Table::PRODUCTS, ['shopifyId']);
23+
$this->createIndexIfMissing(Table::PRODUCTS, ['shopifyGid']);
24+
25+
return true;
26+
}
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
public function safeDown(): bool
32+
{
33+
echo "m250808_100206_update_shopify_product_indexes cannot be reverted.\n";
34+
return false;
35+
}
36+
}

0 commit comments

Comments
 (0)