init
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Multishipping\Block\Checkout\Address;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class SelectTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Multishipping\Block\Checkout\Address\Select */
|
||||
protected $_selectBlock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_selectBlock = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Multishipping\Block\Checkout\Address\Select::class
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
*/
|
||||
public function testGetAddressAsHtml()
|
||||
{
|
||||
/** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */
|
||||
$addressRepository = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Api\AddressRepositoryInterface::class
|
||||
);
|
||||
$fixtureAddressId = 1;
|
||||
$address = $addressRepository->getById($fixtureAddressId);
|
||||
$addressAsHtml = $this->_selectBlock->getAddressAsHtml($address);
|
||||
$this->assertEquals(
|
||||
"John Smith<br />CompanyName<br />Green str, 67<br />CityM, Alabama, 75477"
|
||||
. "<br />United States<br />T: <a href=\"tel:3468676\">3468676</a>",
|
||||
str_replace("\n", '', $addressAsHtml),
|
||||
"Address was represented as HTML incorrectly"
|
||||
);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Multishipping\Block\Checkout;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class AddressesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const FIXTURE_CUSTOMER_ID = 1;
|
||||
|
||||
/**
|
||||
* @var \Magento\Multishipping\Block\Checkout\Addresses
|
||||
*/
|
||||
protected $_addresses;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $_objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Api\CustomerRepositoryInterface::class
|
||||
);
|
||||
$customerData = $customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
|
||||
|
||||
/** @var \Magento\Customer\Model\Session $customerSession */
|
||||
$customerSession = $this->_objectManager->get(\Magento\Customer\Model\Session::class);
|
||||
$customerSession->setCustomerData($customerData);
|
||||
|
||||
/** @var \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection */
|
||||
$quoteCollection = $this->_objectManager->get(\Magento\Quote\Model\ResourceModel\Quote\Collection::class);
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = $quoteCollection->getLastItem();
|
||||
|
||||
/** @var $checkoutSession \Magento\Checkout\Model\Session */
|
||||
$checkoutSession = $this->_objectManager->get(\Magento\Checkout\Model\Session::class);
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
$checkoutSession->setLoadInactive(true);
|
||||
|
||||
$this->_addresses = $this->_objectManager->create(
|
||||
\Magento\Multishipping\Block\Checkout\Addresses::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_product_and_payment.php
|
||||
*/
|
||||
public function testGetAddressOptions()
|
||||
{
|
||||
$expectedResult = [
|
||||
[
|
||||
'value' => '1',
|
||||
'label' => 'John Smith, Green str, 67, CityM, Alabama 75477, United States',
|
||||
],
|
||||
];
|
||||
|
||||
$addressAsHtml = $this->_addresses->getAddressOptions();
|
||||
$this->assertEquals($expectedResult, $addressAsHtml);
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Multishipping\Block\Checkout;
|
||||
|
||||
use Magento\Catalog\Model\ProductRepository;
|
||||
use Magento\Checkout\Block\Cart\Item\Renderer;
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\Element\RendererList;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Item;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Verify default items template
|
||||
*/
|
||||
class OverviewTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Overview
|
||||
*/
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Quote
|
||||
*/
|
||||
private $quote;
|
||||
|
||||
/**
|
||||
* @var ProductRepository
|
||||
*/
|
||||
private $product;
|
||||
|
||||
/**
|
||||
* @var Item
|
||||
*/
|
||||
private $item;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
Bootstrap::getInstance()->loadArea(Area::AREA_FRONTEND);
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->block = $this->objectManager->get(LayoutInterface::class)
|
||||
->createBlock(
|
||||
Overview::class,
|
||||
'checkout_overview',
|
||||
[
|
||||
'data' => [
|
||||
'renderer_template' => 'Magento_Multishipping::checkout/item/default.phtml',
|
||||
'row_renderer_template' => 'Magento_Multishipping::checkout/overview/item.phtml',
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$this->block->addChild('renderer.list', RendererList::class);
|
||||
$this->block->getChildBlock(
|
||||
'renderer.list'
|
||||
)->addChild(
|
||||
'default',
|
||||
Renderer::class,
|
||||
['template' => 'cart/item/default.phtml']
|
||||
);
|
||||
$this->quote = $this->objectManager->create(Quote::class);
|
||||
$this->product = $this->objectManager->create(ProductRepository::class);
|
||||
$this->item = $this->objectManager->create(Item::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
|
||||
*/
|
||||
public function testGetRowItemHtml()
|
||||
{
|
||||
$product = $this->product->get('simple');
|
||||
$item = $this->item->setProduct($product);
|
||||
$item->setQuote($this->quote);
|
||||
// assure that default renderer was obtained
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
'//*[contains(@class,"product") and contains(@class,"name")]/a',
|
||||
$this->block->getRowItemHtml($item)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/customer_quote_with_items_simple_product_options.php
|
||||
*/
|
||||
public function testLinkOptionalProductFileItemHtml()
|
||||
{
|
||||
$quote = $this->quote->load('customer_quote_product_custom_options', 'reserved_order_id');
|
||||
$item = current($quote->getAllItems());
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
'//dd/a[contains(text(), "test.jpg")]',
|
||||
$this->block->getRowItemHtml($item)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Multishipping\Controller\Checkout;
|
||||
|
||||
use Magento\Customer\Api\AccountManagementInterface;
|
||||
use Magento\Customer\Model\Session as CustomerSession;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Quote\Api\CartRepositoryInterface as QuoteRepository;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Test class for @see \Magento\Multishipping\Controller\Checkout\AddressesPost.
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class AddressesPostTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var QuoteRepository
|
||||
*/
|
||||
private $quoteRepository;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->quoteRepository = $this->_objectManager->get(QuoteRepository::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_address.php
|
||||
*/
|
||||
public function testExecute()
|
||||
{
|
||||
$quote = $this->getQuote('test_order_1');
|
||||
$this->setMultiShippingToQuote($quote);
|
||||
$quoteItems = $quote->getItems();
|
||||
$quoteItemId = array_shift($quoteItems)->getItemId();
|
||||
$this->loginCustomer();
|
||||
|
||||
$qty = 3;
|
||||
$productPrice = 10;
|
||||
$request = [
|
||||
'ship' => [
|
||||
1 => [
|
||||
$quoteItemId => [
|
||||
'qty' => $qty,
|
||||
'address' => 1,
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue($request);
|
||||
$this->dispatch('multishipping/checkout/addressesPost');
|
||||
$freshQuote = $this->getQuote('test_order_1');
|
||||
|
||||
$this->assertEquals($qty, $freshQuote->getItemsQty());
|
||||
$this->assertEquals($productPrice * $qty, $freshQuote->getGrandTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_address.php
|
||||
*/
|
||||
public function testExecuteFail()
|
||||
{
|
||||
$msg = 'Verify the shipping address information and continue.';
|
||||
|
||||
$quote = $this->getQuote('test_order_1');
|
||||
$this->setMultiShippingToQuote($quote);
|
||||
$quoteItems = $quote->getItems();
|
||||
$quoteItemId = array_shift($quoteItems)->getItemId();
|
||||
$this->loginCustomer();
|
||||
$request = [
|
||||
'ship' => [
|
||||
1 => [
|
||||
$quoteItemId => [
|
||||
'qty' => 1,
|
||||
'address' => $quoteItemId,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue($request);
|
||||
$this->dispatch('multishipping/checkout/addressesPost');
|
||||
|
||||
$this->assertSessionMessages($this->equalTo([$msg]), MessageInterface::TYPE_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CartInterface $quote
|
||||
* @return void
|
||||
*/
|
||||
private function setMultiShippingToQuote(CartInterface $quote): void
|
||||
{
|
||||
$quote->setIsMultiShipping(1);
|
||||
$this->quoteRepository->save($quote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticates customer and creates customer session.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function loginCustomer(): void
|
||||
{
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
/** @var AccountManagementInterface $service */
|
||||
$service = $this->_objectManager->create(AccountManagementInterface::class);
|
||||
try {
|
||||
$customer = $service->authenticate('customer@example.com', 'password');
|
||||
} catch (LocalizedException $e) {
|
||||
$this->fail($e->getMessage());
|
||||
}
|
||||
/** @var CustomerSession $customerSession */
|
||||
$customerSession = $this->_objectManager->get(CustomerSession::class, [$logger]);
|
||||
$customerSession->setCustomerDataAsLoggedIn($customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote by reserved order id.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return CartInterface
|
||||
*/
|
||||
private function getQuote(string $reservedOrderId): CartInterface
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->_objectManager->create(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId)->create();
|
||||
/** @var QuoteRepository $quoteRepository */
|
||||
$quoteRepository = $this->_objectManager->get(QuoteRepository::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
}
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Multishipping\Controller\Checkout;
|
||||
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Customer\Api\AccountManagementInterface;
|
||||
use Magento\Customer\Model\Session as CustomerSession;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Quote\Api\CartRepositoryInterface as QuoteRepository;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Multishipping\Controller\Checkout
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
class CheckItemsTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @var Quote
|
||||
*/
|
||||
private $quote;
|
||||
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
private $checkoutSession;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var Json
|
||||
*/
|
||||
private $json;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->checkoutSession = $this->_objectManager->get(Session::class);
|
||||
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->json = $this->_objectManager->get(Json::class);
|
||||
$this->quote = $this->getQuote('test01');
|
||||
$this->checkoutSession->setQuoteId($this->quote->getId());
|
||||
$this->checkoutSession->setCartWasUpdated(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validator of quote items.
|
||||
*
|
||||
* @param array $requestQuantity
|
||||
* @param array $expectedResponse
|
||||
*
|
||||
* @magentoConfigFixture current_store multishipping/options/checkout_multiple 1
|
||||
* @magentoConfigFixture current_store multishipping/options/checkout_multiple_maximum_qty 200
|
||||
* @dataProvider requestDataProvider
|
||||
*/
|
||||
public function testExecute($requestQuantity, $expectedResponse)
|
||||
{
|
||||
$this->loginCustomer();
|
||||
|
||||
try {
|
||||
/** @var $product Product */
|
||||
$product = $this->productRepository->get('simple');
|
||||
} catch (\Exception $e) {
|
||||
$this->fail('No such product entity');
|
||||
}
|
||||
|
||||
$quoteItem = $this->quote->getItemByProduct($product);
|
||||
$this->assertNotFalse($quoteItem, 'Cannot get quote item for simple product');
|
||||
|
||||
$request = [];
|
||||
if (!empty($requestQuantity) && is_array($requestQuantity)) {
|
||||
$request= [
|
||||
'ship' => [
|
||||
[$quoteItem->getId() => $requestQuantity],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$this->getRequest()->setPostValue($request);
|
||||
$this->dispatch('multishipping/checkout/checkItems');
|
||||
$response = $this->getResponse()->getBody();
|
||||
|
||||
$this->assertEquals($expectedResponse, $this->json->unserialize($response));
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticates customer and creates customer session.
|
||||
*/
|
||||
private function loginCustomer()
|
||||
{
|
||||
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
|
||||
/** @var AccountManagementInterface $service */
|
||||
$service = $this->_objectManager->create(AccountManagementInterface::class);
|
||||
try {
|
||||
$customer = $service->authenticate('customer@example.com', 'password');
|
||||
} catch (LocalizedException $e) {
|
||||
$this->fail($e->getMessage());
|
||||
}
|
||||
/** @var CustomerSession $customerSession */
|
||||
$customerSession = $this->_objectManager->create(CustomerSession::class, [$logger]);
|
||||
$customerSession->setCustomerDataAsLoggedIn($customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote by reserved order id.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return Quote
|
||||
*/
|
||||
private function getQuote($reservedOrderId)
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->_objectManager->create(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId)
|
||||
->create();
|
||||
/** @var QuoteRepository $quoteRepository */
|
||||
$quoteRepository = $this->_objectManager->get(QuoteRepository::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
return array_pop($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Variations of request data.
|
||||
* @returns array
|
||||
*/
|
||||
public function requestDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'request' => [],
|
||||
'response' => [
|
||||
'success' => false,
|
||||
'error_message' => 'We are unable to process your request. Please, try again later.'
|
||||
]
|
||||
],
|
||||
[
|
||||
'request' => ['qty' => 2],
|
||||
'response' => [
|
||||
'success' => true,
|
||||
]
|
||||
],
|
||||
[
|
||||
'request' => ['qty' => 101],
|
||||
'response' => [
|
||||
'success' => false,
|
||||
'error_message' => 'The requested qty is not available']
|
||||
],
|
||||
[
|
||||
'request' => ['qty' => 230],
|
||||
'response' => [
|
||||
'success' => false,
|
||||
'error_message' => 'Maximum qty allowed for Shipping to multiple addresses is 200']
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Multishipping\Controller;
|
||||
|
||||
use Magento\Multishipping\Model\Checkout\Type\Multishipping\State;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Multishipping\Controller\Checkout
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
class CheckoutTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Quote\Model\Quote
|
||||
*/
|
||||
protected $quote;
|
||||
|
||||
/**
|
||||
* @var \Magento\Checkout\Model\Session
|
||||
*/
|
||||
protected $checkoutSession;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->quote = $this->_objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$this->checkoutSession = $this->_objectManager->get(\Magento\Checkout\Model\Session::class);
|
||||
|
||||
$this->quote->load('test01', 'reserved_order_id');
|
||||
$this->checkoutSession->setQuoteId($this->quote->getId());
|
||||
$this->checkoutSession->setCartWasUpdated(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Covers \Magento\Multishipping\Block\Checkout\Payment\Info and \Magento\Multishipping\Block\Checkout\Overview
|
||||
*
|
||||
* @magentoConfigFixture current_store multishipping/options/checkout_multiple 1
|
||||
*/
|
||||
public function testOverviewAction()
|
||||
{
|
||||
/** @var \Magento\Framework\Data\Form\FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
|
||||
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
|
||||
/** @var \Magento\Customer\Api\AccountManagementInterface $service */
|
||||
$service = $this->_objectManager->create(\Magento\Customer\Api\AccountManagementInterface::class);
|
||||
$customer = $service->authenticate('customer@example.com', 'password');
|
||||
/** @var \Magento\Customer\Model\Session $customerSession */
|
||||
$customerSession = $this->_objectManager->create(\Magento\Customer\Model\Session::class, [$logger]);
|
||||
$customerSession->setCustomerDataAsLoggedIn($customer);
|
||||
$this->checkoutSession->setCheckoutState(State::STEP_BILLING);
|
||||
$this->getRequest()->setPostValue('payment', ['method' => 'checkmo']);
|
||||
$this->dispatch('multishipping/checkout/overview');
|
||||
$html = $this->getResponse()->getBody();
|
||||
$this->assertStringContainsString('<div class="box box-billing-method">', $html);
|
||||
$this->assertStringContainsString('<div class="box box-shipping-method">', $html);
|
||||
$this->assertStringContainsString(
|
||||
'<dt class="title">' . $this->quote->getPayment()->getMethodInstance()->getTitle() . '</dt>',
|
||||
$html
|
||||
);
|
||||
$this->assertStringContainsString('<span class="price">$10.00</span>', $html);
|
||||
$this->assertStringContainsString(
|
||||
'<input name="form_key" type="hidden" value="' . $formKey->getFormKey(),
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Quote\Api\Data\AddressInterface;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'multishipping_quote_id', 'reserved_order_id');
|
||||
|
||||
$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',
|
||||
];
|
||||
|
||||
/** @var AddressInterface $address */
|
||||
$address = $objectManager->create(AddressInterface::class, ['data' => $data]);
|
||||
$quote->setBillingAddress($address);
|
||||
$quoteResource->save($quote);
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote\Item;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
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);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'multishipping_quote_id', 'reserved_order_id');
|
||||
$productList = [];
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Multishipping/Fixtures/simple_product_10.php');
|
||||
$productList[] = $productRepository->get('simple_10');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Multishipping/Fixtures/simple_product_20.php');
|
||||
$productList[] = $productRepository->get('simple_20');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Multishipping/Fixtures/virtual_product_5.php');
|
||||
$productList[] = $productRepository->get('virtual_5');
|
||||
|
||||
foreach ($productList as $product) {
|
||||
/** @var Item $item */
|
||||
$item = $objectManager->create(Item::class);
|
||||
$item->setProduct($product)
|
||||
->setPrice($product->getPrice())
|
||||
->setQty(1);
|
||||
$quote->addItem($item);
|
||||
}
|
||||
$quoteResource->save($quote);
|
||||
@@ -0,0 +1,12 @@
|
||||
<?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/Multishipping/Fixtures/simple_product_10_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Multishipping/Fixtures/simple_product_20_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Multishipping/Fixtures/virtual_product_5_rollback.php');
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Model\Quote;
|
||||
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\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\PaymentInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterface;
|
||||
use Magento\Quote\Model\Quote\Address\Rate;
|
||||
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 = $objectManager->create(Quote::class);
|
||||
$quote->setReservedOrderId('multishipping_quote_id')
|
||||
->setCustomerEmail('customer001@test.com')
|
||||
->setStoreId($storeManager->getStore()->getId());
|
||||
|
||||
$addressList = [
|
||||
[
|
||||
'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',
|
||||
],
|
||||
[
|
||||
'firstname' => 'Antoni',
|
||||
'lastname' => 'Holmes',
|
||||
'telephone' => '0333-233-221',
|
||||
'street' => ['Second Division 2'],
|
||||
'city' => 'Denver',
|
||||
'region' => 'CO',
|
||||
'postcode' => 80203,
|
||||
'country_id' => 'US',
|
||||
'email' => 'customer002@shipping.test',
|
||||
'address_type' => 'shipping'
|
||||
]
|
||||
];
|
||||
$methodCode = 'flatrate_flatrate';
|
||||
foreach ($addressList as $data) {
|
||||
/** @var Rate $rate */
|
||||
$rate = $objectManager->create(Rate::class);
|
||||
$rate->setCode($methodCode)
|
||||
->setPrice(5.00);
|
||||
|
||||
$address = $objectManager->create(AddressInterface::class, ['data' => $data]);
|
||||
$address->setShippingMethod($methodCode)
|
||||
->addShippingRate($rate)
|
||||
->setShippingAmount(5.00)
|
||||
->setBaseShippingAmount(5.00);
|
||||
|
||||
$quote->addAddress($address);
|
||||
}
|
||||
$quote->setIsMultiShipping(1);
|
||||
$quoteRepository->save($quote);
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Multishipping/Fixtures/billing_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Multishipping/Fixtures/items.php');
|
||||
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'multishipping_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;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Multishipping/Fixtures/items_rollback.php');
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', 'multishipping_quote_id')
|
||||
->create();
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
if (!empty($items)) {
|
||||
$quote = array_pop($items);
|
||||
$quoteRepository->delete($quote);
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Eav\Model\Config;
|
||||
use Magento\Framework\DataObject;
|
||||
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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_products.php');
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple_10');
|
||||
$product->setStockData(['use_config_manage_stock' => 1, 'qty' => 4, 'is_qty_decimal' => 0, 'is_in_stock' => 1]);
|
||||
$productRepository->save($product);
|
||||
|
||||
/** @var Quote $quote */
|
||||
$quote = $objectManager->create(Quote::class);
|
||||
$request = $objectManager->create(DataObject::class);
|
||||
|
||||
/** @var Config $eavConfig */
|
||||
$eavConfig = $objectManager->get(Config::class);
|
||||
/** @var $attribute */
|
||||
$attribute = $eavConfig->getAttribute('catalog_product', 'test_configurable');
|
||||
|
||||
$request->setData(
|
||||
[
|
||||
'product_id' => $productRepository->get('configurable')->getId(),
|
||||
'selected_configurable_option' => '1',
|
||||
'super_attribute' => [
|
||||
$attribute->getAttributeId() => $attribute->getOptions()[1]->getValue()
|
||||
],
|
||||
'qty' => '2'
|
||||
]
|
||||
);
|
||||
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(
|
||||
true
|
||||
)->setIsMultiShipping(
|
||||
1
|
||||
)->setReservedOrderId(
|
||||
'test_order_with_configurable_product'
|
||||
)->setCustomerEmail(
|
||||
'store@example.com'
|
||||
)->addProduct(
|
||||
$productRepository->get('configurable'),
|
||||
$request
|
||||
);
|
||||
|
||||
/** @var PaymentInterface $payment */
|
||||
$payment = $objectManager->create(PaymentInterface::class);
|
||||
$payment->setMethod('checkmo');
|
||||
$quote->setPayment($payment);
|
||||
|
||||
$addressList = [
|
||||
[
|
||||
'firstname' => 'Jonh',
|
||||
'lastname' => 'Doe',
|
||||
'telephone' => '0333-233-221',
|
||||
'street' => ['Main Division 1'],
|
||||
'city' => 'Culver City',
|
||||
'region' => 'CA',
|
||||
'postcode' => 90800,
|
||||
'country_id' => 'US',
|
||||
'email' => 'store@example.com',
|
||||
'address_type' => 'shipping',
|
||||
],
|
||||
[
|
||||
'firstname' => 'Antoni',
|
||||
'lastname' => 'Holmes',
|
||||
'telephone' => '0333-233-221',
|
||||
'street' => ['Second Division 2'],
|
||||
'city' => 'Denver',
|
||||
'region' => 'CO',
|
||||
'postcode' => 80203,
|
||||
'country_id' => 'US',
|
||||
'email' => 'customer002@shipping.test',
|
||||
'address_type' => 'shipping'
|
||||
],
|
||||
];
|
||||
|
||||
$methodCode = 'flatrate_flatrate';
|
||||
foreach ($addressList as $data) {
|
||||
/** @var Rate $rate */
|
||||
$rate = $objectManager->create(Rate::class);
|
||||
$rate->setCode($methodCode)
|
||||
->setPrice(5.00);
|
||||
|
||||
$address = $objectManager->create(AddressInterface::class, ['data' => $data]);
|
||||
$address->setShippingMethod($methodCode)
|
||||
->addShippingRate($rate)
|
||||
->setShippingAmount(5.00)
|
||||
->setBaseShippingAmount(5.00);
|
||||
|
||||
$quote->addAddress($address);
|
||||
}
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
$quoteRepository->save($quote);
|
||||
|
||||
$items = $quote->getAllItems();
|
||||
|
||||
foreach ($quote->getAllShippingAddresses() as $address) {
|
||||
foreach ($items as $item) {
|
||||
$item->setQty(1);
|
||||
$address->setTotalQty(1);
|
||||
$address->addItem($item);
|
||||
}
|
||||
}
|
||||
|
||||
$billingAddressData = [
|
||||
'firstname' => 'Jonh',
|
||||
'lastname' => 'Doe',
|
||||
'telephone' => '0333-233-221',
|
||||
'street' => ['Third Division 1'],
|
||||
'city' => 'New York',
|
||||
'region' => 'NY',
|
||||
'postcode' => 10029,
|
||||
'country_id' => 'US',
|
||||
'email' => 'store@example.com',
|
||||
'address_type' => 'billing',
|
||||
];
|
||||
|
||||
/** @var AddressInterface $address */
|
||||
$billingAddress = $objectManager->create(AddressInterface::class, ['data' => $billingAddressData]);
|
||||
$quote->setBillingAddress($billingAddress);
|
||||
$quote->collectTotals();
|
||||
$quoteRepository->save($quote);
|
||||
|
||||
/** @var Session $session */
|
||||
$session = $objectManager->get(Session::class);
|
||||
$session->setQuoteId($quote->getId());
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Rollback for quote_with_configurable_product_last_variation.php fixture.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/** @var $objectManager ObjectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(Quote::class);
|
||||
$quote->load('test_order_with_configurable_product', 'reserved_order_id')->delete();
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Multishipping/Fixtures/quote.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = $objectManager->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = $objectManager->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'multishipping_quote_id', 'reserved_order_id');
|
||||
|
||||
$items = $quote->getAllItems();
|
||||
$addressList = $quote->getAllShippingAddresses();
|
||||
|
||||
foreach ($addressList as $key => $address) {
|
||||
$item = $items[$key];
|
||||
// set correct quantity per shipping address
|
||||
$item->setQty(1);
|
||||
$address->setTotalQty(1);
|
||||
$address->addItem($item);
|
||||
}
|
||||
|
||||
// assign virtual product to the billing address
|
||||
$billingAddress = $quote->getBillingAddress();
|
||||
$virtualItem = $items[count($items) - 1];
|
||||
$billingAddress->setTotalQty(1);
|
||||
$billingAddress->addItem($virtualItem);
|
||||
|
||||
// need to recollect totals
|
||||
$quote->setTotalsCollectedFlag(false);
|
||||
$quote->collectTotals();
|
||||
$quoteRepository->save($quote);
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\CatalogInventory\Api\Data\StockItemInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var Product $product */
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(Type::TYPE_SIMPLE)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Simple Product 10')
|
||||
->setSku('simple_10')
|
||||
->setPrice(10)
|
||||
->setWeight(1)
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED);
|
||||
|
||||
/** @var StockItemInterface $stockItem */
|
||||
$stockItem = $objectManager->create(StockItemInterface::class);
|
||||
$stockItem->setQty(100)
|
||||
->setIsInStock(true);
|
||||
$extensionAttributes = $product->getExtensionAttributes();
|
||||
$extensionAttributes->setStockItem($stockItem);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->save($product);
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->deleteById('simple_10');
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\CatalogInventory\Api\Data\StockItemInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var Product $product */
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(Type::TYPE_SIMPLE)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Simple Product 20')
|
||||
->setSku('simple_20')
|
||||
->setPrice(20)
|
||||
->setWeight(1)
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED);
|
||||
|
||||
/** @var StockItemInterface $stockItem */
|
||||
$stockItem = $objectManager->create(StockItemInterface::class);
|
||||
$stockItem->setQty(100)
|
||||
->setIsInStock(true);
|
||||
$extensionAttributes = $product->getExtensionAttributes();
|
||||
$extensionAttributes->setStockItem($stockItem);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->save($product);
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->deleteById('simple_20');
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\CatalogInventory\Api\Data\StockItemInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var Product $product */
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(Type::TYPE_VIRTUAL)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Virtual Product 5')
|
||||
->setSku('virtual_5')
|
||||
->setPrice(5)
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED);
|
||||
|
||||
/** @var StockItemInterface $stockItem */
|
||||
$stockItem = $objectManager->create(StockItemInterface::class);
|
||||
$stockItem->setQty(100)
|
||||
->setIsInStock(true);
|
||||
$extensionAttributes = $product->getExtensionAttributes();
|
||||
$extensionAttributes->setStockItem($stockItem);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->save($product);
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->deleteById('virtual_5');
|
||||
+515
@@ -0,0 +1,515 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Multishipping\Model\Checkout\Type;
|
||||
|
||||
use Magento\Checkout\Model\Session as CheckoutSession;
|
||||
use Magento\Customer\Api\AddressRepositoryInterface;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Session\SessionManagerInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Sales\Api\Data\OrderAddressInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
|
||||
use Magento\Sales\Model\Service\OrderService;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use \PHPUnit\Framework\MockObject\MockObject as MockObject;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class MultishippingTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const ADDRESS_TYPE_SHIPPING = 'shipping';
|
||||
|
||||
const ADDRESS_TYPE_BILLING = 'billing';
|
||||
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Multishipping
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var AddressRepositoryInterface
|
||||
*/
|
||||
private $addressRepository;
|
||||
|
||||
/**
|
||||
* @var CustomerRepositoryInterface
|
||||
*/
|
||||
private $customerRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->addressRepository = $this->objectManager->get(AddressRepositoryInterface::class);
|
||||
$this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
|
||||
$orderSender = $this->getMockBuilder(OrderSender::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->model = $this->objectManager->create(
|
||||
Multishipping::class,
|
||||
['orderSender' => $orderSender]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case when default billing and shipping addresses are set and they are different.
|
||||
*
|
||||
* @param string $addressType
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @dataProvider getCustomerDefaultAddressDataProvider
|
||||
*/
|
||||
public function testGetCustomerDefaultAddress($addressType)
|
||||
{
|
||||
/**
|
||||
* Preconditions:
|
||||
* - second address is default address of {$addressType},
|
||||
* - current customer is set to customer session
|
||||
*/
|
||||
$secondFixtureAddressId = 2;
|
||||
$secondFixtureAddressStreet = ['Black str, 48'];
|
||||
|
||||
$methodName = 'getCustomerDefault' . ucfirst($addressType) . 'Address';
|
||||
$setterMethodName = 'setDefault' . ucfirst($addressType);
|
||||
|
||||
$customer = $this->customerRepository->get('customer@example.com');
|
||||
$customer->$setterMethodName($secondFixtureAddressId);
|
||||
$this->customerRepository->save($customer);
|
||||
|
||||
/** @var Customer $customerModel */
|
||||
$customerModel = $this->objectManager->create(Customer::class);
|
||||
$customerModel->updateData($customer);
|
||||
/** @var Session $customerSession */
|
||||
$customerSession = $this->objectManager->get(Session::class);
|
||||
$customerSession->setCustomer($customerModel);
|
||||
|
||||
$addressId = $this->model->$methodName();
|
||||
$address = $this->addressRepository->getById($addressId);
|
||||
|
||||
self::assertEquals($secondFixtureAddressId, $address->getId(), "Invalid address loaded.");
|
||||
self::assertEquals(
|
||||
$secondFixtureAddressStreet,
|
||||
$address->getStreet(),
|
||||
"Street in default {$addressType} address is invalid."
|
||||
);
|
||||
|
||||
/** Ensure that results are cached properly by changing default address and invoking SUT once again */
|
||||
$firstFixtureAddressId = 1;
|
||||
$customer->$setterMethodName($firstFixtureAddressId);
|
||||
$this->customerRepository->save($customer);
|
||||
$addressId = $this->model->$methodName();
|
||||
|
||||
$address = $this->addressRepository->getById($addressId);
|
||||
|
||||
self::assertEquals(
|
||||
$secondFixtureAddressId,
|
||||
$address->getId(),
|
||||
"Method results are not cached properly."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case when customer has addresses, but default {$addressType} address is not set.
|
||||
*
|
||||
* @param string $addressType
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @dataProvider getCustomerDefaultAddressDataProvider
|
||||
*/
|
||||
public function testGetCustomerDefaultAddressDefaultAddressNotSet($addressType)
|
||||
{
|
||||
/**
|
||||
* Preconditions:
|
||||
* - customer has addresses, but default address of {$addressType} is not set
|
||||
* - current customer is set to customer session
|
||||
*/
|
||||
$firstFixtureAddressId = 1;
|
||||
$firstFixtureAddressStreet = ['Green str, 67'];
|
||||
$customer = $this->customerRepository->get('customer@example.com');
|
||||
$methodName = 'setDefault' . ucfirst($addressType);
|
||||
$customer->$methodName(null);
|
||||
$this->customerRepository->save($customer);
|
||||
|
||||
/** @var Customer $customerModel */
|
||||
$customerModel = $this->objectManager->create(Customer::class);
|
||||
$customerModel->updateData($customer);
|
||||
/** @var Session $customerSession */
|
||||
$customerSession = $this->objectManager->get(Session::class);
|
||||
$customerSession->setCustomer($customerModel);
|
||||
|
||||
$methodName = 'getCustomerDefault' . ucfirst($addressType) . 'Address';
|
||||
$addressId = $this->model->$methodName();
|
||||
$address = $this->addressRepository->getById($addressId);
|
||||
|
||||
self::assertEquals($firstFixtureAddressId, $address->getId(), "Invalid address loaded.");
|
||||
self::assertEquals(
|
||||
$firstFixtureAddressStreet,
|
||||
$address->getStreet(),
|
||||
"Street in default {$addressType} address is invalid."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case when customer has no addresses.
|
||||
*
|
||||
* @param string $addressType
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @dataProvider getCustomerDefaultAddressDataProvider
|
||||
*/
|
||||
public function testGetCustomerDefaultAddressCustomerWithoutAddresses($addressType)
|
||||
{
|
||||
/**
|
||||
* Preconditions:
|
||||
* - customer has no addresses
|
||||
* - current customer is set to customer session
|
||||
*/
|
||||
$customer = $this->customerRepository->get('customer@example.com');
|
||||
$customer->setDefaultShipping(null)
|
||||
->setDefaultBilling(null);
|
||||
$this->customerRepository->save($customer);
|
||||
|
||||
/** @var Customer $customerModel */
|
||||
$customerModel = $this->objectManager->create(Customer::class);
|
||||
$customerModel->updateData($customer);
|
||||
/** @var Session $customerSession */
|
||||
$customerSession = $this->objectManager->get(Session::class);
|
||||
$customerSession->setCustomer($customerModel);
|
||||
|
||||
$methodName = 'getCustomerDefault' . ucfirst($addressType) . 'Address';
|
||||
$address = $this->model->$methodName();
|
||||
|
||||
self::assertNull($address, "When customer has no addresses, null is expected.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerDefaultAddressDataProvider()
|
||||
{
|
||||
return [
|
||||
self::ADDRESS_TYPE_SHIPPING => [self::ADDRESS_TYPE_SHIPPING],
|
||||
self::ADDRESS_TYPE_BILLING => [self::ADDRESS_TYPE_BILLING],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when multiple orders with different shipping addresses are created successfully.
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Multishipping/Fixtures/quote_with_split_items.php
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateOrders()
|
||||
{
|
||||
$quote = $this->getQuote('multishipping_quote_id');
|
||||
/** @var CheckoutSession $session */
|
||||
$session = $this->objectManager->get(CheckoutSession::class);
|
||||
$session->replaceQuote($quote);
|
||||
|
||||
$this->model->createOrders();
|
||||
|
||||
$orderList = $this->getOrderList((int)$quote->getId());
|
||||
self::assertCount(3, $orderList);
|
||||
|
||||
/**
|
||||
* @var Order $firstOrder
|
||||
* The order with $10 simple product
|
||||
*/
|
||||
$firstOrder = array_shift($orderList);
|
||||
/**
|
||||
* @var Order $secondOrder
|
||||
* The order with $20 simple product
|
||||
*/
|
||||
$secondOrder = array_shift($orderList);
|
||||
/**
|
||||
* @var Order $thirdOrder
|
||||
* The order with $5 virtual product and billing address as shipping
|
||||
*/
|
||||
$thirdOrder = array_shift($orderList);
|
||||
|
||||
$this->performOrderAddressAssertions(
|
||||
$firstOrder->getShippingAddress(),
|
||||
[
|
||||
'street' => ['Main Division 1'],
|
||||
'city' => 'Culver City',
|
||||
'region' => 'California',
|
||||
'postcode' => 90800,
|
||||
]
|
||||
);
|
||||
$this->performOrderAddressAssertions(
|
||||
$secondOrder->getShippingAddress(),
|
||||
[
|
||||
'street' => ['Second Division 2'],
|
||||
'city' => 'Denver',
|
||||
'region' => 'Colorado',
|
||||
'postcode' => 80203,
|
||||
]
|
||||
);
|
||||
$this->performOrderAddressAssertions(
|
||||
$thirdOrder->getBillingAddress(),
|
||||
[
|
||||
'street' => ['Third Division 1'],
|
||||
'city' => 'New York',
|
||||
'region' => 'New York',
|
||||
'postcode' => 10029,
|
||||
]
|
||||
);
|
||||
|
||||
$this->performOrderTotalAssertions(
|
||||
$firstOrder->getBaseGrandTotal(),
|
||||
15.00
|
||||
);
|
||||
$this->performOrderTotalAssertions(
|
||||
$secondOrder->getBaseGrandTotal(),
|
||||
25.00
|
||||
);
|
||||
$this->performOrderTotalAssertions(
|
||||
$thirdOrder->getBaseGrandTotal(),
|
||||
5.00
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when some of multiple orders are failed to place.
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Multishipping/Fixtures/quote_with_split_items.php
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateOrdersWithSomeFailedOrders()
|
||||
{
|
||||
$quote = $this->getQuote('multishipping_quote_id');
|
||||
/** @var CheckoutSession $session */
|
||||
$checkoutSession = $this->objectManager->get(CheckoutSession::class);
|
||||
$checkoutSession->replaceQuote($quote);
|
||||
|
||||
$this->objectManager->addSharedInstance(
|
||||
$this->getOrderServiceMock(),
|
||||
OrderService::class
|
||||
);
|
||||
|
||||
$this->model->createOrders();
|
||||
$session = $this->objectManager->get(SessionManagerInterface::class);
|
||||
|
||||
// get address errors, stored in session
|
||||
$addressErrorsIds = array_keys($session->getAddressErrors());
|
||||
$shippingFailedAddressId = $addressErrorsIds[0];
|
||||
$billingFailedAddressId = $addressErrorsIds[1];
|
||||
|
||||
// successfully placed order shipping address has to be removed from quote
|
||||
$this->assertFalse(
|
||||
$this->findAddressInQuote(
|
||||
[
|
||||
'street' => ['Main Division 1'],
|
||||
'city' => 'Culver City',
|
||||
'region' => 'California',
|
||||
'postcode' => '90800',
|
||||
],
|
||||
$this->model->getQuote()
|
||||
),
|
||||
'This shipping address shouldn\'t be present in quote'
|
||||
);
|
||||
|
||||
// failed order shipping address has to remain in quote
|
||||
$this->assertTrue(
|
||||
$this->findAddressInQuote(
|
||||
[
|
||||
'id' => (string)$shippingFailedAddressId,
|
||||
'street' => ['Second Division 2'],
|
||||
'city' => 'Denver',
|
||||
'region' => 'Colorado',
|
||||
'postcode' => '80203',
|
||||
],
|
||||
$this->model->getQuote()
|
||||
),
|
||||
'This shipping address should be present in quote'
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->findAddressInQuote(
|
||||
[
|
||||
'id' => (string)$billingFailedAddressId,
|
||||
'street' => ['Third Division 1'],
|
||||
'city' => 'New York',
|
||||
'region' => 'New York',
|
||||
'postcode' => '10029',
|
||||
],
|
||||
$this->model->getQuote()
|
||||
),
|
||||
'Billing address should be present in quote'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check product parent item id in order item
|
||||
*
|
||||
* @magentoDataFixture Magento/Multishipping/Fixtures/quote_with_configurable_product.php
|
||||
*/
|
||||
public function testCreateOrdersWithConfigurableProduct()
|
||||
{
|
||||
$quote = $this->getQuote('test_order_with_configurable_product');
|
||||
/** @var CheckoutSession $session */
|
||||
$session = $this->objectManager->get(CheckoutSession::class);
|
||||
$session->replaceQuote($quote);
|
||||
|
||||
$this->model->createOrders();
|
||||
|
||||
$quoteItemParentIds = [];
|
||||
foreach ($quote->getAllItems() as $quoteItem) {
|
||||
$quoteItemParentIds[] = $quoteItem->getParentItemId();
|
||||
}
|
||||
|
||||
$orderList = $this->getOrderList((int)$quote->getId());
|
||||
$firstOrder = array_shift($orderList);
|
||||
$secondOrder = array_shift($orderList);
|
||||
|
||||
$firstOrderItemParentsIds = [];
|
||||
foreach ($firstOrder->getItems() as $orderItem) {
|
||||
$firstOrderItemParentsIds[] = $orderItem->getParentItemId();
|
||||
}
|
||||
$secondOrderItemParentsIds = [];
|
||||
foreach ($secondOrder->getItems() as $orderItem) {
|
||||
$secondOrderItemParentsIds[] = $orderItem->getParentItemId();
|
||||
}
|
||||
|
||||
$this->assertNotNull($firstOrderItemParentsIds[1]);
|
||||
$this->assertNotNull($secondOrderItemParentsIds[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order service mock with successful place on first call and exceptions on other calls.
|
||||
*
|
||||
* @return MockObject
|
||||
*/
|
||||
private function getOrderServiceMock(): MockObject
|
||||
{
|
||||
$orderService = $this->getMockBuilder(OrderService::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$exception = new \Exception('Place order error');
|
||||
$orderService->expects($this->exactly(3))
|
||||
->method('place')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$this->returnArgument(0),
|
||||
$this->throwException($exception),
|
||||
$this->throwException($exception)
|
||||
);
|
||||
|
||||
return $orderService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves quote by reserved order id.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return Quote
|
||||
*/
|
||||
private function getQuote(string $reservedOrderId): Quote
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId)
|
||||
->create();
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $this->objectManager->get(CartRepositoryInterface::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of orders by quote id.
|
||||
*
|
||||
* @param int $quoteId
|
||||
* @return array
|
||||
*/
|
||||
private function getOrderList(int $quoteId): array
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('quote_id', $quoteId)
|
||||
->create();
|
||||
|
||||
/** @var OrderRepositoryInterface $orderRepository */
|
||||
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
|
||||
return $orderRepository->getList($searchCriteria)->getItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs assertions for order address.
|
||||
*
|
||||
* @param OrderAddressInterface $address
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
private function performOrderAddressAssertions(OrderAddressInterface $address, array $expected)
|
||||
{
|
||||
foreach ($expected as $key => $item) {
|
||||
$methodName = 'get' . ucfirst($key);
|
||||
self::assertEquals($item, $address->$methodName(), 'The "'. $key . '" does not match.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search address in quote address array.
|
||||
*
|
||||
* @param array $searchAddress
|
||||
* @param Quote $quote
|
||||
* @return bool
|
||||
*/
|
||||
private function findAddressInQuote(array $searchAddress, Quote $quote)
|
||||
{
|
||||
$quoteAddresses = $quote->getAllShippingAddresses();
|
||||
if ($quote->hasVirtualItems()) {
|
||||
$quoteAddresses[] = $quote->getBillingAddress();
|
||||
}
|
||||
|
||||
foreach ($quoteAddresses as $quoteAddress) {
|
||||
$isFound = true;
|
||||
foreach ($searchAddress as $key => $item) {
|
||||
$methodName = 'get' . ucfirst($key);
|
||||
$isFound = $isFound ? $item === $quoteAddress->$methodName() : false;
|
||||
}
|
||||
if ($isFound) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform assertions for order total amount.
|
||||
*
|
||||
* @param float $total
|
||||
* @param float $expected
|
||||
* @return void
|
||||
*/
|
||||
private function performOrderTotalAssertions(float $total, float $expected)
|
||||
{
|
||||
self::assertEquals($expected, $total, 'Order total amount does not match.');
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Multishipping\Observer;
|
||||
|
||||
use Magento\Checkout\Model\Cart;
|
||||
use Magento\Checkout\Model\Session as CheckoutSession;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* 'Disable Multishipping' observer integration tests.
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class DisableMultishippingObserverTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Cart
|
||||
*/
|
||||
private $cart;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->cart = $this->objectManager->get(Cart::class);
|
||||
$this->prepareQuote();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that Quote totals are calculated correctly when Cart is saved with 'Multishipping' mode enabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testObserverWithEnabledMultishippingMode(): void
|
||||
{
|
||||
$quote = $this->cart->getQuote();
|
||||
$extensionAttributes = $quote->getExtensionAttributes();
|
||||
$this->assertEquals(1, (int)$quote->getItemsQty());
|
||||
$this->assertCount(1, $extensionAttributes->getShippingAssignments());
|
||||
|
||||
$quote->setIsMultiShipping(1);
|
||||
$quoteItem = current($quote->getItems());
|
||||
$itemData = [$quoteItem->getId() => ['qty' => 2]];
|
||||
|
||||
$this->cart->updateItems($itemData)->save();
|
||||
|
||||
$this->assertEquals(2, (int)$quote->getItemsQty());
|
||||
$this->assertEquals(0, $quote->getIsMultiShipping());
|
||||
$this->assertCount(0, $extensionAttributes->getShippingAssignments());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare Quote before test execution.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function prepareQuote(): void
|
||||
{
|
||||
/** @var CartInterface $quote */
|
||||
$quote = $this->objectManager->get(GetQuoteByReservedOrderId::class)
|
||||
->execute('test_order_with_simple_product_without_address');
|
||||
$shippingAssignment = $this->objectManager->get(ShippingAssignmentInterface::class);
|
||||
$quote->getExtensionAttributes()->setShippingAssignments([$shippingAssignment]);
|
||||
/** @var CheckoutSession $checkoutSession */
|
||||
$checkoutSession = $this->objectManager->get(CheckoutSession::class);
|
||||
$checkoutSession->clearQuote();
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Multishipping\Plugin;
|
||||
|
||||
use Magento\Checkout\Model\Cart;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* 'Disable Multishipping' plugin integration tests.
|
||||
*
|
||||
* @see DisableMultishippingMode
|
||||
*/
|
||||
class DisableMultishippingModeTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var Cart
|
||||
*/
|
||||
private $cart;
|
||||
|
||||
/**
|
||||
* @var FormKey
|
||||
*/
|
||||
private $formKey;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->cart = $this->_objectManager->get(Cart::class);
|
||||
$this->formKey = $this->_objectManager->get(FormKey::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that Quote totals are updated correctly when 'Multishipping' mode is enabled.
|
||||
*
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
* @return void
|
||||
*/
|
||||
public function testPluginWithEnabledMultishippingMode(): void
|
||||
{
|
||||
$quote = $this->cart->getQuote();
|
||||
$postData = [
|
||||
'qty' => '1',
|
||||
'product' => '1',
|
||||
];
|
||||
$this->getRequest()->setPostValue($postData)
|
||||
->setMethod(HttpRequest::METHOD_POST)
|
||||
->setParam('form_key', $this->formKey->getFormKey());
|
||||
|
||||
$this->dispatch('checkout/cart/add');
|
||||
$this->assertEquals(1, (int)$quote->getItemsQty());
|
||||
|
||||
$quote->setTotalsCollectedFlag(false)
|
||||
->setIsMultiShipping(true);
|
||||
|
||||
$this->dispatch('checkout/cart/add');
|
||||
$this->assertEquals(2, (int)$quote->getItemsQty());
|
||||
$this->assertEquals(0, $quote->getIsMultiShipping());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user