init
This commit is contained in:
+439
@@ -0,0 +1,439 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Weee\Block\Product\View\Attribute;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Block\Product\ListProduct;
|
||||
use Magento\Catalog\Pricing\Render as CatalogPricingRender;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Pricing\Render;
|
||||
use Magento\Framework\Pricing\Render\RendererPool;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class checks FPT attribute displaying on frontend
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class FixedProductTaxAttributeTest extends TestCase
|
||||
{
|
||||
/** @var array */
|
||||
private $textTaxData;
|
||||
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var ProductRepositoryInterface */
|
||||
private $productRepository;
|
||||
|
||||
/** @var string */
|
||||
private $attributeCode;
|
||||
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/** @var ListProduct */
|
||||
private $productListBlock;
|
||||
|
||||
/** @var Registry */
|
||||
private $registry;
|
||||
|
||||
/** @var StoreManagerInterface */
|
||||
private $storeManager;
|
||||
|
||||
/** @var CustomerRepositoryInterface */
|
||||
private $customerRepository;
|
||||
|
||||
/** @var Session */
|
||||
private $customerSession;
|
||||
|
||||
/** @var int */
|
||||
private $baseWebsiteId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->productListBlock = $this->layout->createBlock(ListProduct::class);
|
||||
$this->attributeCode = 'fixed_product_attribute';
|
||||
$this->registry = $this->objectManager->get(Registry::class);
|
||||
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
|
||||
$this->customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class);
|
||||
$this->customerSession = $this->objectManager->get(Session::class);
|
||||
$this->baseWebsiteId = (int) $this->storeManager->getWebsite('base')->getId();
|
||||
$this->textTaxData = [
|
||||
[
|
||||
'country' => 'US',
|
||||
'val' => '',
|
||||
'value' => '5',
|
||||
'website_id' => $this->baseWebsiteId,
|
||||
'state' => '',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister('product');
|
||||
$this->registry->unregister('current_product');
|
||||
$this->customerSession->logout();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display_list 0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFPTCategoryPageIncludingFPTOnly(): void
|
||||
{
|
||||
$this->prepareLayoutCategoryPage();
|
||||
$product = $this->updateProduct('simple2', $this->textTaxData);
|
||||
$productPrice = $this->productListBlock->getProductPrice($product);
|
||||
$this->assertEquals('$15.00', preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display_list 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFPTCategoryPageIncludingFPTAndDescription(): void
|
||||
{
|
||||
$this->prepareLayoutCategoryPage();
|
||||
$product = $this->updateProduct('simple2', $this->textTaxData);
|
||||
$productPrice = $this->productListBlock->getProductPrice($product);
|
||||
$this->assertStringContainsString('data-label="fixed product tax"', $productPrice);
|
||||
$this->assertEquals('$15.00$5.00', preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display_list 2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFPTCategoryPageExcludingFPTIncludingDescriptionAndPrice(): void
|
||||
{
|
||||
$this->prepareLayoutCategoryPage();
|
||||
$product = $this->updateProduct('simple2', $this->textTaxData);
|
||||
$productPrice = $this->productListBlock->getProductPrice($product);
|
||||
$this->assertStringContainsString('data-label="fixed product tax"', $productPrice);
|
||||
$this->assertEquals('$10.00$5.00$15.00', preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display_list 3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFPTCategoryPageExcludingFPT(): void
|
||||
{
|
||||
$this->prepareLayoutCategoryPage();
|
||||
$product = $this->updateProduct('simple2', $this->textTaxData);
|
||||
$productPrice = $this->productListBlock->getProductPrice($product);
|
||||
$this->assertEquals('$10.00', preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display 0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFPTProductPageIncludingFPTOnly(): void
|
||||
{
|
||||
$product = $this->updateProduct('simple2', $this->textTaxData);
|
||||
$this->registerProduct($product);
|
||||
$block = $this->prepareLayoutProductPage();
|
||||
$productPrice = $block->toHtml();
|
||||
$this->assertEquals('$15.00', preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFPTProductPageIncludingFPTAndDescription(): void
|
||||
{
|
||||
$product = $this->updateProduct('simple2', $this->textTaxData);
|
||||
$this->registerProduct($product);
|
||||
$block = $this->prepareLayoutProductPage();
|
||||
$productPrice = $block->toHtml();
|
||||
$this->assertStringContainsString('data-label="fixed product tax"', $productPrice);
|
||||
$this->assertEquals('$15.00$5.00', preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display 2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFPTProductPageExcludingFPTIncludingDescriptionAndPrice(): void
|
||||
{
|
||||
$product = $this->updateProduct('simple2', $this->textTaxData);
|
||||
$this->registerProduct($product);
|
||||
$block = $this->prepareLayoutProductPage();
|
||||
$productPrice = $block->toHtml();
|
||||
$this->assertStringContainsString('data-label="fixed product tax"', $productPrice);
|
||||
$this->assertEquals('$10.00$5.00$15.00', preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display 3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFPTProductPageExcludingFPT(): void
|
||||
{
|
||||
$product = $this->updateProduct('simple2', $this->textTaxData);
|
||||
$this->registerProduct($product);
|
||||
$block = $this->prepareLayoutProductPage();
|
||||
$productPrice = $block->toHtml();
|
||||
$this->assertEquals('$10.00', preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
*
|
||||
* @magentoConfigFixture default/catalog/price/scope 1
|
||||
* @magentoConfigFixture fixture_second_store_store tax/weee/enable 1
|
||||
* @magentoConfigFixture fixture_second_store_store tax/weee/display 2
|
||||
*
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_two_websites.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFPTPerWebsites(): void
|
||||
{
|
||||
$currentStore = $this->storeManager->getStore();
|
||||
try {
|
||||
$secondStore = $this->storeManager->getStore('fixture_second_store');
|
||||
$taxData = [
|
||||
[
|
||||
'region_id' => '1',
|
||||
'country' => 'US',
|
||||
'val' => '',
|
||||
'value' => '5',
|
||||
'website_id' => $secondStore->getWebsiteId(),
|
||||
'state' => '',
|
||||
]
|
||||
];
|
||||
$this->storeManager->setCurrentStore($secondStore);
|
||||
$product = $this->updateProduct('simple-on-two-websites', $taxData);
|
||||
$this->registerProduct($product);
|
||||
$block = $this->prepareLayoutProductPage();
|
||||
$productPrice = $block->toHtml();
|
||||
$this->assertEquals('$10.00$5.00$15.00', preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
} finally {
|
||||
$this->storeManager->setCurrentStore($currentStore);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display 0
|
||||
*
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_one_address.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApplyTwoFPTForCustomer(): void
|
||||
{
|
||||
$email = 'customer_one_address@test.com';
|
||||
$expectedPrice = '$30.00';
|
||||
$taxData = [
|
||||
[
|
||||
'country' => 'US',
|
||||
'val' => '',
|
||||
'value' => '5',
|
||||
'website_id' => $this->baseWebsiteId,
|
||||
'state' => '',
|
||||
],
|
||||
[
|
||||
'country' => 'US',
|
||||
'val' => '',
|
||||
'value' => '15',
|
||||
'website_id' => $this->baseWebsiteId,
|
||||
'state' => 1,
|
||||
]
|
||||
];
|
||||
$this->loginCustomerByEmail($email);
|
||||
$product = $this->updateProduct('simple2', $taxData);
|
||||
$this->registerProduct($product);
|
||||
$block = $this->prepareLayoutProductPage();
|
||||
$productPrice = $block->toHtml();
|
||||
$this->assertEquals($expectedPrice, preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/defaults/country GB
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display 0
|
||||
*
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApplyFPTWithoutAddressCustomer(): void
|
||||
{
|
||||
$email = 'customer5@example.com';
|
||||
$expectedPrice = '$10.00';
|
||||
$taxData = [
|
||||
[
|
||||
'country' => 'US',
|
||||
'val' => '',
|
||||
'value' => '5',
|
||||
'website_id' => $this->baseWebsiteId,
|
||||
'state' => '',
|
||||
],
|
||||
[
|
||||
'country' => 'US',
|
||||
'val' => '',
|
||||
'value' => '15',
|
||||
'website_id' => $this->baseWebsiteId,
|
||||
'state' => 1,
|
||||
],
|
||||
];
|
||||
$this->loginCustomerByEmail($email);
|
||||
$product = $this->updateProduct('simple2', $taxData);
|
||||
$this->registerProduct($product);
|
||||
$block = $this->prepareLayoutProductPage();
|
||||
$productPrice = $block->toHtml();
|
||||
$this->assertEquals($expectedPrice, preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store tax/weee/enable 1
|
||||
* @magentoConfigFixture default_store tax/weee/display 0
|
||||
*
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_with_uk_address.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApplyFPTWithForeignCountryAddress(): void
|
||||
{
|
||||
$this->loginCustomerByEmail('customer_uk_address@test.com');
|
||||
$product = $this->updateProduct('simple2', $this->textTaxData);
|
||||
$this->registerProduct($product);
|
||||
$block = $this->prepareLayoutProductPage();
|
||||
$productPrice = $block->toHtml();
|
||||
$this->assertEquals('$10.00', preg_replace('/\s+/', '', strip_tags($productPrice)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update product
|
||||
*
|
||||
* @param string $productSku
|
||||
* @param array $data
|
||||
* @return ProductInterface
|
||||
*/
|
||||
private function updateProduct(string $productSku, array $data): ProductInterface
|
||||
{
|
||||
$product = $this->productRepository->get($productSku);
|
||||
$product->addData([$this->attributeCode => $data]);
|
||||
|
||||
return $this->productRepository->save($product);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare layout for category page view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function prepareLayoutCategoryPage(): void
|
||||
{
|
||||
$this->layout->createBlock(RendererPool::class, 'render.product.prices');
|
||||
$block = $this->objectManager->create(Render::class);
|
||||
$block->setPriceRenderHandle('catalog_product_prices');
|
||||
$block->setLayout($this->layout);
|
||||
$this->layout->addBlock($block, 'product.price.render.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare layout for product page
|
||||
*
|
||||
* @return CatalogPricingRender
|
||||
*/
|
||||
private function prepareLayoutProductPage(): CatalogPricingRender
|
||||
{
|
||||
$render = $this->objectManager->create(Render::class);
|
||||
$render->setPriceRenderHandle('catalog_product_prices');
|
||||
$this->layout->addBlock($render, 'product.price.render.default');
|
||||
$block = $this->objectManager->create(CatalogPricingRender::class);
|
||||
$block->setPriceRender('product.price.render.default');
|
||||
$block->setPriceTypeCode('final_price');
|
||||
$this->layout->addBlock($block, 'render.product.prices');
|
||||
$block->setLayout($this->layout);
|
||||
$render->setLayout($this->layout);
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the product
|
||||
*
|
||||
* @param ProductInterface $product
|
||||
* @return void
|
||||
*/
|
||||
private function registerProduct(ProductInterface $product): void
|
||||
{
|
||||
$this->registry->unregister('product');
|
||||
$this->registry->register('product', $product);
|
||||
$this->registry->unregister('current_product');
|
||||
$this->registry->register('current_product', $product);
|
||||
}
|
||||
|
||||
/**
|
||||
* Login customer by email
|
||||
*
|
||||
* @param string $email
|
||||
* @return void
|
||||
*/
|
||||
private function loginCustomerByEmail(string $email): void
|
||||
{
|
||||
$customer = $this->customerRepository->get($email);
|
||||
$this->customerSession->loginById($customer->getId());
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Weee\Controller\Adminhtml\Product\Attribute\Delete;
|
||||
|
||||
use Magento\Catalog\Controller\Adminhtml\Product\Attribute\Delete\AbstractDeleteAttributeControllerTest;
|
||||
|
||||
/**
|
||||
* Delete catalog product attributes with input types like "weee".
|
||||
* Attributes from Magento_Weee module.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class WeeeAttributesControllerTest extends AbstractDeleteAttributeControllerTest
|
||||
{
|
||||
/**
|
||||
* Assert that attribute with input type "weee" will be deleted
|
||||
* after dispatch delete product attribute action.
|
||||
*
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteSwatchTextAttribute(): void
|
||||
{
|
||||
$this->dispatchDeleteAttribute('fixed_product_attribute');
|
||||
$this->assertAttributeIsDeleted('fixed_product_attribute');
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Weee\Controller\Adminhtml\Product\Attribute\Save\InputType;
|
||||
|
||||
use Magento\Catalog\Controller\Adminhtml\Product\Attribute\Save\AbstractSaveAttributeTest;
|
||||
|
||||
/**
|
||||
* Test cases related to create attribute with input type fixed product tax.
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FixedProductTaxTest extends AbstractSaveAttributeTest
|
||||
{
|
||||
/**
|
||||
* Test create attribute and compare attribute data and input data.
|
||||
*
|
||||
* @dataProvider \Magento\TestFramework\Weee\Model\Attribute\DataProvider\FixedProductTax::getAttributeDataWithCheckArray
|
||||
*
|
||||
* @param array $attributePostData
|
||||
* @param array $checkArray
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateAttribute(array $attributePostData, array $checkArray): void
|
||||
{
|
||||
$this->createAttributeUsingDataAndAssert($attributePostData, $checkArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create attribute with error.
|
||||
*
|
||||
* @dataProvider \Magento\TestFramework\Weee\Model\Attribute\DataProvider\FixedProductTax::getAttributeDataWithErrorMessage
|
||||
*
|
||||
* @param array $attributePostData
|
||||
* @param string $errorMessage
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateAttributeWithError(array $attributePostData, string $errorMessage): void
|
||||
{
|
||||
$this->createAttributeUsingDataWithErrorAndAssert($attributePostData, $errorMessage);
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Weee\Controller\Adminhtml\Product\Attribute\Update\InputType;
|
||||
|
||||
use Magento\Catalog\Controller\Adminhtml\Product\Attribute\Update\AbstractUpdateAttributeTest;
|
||||
|
||||
/**
|
||||
* Test cases related to update attribute with input type fixed product tax.
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FixedProductTaxTest extends AbstractUpdateAttributeTest
|
||||
{
|
||||
/**
|
||||
* Test update attribute.
|
||||
*
|
||||
* @dataProvider \Magento\TestFramework\Weee\Model\Attribute\DataProvider\FixedProductTax::getUpdateProvider
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
*
|
||||
* @param array $postData
|
||||
* @param array $expectedData
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateAttribute(array $postData, array $expectedData): void
|
||||
{
|
||||
$this->updateAttributeUsingData('fixed_product_attribute', $postData);
|
||||
$this->assertUpdateAttributeProcess('fixed_product_attribute', $postData, $expectedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update attribute with error.
|
||||
*
|
||||
* @dataProvider \Magento\TestFramework\Weee\Model\Attribute\DataProvider\FixedProductTax::getUpdateProviderWithErrorMessage
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
*
|
||||
* @param array $postData
|
||||
* @param string $errorMessage
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateAttributeWithError(array $postData, string $errorMessage): void
|
||||
{
|
||||
$this->updateAttributeUsingData('fixed_product_attribute', $postData);
|
||||
$this->assertErrorSessionMessages($errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update attribute frontend labels on stores.
|
||||
*
|
||||
* @dataProvider \Magento\TestFramework\Weee\Model\Attribute\DataProvider\FixedProductTax::getUpdateFrontendLabelsProvider
|
||||
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
*
|
||||
* @param array $postData
|
||||
* @param array $expectedData
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateFrontendLabelOnStores(array $postData, array $expectedData): void
|
||||
{
|
||||
$this->processUpdateFrontendLabelOnStores('fixed_product_attribute', $postData, $expectedData);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Weee\Plugin\Catalog\Ui\Component\Listing;
|
||||
|
||||
use Magento\Catalog\Ui\Component\Listing\Attribute\Repository;
|
||||
use Magento\Catalog\Ui\Component\Listing\Columns;
|
||||
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider;
|
||||
use Magento\Framework\View\Element\UiComponent\ContextInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class ColumnsTest
|
||||
* Check if FPT attribute column in product grid won't be sortable
|
||||
*/
|
||||
class ColumnsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Columns
|
||||
*/
|
||||
private $columns;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$attributeRepository = $objectManager->get(Repository::class);
|
||||
$dataProvider = $objectManager->create(
|
||||
ProductDataProvider::class,
|
||||
[
|
||||
'name' => "product_listing_data_source",
|
||||
'primaryFieldName' => "entity_id",
|
||||
'requestFieldName' => "id",
|
||||
]
|
||||
);
|
||||
$context = $objectManager->create(ContextInterface::class);
|
||||
$context->setDataProvider($dataProvider);
|
||||
$this->columns = $objectManager->create(
|
||||
Columns::class,
|
||||
['attributeRepository' => $attributeRepository, 'context' => $context]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
*/
|
||||
public function testGetProductWeeeAttributesConfig()
|
||||
{
|
||||
$this->columns->prepare();
|
||||
$column = $this->columns->getComponent('fixed_product_attribute');
|
||||
$columnConfig = $column->getData('config');
|
||||
$this->assertArrayHasKey('sortable', $columnConfig);
|
||||
$this->assertFalse($columnConfig['sortable']);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Weee\Ui\DataProvider\Product\Form\Modifier\Eav;
|
||||
|
||||
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractEavTest;
|
||||
|
||||
/**
|
||||
* Provides tests for product form eav modifier with custom weee attribute.
|
||||
*
|
||||
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class FixedAttributeTest extends AbstractEavTest
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testModifyMeta(): void
|
||||
{
|
||||
$this->callModifyMetaAndAssert(
|
||||
$this->getProduct(),
|
||||
$this->addMetaNesting($this->getAttributeMeta(), 'product-details', 'fixed_product_attribute')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testModifyData(): void
|
||||
{
|
||||
$product = $this->getProduct();
|
||||
$attributeData = [
|
||||
'fixed_product_attribute' => [
|
||||
['website_id' => 0, 'country' => 'US', 'state' => 0, 'price' => 12.70, 'delete' => '']
|
||||
]
|
||||
];
|
||||
$this->saveProduct($product, $attributeData);
|
||||
$expectedData = $this->addDataNesting(
|
||||
[
|
||||
'fixed_product_attribute' => [
|
||||
[
|
||||
'website_id' => '0',
|
||||
'country' => 'US',
|
||||
'state' => '0',
|
||||
'value' => '12.7000',
|
||||
'website_value' => 12.7,
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
$this->callModifyDataAndAssert($this->getProduct(), $expectedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getAttributeMeta(): array
|
||||
{
|
||||
return [
|
||||
'visible' => '1',
|
||||
'required' => '0',
|
||||
'label' => 'fixed product tax',
|
||||
'code' => 'fixed_product_attribute',
|
||||
'source' => 'product-details',
|
||||
'scopeLabel' => '[GLOBAL]',
|
||||
'globalScope' => true,
|
||||
'sortOrder' => '__placeholder__',
|
||||
'componentType' => 'field',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Weee/_files/fixed_product_attribute_rollback.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
|
||||
$attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class);
|
||||
|
||||
$entityType = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)->loadByCode('catalog_product');
|
||||
$defaultSetId = $objectManager->create(\Magento\Catalog\Model\Product::class)->getDefaultAttributeSetid();
|
||||
|
||||
$attributeGroupId = $attributeSet->getDefaultGroupId($entityType->getDefaultAttributeSetId());
|
||||
|
||||
$attributeData = [
|
||||
'entity_type_id' => $entityType->getId(),
|
||||
'attribute_code' => 'fixed_product_attribute',
|
||||
'backend_model' => 'Magento\Weee\Model\Attribute\Backend\Weee\Tax',
|
||||
'is_required' => 0,
|
||||
'is_user_defined' => 1,
|
||||
'is_static' => 1,
|
||||
'attribute_set_id' => $defaultSetId,
|
||||
'attribute_group_id' => $attributeGroupId,
|
||||
'frontend_input' => 'weee',
|
||||
'frontend_label' => 'fixed product tax',
|
||||
'is_used_in_grid' => '1',
|
||||
];
|
||||
|
||||
/** @var \Magento\Catalog\Model\Entity\Attribute $attribute */
|
||||
$attribute = $objectManager->create(\Magento\Eav\Model\Entity\Attribute::class);
|
||||
$attribute->setData($attributeData);
|
||||
$attribute->save();
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/* @var \Magento\Eav\Model\Entity\Attribute $attribute */
|
||||
$attribute = $objectManager->get(\Magento\Eav\Model\Entity\Attribute::class);
|
||||
$attribute->loadByCode(\Magento\Catalog\Model\Product::ENTITY, 'fixed_product_attribute');
|
||||
$attribute->delete();
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/** @var \Magento\Catalog\Setup\CategorySetup $installer */
|
||||
$installer = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Catalog\Setup\CategorySetup::class
|
||||
);
|
||||
$attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default');
|
||||
$entityModel = Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Entity::class);
|
||||
$entityTypeId = $entityModel->setType(Product::ENTITY)->getTypeId();
|
||||
$groupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
|
||||
|
||||
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
|
||||
$attribute = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
|
||||
);
|
||||
$attribute->setAttributeCode(
|
||||
'fpt_for_all'
|
||||
)->setEntityTypeId(
|
||||
$entityTypeId
|
||||
)->setAttributeGroupId(
|
||||
$groupId
|
||||
)->setAttributeSetId(
|
||||
$attributeSetId
|
||||
)->setFrontendLabel(
|
||||
'fpt_for_all_front_label'
|
||||
)->setFrontendInput(
|
||||
'weee'
|
||||
)->setIsUserDefined(
|
||||
1
|
||||
)->save();
|
||||
|
||||
/** @var Product $product */
|
||||
$product = Bootstrap::getObjectManager()->create(Product::class);
|
||||
$product->setTypeId(
|
||||
'simple'
|
||||
)->setAttributeSetId(
|
||||
$attributeSetId
|
||||
)->setStoreId(
|
||||
1
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->setStockData(
|
||||
['qty' => 100, 'is_in_stock' => 1, 'manage_stock' => 1]
|
||||
)->setName(
|
||||
'Simple Product FPT'
|
||||
)->setSku(
|
||||
'simple-with-ftp'
|
||||
)->setPrice(
|
||||
100
|
||||
)->setFptForAll(
|
||||
[['website_id' => 0, 'country' => 'US', 'state' => 0, 'price' => 12.70, 'delete' => '']]
|
||||
)->save();
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
|
||||
$product = $product->loadByAttribute('sku', 'simple-with-ftp');
|
||||
if ($product && $product->getId()) {
|
||||
$product->delete();
|
||||
}
|
||||
|
||||
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
|
||||
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
|
||||
$attribute->load('fpt_for_all', 'attribute_code');
|
||||
if ($attribute->getId()) {
|
||||
$attribute->delete();
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Weee/_files/product_with_fpt.php');
|
||||
|
||||
/** @var \Magento\Catalog\Setup\CategorySetup $installer */
|
||||
$installer = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Catalog\Setup\CategorySetup::class
|
||||
);
|
||||
$attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default');
|
||||
$entityModel = Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Entity::class);
|
||||
$entityTypeId = $entityModel->setType(Product::ENTITY)->getTypeId();
|
||||
$groupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
|
||||
|
||||
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
|
||||
$attribute = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
|
||||
);
|
||||
$attribute->setAttributeCode(
|
||||
'fixed_product_attribute'
|
||||
)->setEntityTypeId(
|
||||
$entityTypeId
|
||||
)->setAttributeGroupId(
|
||||
$groupId
|
||||
)->setAttributeSetId(
|
||||
$attributeSetId
|
||||
)->setFrontendLabel(
|
||||
'fixed_product_attribute_front_label'
|
||||
)->setFrontendInput(
|
||||
'weee'
|
||||
)->setIsUserDefined(
|
||||
1
|
||||
)->save();
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
|
||||
$product = $product->loadByAttribute('sku', 'simple-with-ftp');
|
||||
if ($product && $product->getId()) {
|
||||
$product->setFixedProductAttribute(
|
||||
[['website_id' => 0, 'country' => 'US', 'state' => 0, 'price' => 10.00, 'delete' => '']]
|
||||
)->save();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
|
||||
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
|
||||
$attribute->load('fixed_product_attribute', 'attribute_code');
|
||||
if ($attribute->getId()) {
|
||||
$attribute->delete();
|
||||
}
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Weee/_files/product_with_fpt_rollback.php');
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterface;
|
||||
use Magento\Quote\Api\Data\PaymentInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Address\Rate;
|
||||
use Magento\Quote\Model\Quote\Item;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
$store = $storeManager->getStore();
|
||||
/** @var Quote $quote */
|
||||
$quote = $quoteFactory->create();
|
||||
$quote->setReservedOrderId('multishipping_fpt_quote_id')
|
||||
->setCustomerEmail('customer001@test.com')
|
||||
->setStoreId($storeManager->getStore()->getId());
|
||||
|
||||
$shipping = [
|
||||
'firstname' => 'Jonh',
|
||||
'lastname' => 'Doe',
|
||||
'telephone' => '0333-233-221',
|
||||
'street' => ['Main Division 1'],
|
||||
'city' => 'Culver City',
|
||||
'region' => 'CA',
|
||||
'postcode' => 90800,
|
||||
'country_id' => 'US',
|
||||
'email' => 'customer001@shipping.test',
|
||||
'address_type' => 'shipping',
|
||||
];
|
||||
$methodCode = 'flatrate_flatrate';
|
||||
/** @var Rate $rate */
|
||||
$rate = $objectManager->create(Rate::class);
|
||||
$rate->setCode($methodCode)
|
||||
->setPrice(5.00);
|
||||
|
||||
$address = $objectManager->create(AddressInterface::class, ['data' => $shipping]);
|
||||
$address->setShippingMethod($methodCode)
|
||||
->addShippingRate($rate)
|
||||
->setShippingAmount(5.00)
|
||||
->setBaseShippingAmount(5.00);
|
||||
|
||||
$quote->addAddress($address);
|
||||
|
||||
/** @var AddressInterface $address */
|
||||
$address = $objectManager->create(
|
||||
AddressInterface::class,
|
||||
[
|
||||
'data' => [
|
||||
'firstname' => 'Jonh',
|
||||
'lastname' => 'Doe',
|
||||
'telephone' => '0333-233-221',
|
||||
'street' => ['Third Division 1'],
|
||||
'city' => 'New York',
|
||||
'region' => 'NY',
|
||||
'postcode' => 10029,
|
||||
'country_id' => 'US',
|
||||
'email' => 'customer001@billing.test',
|
||||
'address_type' => 'billing',
|
||||
],
|
||||
]
|
||||
);
|
||||
$quote->setBillingAddress($address);
|
||||
|
||||
$quote->setIsMultiShipping(1);
|
||||
$quoteRepository->save($quote);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Weee/_files/product_with_fpt.php');
|
||||
/** @var Product $product */
|
||||
$product = $productRepository->get('simple-with-ftp');
|
||||
|
||||
/** @var Item $item */
|
||||
$item = $objectManager->create(Item::class);
|
||||
$item->setProduct($product)
|
||||
->setPrice($product->getPrice())
|
||||
->setQty(2);
|
||||
$quote->addItem($item);
|
||||
$quoteRepository->save($quote);
|
||||
|
||||
$addressList = $quote->getAllShippingAddresses();
|
||||
$address = reset($addressList);
|
||||
$item->setQty(2);
|
||||
$address->setTotalQty(2);
|
||||
$address->addItem($item);
|
||||
$quoteRepository->save($quote);
|
||||
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'multishipping_fpt_quote_id', 'reserved_order_id');
|
||||
/** @var PaymentInterface $payment */
|
||||
$payment = $objectManager->create(PaymentInterface::class);
|
||||
$payment->setMethod('checkmo');
|
||||
$quote->setPayment($payment);
|
||||
$quote->collectTotals();
|
||||
$quoteRepository->save($quote);
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder
|
||||
->addFilter('reserved_order_id', 'multishipping_fpt_quote_id')
|
||||
->create();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
$quotesList = $quoteRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
if (!empty($quotesList)) {
|
||||
$quote = array_pop($quotesList);
|
||||
$quoteRepository->delete($quote);
|
||||
}
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Weee/_files/product_with_fpt_rollback.php');
|
||||
Reference in New Issue
Block a user