Spec the group based calculator

This commit is contained in:
Paweł Jędrzejewski 2014-04-17 17:36:02 +02:00
parent 7b8ef50972
commit 0748d70a13
9 changed files with 121 additions and 23 deletions

View file

@ -35,11 +35,11 @@ Feature: Volume based pricing
When I add product "Symfony Tee" to cart, with quantity "11"
Then I should be on the cart summary page
And "Tax total: 107.25" should appear on the page
And "Grand total: 882.25" should appear on the page
And "Grand total: 822.25" should appear on the page
Scenario: Lower price is given for higher quantity
Given I am on the store homepage
When I add product "Symfony Tee" to cart, with quantity "25"
Then I should be on the cart summary page
And "Tax total: 225" should appear on the page
And "Grand total: 1725" should appear on the page
And "Tax total: 225.00" should appear on the page
And "Grand total: 1,725.00" should appear on the page

View file

@ -88,7 +88,7 @@
<parameter key="sylius.form.type.promotion_action.add_product_configuration.class">Sylius\Bundle\CoreBundle\Form\Type\Action\AddProductConfigurationType</parameter>
<parameter key="sylius.form.type.price_calculator.group_based.class">Sylius\Bundle\CoreBundle\Form\Type\Pricing\GroupBasedConfigurationType</parameter>
<parameter key="sylius.price_calculator.group_based.class">Sylius\Bundle\CoreBundle\Pricing\GroupBasedCalculator</parameter>
<parameter key="sylius.price_calculator.group_based.class">Sylius\Component\Core\Pricing\GroupBasedCalculator</parameter>
<parameter key="sylius.listener.locale.class">Sylius\Bundle\CoreBundle\EventListener\LocaleListener</parameter>

View file

@ -11,8 +11,8 @@
namespace Sylius\Bundle\PricingBundle\Twig;
use Sylius\Bundle\PricingBundle\Calculator\DelegatingCalculatorInterface;
use Sylius\Bundle\PricingBundle\Model\PriceableInterface;
use Sylius\Component\Pricing\Calculator\DelegatingCalculatorInterface;
use Sylius\Component\Pricing\Model\PriceableInterface;
/**
* Sylius pricing Twig helper.

View file

@ -70,10 +70,10 @@
</service>
<service id="sylius.registry.promotion_rule_checker" class="%sylius.registry.promotion_rule_checker.class%">
<argument>Sylius\Bundle\PromotionsBundle\Checker\RuleCheckerInterface</argument>
<argument>Sylius\Component\Promotion\Checker\RuleCheckerInterface</argument>
</service>
<service id="sylius.registry.promotion_action" class="%sylius.registry.promotion_action.class%">
<argument>Sylius\Bundle\PromotionsBundle\Action\PromotionActionInterface</argument>
<argument>Sylius\Component\Promotion\Action\PromotionActionInterface</argument>
</service>
<service id="sylius.form.type.promotion" class="%sylius.form.type.promotion.class%">

View file

@ -27,6 +27,7 @@ use Sylius\Component\Core\Model\OrderItem;
use Sylius\Component\Core\Model\ShipmentInterface;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Core\Model\UserInterface;
use Sylius\Component\Core\Pricing\Calculators as PriceCalculators;
use Sylius\Component\Money\Model\ExchangeRateInterface;
use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Payment\Model\PaymentMethodInterface;
@ -35,7 +36,6 @@ use Sylius\Component\Shipping\Model\RuleInterface;
use Sylius\Component\Shipping\Model\ShippingCategoryInterface;
use Sylius\Component\Taxation\Model\TaxRateInterface;
use Sylius\Component\Taxonomy\Model\TaxonInterface;
use Sylius\Component\PricingBundle\Calculator\DefaultCalculators as DefaultPriceCalculators;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpKernel\KernelInterface;
@ -511,7 +511,7 @@ class DataContext extends BehatContext implements KernelAwareInterface
$product = $this->findOneByName('product', $productName);
$masterVariant = $product->getMasterVariant();
$masterVariant->setPricingCalculator('group_based');
$masterVariant->setPricingCalculator(PriceCalculators::GROUP_BASED);
$configuration = array();
foreach ($table->getHash() as $data) {
@ -534,7 +534,7 @@ class DataContext extends BehatContext implements KernelAwareInterface
$product = $this->findOneByName('product', $productName);
$masterVariant = $product->getMasterVariant();
$masterVariant->setPricingCalculator(DefaultPriceCalculators::VOLUME_BASED);
$masterVariant->setPricingCalculator(PriceCalculators::VOLUME_BASED);
$configuration = array();
foreach ($table->getHash() as $data) {

View file

@ -13,7 +13,7 @@ namespace Sylius\Component\Core\Model;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Pricing\Calculator\DefaultCalculators;
use Sylius\Component\Core\Pricing\Calculators;
use Sylius\Component\Product\Model\Variant as BaseVariant;
use Sylius\Component\Variation\Model\VariantInterface as BaseVariantInterface;
@ -43,7 +43,7 @@ class ProductVariant extends BaseVariant implements ProductVariantInterface
*
* @var string
*/
protected $pricingCalculator = DefaultCalculators::STANDARD;
protected $pricingCalculator = Calculators::STANDARD;
/**
* The pricing configuration.

View file

@ -0,0 +1,91 @@
<?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 spec\Sylius\Component\Core\Pricing;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\GroupInterface;
use Sylius\Component\Core\Pricing\Calculators;
use Sylius\Component\Pricing\Model\PriceableInterface;;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class GroupBasedCalculatorSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Component\Core\Pricing\GroupBasedCalculator');
}
function it_implements_Sylius_pricing_calculator_interface()
{
$this->shouldImplement('Sylius\Component\Pricing\Calculator\CalculatorInterface');
}
function it_returns_default_price_if_groups_are_not_in_context(PriceableInterface $priceable)
{
$configuration = array(
42 => 4999,
17 => 4599,
95 => 4400
);
$priceable->getPrice()->shouldBeCalled()->willReturn(5500);
$context = array();
$this->calculate($priceable, $configuration, $context)->shouldReturn(5500);
}
function it_returns_the_default_price_if_configuration_does_not_exist_for_group(PriceableInterface $priceable, GroupInterface $group)
{
$configuration = array(
42 => 4999,
17 => 4599,
95 => 4400
);
$context = array('groups' => array($group));
$group->getId()->shouldBeCalled()->willReturn(22);
$priceable->getPrice()->shouldBeCalled()->willReturn(3500);
$this->calculate($priceable, $configuration, $context)->shouldReturn(3500);
}
function it_returns_the_price_for_group_if_configuration_exists(PriceableInterface $priceable, GroupInterface $group)
{
$configuration = array(
42 => 4999,
17 => 4599,
95 => 4400
);
$context = array('groups' => array($group));
$group->getId()->shouldBeCalled()->willReturn(17);
$this->calculate($priceable, $configuration, $context)->shouldReturn(17);
}
function it_returns_the_lowest_price_if_more_than_1_group_provided_in_context(PriceableInterface $priceable, GroupInterface $group1, GroupInterface $group2)
{
$configuration = array(
42 => 4999,
17 => 4599,
95 => 4400
);
$context = array('groups' => array($group1, $group2));
$group1->getId()->shouldBeCalled()->willReturn(17);
$group2->getId()->shouldBeCalled()->willReturn(95);
$this->calculate($priceable, $configuration, $context)->shouldReturn(4400);
}
}

View file

@ -9,10 +9,11 @@
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\PricingBundle\Calculator;
namespace spec\Sylius\Component\Pricing\Calculator;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\PricingBundle\Model\PriceableInterface;;
use Sylius\Component\Pricing\Calculator\Calculators;
use Sylius\Component\Pricing\Model\PriceableInterface;;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
@ -21,12 +22,12 @@ class StandardCalculatorSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\PricingBundle\Calculator\StandardCalculator');
$this->shouldHaveType('Sylius\Component\Pricing\Calculator\StandardCalculator');
}
function it_implements_Sylius_pricing_calculator_interface()
{
$this->shouldImplement('Sylius\Bundle\PricingBundle\Calculator\CalculatorInterface');
$this->shouldImplement('Sylius\Component\Pricing\Calculator\CalculatorInterface');
}
function it_returns_the_default_price_stored_on_the_priceable_object(PriceableInterface $priceable)
@ -34,4 +35,9 @@ class StandardCalculatorSpec extends ObjectBehavior
$priceable->getPrice()->shouldBeCalled()->willReturn(1299);
$this->calculate($priceable, array())->shouldReturn(1299);
}
function it_has_valid_type()
{
$this->getType()->shouldReturn(Calculators::STANDARD);
}
}

View file

@ -9,10 +9,11 @@
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\PricingBundle\Calculator;
namespace spec\Sylius\Component\Pricing\Calculator;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\PricingBundle\Model\PriceableInterface;;
use Sylius\Component\Pricing\Calculator\Calculators;
use Sylius\Component\Pricing\Model\PriceableInterface;;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
@ -21,12 +22,12 @@ class VolumeBasedCalculatorSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Bundle\PricingBundle\Calculator\VolumeBasedCalculator');
$this->shouldHaveType('Sylius\Component\Pricing\Calculator\VolumeBasedCalculator');
}
function it_implements_Sylius_pricing_calculator_interface()
{
$this->shouldImplement('Sylius\Bundle\PricingBundle\Calculator\CalculatorInterface');
$this->shouldImplement('Sylius\Component\Pricing\Calculator\CalculatorInterface');
}
function it_assumes_quantity_is_1_if_not_provided_in_context(PriceableInterface $priceable)
@ -65,8 +66,8 @@ class VolumeBasedCalculatorSpec extends ObjectBehavior
$this->calculate($priceable, $configuration, array('quantity' => 600))->shouldReturn(1099);
}
function it_has_valid_configuration_form_type()
function it_has_valid_type()
{
$this->getConfigurationFormType()->shouldReturn('sylius_price_calculator_volume_based');
$this->getType()->shouldReturn(Calculators::VOLUME_BASED);
}
}