ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,378 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\GraphQl\Weee;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\ObjectManager\ObjectManager;
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;
/**
* Test for cart item fixed product tax
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class CartItemPricesWithFPTTest extends GraphQlAbstract
{
/**
* @var ObjectManager $objectManager
*/
private $objectManager;
/**
* @var string[]
*/
private $initialConfig;
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var GetMaskedQuoteIdByReservedOrderId
*/
private $getMaskedQuoteIdByReservedOrderId;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
$this->getMaskedQuoteIdByReservedOrderId = $this->objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
$currentSettingsArray = [
'tax/display/type',
'tax/weee/enable',
'tax/weee/display',
'tax/defaults/region',
'tax/weee/apply_vat',
'tax/calculation/price_includes_tax'
];
foreach ($currentSettingsArray as $configPath) {
$this->initialConfig[$configPath] = $this->scopeConfig->getValue(
$configPath
);
}
/** @var ReinitableConfigInterface $config */
$config = $this->objectManager->get(ReinitableConfigInterface::class);
$config->reinit();
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->writeConfig($this->initialConfig);
}
/**
* Write configuration for weee
*
* @param array $settings
* @return void
*/
private function writeConfig(array $settings): void
{
/** @var WriterInterface $configWriter */
$configWriter = $this->objectManager->get(WriterInterface::class);
foreach ($settings as $path => $value) {
$configWriter->save($path, $value);
}
$this->scopeConfig->clean();
}
/**
* @param array $taxSettings
* @param array $expectedFtps
* @return void
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @dataProvider cartItemFixedProductTaxDataProvider
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
* @magentoApiDataFixture Magento/Weee/_files/product_with_two_fpt.php
* @magentoApiDataFixture Magento/GraphQl/Weee/_files/add_fpt_for_region_1.php
* @magentoApiDataFixture Magento/GraphQl/Weee/_files/apply_tax_for_simple_product_with_fpt.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Weee/_files/add_simple_product_with_fpt_to_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
*/
public function testCartItemFixedProductTax(array $taxSettings, array $expectedFtps): void
{
$this->writeConfig($taxSettings);
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
$query = $this->getQuery($maskedQuoteId);
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['cart']['items']);
$actualFtps = $result['cart']['items'][0]['prices']['fixed_product_taxes'];
$this->assertEqualsCanonicalizing($expectedFtps, $actualFtps);
}
/**
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function cartItemFixedProductTaxDataProvider(): array
{
return [
[
'taxSettings' => [
'tax/weee/enable' => '1',
'tax/weee/apply_vat' => '0',
'tax/calculation/price_includes_tax' => '0',
'tax/display/type' => '1',
],
'expectedFtps' => [
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 10.0
]
],
[
'label' => 'fpt_for_all_front_label',
'amount' => [
'value' => 12.7
]
],
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 5.0
]
],
]
],
[
'taxSettings' => [
'tax/weee/enable' => '1',
'tax/weee/apply_vat' => '0',
'tax/calculation/price_includes_tax' => '1',
'tax/display/type' => '1',
],
'expectedFtps' => [
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 10.0
]
],
[
'label' => 'fpt_for_all_front_label',
'amount' => [
'value' => 12.7
]
],
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 5.0
]
],
]
],
[
'taxSettings' => [
'tax/weee/enable' => '1',
'tax/weee/apply_vat' => '1',
'tax/calculation/price_includes_tax' => '0',
'tax/display/type' => '1',
],
'expectedFtps' => [
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 10.0
]
],
[
'label' => 'fpt_for_all_front_label',
'amount' => [
'value' => 12.7
]
],
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 5.0
]
],
]
],
[
'taxSettings' => [
'tax/weee/enable' => '1',
'tax/weee/apply_vat' => '1',
'tax/calculation/price_includes_tax' => '0',
'tax/display/type' => '2',
],
'expectedFtps' => [
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 10.75
]
],
[
'label' => 'fpt_for_all_front_label',
'amount' => [
'value' => 13.66
]
],
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 5.38
]
],
]
],
[
'taxSettings' => [
'tax/weee/enable' => '1',
'tax/weee/apply_vat' => '1',
'tax/calculation/price_includes_tax' => '1',
'tax/display/type' => '1',
],
'expectedFtps' => [
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 10.0
]
],
[
'label' => 'fpt_for_all_front_label',
'amount' => [
'value' => 12.7
]
],
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 5.01
]
],
]
],
[
'taxSettings' => [
'tax/weee/enable' => '1',
'tax/weee/apply_vat' => '1',
'tax/calculation/price_includes_tax' => '1',
'tax/display/type' => '2',
],
'expectedFtps' => [
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 10.75
]
],
[
'label' => 'fpt_for_all_front_label',
'amount' => [
'value' => 13.65
]
],
[
'label' => 'fixed_product_attribute_front_label',
'amount' => [
'value' => 5.38
]
],
]
],
[
'taxSettings' => [
'tax/weee/enable' => '0',
'tax/weee/apply_vat' => '1',
'tax/calculation/price_includes_tax' => '1',
'tax/display/type' => '1',
],
'expectedFtps' => []
]
];
}
/**
* Generates GraphQl query for retrieving cart totals
*
* @param string $maskedQuoteId
* @return string
*/
private function getQuery(string $maskedQuoteId): string
{
return <<<QUERY
{
cart(cart_id: "$maskedQuoteId") {
items {
prices {
price {
value
currency
}
price_including_tax {
value
currency
}
row_total {
value
currency
}
row_total_including_tax {
value
currency
}
fixed_product_taxes {
label
amount {
value
}
}
}
}
prices {
grand_total {
value
currency
}
subtotal_including_tax {
value
currency
}
subtotal_excluding_tax {
value
currency
}
subtotal_with_discount_excluding_tax {
value
currency
}
applied_taxes {
label
amount {
value
currency
}
}
}
}
}
QUERY;
}
}
@@ -0,0 +1,733 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\GraphQl\Weee;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\ObjectManager\ObjectManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;
use Magento\Tax\Model\ClassModel as TaxClassModel;
use Magento\Tax\Model\ResourceModel\TaxClass\CollectionFactory as TaxClassCollectionFactory;
/**
* Test for Product Price With FPT
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class ProductPriceWithFPTTest extends GraphQlAbstract
{
/** @var ObjectManager $objectManager */
private $objectManager;
/** @var string[] $objectManager */
private $initialConfig;
/** @var ScopeConfigInterface */
private $scopeConfig;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
/** @var ScopeConfigInterface $scopeConfig */
$this->scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
$currentSettingsArray = [
'tax/display/type',
'tax/weee/enable',
'tax/weee/display',
'tax/defaults/region',
'tax/weee/apply_vat',
'tax/calculation/price_includes_tax'
];
foreach ($currentSettingsArray as $configPath) {
$this->initialConfig[$configPath] = $this->scopeConfig->getValue(
$configPath
);
}
/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */
$config = $this->objectManager->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class);
$config->reinit();
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->writeConfig($this->initialConfig);
}
/**
* Write configuration for weee
*
* @param array $weeTaxSettings
* @return void
*/
private function writeConfig(array $weeTaxSettings): void
{
/** @var WriterInterface $configWriter */
$configWriter = $this->objectManager->get(WriterInterface::class);
foreach ($weeTaxSettings as $path => $value) {
$configWriter->save($path, $value);
}
$this->scopeConfig->clean();
}
/**
* Catalog Prices : Excluding Tax
* Catalog Display setting: Excluding Tax
* FPT Display setting: Including FPT only
*
* @param array $weeTaxSettings
* @return void
*
* @dataProvider catalogPriceExcludeTaxAndIncludeFPTOnlySettingsProvider
* @magentoApiDataFixture Magento/Weee/_files/product_with_fpt.php
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
*/
public function testCatalogPriceExcludeTaxAndIncludeFPTOnly(array $weeTaxSettings)
{
$this->writeConfig($weeTaxSettings);
$skus = ['simple-with-ftp'];
$query = $this->getProductQuery($skus);
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['products']['items']);
$product = $result['products']['items'][0];
// final price and regular price are the sum of product price and FPT
$this->assertEquals(112.7, $product['price_range']['minimum_price']['regular_price']['value']);
$this->assertEquals(112.7, $product['price_range']['minimum_price']['final_price']['value']);
$this->assertEquals(112.7, $product['price_range']['maximum_price']['regular_price']['value']);
$this->assertEquals(112.7, $product['price_range']['maximum_price']['final_price']['value']);
$this->assertNotEmpty($product['price_range']['minimum_price']['fixed_product_taxes']);
$fixedProductTax = $product['price_range']['minimum_price']['fixed_product_taxes'][0];
$this->assertEquals(12.7, $fixedProductTax['amount']['value']);
$this->assertEquals('fpt_for_all_front_label', $fixedProductTax['label']);
}
/**
* CatalogPriceExcludeTaxAndIncludeFPTOnlyProvider settings data provider
*
* @return array
*/
public function catalogPriceExcludeTaxAndIncludeFPTOnlySettingsProvider()
{
return [
[
'weeTaxSettings' => [
'tax/display/type' => '1',
'tax/weee/enable' => '1',
'tax/weee/display' => '0',
'tax/defaults/region' => '1',
'tax/weee/apply_vat' => '0',
]
]
];
}
/**
* Catalog Prices : Excluding Tax
* Catalog Display setting: Excluding Tax
* FPT Display setting: Including FPT and FPT description
*
* @param array $weeTaxSettings
* @return void
*
* @dataProvider catalogPriceExcludeTaxAndIncludeFPTWithDescriptionSettingsProvider
* @magentoApiDataFixture Magento/Weee/_files/product_with_fpt.php
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
*/
public function testCatalogPriceExcludeTaxAndIncludeFPTWithDescription(array $weeTaxSettings)
{
$this->writeConfig($weeTaxSettings);
$skus = ['simple-with-ftp'];
$query = $this->getProductQuery($skus);
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['products']['items']);
$product = $result['products']['items'][0];
// final price and regular price are the sum of product price and FPT
$this->assertEquals(112.7, $product['price_range']['minimum_price']['regular_price']['value']);
$this->assertEquals(112.7, $product['price_range']['minimum_price']['final_price']['value']);
$this->assertEquals(112.7, $product['price_range']['maximum_price']['regular_price']['value']);
$this->assertEquals(112.7, $product['price_range']['maximum_price']['final_price']['value']);
$this->assertNotEmpty($product['price_range']['minimum_price']['fixed_product_taxes']);
$fixedProductTax = $product['price_range']['minimum_price']['fixed_product_taxes'][0];
$this->assertEquals(12.7, $fixedProductTax['amount']['value']);
$this->assertEquals('fpt_for_all_front_label', $fixedProductTax['label']);
}
/**
* CatalogPriceExcludeTaxAndIncludeFPTWithDescription settings data provider
*
* @return array
*/
public function catalogPriceExcludeTaxAndIncludeFPTWithDescriptionSettingsProvider()
{
return [
[
'weeTaxSettings' => [
'tax/display/type' => '1',
'tax/weee/enable' => '1',
'tax/weee/display' => '1',
'tax/defaults/region' => '1',
'tax/weee/apply_vat' => '0',
]
]
];
}
/**
* Catalog Prices : Excluding Tax
* Catalog Display setting: Including Tax
* FPT Display setting: Including FPT only
*
* @param array $weeTaxSettings
* @return void
*
* @dataProvider catalogPriceExcludeTaxCatalogDisplayIncludeTaxAndIncludeFPTOnlySettingsProvider
* @magentoApiDataFixture Magento/Weee/_files/product_with_fpt.php
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
*/
public function testCatalogPriceExcludeTaxCatalogDisplayIncludeTaxAndIncludeFPTOnly(array $weeTaxSettings)
{
$this->writeConfig($weeTaxSettings);
/** @var TaxClassCollectionFactory $taxClassCollectionFactory */
$taxClassCollectionFactory = $this->objectManager->get(TaxClassCollectionFactory::class);
$taxClassCollection = $taxClassCollectionFactory->create();
/** @var TaxClassModel $taxClass */
$taxClassCollection->addFieldToFilter('class_type', TaxClassModel::TAX_CLASS_TYPE_PRODUCT);
$taxClass = $taxClassCollection->getFirstItem();
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
/** @var Product $prod2 */
$product1 = $productRepository->get('simple-with-ftp');
$product1->setCustomAttribute('tax_class_id', $taxClass->getClassId());
$productRepository->save($product1);
$skus = ['simple-with-ftp'];
$query = $this->getProductQuery($skus);
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['products']['items']);
$product = $result['products']['items'][0];
$this->assertNotEmpty($product['price_range']['minimum_price']['fixed_product_taxes']);
// final price and regular price are the sum of product price, FPT and product tax
$this->assertEquals(120.2, round($product['price_range']['minimum_price']['regular_price']['value'], 2));
$this->assertEquals(120.2, round($product['price_range']['minimum_price']['final_price']['value'], 2));
$this->assertEquals(120.2, round($product['price_range']['maximum_price']['regular_price']['value'], 2));
$this->assertEquals(120.2, round($product['price_range']['maximum_price']['final_price']['value'], 2));
}
/**
* CatalogPriceExcludeTaxCatalogDisplayIncludeTaxAndIncludeFPTOnly settings data provider
*
* @return array
*/
public function catalogPriceExcludeTaxCatalogDisplayIncludeTaxAndIncludeFPTOnlySettingsProvider()
{
return [
[
'weeTaxSettings' => [
'tax/calculation/price_includes_tax' => '0',
'tax/display/type' => '2',
'tax/weee/enable' => '1',
'tax/weee/display' => '0',
'tax/defaults/region' => '1',
'tax/weee/apply_vat' => '0',
]
]
];
}
/**
* Catalog Prices : Excluding Tax
* Catalog Display setting: Including Tax
* FPT Display setting: Including FPT and FPT description
*
* @param array $weeTaxSettings
* @return void
*
* @dataProvider catalogPriceExclTaxCatalogDisplayInclTaxAndInclFPTWithDescriptionSettingsProvider
* @magentoApiDataFixture Magento/Weee/_files/product_with_fpt.php
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
*/
public function testCatalogPriceExclTaxCatalogDisplayInclTaxAndInclFPTWithDescription(array $weeTaxSettings)
{
$this->writeConfig($weeTaxSettings);
/** @var TaxClassCollectionFactory $taxClassCollectionFactory */
$taxClassCollectionFactory = $this->objectManager->get(TaxClassCollectionFactory::class);
$taxClassCollection = $taxClassCollectionFactory->create();
/** @var TaxClassModel $taxClass */
$taxClassCollection->addFieldToFilter('class_type', TaxClassModel::TAX_CLASS_TYPE_PRODUCT);
$taxClass = $taxClassCollection->getFirstItem();
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
/** @var Product $product1 */
$product1 = $productRepository->get('simple-with-ftp');
$product1->setCustomAttribute('tax_class_id', $taxClass->getClassId());
$productRepository->save($product1);
$skus = ['simple-with-ftp'];
$query = $this->getProductQuery($skus);
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['products']['items']);
$product = $result['products']['items'][0];
$this->assertNotEmpty($product['price_range']['minimum_price']['fixed_product_taxes']);
// final price and regular price are the sum of product price and FPT
$this->assertEquals(120.2, round($product['price_range']['minimum_price']['regular_price']['value'], 2));
$this->assertEquals(120.2, round($product['price_range']['minimum_price']['final_price']['value'], 2));
$this->assertEquals(120.2, round($product['price_range']['maximum_price']['regular_price']['value'], 2));
$this->assertEquals(120.2, round($product['price_range']['maximum_price']['final_price']['value'], 2));
}
/**
* CatalogPriceExclTaxCatalogDisplayInclTaxAndInclFPTWithDescription settings data provider
*
* @return array
*/
public function catalogPriceExclTaxCatalogDisplayInclTaxAndInclFPTWithDescriptionSettingsProvider()
{
return [
[
'weeTaxSettings' => [
'tax/calculation/price_includes_tax' => '0',
'tax/display/type' => '2',
'tax/weee/enable' => '1',
'tax/weee/display' => '1',
'tax/defaults/region' => '1',
'tax/weee/apply_vat' => '0',
]
]
];
}
/**
* Catalog Prices : Including Tax
* Catalog Display setting: Excluding Tax
* FPT Display setting: Including FPT and FPT description
*
* @param array $weeTaxSettings
* @return void
*
* @dataProvider catalogPriceInclTaxCatalogDisplayExclTaxAndInclFPTWithDescriptionSettingsProvider
* @magentoApiDataFixture Magento/Weee/_files/product_with_fpt.php
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
*/
public function testCatalogPriceInclTaxCatalogDisplayExclTaxAndInclFPTWithDescription(array $weeTaxSettings)
{
$this->writeConfig($weeTaxSettings);
$skus = ['simple-with-ftp'];
$query = $this->getProductQuery($skus);
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['products']['items']);
$product = $result['products']['items'][0];
// final price and regular price are the sum of product price and FPT
$this->assertEquals(112.7, $product['price_range']['minimum_price']['regular_price']['value']);
$this->assertEquals(112.7, $product['price_range']['minimum_price']['final_price']['value']);
$this->assertEquals(112.7, $product['price_range']['maximum_price']['regular_price']['value']);
$this->assertEquals(112.7, $product['price_range']['maximum_price']['final_price']['value']);
$this->assertNotEmpty($product['price_range']['minimum_price']['fixed_product_taxes']);
$fixedProductTax = $product['price_range']['minimum_price']['fixed_product_taxes'][0];
$this->assertEquals(12.7, $fixedProductTax['amount']['value']);
$this->assertEquals('fpt_for_all_front_label', $fixedProductTax['label']);
}
/**
* CatalogPriceInclTaxCatalogDisplayExclTaxAndInclFPTWithDescription settings data provider
*
* @return array
*/
public function catalogPriceInclTaxCatalogDisplayExclTaxAndInclFPTWithDescriptionSettingsProvider()
{
return [
[
'weeTaxSettings' => [
'tax/calculation/price_includes_tax' => '1',
'tax/display/type' => '1',
'tax/weee/enable' => '1',
'tax/weee/display' => '1',
'tax/defaults/region' => '1',
'tax/weee/apply_vat' => '1',
]
]
];
}
/**
* Catalog Prices : Including Tax
* Catalog Display setting: Including Tax
* FPT Display setting: Including FPT Only
*
* @param array $weeTaxSettings
* @return void
*
* @dataProvider catalogPriceInclTaxCatalogDisplayInclTaxAndInclFPTOnlySettingsProvider
* @magentoApiDataFixture Magento/Weee/_files/product_with_fpt.php
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
*/
public function testCatalogPriceInclTaxCatalogDisplayInclTaxAndInclFPTOnly(array $weeTaxSettings)
{
$this->writeConfig($weeTaxSettings);
$skus = ['simple-with-ftp'];
$query = $this->getProductQuery($skus);
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['products']['items']);
$product = $result['products']['items'][0];
// final price and regular price are the sum of product price and FPT
$this->assertEquals(112.7, $product['price_range']['minimum_price']['regular_price']['value']);
$this->assertEquals(112.7, $product['price_range']['minimum_price']['final_price']['value']);
$this->assertEquals(112.7, $product['price_range']['maximum_price']['regular_price']['value']);
$this->assertEquals(112.7, $product['price_range']['maximum_price']['final_price']['value']);
$this->assertNotEmpty($product['price_range']['minimum_price']['fixed_product_taxes']);
$fixedProductTax = $product['price_range']['minimum_price']['fixed_product_taxes'][0];
$this->assertEquals(12.7, $fixedProductTax['amount']['value']);
$this->assertEquals('fpt_for_all_front_label', $fixedProductTax['label']);
}
/**
* CatalogPriceInclTaxCatalogDisplayInclTaxAndInclFPTOnly settings data provider
*
* @return array
*/
public function catalogPriceInclTaxCatalogDisplayInclTaxAndInclFPTOnlySettingsProvider()
{
return [
[
'weeTaxSettings' => [
'tax/calculation/price_includes_tax' => '1',
'tax/display/type' => '2',
'tax/weee/enable' => '1',
'tax/weee/display' => '0',
'tax/defaults/region' => '1',
'tax/weee/apply_vat' => '0',
]
]
];
}
/**
* Catalog Prices : Including Tax
* Catalog Display setting: Including Tax
* FPT Display setting: Including FPT and FPT Description
* Apply Tax to FPT = Yes
*
* @param array $weeTaxSettings
* @return void
*
* @dataProvider catalogPriceIncTaxCatalogDisplayInclTaxInclFPTWithDescrWithTaxAppliedOnFPTSettingsProvider
* @magentoApiDataFixture Magento/Weee/_files/product_with_fpt.php
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
*/
public function testCatalogPriceIncTaxCatalogDisplayInclTaxInclFPTWithDescrWithTaxAppliedOnFPT(
array $weeTaxSettings
) {
$this->writeConfig($weeTaxSettings);
/** @var TaxClassCollectionFactory $taxClassCollectionFactory */
$taxClassCollectionFactory = $this->objectManager->get(TaxClassCollectionFactory::class);
$taxClassCollection = $taxClassCollectionFactory->create();
/** @var TaxClassModel $taxClass */
$taxClassCollection->addFieldToFilter('class_type', TaxClassModel::TAX_CLASS_TYPE_PRODUCT);
$taxClass = $taxClassCollection->getFirstItem();
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
/** @var Product $product1 */
$product1 = $productRepository->get('simple-with-ftp');
$product1->setCustomAttribute('tax_class_id', $taxClass->getClassId());
$productRepository->save($product1);
$skus = ['simple-with-ftp'];
$query = $this->getProductQuery($skus);
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['products']['items']);
$product = $result['products']['items'][0];
//12.7 + 7.5% of 12.7 = 13.65
$fptWithTax = round(13.65, 2);
// final price and regular price are the sum of product price and FPT
$this->assertEquals(113.65, round($product['price_range']['minimum_price']['regular_price']['value'], 2));
$this->assertEquals(113.65, round($product['price_range']['minimum_price']['final_price']['value'], 2));
$this->assertEquals(113.65, round($product['price_range']['maximum_price']['regular_price']['value'], 2));
$this->assertEquals(113.65, round($product['price_range']['maximum_price']['final_price']['value'], 2));
$this->assertNotEmpty($product['price_range']['minimum_price']['fixed_product_taxes']);
$fixedProductTax = $product['price_range']['minimum_price']['fixed_product_taxes'][0];
$this->assertEquals($fptWithTax, round($fixedProductTax['amount']['value'], 2));
$this->assertEquals('fpt_for_all_front_label', $fixedProductTax['label']);
}
/**
* CatalogPriceIncTaxCatalogDisplayInclTaxInclFPTWithDescrWithTaxAppliedOnFPT settings data provider
*
* @return array
*/
public function catalogPriceIncTaxCatalogDisplayInclTaxInclFPTWithDescrWithTaxAppliedOnFPTSettingsProvider()
{
return [
[
'weeTaxSettings' => [
'tax/calculation/price_includes_tax' => '1',
'tax/display/type' => '2',
'tax/weee/enable' => '1',
'tax/weee/display' => '0',
'tax/defaults/region' => '1',
'tax/weee/apply_vat' => '1',
]
]
];
}
/**
* Use multiple FPTs per product with the below tax/fpt configurations
*
* Catalog Prices : Including Tax
* Catalog Display setting: Including Tax
* FPT Display setting: Including FPT and FPT description
* Apply tax on FPT : Yes
*
* @param array $weeTaxSettings
* @return void
*
* @dataProvider catalogPriceInclTaxCatalogDisplayIncludeTaxAndMuyltipleFPTsSettingsProvider
* @magentoApiDataFixture Magento/Weee/_files/product_with_two_fpt.php
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
*/
public function testCatalogPriceInclTaxCatalogDisplayIncludeTaxAndMuyltipleFPTs(array $weeTaxSettings)
{
$this->writeConfig($weeTaxSettings);
/** @var TaxClassCollectionFactory $taxClassCollectionFactory */
$taxClassCollectionFactory = $this->objectManager->get(TaxClassCollectionFactory::class);
$taxClassCollection = $taxClassCollectionFactory->create();
/** @var TaxClassModel $taxClass */
$taxClassCollection->addFieldToFilter('class_type', TaxClassModel::TAX_CLASS_TYPE_PRODUCT);
$taxClass = $taxClassCollection->getFirstItem();
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
/** @var Product $product1 */
$product1 = $productRepository->get('simple-with-ftp');
$product1->setCustomAttribute('tax_class_id', $taxClass->getClassId());
$product1->setFixedProductAttribute(
[['website_id' => 0, 'country' => 'US', 'state' => 0, 'price' => 10, 'delete' => '']]
);
$productRepository->save($product1);
$skus = ['simple-with-ftp'];
$query = $this->getProductQuery($skus);
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['products']['items']);
$product = $result['products']['items'][0];
$this->assertEquals(124.40, round($product['price_range']['minimum_price']['regular_price']['value'], 2));
$this->assertCount(
2,
$product['price_range']['minimum_price']['fixed_product_taxes'],
'Fixed product tax count is incorrect'
);
$this->assertResponseFields(
$product['price_range']['minimum_price']['fixed_product_taxes'],
[
[
'amount' => [
'value' => 13.6525
],
'label' => 'fpt_for_all_front_label'
],
[
'amount' => [
'value' => 10.75
],
'label' => 'fixed_product_attribute_front_label'
],
]
);
}
/**
* CatalogPriceInclTaxCatalogDisplayIncludeTaxAndMuyltipleFPTsSettingsProvider settings data provider
*
* @return array
*/
public function catalogPriceInclTaxCatalogDisplayIncludeTaxAndMuyltipleFPTsSettingsProvider()
{
return [
[
'weeTaxSettings' => [
'tax/calculation/price_includes_tax' => '1',
'tax/display/type' => '2',
'tax/weee/enable' => '1',
'tax/weee/display' => '1',
'tax/defaults/region' => '1',
'tax/weee/apply_vat' => '1',
]
]
];
}
/**
* Test FPT disabled feature
*
* FPT enabled : FALSE
*
* @param array $weeTaxSettings
* @return void
*
* @dataProvider catalogPriceDisabledFPTSettingsProvider
* @magentoApiDataFixture Magento/Weee/_files/product_with_fpt.php
*/
public function testCatalogPriceDisableFPT(array $weeTaxSettings)
{
$this->writeConfig($weeTaxSettings);
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
/** @var Product $product1 */
$product1 = $productRepository->get('simple-with-ftp');
$product1->setFixedProductAttribute(
[['website_id' => 0, 'country' => 'US', 'state' => 0, 'price' => 10, 'delete' => '']]
);
$productRepository->save($product1);
$skus = ['simple-with-ftp'];
$query = $this->getProductQuery($skus);
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['products']['items']);
$product = $result['products']['items'][0];
$this->assertEquals(100, round($product['price_range']['minimum_price']['regular_price']['value'], 2));
$this->assertCount(
0,
$product['price_range']['minimum_price']['fixed_product_taxes'],
'Fixed product tax count is incorrect'
);
$this->assertResponseFields(
$product['price_range']['minimum_price']['fixed_product_taxes'],
[]
);
}
/**
* CatalogPriceDisableFPT settings data provider
*
* @return array
*/
public function catalogPriceDisabledFPTSettingsProvider()
{
return [
[
'weeTaxSettings' => [
'tax/weee/enable' => '0',
'tax/weee/display' => '1',
],
],
];
}
/**
* Get GraphQl query to fetch products by sku
*
* @param array $skus
* @return string
*/
private function getProductQuery(array $skus): string
{
$stringSkus = '"' . implode('","', $skus) . '"';
return <<<QUERY
{
products(filter: {sku: {in: [$stringSkus]}}, sort: {name: ASC}) {
items {
name
sku
price_range {
minimum_price {
regular_price {
value
currency
}
final_price {
value
currency
}
discount {
amount_off
percent_off
}
fixed_product_taxes{
amount{value}
label
}
}
maximum_price {
regular_price {
value
currency
}
final_price {
value
currency
}
discount {
amount_off
percent_off
}
fixed_product_taxes
{
amount{value}
label
}
}
}
}
}
}
QUERY;
}
}
@@ -0,0 +1,204 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\GraphQl\Weee;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\ObjectManager\ObjectManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;
use Magento\Weee\Model\Tax as WeeeDisplayConfig;
use Magento\Weee\Model\Config;
/**
* Test for storeConfig FPT config values
*/
class StoreConfigFPTTest extends GraphQlAbstract
{
/** @var ObjectManager $objectManager */
private $objectManager;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
}
/**
* FPT All Display settings
*
* @param array $weeTaxSettings
* @param string $displayValue
* @return void
*
* @dataProvider sameFPTDisplaySettingsProvider
*/
public function testSameFPTDisplaySettings(array $weeTaxSettings, $displayValue)
{
/** @var WriterInterface $configWriter */
$configWriter = $this->objectManager->get(WriterInterface::class);
foreach ($weeTaxSettings as $path => $value) {
$configWriter->save($path, $value);
}
/** @var ScopeConfigInterface $scopeConfig */
$scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
$scopeConfig->clean();
$query = $this->getStoreConfigQuery();
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['storeConfig']['product_fixed_product_tax_display_setting']);
$this->assertNotEmpty($result['storeConfig']['category_fixed_product_tax_display_setting']);
$this->assertNotEmpty($result['storeConfig']['sales_fixed_product_tax_display_setting']);
$this->assertEquals($displayValue, $result['storeConfig']['product_fixed_product_tax_display_setting']);
$this->assertEquals($displayValue, $result['storeConfig']['category_fixed_product_tax_display_setting']);
$this->assertEquals($displayValue, $result['storeConfig']['sales_fixed_product_tax_display_setting']);
}
/**
* SameFPTDisplaySettings settings data provider
*
* @return array
*/
public function sameFPTDisplaySettingsProvider()
{
return [
[
'weeTaxSettingsDisplayIncludedOnly' => [
'tax/weee/enable' => '1',
Config::XML_PATH_FPT_DISPLAY_PRODUCT_VIEW => WeeeDisplayConfig::DISPLAY_INCL,
Config::XML_PATH_FPT_DISPLAY_PRODUCT_LIST => WeeeDisplayConfig::DISPLAY_INCL,
Config::XML_PATH_FPT_DISPLAY_SALES => WeeeDisplayConfig::DISPLAY_INCL,
],
'displayValue' => 'INCLUDE_FPT_WITHOUT_DETAILS',
],
[
'weeTaxSettingsDisplayIncludedAndDescription' => [
'tax/weee/enable' => '1',
Config::XML_PATH_FPT_DISPLAY_PRODUCT_VIEW => WeeeDisplayConfig::DISPLAY_INCL_DESCR,
Config::XML_PATH_FPT_DISPLAY_PRODUCT_LIST => WeeeDisplayConfig::DISPLAY_INCL_DESCR,
Config::XML_PATH_FPT_DISPLAY_SALES => WeeeDisplayConfig::DISPLAY_INCL_DESCR,
],
'displayValue' => 'INCLUDE_FPT_WITH_DETAILS',
],
[
'weeTaxSettingsDisplayIncludedAndExcludedAndDescription' => [
'tax/weee/enable' => '1',
Config::XML_PATH_FPT_DISPLAY_PRODUCT_VIEW => WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL,
Config::XML_PATH_FPT_DISPLAY_PRODUCT_LIST => WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL,
Config::XML_PATH_FPT_DISPLAY_SALES => WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL,
],
'displayValue' => 'EXCLUDE_FPT_AND_INCLUDE_WITH_DETAILS',
],
[
'weeTaxSettingsDisplayExcluded' => [
'tax/weee/enable' => '1',
Config::XML_PATH_FPT_DISPLAY_PRODUCT_VIEW => WeeeDisplayConfig::DISPLAY_EXCL,
Config::XML_PATH_FPT_DISPLAY_PRODUCT_LIST => WeeeDisplayConfig::DISPLAY_EXCL,
Config::XML_PATH_FPT_DISPLAY_SALES => WeeeDisplayConfig::DISPLAY_EXCL,
],
'displayValue' => 'EXCLUDE_FPT_WITHOUT_DETAILS',
],
[
'weeTaxSettingsDisplayExcluded' => [
'tax/weee/enable' => '0',
Config::XML_PATH_FPT_DISPLAY_PRODUCT_VIEW => WeeeDisplayConfig::DISPLAY_EXCL,
Config::XML_PATH_FPT_DISPLAY_PRODUCT_LIST => WeeeDisplayConfig::DISPLAY_EXCL,
Config::XML_PATH_FPT_DISPLAY_SALES => WeeeDisplayConfig::DISPLAY_EXCL,
],
'displayValue' => 'FPT_DISABLED',
],
];
}
/**
* FPT Display setting shuffled
*
* @param array $weeTaxSettings
* @return void
*
* @dataProvider differentFPTDisplaySettingsProvider
*/
public function testDifferentFPTDisplaySettings(array $weeTaxSettings)
{
/** @var WriterInterface $configWriter */
$configWriter = $this->objectManager->get(WriterInterface::class);
foreach ($weeTaxSettings as $path => $value) {
$configWriter->save($path, $value);
}
/** @var ScopeConfigInterface $scopeConfig */
$scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
$scopeConfig->clean();
$query = $this->getStoreConfigQuery();
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertNotEmpty($result['storeConfig']['product_fixed_product_tax_display_setting']);
$this->assertNotEmpty($result['storeConfig']['category_fixed_product_tax_display_setting']);
$this->assertNotEmpty($result['storeConfig']['sales_fixed_product_tax_display_setting']);
$this->assertEquals(
'INCLUDE_FPT_WITHOUT_DETAILS',
$result['storeConfig']['product_fixed_product_tax_display_setting']
);
$this->assertEquals(
'INCLUDE_FPT_WITH_DETAILS',
$result['storeConfig']['category_fixed_product_tax_display_setting']
);
$this->assertEquals(
'EXCLUDE_FPT_AND_INCLUDE_WITH_DETAILS',
$result['storeConfig']['sales_fixed_product_tax_display_setting']
);
}
/**
* DifferentFPTDisplaySettings settings data provider
*
* @return array
*/
public function differentFPTDisplaySettingsProvider()
{
return [
[
'weeTaxSettingsDisplay' => [
'tax/weee/enable' => '1',
Config::XML_PATH_FPT_DISPLAY_PRODUCT_VIEW => WeeeDisplayConfig::DISPLAY_INCL,
Config::XML_PATH_FPT_DISPLAY_PRODUCT_LIST => WeeeDisplayConfig::DISPLAY_INCL_DESCR,
Config::XML_PATH_FPT_DISPLAY_SALES => WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL,
]
],
];
}
/**
* Get GraphQl query to fetch storeConfig and FPT serttings
*
* @return string
*/
private function getStoreConfigQuery(): string
{
return <<<QUERY
{
storeConfig {
product_fixed_product_tax_display_setting
category_fixed_product_tax_display_setting
sales_fixed_product_tax_display_setting
}
}
QUERY;
}
}