diff --git a/CHANGELOG.md b/CHANGELOG.md index b4d82c1..ddf1876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.1.2 (Mar 28, 2024) + +- Fixed `inventory_quantity` allowing `null` values (Issue #3) +- Fixed API error handling (Issue #2) + ## 2.1.1 (Jan 29, 2024) - Minor improvements diff --git a/src/components/rest/ShopifyAdminRestApi.php b/src/components/rest/ShopifyAdminRestApi.php index bb0daf1..d358a6c 100644 --- a/src/components/rest/ShopifyAdminRestApi.php +++ b/src/components/rest/ShopifyAdminRestApi.php @@ -130,7 +130,8 @@ protected function requestInternal(string $method, string $uri, array $options = // consulting the error log ... if ($exception instanceof ClientException) { $contents = Json::decode($exception->getResponse()->getBody()->getContents()); - $this->_errors = $contents['errors'] ?? [$exception->getMessage() ?: 'Unknown API Error']; + $errors = $contents['errors'] ?? $exception->getMessage() ?: 'Unknown API Error'; + $this->_errors = (array)$errors; } Yii::error($exception); @@ -148,7 +149,7 @@ private function getNextLinkFromHeader(array $headers): ?string $links = $headers['Link'][0] ?? null; if ($links) { - $links = explode(',', (string) $links); + $links = explode(',', (string)$links); foreach ($links as $link) { if (preg_match('/<(.*)>;\srel=\"next\"/', $link, $matches)) { diff --git a/src/migrations/M190904193339Shopify.php b/src/migrations/M190904193339Shopify.php index 701042e..5611b90 100644 --- a/src/migrations/M190904193339Shopify.php +++ b/src/migrations/M190904193339Shopify.php @@ -70,7 +70,7 @@ public function safeUp(): void 'option_3' => $this->string()->null(), 'barcode' => $this->string()->null(), 'sku' => $this->string()->null(), - 'is_taxable' => $this->boolean()->defaultValue(false), + 'is_taxable' => $this->boolean()->defaultValue(false)->notNull(), 'grams' => $this->decimal(10, 2)->unsigned()->null(), 'weight' => $this->string()->null(), 'weight_unit' => $this->string(2)->null(), diff --git a/src/migrations/M240328135307ProductVariant.php b/src/migrations/M240328135307ProductVariant.php new file mode 100644 index 0000000..7943e1a --- /dev/null +++ b/src/migrations/M240328135307ProductVariant.php @@ -0,0 +1,27 @@ +alterColumn(ProductVariant::tableName(), 'inventory_quantity', $this->integer() + ->unsigned() + ->null()); + } + + public function safeDown(): void + { + } +} \ No newline at end of file diff --git a/src/models/Product.php b/src/models/Product.php index ce73757..560dcc0 100644 --- a/src/models/Product.php +++ b/src/models/Product.php @@ -20,7 +20,7 @@ /** * @property int $id * @property int $status - * @property int $variant_id + * @property int|null $variant_id * @property int|null $image_id * @property string $name * @property string|null $content @@ -38,7 +38,7 @@ * * @property-read ProductImage|null $image {@see static::getImage()} * @property-read ProductImage[] $images {@see static::getImages()} - * @property-read ProductVariant $variant {@see static::getVariant()} + * @property-read ProductVariant|null $variant {@see static::getVariant()} * @property-read ProductVariant[] $variants {@see static::getVariants()} */ class Product extends ActiveRecord implements DraftStatusAttributeInterface diff --git a/src/models/ProductImage.php b/src/models/ProductImage.php index ebcb365..6aba414 100644 --- a/src/models/ProductImage.php +++ b/src/models/ProductImage.php @@ -15,11 +15,11 @@ * @property int $id * @property int $product_id * @property int $position - * @property string $alt_text - * @property int $width - * @property int $height - * @property string $src - * @property DateTime $updated_at + * @property string|null $alt_text + * @property int|null $width + * @property int|null $height + * @property string|null $src + * @property DateTime|null $updated_at * @property DateTime $created_at */ class ProductImage extends ActiveRecord diff --git a/src/models/ProductVariant.php b/src/models/ProductVariant.php index 2daae05..48b9529 100644 --- a/src/models/ProductVariant.php +++ b/src/models/ProductVariant.php @@ -18,21 +18,21 @@ * @property string $name * @property int $position * @property int $price - * @property int $compare_at_price - * @property string $presentment_prices - * @property string $option_1 - * @property string $option_2 - * @property string $option_3 - * @property string $barcode - * @property string $sku + * @property int|null $compare_at_price + * @property string|null $presentment_prices + * @property string|null $option_1 + * @property string|null $option_2 + * @property string|null $option_3 + * @property string|null $barcode + * @property string|null $sku * @property bool $is_taxable - * @property int $grams - * @property int $weight - * @property string $weight_unit - * @property bool $inventory_management - * @property int $inventory_quantity - * @property string $inventory_policy - * @property DateTime $updated_at + * @property int|null $grams + * @property int|null $weight + * @property string|null $weight_unit + * @property string|null $inventory_management + * @property int|null $inventory_quantity + * @property string|null $inventory_policy + * @property DateTime|null $updated_at * @property DateTime $created_at */ class ProductVariant extends ActiveRecord @@ -41,7 +41,6 @@ class ProductVariant extends ActiveRecord use ModuleTrait; use ProductRelationTrait; - public function behaviors(): array { return [ @@ -51,7 +50,6 @@ public function behaviors(): array ]; } - public function rules(): array { return $this->getI18nRules([