Skip to content

Commit

Permalink
Merge pull request PrestaShop#35495 from Hlavtox/set-default-tax-rule…
Browse files Browse the repository at this point in the history
…-group

Add most used rule group to new products
  • Loading branch information
Hlavtox authored Feb 27, 2024
2 parents bc4ab51 + 879892d commit b4586bd
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 89 deletions.
1 change: 1 addition & 0 deletions src/Adapter/Product/Repository/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public function create(
$product->id_shop_default = $shopId->getValue();
$product->name = $localizedNames;
$product->link_rewrite = $localizedLinkRewrites;
$product->id_tax_rules_group = $this->taxRulesGroupRepository->getIdTaxRulesGroupMostUsed();

$this->productValidator->validateCreation($product);
$this->addObjectModelToShops($product, [$shopId], CannotAddProductException::class);
Expand Down
11 changes: 11 additions & 0 deletions src/Adapter/TaxRulesGroup/Repository/TaxRulesGroupRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\ValueObject\TaxRulesGroupId;
use PrestaShop\PrestaShop\Core\Exception\CoreException;
use PrestaShop\PrestaShop\Core\Repository\AbstractMultiShopObjectModelRepository;
use Product;
use TaxRulesGroup;

/**
Expand Down Expand Up @@ -197,4 +198,14 @@ public function partialUpdate(
$errorCode
);
}

/**
* Get most used Tax.
*
* @return int
*/
public function getIdTaxRulesGroupMostUsed()
{
return (int) Product::getIdTaxRulesGroupMostUsed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Feature: Update product price fields from Back Office (BO) when default country
| name[en-US] | magic staff |
| type | standard |
And product product1 should have following prices information:
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_ratio | 0 |
| unity | |
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | US-FL Rate (6%) |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_ratio | 0 |
| unity | |

Scenario: I update product prices
And tax rules group named "US-AL Rate (4%)" exists
Expand Down Expand Up @@ -142,85 +142,85 @@ Feature: Update product price fields from Back Office (BO) when default country
| price | 200 |
| unit_price | 300 |
And product product1 should have following prices information:
| price | 200 |
| price_tax_included | 200 |
| ecotax | 0 |
| tax rules group | |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 300 |
| unit_price_tax_included | 300 |
| unit_price_ratio | 0.666666 |
| unity | |
| price | 200 |
| price_tax_included | 212 |
| ecotax | 0 |
| tax rules group | US-FL Rate (6%) |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 300 |
| unit_price_tax_included | 318 |
| unit_price_ratio | 0.666666 |
| unity | |
When I update product "product1" with following values:
| price | 0 |
Then product product1 should have following prices information:
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_tax_included | 0 |
| unit_price_ratio | 0 |
| unity | |
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | US-FL Rate (6%) |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_tax_included | 0 |
| unit_price_ratio | 0 |
| unity | |
# Even if you try to update unit price it remains zero because price is still zero
When I update product "product1" with following values:
| unit_price | 300 |
Then product product1 should have following prices information:
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_tax_included | 0 |
| unit_price_ratio | 0 |
| unity | |
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | US-FL Rate (6%) |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_tax_included | 0 |
| unit_price_ratio | 0 |
| unity | |

Scenario: I update product unit price when product price is 0 even if unit price was being modified
When I update product "product1" with following values:
| price | 200 |
| unit_price | 300 |
And product product1 should have following prices information:
| price | 200 |
| price_tax_included | 200 |
| ecotax | 0 |
| tax rules group | |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 300 |
| unit_price_tax_included | 300 |
| unit_price_ratio | 0.666666 |
| unity | |
| price | 200 |
| price_tax_included | 212 |
| ecotax | 0 |
| tax rules group | US-FL Rate (6%) |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 300 |
| unit_price_tax_included | 318 |
| unit_price_ratio | 0.666666 |
| unity | |
When I update product "product1" with following values:
| price | 0 |
| unit_price | 300 |
And product product1 should have following prices information:
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_tax_included | 0 |
| unit_price_ratio | 0 |
| unity | |
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | US-FL Rate (6%) |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_tax_included | 0 |
| unit_price_ratio | 0 |
| unity | |

Scenario: I update product tax the price tax included and unit price tax included is impacted
When I update product "product1" with following values:
| price | 20 |
| unit_price | 500 |
Then product product1 should have following prices information:
| price | 20 |
| price_tax_included | 20 |
| unit_price | 500 |
| unit_price_tax_included | 500 |
| unit_price_ratio | 0.04 |
| tax rules group | |
| price | 20 |
| price_tax_included | 21.20 |
| unit_price | 500 |
| unit_price_tax_included | 530 |
| unit_price_ratio | 0.04 |
| tax rules group | US-FL Rate (6%) |
When I update product "product1" with following values:
| tax rules group | US-AL Rate (4%) |
Then product product1 should have following prices information:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Feature: Update product price fields from Back Office (BO).
| name[en-US] | washing machine |
| type | standard |
And product ecoProduct should have following prices information:
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_ratio | 0 |
| unity | |
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | US-FL Rate (6%) |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_ratio | 0 |
| unity | |
And shop configuration for "PS_USE_ECOTAX" is set to 1
And I identify tax rules group named "US-AL Rate (4%)" as "us-al-tax-rate"
And I identify tax rules group named "US-KS Rate (5.3%)" as "us-ks-tax-rate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Feature: Update product price fields from Back Office (BO) when default country
| name[en-US] | magic staff |
| type | standard |
And product product1 should have following prices information:
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_ratio | 0 |
| unity | |
| price | 0 |
| price_tax_included | 0 |
| ecotax | 0 |
| tax rules group | US-FL Rate (6%) |
| on_sale | false |
| wholesale_price | 0 |
| unit_price | 0 |
| unit_price_ratio | 0 |
| unity | |
And I add new tax "fr-tax-6" with following properties:
| name | FR Tax (6%) |
| rate | 6 |
Expand Down Expand Up @@ -106,12 +106,12 @@ Feature: Update product price fields from Back Office (BO) when default country
| price | 20 |
| unit_price | 500 |
Then product product1 should have following prices information:
| price | 20 |
| price_tax_included | 20 |
| unit_price | 500 |
| unit_price_tax_included | 500 |
| unit_price_ratio | 0.04 |
| tax rules group | |
| price | 20 |
| price_tax_included | 20 |
| unit_price | 500 |
| unit_price_tax_included | 500 |
| unit_price_ratio | 0.04 |
| tax rules group | US-FL Rate (6%) |
When I update product "product1" with following values:
| tax rules group | FR Tax (6%) |
Then product product1 should have following prices information:
Expand Down

0 comments on commit b4586bd

Please sign in to comment.