mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Core] Make shipping method taxable
This commit is contained in:
parent
c1d7fed34b
commit
37bda9881f
8 changed files with 151 additions and 13 deletions
38
app/migrations/Version20160115104455.php
Normal file
38
app/migrations/Version20160115104455.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Sylius\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
class Version20160115104455 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
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_shipping_method ADD tax_category_id INT DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE sylius_shipping_method ADD CONSTRAINT FK_5FB0EE119DF894ED FOREIGN KEY (tax_category_id) REFERENCES sylius_tax_category (id) ON DELETE SET NULL');
|
||||
$this->addSql('CREATE INDEX IDX_5FB0EE119DF894ED ON sylius_shipping_method (tax_category_id)');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
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('ALTER TABLE sylius_shipping_method DROP FOREIGN KEY FK_5FB0EE119DF894ED');
|
||||
$this->addSql('DROP INDEX IDX_5FB0EE119DF894ED ON sylius_shipping_method');
|
||||
$this->addSql('ALTER TABLE sylius_shipping_method DROP tax_category_id');
|
||||
}
|
||||
}
|
||||
|
|
@ -15,8 +15,6 @@ use Sylius\Bundle\ShippingBundle\Form\Type\ShippingMethodType as BaseShippingMet
|
|||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* Shipping method form type, extended with zone selection field.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class ShippingMethodType extends BaseShippingMethodType
|
||||
|
|
@ -28,8 +26,15 @@ class ShippingMethodType extends BaseShippingMethodType
|
|||
{
|
||||
parent::buildForm($builder, $options);
|
||||
|
||||
$builder->add('zone', 'sylius_zone_choice', array(
|
||||
$builder
|
||||
->add('zone', 'sylius_zone_choice', array(
|
||||
'label' => 'sylius.form.shipping_method.zone'
|
||||
));
|
||||
))
|
||||
->add('taxCategory', 'sylius_tax_category_choice', array(
|
||||
'required' => false,
|
||||
'empty_value' => '---',
|
||||
'label' => 'sylius.form.shipping_method.tax_category'
|
||||
))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@
|
|||
<many-to-one field="zone" target-entity="Sylius\Component\Addressing\Model\ZoneInterface">
|
||||
<join-column name="zone_id" referenced-column-name="id" nullable="false" />
|
||||
</many-to-one>
|
||||
|
||||
<many-to-one field="taxCategory" target-entity="Sylius\Component\Taxation\Model\TaxCategoryInterface">
|
||||
<join-column name="tax_category_id" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
|
||||
</many-to-one>
|
||||
</mapped-superclass>
|
||||
|
||||
</doctrine-mapping>
|
||||
|
|
|
|||
|
|
@ -12,11 +12,19 @@
|
|||
namespace spec\Sylius\Bundle\CoreBundle\Form\Type;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber;
|
||||
use Sylius\Bundle\ShippingBundle\Form\EventListener\BuildShippingMethodFormSubscriber;
|
||||
use Sylius\Bundle\ShippingBundle\Form\Type\ShippingMethodType;
|
||||
use Sylius\Component\Registry\ServiceRegistryInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormRegistryInterface;
|
||||
use Symfony\Component\Form\FormTypeInterface;
|
||||
|
||||
/**
|
||||
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
|
||||
*/
|
||||
class ShippingMethodTypeSpec extends ObjectBehavior
|
||||
{
|
||||
function let(ServiceRegistryInterface $calculatorRegistry, ServiceRegistryInterface $checkerRegistry, FormRegistryInterface $formRegistry)
|
||||
|
|
@ -38,4 +46,58 @@ class ShippingMethodTypeSpec extends ObjectBehavior
|
|||
{
|
||||
$this->shouldHaveType(ShippingMethodType::class);
|
||||
}
|
||||
|
||||
function it_builds_form_with_proper_fields($calculatorRegistry, $checkerRegistry, FormBuilderInterface $builder, FormFactoryInterface $formFactory)
|
||||
{
|
||||
$calculatorRegistry->all()->willReturn(array());
|
||||
$checkerRegistry->all()->willReturn(array());
|
||||
|
||||
$builder->getFormFactory()->willReturn($formFactory);
|
||||
|
||||
$builder
|
||||
->addEventSubscriber(Argument::type(BuildShippingMethodFormSubscriber::class))
|
||||
->willReturn($builder)
|
||||
;
|
||||
|
||||
$builder
|
||||
->addEventSubscriber(Argument::type(AddCodeFormSubscriber::class))
|
||||
->willReturn($builder)
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('translations', 'a2lix_translationsForms', Argument::any())
|
||||
->willReturn($builder)
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('category', 'sylius_shipping_category_choice', Argument::any())
|
||||
->willReturn($builder)
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('categoryRequirement', 'choice', Argument::type('array'))
|
||||
->willReturn($builder)
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('calculator', 'sylius_shipping_calculator_choice', Argument::any())
|
||||
->willReturn($builder)
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('zone', 'sylius_zone_choice', Argument::type('array'))
|
||||
->shouldBeCalled()
|
||||
->willReturn($builder)
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('taxCategory', 'sylius_tax_category_choice', Argument::type('array'))
|
||||
->shouldBeCalled()
|
||||
->willReturn($builder)
|
||||
;
|
||||
|
||||
$builder->setAttribute(Argument::any(), Argument::any())->shouldBeCalled();
|
||||
|
||||
$this->buildForm($builder, array());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
{{ form_row(form.code, {'attr': {'class': 'input-lg'}}) }}
|
||||
{{ form_row(form.translations, {'attr': {'class': 'input-lg'}}) }}
|
||||
{{ form_row(form.zone) }}
|
||||
{{ form_row(form.taxCategory) }}
|
||||
{{ form_row(form.category, {'attr': {'class': 'select2'}}) }}
|
||||
{{ form_row(form.categoryRequirement) }}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ namespace Sylius\Component\Core\Model;
|
|||
use Sylius\Component\Addressing\Model\ZoneInterface;
|
||||
use Sylius\Component\Shipping\Model\ShippingMethod as BaseShippingMethod;
|
||||
use Sylius\Component\Shipping\Model\ShippingMethodTranslation;
|
||||
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
|
||||
|
||||
/**
|
||||
* Shipping method available for selected zone.
|
||||
|
|
@ -24,12 +25,15 @@ use Sylius\Component\Shipping\Model\ShippingMethodTranslation;
|
|||
class ShippingMethod extends BaseShippingMethod implements ShippingMethodInterface
|
||||
{
|
||||
/**
|
||||
* Geographical zone.
|
||||
*
|
||||
* @var ZoneInterface
|
||||
*/
|
||||
protected $zone;
|
||||
|
||||
/**
|
||||
* @var TaxCategoryInterface
|
||||
*/
|
||||
protected $taxCategory;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -55,4 +59,20 @@ class ShippingMethod extends BaseShippingMethod implements ShippingMethodInterfa
|
|||
{
|
||||
return ShippingMethodTranslation::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTaxCategory()
|
||||
{
|
||||
return $this->taxCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setTaxCategory(TaxCategoryInterface $category = null)
|
||||
{
|
||||
$this->taxCategory = $category;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,25 +13,26 @@ namespace Sylius\Component\Core\Model;
|
|||
|
||||
use Sylius\Component\Addressing\Model\ZoneInterface;
|
||||
use Sylius\Component\Shipping\Model\ShippingMethodInterface as BaseShippingMethodInterface;
|
||||
use Sylius\Component\Taxation\Model\TaxableInterface;
|
||||
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
|
||||
|
||||
/**
|
||||
* Shipping method interface.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface ShippingMethodInterface extends BaseShippingMethodInterface
|
||||
interface ShippingMethodInterface extends BaseShippingMethodInterface, TaxableInterface
|
||||
{
|
||||
/**
|
||||
* Get zone.
|
||||
*
|
||||
* @return ZoneInterface
|
||||
*/
|
||||
public function getZone();
|
||||
|
||||
/**
|
||||
* Set zone.
|
||||
*
|
||||
* @param ZoneInterface $zone
|
||||
*/
|
||||
public function setZone(ZoneInterface $zone);
|
||||
|
||||
/**
|
||||
* @param TaxCategoryInterface $category
|
||||
*/
|
||||
public function setTaxCategory(TaxCategoryInterface $category = null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use PhpSpec\ObjectBehavior;
|
|||
use Sylius\Component\Addressing\Model\ZoneInterface;
|
||||
use Sylius\Component\Core\Model\ShippingMethodInterface;
|
||||
use Sylius\Component\Shipping\Model\ShippingMethod;
|
||||
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
|
||||
|
||||
class ShippingMethodSpec extends ObjectBehavior
|
||||
{
|
||||
|
|
@ -43,4 +44,10 @@ class ShippingMethodSpec extends ObjectBehavior
|
|||
$this->setZone($zone);
|
||||
$this->getZone()->shouldReturn($zone);
|
||||
}
|
||||
|
||||
function its_tax_category_is_mutable(TaxCategoryInterface $category)
|
||||
{
|
||||
$this->setTaxCategory($category);
|
||||
$this->getTaxCategory()->shouldReturn($category);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue