Skip to content
This repository has been archived by the owner on Nov 30, 2017. It is now read-only.

Commit

Permalink
Initial taxation and adjustments integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Jędrzejewski committed Jan 3, 2013
1 parent e386c40 commit 4bde09a
Show file tree
Hide file tree
Showing 25 changed files with 527 additions and 104 deletions.
53 changes: 27 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion sandbox/config/container/base.yml
Expand Up @@ -158,7 +158,7 @@ sylius_addressing:

sylius_inventory:
driver: doctrine/orm
backorders: false
backorders: true
classes:
model:
iu: Sylius\Bundle\SandboxBundle\Entity\InventoryUnit
Expand All @@ -173,6 +173,7 @@ sylius_taxonomies:

sylius_taxation:
driver: doctrine/orm
rate_resolver: sylius_sandbox.tax_rate_resolver
classes:
rate:
model: Sylius\Bundle\SandboxBundle\Entity\TaxRate
Expand Down
17 changes: 16 additions & 1 deletion spec/Sylius/Bundle/SandboxBundle/Builder/OrderBuilder.php
Expand Up @@ -11,13 +11,28 @@
*/
class OrderBuilder extends ObjectBehavior
{
/**
* @param Doctrine\Common\Persistence\ObjectRepository $orderItemRepository
* @param Sylius\Bundle\CartBundle\Provider\CartProviderInterface $cartProvider
* @param Symfony\Component\Security\Core\SecurityContextInterface $securityContext
*/
function let($orderItemRepository, $cartProvider, $securityContext)
{
$this->beConstructedWith($orderItemRepository, $cartProvider, $securityContext);
}

function it_should_be_initializable()
{
$this->shouldHaveType('Sylius\Bundle\SandboxBundle\Builder\OrderBuilder');
}

function it_should_be_Sylius_order_builder()
function it_should_be_a_Sylius_order_builder()
{
$this->shouldImplement('Sylius\Bundle\SalesBundle\Builder\OrderBuilderInterface');
}

function it_should_extend_base_Sylius_order_builder()
{
$this->shouldHaveType('Sylius\Bundle\SalesBundle\Builder\OrderBuilder');
}
}
58 changes: 30 additions & 28 deletions src/Sylius/Bundle/SandboxBundle/Builder/OrderBuilder.php 100755 → 100644
Expand Up @@ -2,28 +2,48 @@

namespace Sylius\Bundle\SandboxBundle\Builder;

use Sylius\Bundle\SalesBundle\Builder\OrderBuilderInterface;
use Doctrine\Common\Persistence\ObjectRepository;
use Sylius\Bundle\SalesBundle\Builder\OrderBuilder as BaseOrderBuilder;
use Sylius\Bundle\SalesBundle\Model\OrderInterface;
use Symfony\Component\DependencyInjection\ContainerAware;

class OrderBuilder extends ContainerAware implements OrderBuilderInterface
use Sylius\Bundle\CartBundle\Provider\CartProviderInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;

/**
* Order builder.
*
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
*/
class OrderBuilder extends BaseOrderBuilder
{
private $cartProvider;
private $securityContext;

public function __construct(ObjectRepository $orderItemRepository, CartProviderInterface $cartProvider, SecurityContextInterface $securityContext)
{
$this->cartProvider = $cartProvider;
$this->securityContext = $securityContext;

parent::__construct($orderItemRepository);
}

/**
* {@inheritdoc}
*/
public function build(OrderInterface $order)
{
$order->getItems()->clear();

$cart = $this->container->get('sylius_cart.provider')->getCart();
$cart = $this->cartProvider->getCart();

if ($cart->isEmpty()) {
throw new \LogicException('The cart must be not empty.');
throw new \LogicException('The cart must not be empty.');
}

$order->setUser($this->container->get('security.context')->getToken()->getUser());

$orderItemRepository = $this->container->get('sylius_sales.repository.item');
$order->setUser($this->securityContext->getToken()->getUser());

foreach ($cart->getItems() as $item) {
$orderItem = $orderItemRepository->createNew();
$orderItem = $this->createNewItem();

$orderItem->setVariant($item->getVariant());
$orderItem->setQuantity($item->getQuantity());
$orderItem->setUnitPrice($item->getVariant()->getPrice());
Expand All @@ -33,22 +53,4 @@ public function build(OrderInterface $order)

$order->calculateTotal();
}

public function finalize(OrderInterface $order)
{
$inventoryOperator = $this->container->get('sylius_inventory.operator');
$variantManager = $this->container->get('sylius_assortment.manager.variant');

foreach ($order->getItems() as $item) {
$variant = $item->getVariant();

$inventoryUnits = $inventoryOperator->decrease($variant, $item->getQuantity());
$order->setInventoryUnits($inventoryUnits);

$variantManager->persist($variant);
$variantManager->flush($variant);
}

$this->container->get('sylius_cart.provider')->abandonCart();
}
}
Expand Up @@ -60,7 +60,7 @@ public function load(ObjectManager $manager)
*/
public function getOrder()
{
return 7;
return 5;
}

private function getAddressManager()
Expand Down
Expand Up @@ -36,11 +36,17 @@ public function load(ObjectManager $manager)
);

$manager->saveSettings('general', $general);

$taxation = array(
'defaultTaxZone' => $this->getReference('Zone-EU')
);

$manager->saveSettings('taxation', $taxation);
}

public function getOrder()
{
return 1;
return 4;
}

private function getSettingsManager()
Expand Down
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Bundle\SalesBundle\Model\OrderInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* Builds some simple orders to play with Sylius sandbox.
Expand All @@ -28,12 +29,15 @@ public function load(ObjectManager $manager)
{
$orderManager = $this->container->get('sylius_sales.manager.order');
$orderRepository = $this->container->get('sylius_sales.repository.order');
$eventDispatcher = $this->container->get('event_dispatcher');

for ($i = 1; $i <= 100; $i++) {
$order = $orderRepository->createNew();
$this->buildOrder($order);

$eventDispatcher->dispatch('sylius_sales.order.pre_create', new GenericEvent($order));
$orderManager->persist($order);
$eventDispatcher->dispatch('sylius_sales.order.post_create', new GenericEvent($order));
$this->setReference('Order-'.$i, $order);
}

Expand Down
Expand Up @@ -28,6 +28,7 @@ public function load(ObjectManager $manager)
{
$taxableGoods = $this->createTaxCategory('Taxable goods', 'Default taxation category', 'Default');
$this->createTaxRate($taxableGoods, 'Default Tax', 0.23, 'EU + USA GMT-8');
$this->createTaxRate($taxableGoods, 'EU VAT', 0.23, 'EU');

$clothing = $this->createTaxCategory('Clothing', 'All clothing goods', 'Clothing');
$this->createTaxRate($clothing, 'Clothing US Tax', 0.20, 'USA GMT-8');
Expand Down

0 comments on commit 4bde09a

Please sign in to comment.