-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '5.3' into feature/5.3-teller
- Loading branch information
Showing
19 changed files
with
473 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license https://craftcms.github.io/license/ | ||
*/ | ||
|
||
namespace craft\commerce\base; | ||
|
||
use craft\commerce\models\InventoryItem; | ||
use craft\commerce\Plugin; | ||
|
||
/** | ||
* Inventory Item Trait | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 5.3.0 | ||
*/ | ||
trait InventoryItemTrait | ||
{ | ||
/** | ||
* @var int|null The inventory item ID | ||
*/ | ||
public ?int $inventoryItemId = null; | ||
|
||
/** | ||
* @var InventoryItem|null The inventory item | ||
* @see getInventoryItem() | ||
* @see setInventoryItem() | ||
*/ | ||
private ?InventoryItem $_inventoryItem = null; | ||
|
||
/** | ||
* @param InventoryItem|null $inventoryItem | ||
* @return void | ||
*/ | ||
public function setInventoryItem(?InventoryItem $inventoryItem): void | ||
{ | ||
$this->_inventoryItem = $inventoryItem; | ||
$this->inventoryItemId = $inventoryItem?->id ?? null; | ||
} | ||
|
||
/** | ||
* @return InventoryItem|null | ||
* @throws \yii\base\InvalidConfigException | ||
*/ | ||
public function getInventoryItem(): ?InventoryItem | ||
{ | ||
if (isset($this->_inventoryItem)) { | ||
return $this->_inventoryItem; | ||
} | ||
|
||
if ($this->inventoryItemId) { | ||
$this->_inventoryItem = Plugin::getInstance()->getInventory()->getInventoryItemById($this->inventoryItemId); | ||
|
||
return $this->_inventoryItem; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license https://craftcms.github.io/license/ | ||
*/ | ||
|
||
namespace craft\commerce\base; | ||
|
||
use craft\commerce\models\InventoryLocation; | ||
use craft\commerce\Plugin; | ||
|
||
/** | ||
* Inventory Location Trait | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 5.3.0 | ||
*/ | ||
trait InventoryLocationTrait | ||
{ | ||
/** | ||
* @var int|null The inventory item ID | ||
*/ | ||
public ?int $inventoryLocationId = null; | ||
|
||
/** | ||
* @var InventoryLocation|null The inventory item | ||
* @see getInventoryLocation() | ||
* @see setInventoryLocation() | ||
*/ | ||
private ?InventoryLocation $_inventoryLocation = null; | ||
|
||
/** | ||
* @param InventoryLocation|null $inventoryLocation | ||
* @return void | ||
*/ | ||
public function setInventoryLocation(?InventoryLocation $inventoryLocation): void | ||
{ | ||
$this->_inventoryLocation = $inventoryLocation; | ||
$this->inventoryLocationId = $inventoryLocation?->id ?? null; | ||
} | ||
|
||
/** | ||
* @return InventoryLocation|null | ||
* @throws \yii\base\InvalidConfigException | ||
*/ | ||
public function getInventoryLocation(): ?InventoryLocation | ||
{ | ||
if (isset($this->_inventoryLocation)) { | ||
return $this->_inventoryLocation; | ||
} | ||
|
||
if ($this->inventoryLocationId) { | ||
$this->_inventoryLocation = Plugin::getInstance()->getInventoryLocations()->getInventoryLocationById($this->inventoryLocationId); | ||
|
||
return $this->_inventoryLocation; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.