Skip to content

Commit

Permalink
Merge pull request #2341 from dpfaffenbauer/tax-rule-stores
Browse files Browse the repository at this point in the history
[Core] add tax-rule per store
  • Loading branch information
dpfaffenbauer authored Feb 7, 2024
2 parents 15bc6cd + 732e244 commit c34b3af
Show file tree
Hide file tree
Showing 27 changed files with 208 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/behat.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Behat
on:
push:
branches: [ '4.0' ]
branches: [ '4.0', 'next' ]
pull_request:
branches: [ '4.0' ]
branches: [ '4.0', 'next' ]
release:
types: [ created ]
schedule:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/behat_ui.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Behat UI
on:
push:
branches: [ '4.0' ]
branches: [ '4.0', 'next' ]
pull_request:
branches: [ '4.0' ]
branches: [ '4.0', 'next' ]
release:
types: [ created ]
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codestyles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
branch: [ '4.0' ]
branch: [ '4.0', 'next' ]

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/packages_bundles.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Packages Bundles
on:
push:
branches: [ '4.0' ]
branches: [ '4.0', 'next' ]
pull_request:
branches: [ '4.0' ]
branches: [ '4.0', 'next' ]
release:
types: [ created ]
schedule:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/packages_components.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Packages Components
on:
push:
branches: [ '4.0' ]
branches: [ '4.0', 'next' ]
pull_request:
branches: [ '4.0' ]
branches: [ '4.0', 'next' ]
release:
types: [ created ]
schedule:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Static Tests (Lint, Stan)
on:
push:
branches: [ '4.0' ]
branches: [ '4.0', 'next' ]
pull_request:
branches: [ '4.0' ]
branches: [ '4.0', 'next' ]
release:
types: [ created ]
schedule:
Expand Down
2 changes: 1 addition & 1 deletion features/domain/cache/check_cache_size.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@domain @cache
@domain @cache @wip
Feature: Adding a new Product and adding it to the cache

Background:
Expand Down
4 changes: 3 additions & 1 deletion src/CoreShop/Behat/Context/Domain/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ public function productTaxedRetailPriceShouldBe(ProductInterface $product, int $
*/
public function theProductShouldHaveTaxRuleGroup(ProductInterface $product, TaxRuleGroupInterface $taxRuleGroup): void
{
Assert::eq($product->getTaxRule()->getId(), $taxRuleGroup->getId());
$taxRule = $product->getStoreValuesOfType('taxRule', $this->shopperContext->getStore());

Assert::eq($taxRule?->getId(), $taxRuleGroup->getId());
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/CoreShop/Behat/Context/Setup/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ public function theProductIsInCategory(ProductInterface $product, CategoryInterf
*/
public function theProductHasTaxRuleGroup(ProductInterface $product, TaxRuleGroupInterface $taxRuleGroup): void
{
$product->setTaxRule($taxRuleGroup);
$store = $this->sharedStorage->get('store');

$product->setStoreValuesOfType('taxRule', $taxRuleGroup, $store);

$this->saveProduct($product);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,9 @@ protected function createProduct(string $parentPath): ProductInterface

foreach ($stores as $store) {
$product->setStoreValuesOfType('price', (int) ($faker->randomFloat(2, 200, 400) * $decimalFactor), $store);
$product->setStoreValuesOfType('taxRule', $this->getReference('taxRule'), $store);
}

$product->setTaxRule($this->getReference('taxRule'));
$product->setWidth($faker->numberBetween(5, 10));
$product->setHeight($faker->numberBetween(5, 10));
$product->setDepth($faker->numberBetween(5, 10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use CoreShop\Bundle\ProductBundle\Form\Type\Unit\ProductUnitDefinitionPriceCollectionType;
use CoreShop\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use CoreShop\Bundle\StoreBundle\Form\Type\StoreChoiceType;
use CoreShop\Bundle\TaxationBundle\Form\Type\TaxRuleGroupChoiceType;
use CoreShop\Component\Core\Model\ProductStoreValuesInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
Expand All @@ -37,6 +38,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder
->add('store', StoreChoiceType::class)
->add('price', MoneyType::class)
->add('taxRule', TaxRuleGroupChoiceType::class)
->add('productUnitDefinitionPrices', ProductUnitDefinitionPriceCollectionType::class)
;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace CoreShop\Bundle\CoreBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230711143927 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->addSql("
ALTER TABLE coreshop_product_store_values ADD taxRuleId INT DEFAULT NULL;
ALTER TABLE coreshop_product_store_values ADD CONSTRAINT FK_9EED0E97AC7C6E20 FOREIGN KEY (taxRuleId) REFERENCES coreshop_tax_rule_group (id);
CREATE INDEX IDX_9EED0E97AC7C6E20 ON coreshop_product_store_values (taxRuleId);
");
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace CoreShop\Bundle\CoreBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

final class Version20230711144054 extends AbstractMigration implements ContainerAwareInterface
{
use ContainerAwareTrait;

public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$productClass = $this->container->getParameter('coreshop.model.product.class');
$tmpProduct = new $productClass();
$productClassId = $tmpProduct->getClassId();

$productIds = $this->connection->fetchAllAssociative('SELECT oo_id, taxRule FROM object_query_' . $productClassId);

foreach ($productIds as $id) {
$this->addSql('UPDATE coreshop_product_store_values SET taxRuleId = :taxRuleId WHERE product = :product', ['product' => $id['oo_id'], 'taxRuleId' => $id['taxRule']]);
}
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<field name="product" column="product" type="pimcoreObject"/>
<field name="price" column="price" type="bigintInteger"/>

<many-to-one field="taxRule" target-entity="CoreShop\Component\Taxation\Model\TaxRuleGroupInterface">
<join-column name="taxRuleId" referenced-column-name="id" nullable="true"/>
</many-to-one>

<many-to-one field="store" target-entity="CoreShop\Component\Store\Model\StoreInterface">
<join-column name="store" referenced-column-name="id" on-delete="CASCADE"/>
<cascade>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ core_shop_core:
core_extension_product_store_values_builder: '/bundles/coreshopcore/pimcore/js/product/storevalues/builder.js'
core_extension_product_store_values_item_abstract: '/bundles/coreshopcore/pimcore/js/product/storevalues/items/abstract.js'
core_extension_product_store_values_item_price: '/bundles/coreshopcore/pimcore/js/product/storevalues/items/price.js'
core_extension_product_store_values_item_tax_rule: '/bundles/coreshopcore/pimcore/js/product/storevalues/items/taxRule.js'
core_extension_product_store_values_item_unit_price: '/bundles/coreshopcore/pimcore/js/product/storevalues/items/unitPrice.js'
core_extension_tag_product_unit_definitions_builder: '/bundles/coreshopcore/pimcore/js/product/units/builder.js'
notification_rule_condition_abstract_transition: '/bundles/coreshopcore/pimcore/js/notification/conditions/abstractTransition.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ CoreShop\Component\Core\Model\ProductStoreValues:
expose: true
type: relation<CoreShop\Component\Core\Model\Store>
groups: [List, Detailed, Version]
taxRule:
expose: true
type: relation<CoreShop\Component\Taxation\Model\TaxRuleGroup>
groups: [List, Detailed, Version]
Original file line number Diff line number Diff line change
Expand Up @@ -975,27 +975,6 @@
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopTaxRuleGroup",
"allowEmpty": true,
"options": null,
"width": "",
"defaultValue": null,
"name": "taxRule",
"title": "coreshop.product.tax_rule",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
}
],
"locked": false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* CoreShop
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - CoreShop Commercial License (CCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GPLv3 and CCL
*
*/

pimcore.registerNS('coreshop.product.storeValues.items.tax_rule');
coreshop.product.storeValues.items.tax_rule = Class.create(coreshop.product.storeValues.items.abstract, {

getForm: function () {

var taxRule = this.getDataValue('taxRule'),
taxRuleField = new CoreShop.taxation.TaxRuleGroup({
fieldLabel: t('coreshop_store_values_store_tax_rule'),
name: 'taxRule',
componentCls: 'object_field',
labelWidth: 250,
});

// do not fire dirty flag on initial data setup
taxRuleField.suspendEvents();

if (taxRule !== null) {
taxRuleField.setValue(taxRule);
}

if (this.builder.fieldConfig.width) {
taxRuleField.setWidth(this.builder.fieldConfig.width + taxRuleField.labelWidth);
} else {
taxRuleField.setWidth(350 + taxRuleField.labelWidth);
}

taxRuleField.resumeEvents(true);

return taxRuleField;
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ coreshop_order_create_shipping: 'Versand'
coreshop_store_price: 'Store Preis'
coreshop_store_values: 'Store Werte'
coreshop_store_values_store_price: 'Store Preis'
coreshop_store_values_store_tax_rule: 'Steuerregel'
coreshop_store_values_store_unit_prices: 'Store Einheitspreis'
coreshop_transition_direction_state: 'Zustand'
coreshop_transition_direction_mode: 'Modus'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ coreshop_order_create_shipping: 'Shipping'
coreshop_store_price: 'Store Price'
coreshop_store_values: 'Store Values'
coreshop_store_values_store_price: 'Store Price'
coreshop_store_values_store_tax_rule: 'Tax Rule'
coreshop_store_values_store_unit_prices: 'Store Unit Prices'
coreshop_transition_direction_state: 'State'
coreshop_transition_direction_mode: 'Mode'
Expand Down
1 change: 1 addition & 0 deletions src/CoreShop/Component/Core/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use CoreShop\Component\Index\Model\IndexInterface;
use CoreShop\Component\Product\Model\Product as BaseProduct;
use CoreShop\Component\Taxation\Model\TaxRuleGroupInterface;
use CoreShop\Component\Variant\Model\ProductVariantTrait;

abstract class Product extends BaseProduct implements ProductInterface
Expand Down
2 changes: 0 additions & 2 deletions src/CoreShop/Component/Core/Model/ProductInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public function getStoreValuesOfType(string $type, \CoreShop\Component\Store\Mod

public function setStoreValuesOfType(string $type, $value, \CoreShop\Component\Store\Model\StoreInterface $store): self;

public function setTaxRule(?TaxRuleGroupInterface $taxRule);

public function getDigitalProduct(): ?bool;

public function setDigitalProduct(?bool $digitalProduct);
Expand Down
Loading

0 comments on commit c34b3af

Please sign in to comment.