mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[CoreBundle] Add ability to information how many products were sold
This commit is contained in:
parent
9264b61c40
commit
4d6b6bd42d
7 changed files with 111 additions and 2 deletions
30
app/migrations/Version20140909144526.php
Normal file
30
app/migrations/Version20140909144526.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Sylius\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
class Version20140909144526 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE sylius_product_variant ADD sold INT NOT NULL');
|
||||
$this->addSql('CREATE INDEX IDX_A29B52398D2DD99 ON sylius_product_variant (sold)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('DROP INDEX IDX_A29B52398D2DD99 ON sylius_product_variant');
|
||||
$this->addSql('ALTER TABLE sylius_product_variant DROP sold');
|
||||
}
|
||||
}
|
||||
|
|
@ -19,13 +19,15 @@
|
|||
|
||||
<mapped-superclass name="Sylius\Component\Core\Model\ProductVariant" table="sylius_product_variant">
|
||||
<indexes>
|
||||
<index columns="sku"/>
|
||||
<index columns="sku" />
|
||||
<index columns="sold" />
|
||||
</indexes>
|
||||
|
||||
<field name="sku" column="sku" type="string" nullable="true" />
|
||||
|
||||
<field name="onHold" column="on_hold" type="integer" />
|
||||
<field name="onHand" column="on_hand" type="integer" />
|
||||
<field name="sold" column="sold" type="integer" />
|
||||
<field name="availableOnDemand" column="available_on_demand" type="boolean" />
|
||||
|
||||
<field name="price" column="price" type="integer">
|
||||
|
|
|
|||
|
|
@ -93,6 +93,8 @@
|
|||
<parameter key="sylius.dynamic_router.class">Symfony\Cmf\Component\Routing\DynamicRouter</parameter>
|
||||
<parameter key="sylius.generator.class">Sylius\Bundle\CoreBundle\Routing\SyliusAwareGenerator</parameter>
|
||||
<parameter key="sylius.route_provider.class">Sylius\Bundle\CoreBundle\Routing\RouteProvider</parameter>
|
||||
|
||||
<parameter key="sylius.callback.complete_order.class">Sylius\Bundle\CoreBundle\StateMachineCallback\CompleteOrderCallback</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
|
|
|
|||
|
|
@ -103,6 +103,10 @@ winzou_state_machine:
|
|||
on: 'release'
|
||||
do: [@sm.callback.cascade_transition, 'apply']
|
||||
args: ['object.getPayments()', 'event', '"void"', '"sylius_payment"']
|
||||
sylius_complete:
|
||||
on: 'create'
|
||||
do: [@sylius.callback.complete_order, 'countSoldVariants'],
|
||||
args: ['object']
|
||||
|
||||
sylius_inventory_unit:
|
||||
callbacks:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?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\CoreBundle\StateMachineCallback;
|
||||
|
||||
use Sylius\Bundle\OrderBundle\StateMachineCallback\CompleteOrderCallback as BaseCompleteOrderCallback;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Core\Model\OrderItemInterface;
|
||||
|
||||
/**
|
||||
* Set update sold value for items in order.
|
||||
*/
|
||||
class CompleteOrderCallback extends BaseCompleteOrderCallback
|
||||
{
|
||||
/**
|
||||
* @param OrderInterface $order
|
||||
*/
|
||||
public function countSoldVariants(OrderInterface $order)
|
||||
{
|
||||
/** @var $item OrderItemInterface */
|
||||
foreach ($order->getItems() as $item) {
|
||||
$variant = $item->getVariant();
|
||||
$variant->setSold($variant->getSold() + $item->getQuantity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -66,6 +66,13 @@ class ProductVariant extends BaseVariant implements ProductVariantInterface
|
|||
*/
|
||||
protected $onHand = 0;
|
||||
|
||||
/**
|
||||
* Sold amount.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $sold = 0;
|
||||
|
||||
/**
|
||||
* Is variant available on demand?
|
||||
*
|
||||
|
|
@ -76,7 +83,7 @@ class ProductVariant extends BaseVariant implements ProductVariantInterface
|
|||
/**
|
||||
* Images.
|
||||
*
|
||||
* @var Collection|VariantImageInterface[]
|
||||
* @var Collection|ProductVariantImageInterface[]
|
||||
*/
|
||||
protected $images;
|
||||
|
||||
|
|
@ -255,6 +262,24 @@ class ProductVariant extends BaseVariant implements ProductVariantInterface
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSold()
|
||||
{
|
||||
return $this->sold;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSold($sold)
|
||||
{
|
||||
$this->sold = (int) $sold;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -58,6 +58,18 @@ interface ProductVariantInterface extends
|
|||
*/
|
||||
public function removeImage(ProductVariantImageInterface $image);
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getSold();
|
||||
|
||||
/**
|
||||
* @param int $sold
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSold($sold);
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue