Skip to content

Commit

Permalink
feature #10079 [Channel] Shop billing data (Zales0123)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.4-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | associated with Sylius/RefundPlugin#106, Sylius/InvoicingPlugin#52
| License         | MIT

During the development of `InvoicingPlugin`, we introduced a concept of shop billing data (set per channel) that is required to be displayed on an invoice. On the other hand, we also should have it in a `RefundPlugin` to generate a credit memo properly.

We considered a few options, but in the end, it's quite a common use case to have such a bunch of data manageable in Admin panel.

<img width="563" alt="zrzut ekranu 2019-01-9 o 11 04 31" src="https://user-images.githubusercontent.com/6212718/50892815-a35ed480-13ff-11e9-81e7-d5a96c6f8e28.png">


Commits
-------

f7cdb5522feec956a5964dbd97b444e89ea11448 Shop billing data on channel tests
ea37635e60d9ff0bd47273978bbc6a3f3652cc75 ShopBillingData entity and Channel relation
1185ef8657c327190004e297be93e52c1ca05235 Shop billing data in channel form
0848c16074c707e57fa981fe7ae838c820e0f731 Tests fixes and nullable fields
801247abb80c5feaa357073987beb770a9a6eada PR review changes
cfdca1e8363abf739f2a601021171d6f6a1d7dd1 Change column names to fulfill conventions
  • Loading branch information
pamil authored Jan 10, 2019
2 parents 27c998b + c043954 commit 285b23c
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Form/Extension/ChannelTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sylius\Bundle\ChannelBundle\Form\Type\ChannelType;
use Sylius\Bundle\CoreBundle\Form\EventSubscriber\AddBaseCurrencySubscriber;
use Sylius\Bundle\CoreBundle\Form\EventSubscriber\ChannelFormSubscriber;
use Sylius\Bundle\CoreBundle\Form\Type\ShopBillingDataType;
use Sylius\Bundle\CoreBundle\Form\Type\TaxCalculationStrategyChoiceType;
use Sylius\Bundle\CurrencyBundle\Form\Type\CurrencyChoiceType;
use Sylius\Bundle\LocaleBundle\Form\Type\LocaleChoiceType;
Expand Down Expand Up @@ -80,6 +81,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'sylius.form.channel.account_verification_required',
'required' => false,
])
->add('shopBillingData', ShopBillingDataType::class, [
'label' => 'sylius.form.channel.shop_billing_data',
])
->addEventSubscriber(new AddBaseCurrencySubscriber())
->addEventSubscriber(new ChannelFormSubscriber())
;
Expand Down
59 changes: 59 additions & 0 deletions Form/Type/ShopBillingDataType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Sylius\Bundle\CoreBundle\Form\Type;

use Sylius\Bundle\AddressingBundle\Form\Type\CountryCodeChoiceType;
use Sylius\Component\Core\Model\ShopBillingData;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class ShopBillingDataType extends AbstractType
{
/** @var string */
private $dataClass;

public function __construct(string $dataClass)
{
$this->dataClass = $dataClass;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('taxId', TextType::class, [
'label' => 'sylius.form.channel.billing_data.tax_id',
'required' => false,
])
->add('company', TextType::class, [
'required' => false,
'label' => 'sylius.form.channel.billing_data.company',
])
->add('countryCode', CountryCodeChoiceType::class, [
'label' => 'sylius.form.channel.billing_data.country',
'enabled' => true,
'required' => false,
])
->add('street', TextType::class, [
'label' => 'sylius.form.channel.billing_data.street',
'required' => false,
])
->add('city', TextType::class, [
'label' => 'sylius.form.channel.billing_data.city',
'required' => false,
])
->add('postcode', TextType::class, [
'label' => 'sylius.form.channel.billing_data.postcode',
'required' => false,
])
;
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('data_class', $this->dataClass);
}
}
8 changes: 7 additions & 1 deletion Resources/config/doctrine/model/Channel.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
</inverse-join-columns>
</join-table>
</many-to-many>
</mapped-superclass>

<one-to-one field="shopBillingData" target-entity="Sylius\Component\Core\Model\ShopBillingData">
<join-column name="shop_billing_data_id" on-delete="CASCADE"/>
<cascade>
<cascade-all />
</cascade>
</one-to-one>
</mapped-superclass>
</doctrine-mapping>
31 changes: 31 additions & 0 deletions Resources/config/doctrine/model/ShopBillingData.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="Sylius\Component\Core\Model\ShopBillingData" table="sylius_shop_billing_data">
<id name="id" column="id" type="integer">
<generator/>
</id>

<field name="company" nullable="true" />
<field name="taxId" column="tax_id" nullable="true" />
<field name="countryCode" column="country_code" nullable="true" />
<field name="street" nullable="true" />
<field name="city" nullable="true" />
<field name="postcode" nullable="true" />
</entity>
</doctrine-mapping>
6 changes: 6 additions & 0 deletions Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<parameter key="sylius.form.type.product_image.validation_groups" type="collection">
<parameter>sylius</parameter>
</parameter>
<parameter key="sylius.model.shop_billing_data.class">Sylius\Component\Core\Model\ShopBillingData</parameter>
</parameters>

<services>
Expand Down Expand Up @@ -241,6 +242,11 @@
<tag name="form.type" />
</service>

<service id="sylius.form.type.shop_billing_data" class="Sylius\Bundle\CoreBundle\Form\Type\ShopBillingDataType">
<argument>%sylius.model.shop_billing_data.class%</argument>
<tag name="form.type" />
</service>

<service id="sylius.form.type.autocomplete_product_taxon_choice" class="Sylius\Bundle\CoreBundle\Form\Type\Taxon\ProductTaxonAutocompleteChoiceType">
<argument type="service" id="sylius.factory.product_taxon" />
<argument type="service" id="sylius.repository.product_taxon" />
Expand Down
8 changes: 8 additions & 0 deletions Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ sylius:
name: Name
roles: Roles
channel:
billing_data:
city: City
company: Company
country: Country
postcode: Postcode
street: Street
tax_id: Tax ID
contact_email: Contact email
currencies: Currencies
currency_base: Base currency
Expand All @@ -31,6 +38,7 @@ sylius:
locales: Locales
payment_methods: Payment Methods
shipping_methods: Shipping Methods
shop_billing_data: Shop billing data
skipping_shipping_step_allowed: Skip shipping step if only one shipping method is available?
skipping_payment_step_allowed: Skip payment step if only one payment method is available?
tax_calculation_strategy: Tax calculation strategy
Expand Down

0 comments on commit 285b23c

Please sign in to comment.