Skip to content

Commit

Permalink
Channel based pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Jędrzejewski committed Nov 19, 2014
1 parent 3309b95 commit c103d8f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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\Form\Type\Pricing;

use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* Channel based pricing configuration form type.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class ChannelBasedConfigurationType extends AbstractType
{
protected $channelRepository;

/**
* @param RepositoryInterface $channelRepository
*/
public function __construct(RepositoryInterface $channelRepository)
{
$this->channelRepository = $channelRepository;
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
foreach ($this->channelRepository->findAll() as $channel) {
$builder
->add($channel->getId(), 'sylius_money', array(
'label' => $channel->getName(),
'required' => false,
))
;
}
}

/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver
->setDefaults(array(
'data_class' => null
))
;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'sylius_price_calculator_channel_based';
}
}
5 changes: 5 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Resources/config/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<parameter key="sylius.form.type.order_filter.class">Sylius\Bundle\CoreBundle\Form\Type\Filter\OrderFilterType</parameter>
<parameter key="sylius.form.type.shipment_filter.class">Sylius\Bundle\CoreBundle\Form\Type\Filter\ShipmentFilterType</parameter>

<parameter key="sylius.form.type.price_calculator.channel_based.class">Sylius\Bundle\CoreBundle\Form\Type\Pricing\ChannelBasedConfigurationType</parameter>
<parameter key="sylius.form.type.price_calculator.group_based.class">Sylius\Bundle\CoreBundle\Form\Type\Pricing\GroupBasedConfigurationType</parameter>
<parameter key="sylius.form.type.price_calculator.zone_based.class">Sylius\Bundle\CoreBundle\Form\Type\Pricing\ZoneBasedConfigurationType</parameter>

Expand Down Expand Up @@ -145,6 +146,10 @@
<tag name="form.type" alias="sylius_promotion_action_add_product_configuration" />
</service>

<service id="sylius.form.type.price_calculator.channel_based" class="%sylius.form.type.price_calculator.channel_based.class%">
<argument type="service" id="sylius.repository.channel" />
<tag name="form.type" alias="sylius_price_calculator_channel_based" />
</service>
<service id="sylius.form.type.price_calculator.group_based" class="%sylius.form.type.price_calculator.group_based.class%">
<argument type="service" id="sylius.repository.group" />
<tag name="form.type" alias="sylius_price_calculator_group_based" />
Expand Down
5 changes: 5 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<parameter key="sylius.currency_context.class">Sylius\Bundle\CoreBundle\Context\CurrencyContext</parameter>
<parameter key="sylius.cart_item_resolver.default.class">Sylius\Bundle\CoreBundle\Cart\ItemResolver</parameter>
<parameter key="sylius.checker.restricted_zone.class">Sylius\Bundle\CoreBundle\Checker\RestrictedZoneChecker</parameter>
<parameter key="sylius.price_calculator.channel_based.class">Sylius\Component\Core\Pricing\ChannelBasedCalculator</parameter>
<parameter key="sylius.price_calculator.group_based.class">Sylius\Component\Core\Pricing\GroupBasedCalculator</parameter>
<parameter key="sylius.price_calculator.zone_based.class">Sylius\Component\Core\Pricing\ZoneBasedCalculator</parameter>
<parameter key="sylius.oauth.user_provider.class">Sylius\Bundle\CoreBundle\OAuth\UserProvider</parameter>
Expand Down Expand Up @@ -352,6 +353,10 @@
<argument type="service" id="event_dispatcher" />
</service>

<service id="sylius.price_calculator.channel_based" class="%sylius.price_calculator.channel_based.class%">
<tag name="sylius.price_calculator" type="channel_based" label="Channel based" />
</service>

<service id="sylius.price_calculator.group_based" class="%sylius.price_calculator.group_based.class%">
<tag name="sylius.price_calculator" type="group_based" label="Customer group based" />
</service>
Expand Down
3 changes: 3 additions & 0 deletions src/Sylius/Component/Core/Pricing/Calculators.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/
class Calculators extends BaseCalculators
{
// Channel based pricing.
const CHANNEL_BASED = 'channel_based';

// Group based pricing.
const GROUP_BASED = 'group_based';

Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Component/Core/Pricing/ChannelBasedCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class GroupBasedCalculator extends AbstractCalculator implements CalculatorInterface
class ChannelBasedCalculator extends AbstractCalculator implements CalculatorInterface
{
protected $parameterName = 'channel';
protected $className = 'Sylius\Component\Core\Model\ChannelInterface';
Expand All @@ -28,6 +28,6 @@ class GroupBasedCalculator extends AbstractCalculator implements CalculatorInter
*/
public function getType()
{
return Calculators::GROUP_BASED;
return Calculators::CHANNEL_BASED;
}
}

0 comments on commit c103d8f

Please sign in to comment.