init
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Weee\Model\Attribute\Set;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductAttributeInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\SetRepository;
|
||||
use Magento\Eav\Model\Config;
|
||||
use Magento\Eav\Model\Entity\Type;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\TestFramework\Eav\Model\ResourceModel\GetEntityIdByAttributeId;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Weee\Model\ResourceModel\Tax as WeeTaxResource;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test checks that wee attributes data was deleted after unassigning wee attributes from attribute set.
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
* @magentoDataFixture Magento/Weee/_files/product_with_fpt.php
|
||||
*/
|
||||
class SaveTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Type
|
||||
*/
|
||||
private $productEntityType;
|
||||
|
||||
/**
|
||||
* @var GetEntityIdByAttributeId
|
||||
*/
|
||||
private $getEntityIdByAttributeId;
|
||||
|
||||
/**
|
||||
* @var SetRepository
|
||||
*/
|
||||
private $setRepository;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $eavConfig;
|
||||
|
||||
/**
|
||||
* @var WeeTaxResource
|
||||
*/
|
||||
private $taxResource;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->productEntityType = $this->objectManager->get(Type::class)
|
||||
->loadByCode(ProductAttributeInterface::ENTITY_TYPE_CODE);
|
||||
$this->getEntityIdByAttributeId = $this->objectManager->get(GetEntityIdByAttributeId::class);
|
||||
$this->setRepository = $this->objectManager->get(SetRepository::class);
|
||||
$this->eavConfig = $this->objectManager->get(Config::class);
|
||||
$this->taxResource = $this->objectManager->get(WeeTaxResource::class);
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->productRepository->cleanCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveAttributeSet(): void
|
||||
{
|
||||
$fptAttribute = $this->eavConfig->getAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'fpt_for_all');
|
||||
$attributeSet = $this->setRepository->get($this->productEntityType->getDefaultAttributeSetId());
|
||||
$entityAttributeId = $this->getEntityIdByAttributeId->execute(
|
||||
(int)$attributeSet->getAttributeSetId(),
|
||||
(int)$fptAttribute->getAttributeId(),
|
||||
(int)$attributeSet->getDefaultGroupId($attributeSet->getAttributeSetId())
|
||||
);
|
||||
$attributeSet->organizeData(['attribute_set_name' => 'Default', 'not_attributes' => [$entityAttributeId]]);
|
||||
$this->setRepository->save($attributeSet);
|
||||
$this->assertEmpty(
|
||||
$this->getWeeTaxDataByAttributeAndProduct(
|
||||
(int)$this->productRepository->get('simple-with-ftp')->getId(),
|
||||
(int)$fptAttribute->getAttributeId()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from wee_tax table.
|
||||
*
|
||||
* @param int $productId
|
||||
* @param int $attributeId
|
||||
* @return array
|
||||
*/
|
||||
private function getWeeTaxDataByAttributeAndProduct(int $productId, int $attributeId): array
|
||||
{
|
||||
$select = $this->taxResource->getConnection()
|
||||
->select()
|
||||
->from(['main' => $this->taxResource->getMainTable()])
|
||||
->where('entity_id = ?', $productId)
|
||||
->where('attribute_id = ?', $attributeId);
|
||||
|
||||
return $this->taxResource->getConnection()->fetchAll($select);
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Weee\Model\Product\Attribute\Save;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Eav\Model\Entity\Attribute\Exception;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*/
|
||||
class AttributeFixedProductTaxTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var ProductRepositoryInterface */
|
||||
private $productRepository;
|
||||
|
||||
/** @var string */
|
||||
private $attributeCode;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
|
||||
$this->attributeCode = 'fixed_product_attribute';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider fPTProvider
|
||||
* @param array $data
|
||||
* @param array $expectedData
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveProductWithFPTAttribute(array $data, array $expectedData): void
|
||||
{
|
||||
$product = $this->productRepository->get('simple2');
|
||||
$product->addData([$this->attributeCode => $data]);
|
||||
$product = $this->productRepository->save($product);
|
||||
$this->assertEquals($expectedData, $product->getData($this->attributeCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function fPTProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'data' => [
|
||||
[
|
||||
'region_id' => '0',
|
||||
'country' => 'GB',
|
||||
'val' => '',
|
||||
'value' => '15',
|
||||
'website_id' => '0',
|
||||
'state' => '',
|
||||
],
|
||||
[
|
||||
'region_id' => '1',
|
||||
'country' => 'US',
|
||||
'val' => '',
|
||||
'value' => '35',
|
||||
'website_id' => '0',
|
||||
'state' => '',
|
||||
],
|
||||
],
|
||||
'expected_data' => [
|
||||
[
|
||||
'website_id' => '0',
|
||||
'country' => 'GB',
|
||||
'state' => '0',
|
||||
'value' => '15.0000',
|
||||
'website_value' => 15.0,
|
||||
],
|
||||
[
|
||||
'website_id' => '0',
|
||||
'country' => 'US',
|
||||
'state' => '0',
|
||||
'value' => '35.0000',
|
||||
'website_value' => 35.0
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveProductWithFPTAttributeWithDuplicates(): void
|
||||
{
|
||||
$attributeValues = [
|
||||
[
|
||||
'region_id' => '0',
|
||||
'country' => 'GB',
|
||||
'val' => '',
|
||||
'value' => '15',
|
||||
'website_id' => '0',
|
||||
'state' => '',
|
||||
],
|
||||
[
|
||||
'region_id' => '0',
|
||||
'country' => 'GB',
|
||||
'val' => '',
|
||||
'value' => '15',
|
||||
'website_id' => '0',
|
||||
'state' => '',
|
||||
],
|
||||
];
|
||||
$this->expectException(Exception::class);
|
||||
$message = 'Set unique country-state combinations within the same fixed product tax. '
|
||||
. 'Verify the combinations and try again.';
|
||||
$this->expectExceptionMessage((string)__($message));
|
||||
$product = $this->productRepository->get('simple2');
|
||||
$product->addData([$this->attributeCode => $attributeValues]);
|
||||
$this->productRepository->save($product);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Weee\Model\ResourceModel;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Eav\Model\Entity\Attribute as EavAttribute;
|
||||
use Magento\Framework\EntityManager\MetadataPool;
|
||||
|
||||
/**
|
||||
* Test class for Magento\Catalog\Model\ResourceModel\Attribute class
|
||||
* with backend model Magento\Weee\Model\Attribute\Backend\Weee\Tax.
|
||||
*
|
||||
* @see Magento\Catalog\Model\ResourceModel\Attribute
|
||||
*/
|
||||
class AttributeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\ResourceModel\Attribute
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\ResourceModel\Product
|
||||
*/
|
||||
protected $productResource;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var MetadataPool
|
||||
*/
|
||||
private $metadataPool;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->model = $this->objectManager->get(
|
||||
\Magento\Catalog\Model\ResourceModel\Attribute::class
|
||||
);
|
||||
$this->productResource = $this->objectManager->get(
|
||||
\Magento\Catalog\Model\ResourceModel\Product::class
|
||||
);
|
||||
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
|
||||
$this->metadataPool = $this->objectManager->get(MetadataPool::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve eav attribute row.
|
||||
*
|
||||
* @param int $entityTypeId
|
||||
* @param int $attributeSetId
|
||||
* @param int $attributeId
|
||||
* @return array|false
|
||||
*/
|
||||
private function getEavEntityAttributeRow(int $entityTypeId, int $attributeSetId, int $attributeId)
|
||||
{
|
||||
$connection = $this->productResource->getConnection();
|
||||
$select = $connection->select()
|
||||
->from($this->productResource->getTable('eav_entity_attribute'))
|
||||
->where('attribute_set_id=?', $attributeSetId)
|
||||
->where('attribute_id=?', $attributeId)
|
||||
->where('entity_type_id=?', $entityTypeId);
|
||||
|
||||
return $connection->fetchRow($select);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to delete entity attribute with type "Fixed Product Tax".
|
||||
*
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteEntityFixedTax() : void
|
||||
{
|
||||
/* @var EavAttribute $attribute */
|
||||
$attribute = $this->objectManager->get(EavAttribute::class);
|
||||
$attribute->loadByCode(\Magento\Catalog\Model\Product::ENTITY, 'fixed_product_attribute');
|
||||
|
||||
$entityEavAttributeRow = $this->getEavEntityAttributeRow(
|
||||
(int)$attribute->getEntityTypeId(),
|
||||
4,
|
||||
(int)$attribute->getId()
|
||||
);
|
||||
$this->assertNotEmpty(
|
||||
$entityEavAttributeRow['entity_attribute_id'],
|
||||
'The record is absent in table `eav_entity_attribute` for `fixed_product_attribute`'
|
||||
);
|
||||
|
||||
$attribute->setData('entity_attribute_id', $entityEavAttributeRow['entity_attribute_id']);
|
||||
$this->model->deleteEntity($attribute);
|
||||
|
||||
$entityEavAttributeRow = $this->getEavEntityAttributeRow(
|
||||
(int)$attribute->getEntityTypeId(),
|
||||
4,
|
||||
(int)$attribute->getId()
|
||||
);
|
||||
$this->assertEmpty(
|
||||
$entityEavAttributeRow,
|
||||
'The record was not removed from table `eav_entity_attribute` for `fixed_product_attribute`'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Weee\Model;
|
||||
|
||||
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_sample.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
* @magentoDataFixture Magento/Weee/_files/product_with_fpt.php
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class TaxTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Weee\Model\Tax
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\ExtensibleDataObjectConverter
|
||||
*/
|
||||
private $_extensibleDataObjectConverter;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$weeeConfig = $this->createMock(\Magento\Weee\Model\Config::class);
|
||||
$weeeConfig->expects($this->any())->method('isEnabled')->willReturn(true);
|
||||
$weeeConfig->expects($this->any())->method('isTaxable')->willReturn(true);
|
||||
$attribute = $this->createMock(\Magento\Eav\Model\Entity\Attribute::class);
|
||||
$attribute->expects($this->any())->method('getAttributeCodesByFrontendType')->willReturn(
|
||||
['weee']
|
||||
);
|
||||
$attributeFactory = $this->createPartialMock(\Magento\Eav\Model\Entity\AttributeFactory::class, ['create']);
|
||||
$attributeFactory->expects($this->any())->method('create')->willReturn($attribute);
|
||||
$this->_model = $objectManager->create(
|
||||
\Magento\Weee\Model\Tax::class,
|
||||
['weeeConfig' => $weeeConfig, 'attributeFactory' => $attributeFactory]
|
||||
);
|
||||
$this->_extensibleDataObjectConverter = $objectManager->get(
|
||||
\Magento\Framework\Api\ExtensibleDataObjectConverter::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetProductWeeeAttributes()
|
||||
{
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Api\CustomerRepositoryInterface::class
|
||||
);
|
||||
$customerMetadataService = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Api\CustomerMetadataInterface::class
|
||||
);
|
||||
$customerFactory = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Api\Data\CustomerInterfaceFactory::class,
|
||||
['metadataService' => $customerMetadataService]
|
||||
);
|
||||
$dataObjectHelper = Bootstrap::getObjectManager()->create(\Magento\Framework\Api\DataObjectHelper::class);
|
||||
$expected = $this->_extensibleDataObjectConverter->toFlatArray(
|
||||
$customerRepository->getById(1),
|
||||
[],
|
||||
\Magento\Customer\Api\Data\CustomerInterface::class
|
||||
);
|
||||
$customerDataSet = $customerFactory->create();
|
||||
$dataObjectHelper->populateWithArray(
|
||||
$customerDataSet,
|
||||
$expected,
|
||||
\Magento\Customer\Api\Data\CustomerInterface::class
|
||||
);
|
||||
$fixtureGroupCode = 'custom_group';
|
||||
$fixtureTaxClassId = 3;
|
||||
/** @var \Magento\Customer\Model\Group $group */
|
||||
$group = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Group::class);
|
||||
$fixtureGroupId = $group->load($fixtureGroupCode, 'customer_group_code')->getId();
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setCustomerGroupId($fixtureGroupId);
|
||||
$quote->setCustomerTaxClassId($fixtureTaxClassId);
|
||||
$quote->setCustomer($customerDataSet);
|
||||
$shipping = new \Magento\Framework\DataObject([
|
||||
'quote' => $quote,
|
||||
]);
|
||||
$productRepository = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Catalog\Api\ProductRepositoryInterface::class
|
||||
);
|
||||
$product = $productRepository->get('simple-with-ftp');
|
||||
|
||||
$amount = $this->_model->getProductWeeeAttributes($product, $shipping, null, null, true);
|
||||
$this->assertIsArray($amount);
|
||||
$this->assertArrayHasKey(0, $amount);
|
||||
$this->assertEquals(12.70, $amount[0]->getAmount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Weee\Model\Total\Quote;
|
||||
|
||||
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
||||
use Magento\Checkout\Api\Data\TotalsInformationInterface;
|
||||
use Magento\Checkout\Model\TotalsInformationManagement;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Multishipping\Test\Fixture\AddAddressToCart as AddAddressToCartFixture;
|
||||
use Magento\Multishipping\Test\Fixture\ShippingAssignments as ShippingAssignmentsFixture;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\TotalsInterface;
|
||||
use Magento\Quote\Model\Quote\Address;
|
||||
use Magento\Quote\Model\Quote\AddressFactory;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
|
||||
use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
|
||||
use Magento\TestFramework\Fixture\Config;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\Weee\Test\Fixture\Attribute as FptAttributeFixture;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Quote totals calculate tests class
|
||||
*/
|
||||
class CalculateTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var TotalsInformationManagement
|
||||
*/
|
||||
private $totalsManagement;
|
||||
|
||||
/**
|
||||
* @var CartRepositoryInterface
|
||||
*/
|
||||
private $cartRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\TestFramework\Fixture\DataFixtureStorage
|
||||
*/
|
||||
private $fixtures;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = ObjectManager::getInstance();
|
||||
$this->totalsManagement = $this->objectManager->get(TotalsInformationManagement::class);
|
||||
$this->cartRepository = $this->objectManager->get(CartRepositoryInterface::class);
|
||||
$this->fixtures = DataFixtureStorageManager::getStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Multishipping quote with FPT Weee TAX totals calculation test
|
||||
*
|
||||
* @magentoDataFixture Magento/Weee/_files/quote_multishipping.php
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/apply_vat 1
|
||||
*/
|
||||
public function testGetWeeTaxTotals()
|
||||
{
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = $this->objectManager->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = $this->objectManager->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'multishipping_fpt_quote_id', 'reserved_order_id');
|
||||
$cartId = $quote->getId();
|
||||
|
||||
$actual = $this->getTotals((int) $cartId);
|
||||
|
||||
$items = $actual->getTotalSegments();
|
||||
$this->assertTrue(array_key_exists('weee_tax', $items));
|
||||
$this->assertEquals(25.4, $items['weee_tax']->getValue());
|
||||
}
|
||||
|
||||
#[
|
||||
Config('tax/weee/enable', '1', 'store', 'default'),
|
||||
Config('tax/weee/apply_vat', '1', 'store', 'default'),
|
||||
DataFixture(FptAttributeFixture::class, ['attribute_code' => 'fpt_attr'], 'fpt'),
|
||||
DataFixture(
|
||||
ProductFixture::class,
|
||||
['fpt_attr' => [['website_id' => 0, 'country' => 'US', 'state' => 0, 'price' => 0.3]]],
|
||||
'p1'
|
||||
),
|
||||
DataFixture(
|
||||
ProductFixture::class,
|
||||
['fpt_attr' => [['website_id' => 0, 'country' => 'US', 'state' => 0, 'price' => 0.8]]],
|
||||
'p2'
|
||||
),
|
||||
DataFixture(GuestCartFixture::class, as: 'qt'),
|
||||
DataFixture(AddProductToCartFixture::class, ['cart_id' => '$qt.id$', 'product_id' => '$p1.id$']),
|
||||
DataFixture(AddProductToCartFixture::class, ['cart_id' => '$qt.id$', 'product_id' => '$p2.id$']),
|
||||
]
|
||||
public function testCollectTotalsWithMultipleProducts(): void
|
||||
{
|
||||
$json = $this->objectManager->get(Json::class);
|
||||
$cart = $this->fixtures->get('qt');
|
||||
$totals = $this->getTotals((int) $cart->getId());
|
||||
$this->assertCount(2, $totals->getItems());
|
||||
$items = array_values($totals->getItems());
|
||||
|
||||
$weeeTaxes = $json->unserialize($items[0]->getWeeeTaxApplied());
|
||||
$this->assertCount(1, $weeeTaxes);
|
||||
$this->assertEquals(0.3, $weeeTaxes[0]['base_amount_incl_tax']);
|
||||
$this->assertEquals(0.3, $weeeTaxes[0]['row_amount_incl_tax']);
|
||||
|
||||
$weeeTaxes = $json->unserialize($items[1]->getWeeeTaxApplied());
|
||||
$this->assertCount(1, $weeeTaxes);
|
||||
$this->assertEquals(0.8, $weeeTaxes[0]['base_amount_incl_tax']);
|
||||
$this->assertEquals(0.8, $weeeTaxes[0]['row_amount_incl_tax']);
|
||||
}
|
||||
|
||||
#[
|
||||
Config('tax/weee/enable', '1', 'store', 'default'),
|
||||
Config('tax/weee/apply_vat', '1', 'store', 'default'),
|
||||
DataFixture(FptAttributeFixture::class, ['attribute_code' => 'fpt_attr'], 'fpt'),
|
||||
DataFixture(
|
||||
ProductFixture::class,
|
||||
['fpt_attr' => [['website_id' => 0, 'country' => 'US', 'state' => 0, 'price' => 0.3]]],
|
||||
'p1'
|
||||
),
|
||||
DataFixture(
|
||||
ProductFixture::class,
|
||||
['fpt_attr' => [['website_id' => 0, 'country' => 'US', 'state' => 0, 'price' => 0.8]]],
|
||||
'p2'
|
||||
),
|
||||
DataFixture(GuestCartFixture::class, as: 'qt'),
|
||||
DataFixture(AddProductToCartFixture::class, ['cart_id' => '$qt.id$', 'product_id' => '$p1.id$'], 'qti1'),
|
||||
DataFixture(AddProductToCartFixture::class, ['cart_id' => '$qt.id$', 'product_id' => '$p2.id$'], 'qti2'),
|
||||
DataFixture(AddAddressToCartFixture::class, ['cart_id' => '$qt.id$'], 'qta1'),
|
||||
DataFixture(AddAddressToCartFixture::class, ['cart_id' => '$qt.id$'], 'qta2'),
|
||||
DataFixture(
|
||||
ShippingAssignmentsFixture::class,
|
||||
[
|
||||
'cart_id' => '$qt.id$',
|
||||
'assignments' => [
|
||||
['item_id' => '$qti1.id$', 'address_id' => '$qta1.id$', 'qty' => 1],
|
||||
['item_id' => '$qti2.id$', 'address_id' => '$qta2.id$', 'qty' => 1]
|
||||
]
|
||||
]
|
||||
),
|
||||
]
|
||||
public function testCollectTotalsWithMultipleAddresses(): void
|
||||
{
|
||||
$cart = $this->fixtures->get('qt');
|
||||
$cart = $this->cartRepository->get($cart->getId());
|
||||
$cart->setTotalsCollectedFlag(false);
|
||||
$cart->collectTotals();
|
||||
$addresses = $cart->getAllShippingAddresses();
|
||||
$this->assertCount(2, $addresses);
|
||||
$address = $addresses[0];
|
||||
$totals = $address->getTotals();
|
||||
$this->assertArrayHasKey('weee_tax', $totals);
|
||||
$this->assertEquals(0.3, $totals['weee_tax']['value']);
|
||||
$address = $addresses[1];
|
||||
$totals = $address->getTotals();
|
||||
$this->assertArrayHasKey('weee_tax', $totals);
|
||||
$this->assertEquals(0.8, $totals['weee_tax']['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cartId
|
||||
* @return TotalsInterface
|
||||
*/
|
||||
private function getTotals(int $cartId): TotalsInterface
|
||||
{
|
||||
/** @var Address $address */
|
||||
$address = $this->objectManager->get(AddressFactory::class)->create();
|
||||
$address->setAddressType(Address::ADDRESS_TYPE_SHIPPING)
|
||||
->setCountryId('US')
|
||||
->setRegionId(12)
|
||||
->setRegion('California')
|
||||
->setPostcode('90230');
|
||||
$addressInformation = $this->objectManager->create(
|
||||
TotalsInformationInterface::class,
|
||||
[
|
||||
'data' => [
|
||||
'address' => $address,
|
||||
'shipping_method_code' => 'flatrate',
|
||||
'shipping_carrier_code' => 'flatrate',
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
return $this->totalsManagement->calculate($cartId, $addressInformation);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user