Skip to content

Commit

Permalink
Fix PHP error when editing inventory level in modal
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Dec 11, 2024
1 parent 7f12e65 commit 73b35ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
21 changes: 13 additions & 8 deletions src/models/InventoryItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,25 @@ class InventoryItem extends Model
*/
public ?\DateTime $dateUpdated = null;

public function getCpEditUrl(): string
{
return UrlHelper::cpUrl('commerce/inventory/item/' . $this->id);
}

/**
* @var Purchasable|null
*/
private ?Purchasable $_purchasable = null;
/**
* @return ?Purchasable
* @var null|string|int $siteId
*/
public function getPurchasable(): ?Purchasable
public function getPurchasable(null|string|int $siteId = null): ?Purchasable

Check failure on line 64 in src/models/InventoryItem.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

PHPDoc tag @var above a method has no effect.
{
if ($this->_purchasable !== null) {
return $this->_purchasable;
}

/** @var ?Purchasable $purchasable */
$purchasable = \Craft::$app->getElements()->getElementById($this->purchasableId);
$this->_purchasable = \Craft::$app->getElements()->getElementById(elementId: $this->purchasableId, siteId: $siteId);

Check failure on line 71 in src/models/InventoryItem.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Property craft\commerce\models\InventoryItem::$_purchasable (craft\commerce\base\Purchasable|null) does not accept craft\base\ElementInterface|null.

Check failure on line 71 in src/models/InventoryItem.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Variable $purchasable in PHPDoc tag @var does not exist.

return $purchasable;
return $this->_purchasable;

Check failure on line 73 in src/models/InventoryItem.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Method craft\commerce\models\InventoryItem::getPurchasable() should return craft\commerce\base\Purchasable|null but returns craft\base\ElementInterface|null.
}

public function getSku(): string
Expand Down
6 changes: 4 additions & 2 deletions src/models/InventoryLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ public function getInventoryLocation(): InventoryLocation

/**
* @return Purchasable
* @var null|string|int $siteId
*/
public function getPurchasable(): Purchasable
public function getPurchasable(null|string|int $siteId = null): Purchasable

Check failure on line 134 in src/models/InventoryLevel.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

PHPDoc tag @var above a method has no effect.
{
return $this->getInventoryItem()->getPurchasable();

return $this->getInventoryItem()->getPurchasable($siteId);
}
}

0 comments on commit 73b35ed

Please sign in to comment.