-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from umpirsky/stockable-model
Added default Stockable model
- Loading branch information
Showing
7 changed files
with
287 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sylius\Bundle\InventoryBundle\Entity; | ||
|
||
use Sylius\Bundle\InventoryBundle\Model\Stockable as BaseStockable; | ||
|
||
/** | ||
* Stocakble entity. | ||
* | ||
* @author Саша Стаменковић <[email protected]> | ||
*/ | ||
class Stockable extends BaseStockable | ||
{ | ||
} |
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,129 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sylius\Bundle\InventoryBundle\Model; | ||
|
||
/** | ||
* Stockable model. | ||
* | ||
* @author Саша Стаменковић <[email protected]> | ||
*/ | ||
class Stockable implements StockableInterface | ||
{ | ||
/** | ||
* Stockable id. | ||
* | ||
* @var mixed | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* Stockable SKU. | ||
* | ||
* @var string | ||
*/ | ||
protected $sku; | ||
|
||
/** | ||
* Inventory displayed name. | ||
* | ||
* @var string | ||
*/ | ||
protected $inventoryName; | ||
|
||
/** | ||
* Current stock level. | ||
* | ||
* @var int | ||
*/ | ||
protected $onHand; | ||
|
||
/** | ||
* Is stock available on demand? | ||
* | ||
* @var Boolean | ||
*/ | ||
protected $availableOnDemand; | ||
|
||
public function __construct() | ||
{ | ||
$this->onHand = 1; | ||
$this->availableOnDemand = true; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getSku() | ||
{ | ||
return $this->sku; | ||
} | ||
|
||
public function setSku($sku) | ||
{ | ||
$this->sku = $sku; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getInventoryName() | ||
{ | ||
return $this->inventoryName; | ||
} | ||
|
||
public function setInventoryName($inventoryName) | ||
{ | ||
$this->inventoryName = $inventoryName; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isInStock() | ||
{ | ||
return 0 < $this->onHand; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isAvailableOnDemand() | ||
{ | ||
return $this->availableOnDemand; | ||
} | ||
|
||
public function setAvailableOnDemand($availableOnDemand) | ||
{ | ||
$this->availableOnDemand = (Boolean) $availableOnDemand; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getOnHand() | ||
{ | ||
return $this->onHand; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setOnHand($onHand) | ||
{ | ||
$this->onHand = $onHand; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Sylius/Bundle/InventoryBundle/Resources/config/doctrine/Stockable.orm.xml
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
This file is part of the Sylius package. | ||
(c) Paweł Jędrzejewski | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
--> | ||
|
||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"> | ||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping | ||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | ||
|
||
<mapped-superclass name="Sylius\Bundle\InventoryBundle\Entity\Stockable"> | ||
<field name="sku" column="sku" type="string" /> | ||
<field name="inventoryName" column="inventory_name" type="string" /> | ||
<field name="onHand" column="on_hand" type="integer" /> | ||
<field name="availableOnDemand" column="available_on_demand" type="boolean"/> | ||
</mapped-superclass> | ||
|
||
</doctrine-mapping> |
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
use PHPSpec2\ObjectBehavior; | ||
|
||
/** | ||
* Shipment item mapped superclass spec. | ||
* Inventory unit entity spec. | ||
* | ||
* @author Pawęł Jędrzejewski <[email protected]> | ||
*/ | ||
|
28 changes: 28 additions & 0 deletions
28
src/Sylius/Bundle/InventoryBundle/spec/Sylius/Bundle/InventoryBundle/Entity/Stockable.php
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,28 @@ | ||
<?php | ||
|
||
namespace spec\Sylius\Bundle\InventoryBundle\Entity; | ||
|
||
use PHPSpec2\ObjectBehavior; | ||
|
||
/** | ||
* Stockable entity spec. | ||
* | ||
* @author Саша Стаменковић <[email protected]> | ||
*/ | ||
class Stockable extends ObjectBehavior | ||
{ | ||
function it_should_be_initializable() | ||
{ | ||
$this->shouldHaveType('Sylius\Bundle\InventoryBundle\Entity\Stockable'); | ||
} | ||
|
||
function it_should_be_a_Sylius_stockable() | ||
{ | ||
$this->shouldImplement('Sylius\Bundle\InventoryBundle\Model\StockableInterface'); | ||
} | ||
|
||
function it_should_extend_Sylius_stockable_model() | ||
{ | ||
$this->shouldHaveType('Sylius\Bundle\InventoryBundle\Model\Stockable'); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
use Sylius\Bundle\InventoryBundle\Model\InventoryUnitInterface; | ||
|
||
/** | ||
* Stockable item model spec. | ||
* Inventory unit model spec. | ||
* | ||
* @author Paweł Jędrzejewski <[email protected]> | ||
*/ | ||
|
78 changes: 78 additions & 0 deletions
78
src/Sylius/Bundle/InventoryBundle/spec/Sylius/Bundle/InventoryBundle/Model/Stockable.php
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,78 @@ | ||
<?php | ||
|
||
namespace spec\Sylius\Bundle\InventoryBundle\Model; | ||
|
||
use PHPSpec2\ObjectBehavior; | ||
|
||
/** | ||
* Stockable model spec. | ||
* | ||
* @author Саша Стаменковић <[email protected]> | ||
*/ | ||
class Stockable extends ObjectBehavior | ||
{ | ||
function it_should_be_initializable() | ||
{ | ||
$this->shouldHaveType('Sylius\Bundle\InventoryBundle\Model\Stockable'); | ||
} | ||
|
||
function it_should_be_a_Sylius_stockable() | ||
{ | ||
$this->shouldImplement('Sylius\Bundle\InventoryBundle\Model\StockableInterface'); | ||
} | ||
|
||
function it_should_not_have_id_by_default() | ||
{ | ||
$this->getId()->shouldReturn(null); | ||
} | ||
|
||
function it_should_not_have_defined_sku_by_default() | ||
{ | ||
$this->getSku()->shouldReturn(null); | ||
} | ||
|
||
function its_sku_should_be_mutable() | ||
{ | ||
$this->setSku('1234R'); | ||
$this->getSku()->shouldReturn('1234R'); | ||
} | ||
|
||
function it_should_not_have_defined_inventory_name_by_default() | ||
{ | ||
$this->getInventoryName()->shouldReturn(null); | ||
} | ||
|
||
function its_inventory_name_should_be_mutable() | ||
{ | ||
$this->setInventoryName('Lorem Ipsum'); | ||
$this->getInventoryName()->shouldReturn('Lorem Ipsum'); | ||
} | ||
|
||
function it_should_be_in_stock_by_default() | ||
{ | ||
$this->isInStock()->shouldReturn(true); | ||
} | ||
|
||
function it_should_be_available_on_demand_by_default() | ||
{ | ||
$this->isAvailableOnDemand()->shouldReturn(true); | ||
} | ||
|
||
function its_available_on_demand_should_be_mutable() | ||
{ | ||
$this->setAvailableOnDemand(false); | ||
$this->isAvailableOnDemand()->shouldReturn(false); | ||
} | ||
|
||
function it_should_have_1_on_hand_by_default() | ||
{ | ||
$this->getOnHand()->shouldReturn(1); | ||
} | ||
|
||
|
||
function its_on_hand_should_be_mutable() | ||
{ | ||
$this->setOnHand(5); | ||
$this->getOnHand()->shouldReturn(5); | ||
} | ||
} |