ltsecurityinc安防产品在线商城代码
This commit is contained in:
+182
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Api;
|
||||
|
||||
use Magento\Checkout\Api\Data\ShippingInformationInterface;
|
||||
use Magento\Checkout\Api\Data\ShippingInformationInterfaceFactory;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Exception\InputException;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Quote\Model\QuoteIdMask;
|
||||
use Magento\Quote\Model\QuoteIdMaskFactory;
|
||||
|
||||
/**
|
||||
* Test GuestShippingInformationManagement API.
|
||||
*/
|
||||
class GuestShippingInformationManagementTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var GuestShippingInformationManagementInterface
|
||||
*/
|
||||
private $management;
|
||||
|
||||
/**
|
||||
* @var CartRepositoryInterface
|
||||
*/
|
||||
private $cartRepo;
|
||||
|
||||
/**
|
||||
* @var CustomerRepositoryInterface
|
||||
*/
|
||||
private $customerRepo;
|
||||
|
||||
/**
|
||||
* @var ShippingInformationInterfaceFactory
|
||||
*/
|
||||
private $shippingFactory;
|
||||
|
||||
/**
|
||||
* @var SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteria;
|
||||
|
||||
/**
|
||||
* @var QuoteIdMaskFactory
|
||||
*/
|
||||
private $maskFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->management = $objectManager->get(GuestShippingInformationManagementInterface::class);
|
||||
$this->cartRepo = $objectManager->get(CartRepositoryInterface::class);
|
||||
$this->customerRepo = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
$this->shippingFactory = $objectManager->get(ShippingInformationInterfaceFactory::class);
|
||||
$this->searchCriteria = $objectManager->get(SearchCriteriaBuilder::class);
|
||||
$this->maskFactory = $objectManager->get(QuoteIdMaskFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test using another address for quote.
|
||||
*
|
||||
* @param bool $swapShipping Whether to swap shipping or billing addresses.
|
||||
* @return void
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_with_addresses.php
|
||||
* @dataProvider getAddressesVariation
|
||||
*/
|
||||
public function testDifferentAddresses(bool $swapShipping): void
|
||||
{
|
||||
$carts = $this->cartRepo->getList(
|
||||
$this->searchCriteria->addFilter('reserved_order_id', 'test01')->create()
|
||||
)->getItems();
|
||||
$cart = array_pop($carts);
|
||||
$otherCustomer = $this->customerRepo->get('customer_with_addresses@test.com');
|
||||
$otherAddresses = $otherCustomer->getAddresses();
|
||||
$otherAddress = array_pop($otherAddresses);
|
||||
|
||||
//Setting invalid IDs.
|
||||
/** @var ShippingAssignmentInterface $shippingAssignment */
|
||||
$shippingAssignment = $cart->getExtensionAttributes()->getShippingAssignments()[0];
|
||||
$shippingAddress = $shippingAssignment->getShipping()->getAddress();
|
||||
$billingAddress = $cart->getBillingAddress();
|
||||
if ($swapShipping) {
|
||||
$address = $shippingAddress;
|
||||
} else {
|
||||
$address = $billingAddress;
|
||||
}
|
||||
$address->setCustomerAddressId($otherAddress->getId());
|
||||
$address->setCustomerId($otherCustomer->getId());
|
||||
$address->setId(null);
|
||||
/** @var ShippingInformationInterface $shippingInformation */
|
||||
$shippingInformation = $this->shippingFactory->create();
|
||||
$shippingInformation->setBillingAddress($billingAddress);
|
||||
$shippingInformation->setShippingAddress($shippingAddress);
|
||||
$shippingInformation->setShippingMethodCode('flatrate');
|
||||
/** @var QuoteIdMask $idMask */
|
||||
$idMask = $this->maskFactory->create();
|
||||
$idMask->load($cart->getId(), 'quote_id');
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
sprintf(
|
||||
'The shipping information was unable to be saved. Error: "Invalid customer address id %s"',
|
||||
$address->getCustomerAddressId()
|
||||
)
|
||||
);
|
||||
$this->expectException(InputException::class);
|
||||
$this->management->saveAddressInformation($idMask->getMaskedId(), $shippingInformation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test save address information with customer custom address attribute for quote
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws LocalizedException
|
||||
* @throws NoSuchEntityException
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address_with_custom_text_attribute.php
|
||||
*/
|
||||
public function testSaveAddressInformationWithCustomerCustomAddressAttribute(): void
|
||||
{
|
||||
$carts = $this->cartRepo->getList(
|
||||
$this->searchCriteria->addFilter('reserved_order_id', 'test01')->create()
|
||||
)->getItems();
|
||||
$currentQuote = array_pop($carts);
|
||||
$guestCustomer = $this->customerRepo->get('JohnDoe@mail.com');
|
||||
|
||||
$customerCustomAddressAttribute = $guestCustomer->getCustomAttributes();
|
||||
|
||||
/** @var ShippingAssignmentInterface $shippingAssignment */
|
||||
$shippingAssignment = $currentQuote->getExtensionAttributes()->getShippingAssignments()[0];
|
||||
$shippingAddress = $shippingAssignment->getShipping()->getAddress();
|
||||
$billingAddress = $currentQuote->getBillingAddress();
|
||||
|
||||
if ($customerCustomAddressAttribute) {
|
||||
$shippingAddress->setCustomAttributes($customerCustomAddressAttribute);
|
||||
$billingAddress->setCustomAttributes($customerCustomAddressAttribute);
|
||||
}
|
||||
|
||||
/** @var ShippingInformationInterface $shippingInformation */
|
||||
$shippingInformation = $this->shippingFactory->create();
|
||||
$shippingInformation->setBillingAddress($billingAddress);
|
||||
$shippingInformation->setShippingAddress($shippingAddress);
|
||||
$shippingInformation->setShippingMethodCode('flatrate');
|
||||
$shippingInformation->setShippingCarrierCode('flatrate');
|
||||
/** @var QuoteIdMask $idMask */
|
||||
$idMask = $this->maskFactory->create();
|
||||
$idMask->load($currentQuote->getId(), 'quote_id');
|
||||
|
||||
$paymentDetails = $this->management->saveAddressInformation($idMask->getMaskedId(), $shippingInformation);
|
||||
$this->assertNotEmpty($paymentDetails);
|
||||
$this->assertEquals($currentQuote->getGrandTotal(), $paymentDetails->getTotals()->getSubtotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Different variations for addresses test.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressesVariation(): array
|
||||
{
|
||||
return [
|
||||
'Shipping address swap' => [true],
|
||||
'Billing address swap' => [false]
|
||||
];
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Api;
|
||||
|
||||
use Magento\Checkout\Api\Data\ShippingInformationInterface;
|
||||
use Magento\Checkout\Api\Data\ShippingInformationInterfaceFactory;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\Exception\InputException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test ShippingInformationManagement API.
|
||||
*/
|
||||
class ShippingInformationManagementTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ShippingInformationManagementInterface
|
||||
*/
|
||||
private $management;
|
||||
|
||||
/**
|
||||
* @var CartRepositoryInterface
|
||||
*/
|
||||
private $cartRepo;
|
||||
|
||||
/**
|
||||
* @var CustomerRepositoryInterface
|
||||
*/
|
||||
private $customerRepo;
|
||||
|
||||
/**
|
||||
* @var ShippingInformationInterfaceFactory
|
||||
*/
|
||||
private $shippingFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->management = $objectManager->get(ShippingInformationManagementInterface::class);
|
||||
$this->cartRepo = $objectManager->get(CartRepositoryInterface::class);
|
||||
$this->customerRepo = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
$this->shippingFactory = $objectManager->get(ShippingInformationInterfaceFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test using another address for quote.
|
||||
*
|
||||
* @param bool $swapShipping Whether to swap shipping or billing addresses.
|
||||
* @return void
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_with_addresses.php
|
||||
* @dataProvider getAddressesVariation
|
||||
*/
|
||||
public function testDifferentAddresses(bool $swapShipping): void
|
||||
{
|
||||
$cart = $this->cartRepo->getForCustomer(1);
|
||||
$otherCustomer = $this->customerRepo->get('customer_with_addresses@test.com');
|
||||
$otherAddresses = $otherCustomer->getAddresses();
|
||||
$otherAddress = array_pop($otherAddresses);
|
||||
|
||||
//Setting invalid IDs.
|
||||
/** @var ShippingAssignmentInterface $shippingAssignment */
|
||||
$shippingAssignment = $cart->getExtensionAttributes()->getShippingAssignments()[0];
|
||||
$shippingAddress = $shippingAssignment->getShipping()->getAddress();
|
||||
$billingAddress = $cart->getBillingAddress();
|
||||
if ($swapShipping) {
|
||||
$address = $shippingAddress;
|
||||
} else {
|
||||
$address = $billingAddress;
|
||||
}
|
||||
$address->setCustomerAddressId($otherAddress->getId());
|
||||
$address->setCustomerId($otherCustomer->getId());
|
||||
$address->setId(null);
|
||||
/** @var ShippingInformationInterface $shippingInformation */
|
||||
$shippingInformation = $this->shippingFactory->create();
|
||||
$shippingInformation->setBillingAddress($billingAddress);
|
||||
$shippingInformation->setShippingAddress($shippingAddress);
|
||||
$shippingInformation->setShippingMethodCode('flatrate');
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
sprintf(
|
||||
'The shipping information was unable to be saved. Error: "Invalid customer address id %s"',
|
||||
$address->getCustomerAddressId()
|
||||
)
|
||||
);
|
||||
$this->expectException(InputException::class);
|
||||
$this->management->saveAddressInformation($cart->getId(), $shippingInformation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Different variations for addresses test.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressesVariation(): array
|
||||
{
|
||||
return [
|
||||
'Shipping address swap' => [true],
|
||||
'Billing address swap' => [false]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Checkout\Block\Cart;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
|
||||
use Magento\CatalogInventory\Model\StockRegistryProvider;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class AbstractCartTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Tests that product in shopping cart remains visible even after it becomes out of stock.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
*/
|
||||
public function testProductsOutOfStockIsVisibleInShoppingCart()
|
||||
{
|
||||
$productSku = 'simple';
|
||||
$reservedOrderId = 'test01';
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get($productSku);
|
||||
|
||||
$this->setProductOutOfStock($product->getId());
|
||||
|
||||
$quote = $this->getStoredQuote($reservedOrderId);
|
||||
|
||||
$checkoutSession = $this->getMockBuilder(Session::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$checkoutSession->method('getQuote')->willReturn($quote);
|
||||
|
||||
$abstractCart = $objectManager->create(
|
||||
AbstractCart::class,
|
||||
['checkoutSession' => $checkoutSession]
|
||||
);
|
||||
|
||||
$items = array_filter(
|
||||
$abstractCart->getItems(),
|
||||
function (\Magento\Quote\Model\Quote\Item $item) use ($productSku) {
|
||||
return $item->getSku() === $productSku;
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertNotEmpty(
|
||||
$items,
|
||||
'Product disappeared from shopping cart after it had become out of stock.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @return void
|
||||
*/
|
||||
private function setProductOutOfStock($productId)
|
||||
{
|
||||
/** @var $stockRegistryProvider StockRegistryProvider */
|
||||
$stockRegistryProvider = Bootstrap::getObjectManager()->get(StockRegistryProvider::class);
|
||||
$stockItem = $stockRegistryProvider->getStockItem($productId, 0);
|
||||
$stockItem->setIsInStock(false);
|
||||
|
||||
/** @var $stockItemRepository StockItemRepositoryInterface */
|
||||
$stockItemRepository = Bootstrap::getObjectManager()->get(StockItemRepositoryInterface::class);
|
||||
$stockItemRepository->save($stockItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $reservedOrderId
|
||||
* @return \Magento\Quote\Api\Data\CartInterface
|
||||
*/
|
||||
private function getStoredQuote($reservedOrderId)
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId);
|
||||
|
||||
/** @var CartRepositoryInterface $cartRepository */
|
||||
$cartRepository = Bootstrap::getObjectManager()->create(CartRepositoryInterface::class);
|
||||
$quoteItems = $cartRepository->getList($searchCriteriaBuilder->create())->getItems();
|
||||
|
||||
return current($quoteItems);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Block\Cart;
|
||||
|
||||
use Magento\Catalog\Block\Product\ProductList\AbstractLinksTest;
|
||||
use Magento\Catalog\ViewModel\Product\Listing\PreparePostData;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\Store\ExecuteInStoreContext;
|
||||
|
||||
/**
|
||||
* Check the correct behavior of cross-sell products in the shopping cart
|
||||
*
|
||||
* @see \Magento\Checkout\Block\Cart\Crosssell
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class CrosssellTest extends AbstractLinksTest
|
||||
{
|
||||
private const MAX_ITEM_COUNT = 4;
|
||||
|
||||
/** @var Session */
|
||||
private $checkoutSession;
|
||||
|
||||
/** @var string */
|
||||
private $addToCartButtonXpath = "//div[contains(@class, 'actions-primary')]/button[@type='button']";
|
||||
|
||||
/** @var string */
|
||||
private $addToCartSubmitXpath = "//div[contains(@class, 'actions-primary')]"
|
||||
. "/form[@data-product-sku='%s']/button[@type='submit']";
|
||||
|
||||
/** @var string */
|
||||
private $addToLinksXpath = "//div[contains(@class, 'actions-secondary')]";
|
||||
|
||||
/** @var ExecuteInStoreContext */
|
||||
private $executeInStoreContext;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->block = $this->layout->createBlock(Crosssell::class);
|
||||
$this->linkType = 'crosssell';
|
||||
$this->titleName = (string)__('More Choices:');
|
||||
$this->checkoutSession = $this->objectManager->get(Session::class);
|
||||
$this->executeInStoreContext = $this->objectManager->get(ExecuteInStoreContext::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for a simple cross-sell product when block code is generated
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
* @return void
|
||||
*/
|
||||
public function testSimpleCrosssellProduct(): void
|
||||
{
|
||||
$relatedProduct = $this->productRepository->get('simple-1');
|
||||
$this->linkProducts('simple', ['simple-1' => ['position' => 2]]);
|
||||
$this->setCheckoutSessionQuote('test_order_with_simple_product_without_address');
|
||||
$this->prepareBlock();
|
||||
$html = $this->block->toHtml();
|
||||
|
||||
$this->assertNotEmpty($html);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(sprintf($this->titleXpath, $this->linkType, $this->titleName), $html),
|
||||
'Expected title is incorrect or missing!'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(sprintf($this->addToCartSubmitXpath, $relatedProduct->getSku()), $html),
|
||||
'Expected add to cart button is incorrect or missing!'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($this->addToLinksXpath, $html),
|
||||
'Expected add to links is incorrect or missing!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for a cross-sell product with required option when block code is generated
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_virtual_with_options.php
|
||||
* @return void
|
||||
*/
|
||||
public function testCrosssellProductWithRequiredOption(): void
|
||||
{
|
||||
$this->linkProducts('simple', ['virtual' => ['position' => 1]]);
|
||||
$this->setCheckoutSessionQuote('test_order_with_simple_product_without_address');
|
||||
$this->prepareBlock();
|
||||
$html = $this->block->toHtml();
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($this->addToCartButtonXpath, $html),
|
||||
'Expected add to cart button is incorrect or missing!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the display of cross-sell products in the block
|
||||
*
|
||||
* @dataProvider displayLinkedProductsProvider
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_list.php
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplayCrosssellProducts(array $data): void
|
||||
{
|
||||
$this->updateProducts($data['updateProducts']);
|
||||
$this->linkProducts('simple', $this->existingProducts);
|
||||
$items = $this->getBlockItems('test_order_with_simple_product_without_address');
|
||||
|
||||
$this->assertEquals(
|
||||
$data['expectedProductLinks'],
|
||||
$this->getActualLinks($items),
|
||||
'Expected cross-sell products do not match actual cross-sell products!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the position and max count of cross-sell products in the block
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_list.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @return void
|
||||
*/
|
||||
public function testPositionCrosssellProducts(): void
|
||||
{
|
||||
$positionData = array_merge_recursive(
|
||||
$this->getPositionData(),
|
||||
[
|
||||
'productLinks' => [
|
||||
'simple-1' => ['position' => 5],
|
||||
'simple2' => ['position' => 4],
|
||||
],
|
||||
'expectedProductLinks' => [
|
||||
'simple2',
|
||||
],
|
||||
]
|
||||
);
|
||||
$this->linkProducts('simple', $positionData['productLinks']);
|
||||
$items = $this->getBlockItems('test_order_with_simple_product_without_address');
|
||||
|
||||
$this->assertCount(
|
||||
self::MAX_ITEM_COUNT,
|
||||
$items,
|
||||
'Expected quantity of cross-sell products do not match the actual quantity!'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$positionData['expectedProductLinks'],
|
||||
$this->getActualLinks($items),
|
||||
'Expected cross-sell products do not match actual cross-sell products!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the position and max count of cross-sell products in the block
|
||||
* when set last added product in checkout session
|
||||
*
|
||||
* @dataProvider positionWithLastAddedProductProvider
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_list.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @param array $positionData
|
||||
* @param array $expectedProductLinks
|
||||
* @return void
|
||||
*/
|
||||
public function testPositionCrosssellProductsWithLastAddedProduct(
|
||||
array $positionData,
|
||||
array $expectedProductLinks
|
||||
): void {
|
||||
foreach ($positionData as $sku => $productLinks) {
|
||||
$this->linkProducts($sku, $productLinks);
|
||||
}
|
||||
$this->checkoutSession->setLastAddedProductId($this->productRepository->get('simple-tableRate-1')->getId());
|
||||
$items = $this->getBlockItems('tableRate');
|
||||
|
||||
$this->assertCount(
|
||||
self::MAX_ITEM_COUNT,
|
||||
$items,
|
||||
'Expected quantity of cross-sell products do not match the actual quantity!'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedProductLinks,
|
||||
$this->getActualLinks($items),
|
||||
'Expected cross-sell products do not match actual cross-sell products!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide test data to verify the position of linked products of the last added product.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function positionWithLastAddedProductProvider(): array
|
||||
{
|
||||
return [
|
||||
'less_four_linked_products_to_last_added_product' => [
|
||||
'positionData' => [
|
||||
'simple-tableRate-1' => [
|
||||
'simple-249' => ['position' => 2],
|
||||
'simple-156' => ['position' => 1],
|
||||
],
|
||||
'simple-tableRate-2' => [
|
||||
'simple-1' => ['position' => 2],
|
||||
'simple2' => ['position' => 1],
|
||||
'wrong-simple' => ['position' => 3],
|
||||
],
|
||||
],
|
||||
'expectedProductLinks' => [
|
||||
'simple-156',
|
||||
'simple-249',
|
||||
'simple2',
|
||||
'simple-1',
|
||||
],
|
||||
],
|
||||
'four_linked_products_to_last_added_product' => [
|
||||
'positionData' => [
|
||||
'simple-tableRate-1' => [
|
||||
'wrong-simple' => ['position' => 3],
|
||||
'simple-249' => ['position' => 1],
|
||||
'simple-156' => ['position' => 2],
|
||||
'simple2' => ['position' => 4],
|
||||
],
|
||||
'simple-tableRate-2' => [
|
||||
'simple-1' => ['position' => 1],
|
||||
],
|
||||
],
|
||||
'expectedProductLinks' => [
|
||||
'simple-249',
|
||||
'simple-156',
|
||||
'wrong-simple',
|
||||
'simple2',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the display of cross-sell products in the block on different websites
|
||||
*
|
||||
* @dataProvider multipleWebsitesLinkedProductsProvider
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_with_websites_and_stores.php
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_list.php
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function testMultipleWebsitesCrosssellProducts(array $data): void
|
||||
{
|
||||
$this->updateProducts($this->prepareProductsWebsiteIds());
|
||||
$productLinks = array_merge($this->existingProducts, $data['productLinks']);
|
||||
$this->linkProducts('simple-tableRate-1', $productLinks);
|
||||
$items = $this->executeInStoreContext->execute($data['storeCode'], [$this, 'getBlockItems'], 'tableRate');
|
||||
|
||||
$this->assertEquals(
|
||||
$data['expectedProductLinks'],
|
||||
$this->getActualLinks($items),
|
||||
'Expected cross-sell products do not match actual cross-sell products!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the invisibility of cross-sell products in the block which added to cart
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
* @return void
|
||||
*/
|
||||
public function testInvisibilityCrosssellProductAddedToCart(): void
|
||||
{
|
||||
$productLinks = [
|
||||
'simple-1' => ['position' => 1],
|
||||
'simple-tableRate-2' => ['position' => 2],
|
||||
];
|
||||
$this->linkProducts('simple-tableRate-1', $productLinks);
|
||||
$items = $this->getBlockItems('tableRate');
|
||||
|
||||
$this->assertEquals(
|
||||
['simple-1'],
|
||||
$this->getActualLinks($items),
|
||||
'Expected cross-sell products do not match actual cross-sell products!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get products of block when quote in checkout session
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return array
|
||||
*/
|
||||
public function getBlockItems(string $reservedOrderId): array
|
||||
{
|
||||
$this->setCheckoutSessionQuote($reservedOrderId);
|
||||
|
||||
return $this->block->getItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function prepareBlock(): void
|
||||
{
|
||||
parent::prepareBlock();
|
||||
|
||||
$this->block->setViewModel($this->objectManager->get(PreparePostData::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function prepareProductsWebsiteIds(): array
|
||||
{
|
||||
$productsWebsiteIds = parent::prepareProductsWebsiteIds();
|
||||
$simple = $productsWebsiteIds['simple-1'];
|
||||
unset($productsWebsiteIds['simple-1']);
|
||||
|
||||
return array_merge($productsWebsiteIds, ['simple-tableRate-1' => $simple]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set quoteId in checkoutSession object.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return void
|
||||
*/
|
||||
private function setCheckoutSessionQuote(string $reservedOrderId): void
|
||||
{
|
||||
$this->checkoutSession->clearQuote();
|
||||
$quote = $this->objectManager->get(GetQuoteByReservedOrderId::class)->execute($reservedOrderId);
|
||||
if ($quote !== null) {
|
||||
$this->checkoutSession->setQuoteId($quote->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Checkout\Block\Cart;
|
||||
|
||||
/**
|
||||
* Class GridTest
|
||||
* Test to verify default config value for
|
||||
* Store->Configuration->Sales->Checkout->Shopping Cart->Number of items to display pager
|
||||
*/
|
||||
class GridTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetDefaultConfig()
|
||||
{
|
||||
$configValue = 20;
|
||||
/** @var $scopeConfig \Magento\Framework\App\Config\ScopeConfigInterface */
|
||||
$scopeConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Config\ScopeConfigInterface::class
|
||||
);
|
||||
$defaultConfigValue = $scopeConfig->getValue(
|
||||
\Magento\Checkout\Block\Cart\Grid::XPATH_CONFIG_NUMBER_ITEMS_TO_DISPLAY_PAGER,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
$errorMessage = 'Default Config value for Store->Configuration->Sales->Checkout->Shopping Cart->'
|
||||
. 'Number of items to display pager shouold be ' . $configValue;
|
||||
$this->assertEquals($configValue, $defaultConfigValue, $errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Block\Cart\Item;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Item;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class RendererTest
|
||||
* @package Magento\Checkout\Block\Cart\Item
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class RendererTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $renderer;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public $productRepository;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->renderer = $this->objectManager->get(Renderer::class);
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote by reserved order id.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return Quote
|
||||
*/
|
||||
private function getQuote($reservedOrderId)
|
||||
{
|
||||
/** @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);
|
||||
|
||||
/** @var Quote[] $items */
|
||||
$items = $quoteRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
return $items[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets \Magento\Quote\Model\Quote\Item from \Magento\Quote\Model\Quote by product id
|
||||
*
|
||||
* @param Quote $quote
|
||||
* @param string|int $productId
|
||||
*
|
||||
* @return Item|null
|
||||
*/
|
||||
private function _getQuoteItemIdByProductId($quote, $productId)
|
||||
{
|
||||
/** @var $quoteItems Item[] */
|
||||
$quoteItems = $quote->getAllItems();
|
||||
foreach ($quoteItems as $quoteItem) {
|
||||
if ($productId == $quoteItem->getProductId()) {
|
||||
return $quoteItem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/cart_with_simple_product_and_custom_option_text_area.php
|
||||
*/
|
||||
public function testTextAreaCustomOption()
|
||||
{
|
||||
$quote = $this->getQuote('test_order_item_with_custom_option_text_area');
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $this->productRepository->get('simple_with_custom_option_text_area');
|
||||
|
||||
$quoteItem = $this->_getQuoteItemIdByProductId($quote, $product->getId());
|
||||
$this->assertNotNull($quoteItem, 'Cannot get quote item for simple product with custom option text area');
|
||||
|
||||
$template = 'Magento_Checkout::cart/item/default.phtml';
|
||||
$this->renderer->setTemplate($template);
|
||||
$this->renderer->setItem($quoteItem);
|
||||
|
||||
$priceBlock = $this->objectManager->create(\Magento\Checkout\Block\Item\Price\Renderer::class);
|
||||
$this->renderer->getLayout()->setBlock('checkout.item.price.unit', $priceBlock);
|
||||
$this->renderer->getLayout()->setBlock('checkout.item.price.row', $priceBlock);
|
||||
$html = $this->renderer->toHtml();
|
||||
|
||||
$this->assertMatchesRegularExpression(<<<EOT
|
||||
/Test product simple with
|
||||
custom option text area
|
||||
with more 50 characters/
|
||||
EOT
|
||||
, $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Checkout\Block\Cart
|
||||
*/
|
||||
namespace Magento\Checkout\Block;
|
||||
|
||||
class CartTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetMethods()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
$child = $layout->createBlock(
|
||||
\Magento\Framework\View\Element\Text::class
|
||||
)->setChild(
|
||||
'child1',
|
||||
$layout->createBlock(
|
||||
\Magento\Framework\View\Element\Text::class,
|
||||
'method1'
|
||||
)
|
||||
)->setChild(
|
||||
'child2',
|
||||
$layout->createBlock(
|
||||
\Magento\Framework\View\Element\Text::class,
|
||||
'method2'
|
||||
)
|
||||
);
|
||||
/** @var $block \Magento\Checkout\Block\Cart */
|
||||
$block = $layout->createBlock(\Magento\Checkout\Block\Cart::class)->setChild('child', $child);
|
||||
$methods = $block->getMethods('child');
|
||||
$this->assertEquals(['method1', 'method2'], $methods);
|
||||
}
|
||||
|
||||
public function testGetMethodsEmptyChild()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
$childEmpty = $layout->createBlock(\Magento\Framework\View\Element\Text::class);
|
||||
/** @var $block \Magento\Checkout\Block\Cart */
|
||||
$block = $layout->createBlock(\Magento\Checkout\Block\Cart::class)->setChild('child', $childEmpty);
|
||||
$methods = $block->getMethods('child');
|
||||
$this->assertEquals([], $methods);
|
||||
}
|
||||
|
||||
public function testGetMethodsNoChild()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Checkout\Block\Cart */
|
||||
$block = $layout->createBlock(\Magento\Checkout\Block\Cart::class);
|
||||
$methods = $block->getMethods('child');
|
||||
$this->assertEquals([], $methods);
|
||||
}
|
||||
|
||||
public function testGetPagerHtml()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Checkout\Block\Cart */
|
||||
$block = $layout->createBlock(\Magento\Checkout\Block\Cart::class);
|
||||
$pager = $block->getPagerHtml();
|
||||
$this->assertEquals('', $pager);
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Block\Checkout;
|
||||
|
||||
use Magento\Framework\App\Config\MutableScopeConfigInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LayoutProcessorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Tests default country for shipping address.
|
||||
*
|
||||
* @param string $defaultCountryId
|
||||
* @param bool $isCountryValueExpected
|
||||
* @magentoConfigFixture default_store checkout/options/display_billing_address_on 1
|
||||
* @magentoDataFixture Magento/Backend/_files/allowed_countries_fr.php
|
||||
* @dataProvider defaultCountryDataProvider
|
||||
*/
|
||||
public function testShippingAddressCountryId(string $defaultCountryId, bool $isCountryValueExpected): void
|
||||
{
|
||||
/** @var MutableScopeConfigInterface $mutableConfig */
|
||||
$mutableConfig = Bootstrap::getObjectManager()->get(MutableScopeConfigInterface::class);
|
||||
$mutableConfig->setValue('general/country/default', $defaultCountryId, ScopeInterface::SCOPE_STORE, 'default');
|
||||
|
||||
/** @var $layoutProcessor LayoutProcessor */
|
||||
$layoutProcessor = Bootstrap::getObjectManager()->get(LayoutProcessor::class);
|
||||
|
||||
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
|
||||
['children']['shippingAddress']['children']['shipping-address-fieldset']['children'] = [];
|
||||
$data = $layoutProcessor->process($jsLayout);
|
||||
|
||||
$countryId = $data["components"]["checkout"]["children"]["steps"]["children"]["shipping-step"]["children"]
|
||||
["shippingAddress"]["children"]["shipping-address-fieldset"]["children"]["country_id"];
|
||||
|
||||
$isCountryValueExists = array_key_exists('value', $countryId);
|
||||
|
||||
$this->assertEquals($isCountryValueExpected, $isCountryValueExists);
|
||||
if ($isCountryValueExpected) {
|
||||
$this->assertEquals($defaultCountryId, $countryId['value']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function defaultCountryDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'Default country isn\'t in allowed country list' => [
|
||||
'defaultCountryId' => 'US',
|
||||
'isCountryValueExpected' => false
|
||||
],
|
||||
'Default country is in allowed country list' => [
|
||||
'defaultCountryId' => 'FR',
|
||||
'isCountryValueExpected' => true
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Controller\Cart;
|
||||
|
||||
use Laminas\Stdlib\Parameters;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Checkout\Model\SessionFactory as CheckoutSessionFactory;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\Escaper;
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\TestFramework\Store\ExecuteInStoreContext;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* Class add product to cart controller.
|
||||
*
|
||||
* @see \Magento\Checkout\Controller\Cart\Add
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class AddTest extends AbstractController
|
||||
{
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var CheckoutSessionFactory */
|
||||
private $checkoutSessionFactory;
|
||||
|
||||
/** @var ProductRepositoryInterface */
|
||||
private $productRepository;
|
||||
|
||||
/** @var ExecuteInStoreContext */
|
||||
private $executeInStoreContext;
|
||||
|
||||
/** @var Escaper */
|
||||
private $escaper;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->json = $this->_objectManager->get(SerializerInterface::class);
|
||||
$this->checkoutSessionFactory = $this->_objectManager->get(CheckoutSessionFactory::class);
|
||||
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->productRepository->cleanCache();
|
||||
$this->executeInStoreContext = $this->_objectManager->get(ExecuteInStoreContext::class);
|
||||
$this->escaper = $this->_objectManager->get(Escaper::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with simple product and activated redirect to cart
|
||||
*
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
* @magentoConfigFixture current_store checkout/cart/redirect_to_cart 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMessageAtAddToCartWithRedirect(): void
|
||||
{
|
||||
$this->prepareReferer();
|
||||
$checkoutSession = $this->checkoutSessionFactory->create();
|
||||
$postData = [
|
||||
'qty' => '1',
|
||||
'product' => '1',
|
||||
'custom_price' => 1,
|
||||
'isAjax' => 1,
|
||||
];
|
||||
$this->dispatchAddToCartRequest($postData);
|
||||
$this->assertEquals(
|
||||
$this->json->serialize(['backUrl' => 'http://localhost/checkout/cart/']),
|
||||
$this->getResponse()->getBody()
|
||||
);
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual((string)__('You added %1 to your shopping cart.', 'Simple Product')),
|
||||
MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
$this->assertCount(1, $checkoutSession->getQuote()->getItemsCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with simple product and deactivated redirect to cart
|
||||
*
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
* @magentoConfigFixture current_store checkout/cart/redirect_to_cart 0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMessageAtAddToCartWithoutRedirect(): void
|
||||
{
|
||||
$this->prepareReferer();
|
||||
$checkoutSession = $this->checkoutSessionFactory->create();
|
||||
$postData = [
|
||||
'qty' => '1',
|
||||
'product' => '1',
|
||||
'custom_price' => 1,
|
||||
'isAjax' => 1,
|
||||
];
|
||||
$this->dispatchAddToCartRequest($postData);
|
||||
$this->assertFalse($this->getResponse()->isRedirect());
|
||||
$this->assertEquals('[]', $this->getResponse()->getBody());
|
||||
$message = (string)__(
|
||||
'You added %1 to your <a href="%2">shopping cart</a>.',
|
||||
'Simple Product',
|
||||
'http://localhost/checkout/cart/'
|
||||
);
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual("\n" . $message),
|
||||
MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
$this->assertCount(1, $checkoutSession->getQuote()->getItemsCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider wrongParamsDataProvider
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function testWithWrongParams(array $params): void
|
||||
{
|
||||
$this->prepareReferer();
|
||||
$this->dispatchAddToCartRequest($params);
|
||||
$this->assertRedirect($this->stringContains('http://localhost/test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function wrongParamsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty_params' => ['params' => []],
|
||||
'with_not_existing_product_id' => ['params' => ['product' => 989]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddProductFromUnavailableWebsite(): void
|
||||
{
|
||||
$this->prepareReferer();
|
||||
$product = $this->productRepository->get('simple-1');
|
||||
$postData = ['product' => $product->getId()];
|
||||
$this->executeInStoreContext->execute('fixture_second_store', [$this, 'dispatchAddToCartRequest'], $postData);
|
||||
$this->assertRedirect($this->stringContains('http://localhost/test'));
|
||||
$message = $this->escaper->escapeHtml(
|
||||
(string)__('The product wasn\'t found. Verify the product and try again.')
|
||||
);
|
||||
$this->assertSessionMessages($this->containsEqual($message), MessageInterface::TYPE_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddProductWithUnavailableQty(): void
|
||||
{
|
||||
$product = $this->productRepository->get('simple-1');
|
||||
$postData = ['product' => $product->getId(), 'qty' => '1000'];
|
||||
$this->dispatchAddToCartRequest($postData);
|
||||
$message = (string)__('The requested qty is not available');
|
||||
$this->assertSessionMessages($this->containsEqual($message), MessageInterface::TYPE_ERROR);
|
||||
$this->assertRedirect($this->stringContains($product->getProductUrl()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_related_multiple.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddProductWithRelated(): void
|
||||
{
|
||||
$this->prepareReferer();
|
||||
$checkoutSession = $this->checkoutSessionFactory->create();
|
||||
$product = $this->productRepository->get('simple_with_cross');
|
||||
$params = [
|
||||
'product' => $product->getId(),
|
||||
'related_product' => implode(',', $product->getRelatedProductIds()),
|
||||
];
|
||||
$this->dispatchAddToCartRequest($params);
|
||||
$this->assertCount(3, $checkoutSession->getQuote()->getItemsCollection());
|
||||
$message = (string)__(
|
||||
'You added %1 to your <a href="%2">shopping cart</a>.',
|
||||
$product->getName(),
|
||||
'http://localhost/checkout/cart/'
|
||||
);
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual("\n" . $message),
|
||||
MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch add product to cart request.
|
||||
*
|
||||
* @param array $postData
|
||||
* @return void
|
||||
*/
|
||||
public function dispatchAddToCartRequest(array $postData = []): void
|
||||
{
|
||||
$this->getRequest()->setPostValue($postData);
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->dispatch('checkout/cart/add');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare referer to test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function prepareReferer(): void
|
||||
{
|
||||
$parameters = $this->_objectManager->create(Parameters::class);
|
||||
$parameters->set('HTTP_REFERER', 'http://localhost/test');
|
||||
$this->getRequest()->setServer($parameters);
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Checkout\Controller\Cart\Index;
|
||||
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class CouponPostTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* Test for \Magento\Checkout\Controller\Cart\CouponPost::execute() with simple product
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
|
||||
*/
|
||||
public function testExecute()
|
||||
{
|
||||
/** @var $session \Magento\Checkout\Model\Session */
|
||||
$session = $this->_objectManager->create(\Magento\Checkout\Model\Session::class);
|
||||
$quote = $session->getQuote();
|
||||
$quote->setData('trigger_recollect', 1)->setTotalsCollectedFlag(true);
|
||||
$inputData = [
|
||||
'remove' => 0,
|
||||
'coupon_code' => 'test'
|
||||
];
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue($inputData);
|
||||
$this->dispatch(
|
||||
'checkout/cart/couponPost/'
|
||||
);
|
||||
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(['The coupon code "test" is not valid.']),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing by adding a valid coupon to cart
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
|
||||
* @magentoDataFixture Magento/Usps/Fixtures/cart_rule_coupon_free_shipping.php
|
||||
* @return void
|
||||
*/
|
||||
public function testAddingValidCoupon(): void
|
||||
{
|
||||
/** @var $session \Magento\Checkout\Model\Session */
|
||||
$session = $this->_objectManager->create(\Magento\Checkout\Model\Session::class);
|
||||
$quote = $session->getQuote();
|
||||
$quote->setData('trigger_recollect', 1)->setTotalsCollectedFlag(true);
|
||||
|
||||
$couponCode = 'IMPHBR852R61';
|
||||
$inputData = [
|
||||
'remove' => 0,
|
||||
'coupon_code' => $couponCode
|
||||
];
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue($inputData);
|
||||
$this->dispatch(
|
||||
'checkout/cart/couponPost/'
|
||||
);
|
||||
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(['You used coupon code "' . $couponCode . '".']),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Controller\Cart;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Checkout\Model\Session as CheckoutSession;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\Quote\Model\Quote\Item as QuoteItem;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* Integration tests for \Magento\Checkout\Controller\Cart\UpdateItemOptions class.
|
||||
*/
|
||||
class UpdateItemOptionsTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var FormKey
|
||||
*/
|
||||
private $formKey;
|
||||
|
||||
/**
|
||||
* @var CheckoutSession
|
||||
*/
|
||||
private $checkoutSession;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formKey = $this->_objectManager->get(FormKey::class);
|
||||
$this->checkoutSession = $this->_objectManager->get(CheckoutSession::class);
|
||||
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that product is successfully updated in the shopping cart.
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product.php
|
||||
*/
|
||||
public function testUpdateProductOptionsInQuote()
|
||||
{
|
||||
$product = $this->productRepository->get('simple');
|
||||
$quoteItem = $this->checkoutSession->getQuote()->getItemByProduct($product);
|
||||
$postData = $this->preparePostData($product, $quoteItem);
|
||||
$this->dispatchUpdateItemOptionsRequest($postData);
|
||||
$this->assertTrue($this->getResponse()->isRedirect());
|
||||
$this->assertRedirect($this->stringContains('/checkout/cart/'));
|
||||
$message = (string)__(
|
||||
'%1 was updated in your shopping cart.',
|
||||
$product->getName()
|
||||
);
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual($message),
|
||||
MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that product can't be updated with an empty shopping cart.
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product.php
|
||||
*/
|
||||
public function testUpdateProductOptionsWithEmptyQuote()
|
||||
{
|
||||
$product = $this->productRepository->get('simple');
|
||||
$quoteItem = $this->checkoutSession->getQuote()->getItemByProduct($product);
|
||||
$postData = $this->preparePostData($product, $quoteItem);
|
||||
$this->checkoutSession->clearQuote();
|
||||
$this->dispatchUpdateItemOptionsRequest($postData);
|
||||
$this->assertTrue($this->getResponse()->isRedirect());
|
||||
$this->assertRedirect($this->stringContains('/checkout/cart/'));
|
||||
$message = (string)__('The quote item isn't found. Verify the item and try again.');
|
||||
$this->assertSessionMessages(
|
||||
$this->containsEqual($message),
|
||||
MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare post data for the request.
|
||||
*
|
||||
* @param ProductInterface $product
|
||||
* @param QuoteItem|bool $quoteItem
|
||||
* @return array
|
||||
*/
|
||||
private function preparePostData(ProductInterface $product, $quoteItem): array
|
||||
{
|
||||
return [
|
||||
'product' => $product->getId(),
|
||||
'selected_configurable_option' => '',
|
||||
'related_product' => '',
|
||||
'item' => $quoteItem->getId(),
|
||||
'form_key' => $this->formKey->getFormKey(),
|
||||
'qty' => '2',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform request for updating product options in a quote item.
|
||||
*
|
||||
* @param array $postData
|
||||
* @return void
|
||||
*/
|
||||
private function dispatchUpdateItemOptionsRequest(array $postData): void
|
||||
{
|
||||
$this->getRequest()->setPostValue($postData);
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->dispatch('checkout/cart/updateItemOptions/id/' . $postData['item']);
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Controller\Cart;
|
||||
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
|
||||
class UpdateItemQtyTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @var Json
|
||||
*/
|
||||
private $json;
|
||||
|
||||
/**
|
||||
* @var FormKey
|
||||
*/
|
||||
private $formKey;
|
||||
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->json = $this->_objectManager->create(Json::class);
|
||||
$this->formKey = $this->_objectManager->get(FormKey::class);
|
||||
$this->session = $this->_objectManager->create(Session::class);
|
||||
$this->productRepository = $this->_objectManager->create(ProductRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests of cart validation.
|
||||
*
|
||||
* @param array $requestQuantity
|
||||
* @param array $expectedResponse
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product.php
|
||||
* @dataProvider requestDataProvider
|
||||
*/
|
||||
public function testExecute($requestQuantity, $expectedResponse)
|
||||
{
|
||||
try {
|
||||
/** @var $product Product */
|
||||
$product = $this->productRepository->get('simple');
|
||||
} catch (\Exception $e) {
|
||||
$this->fail('No such product entity');
|
||||
}
|
||||
|
||||
$quoteItem = $this->session
|
||||
->getQuote()
|
||||
->getItemByProduct($product);
|
||||
|
||||
$this->assertNotNull($quoteItem, 'Cannot get quote item for simple product');
|
||||
|
||||
$request = [];
|
||||
if (!empty($requestQuantity) && is_array($requestQuantity)) {
|
||||
$request= [
|
||||
'form_key' => $this->formKey->getFormKey(),
|
||||
'cart' => [
|
||||
$quoteItem->getId() => $requestQuantity,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue($request);
|
||||
$this->dispatch('checkout/cart/updateItemQty');
|
||||
$response = $this->getResponse()->getBody();
|
||||
|
||||
$this->assertEquals($this->getErrorMessage($response), $this->getErrorMessage($expectedResponse));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $response
|
||||
* @return string
|
||||
*/
|
||||
protected function getErrorMessage($response)
|
||||
{
|
||||
$error = '';
|
||||
try {
|
||||
$data = is_array($response) ? $response : $this->json->unserialize($response);
|
||||
$error = $this->json->unserialize($data['error_message'])[0]['error'];
|
||||
} catch (\Exception $e) {
|
||||
if (!empty($data['error_message'])) {
|
||||
$error = $data['error_message'];
|
||||
}
|
||||
}
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Variations of request data.
|
||||
* @returns array
|
||||
*/
|
||||
public function requestDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'request' => [],
|
||||
'response' => [
|
||||
'success' => false,
|
||||
'error_message' => 'Something went wrong while saving the page.'.
|
||||
' Please refresh the page and try again.'
|
||||
]
|
||||
],
|
||||
[
|
||||
'request' => ['qty' => 2],
|
||||
'response' => [
|
||||
'success' => true,
|
||||
]
|
||||
],
|
||||
[
|
||||
'request' => ['qty' => 230],
|
||||
'response' => [
|
||||
'success' => false,
|
||||
'error_message' => '[{"error":"The requested qty is not available","itemId":3}]']
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,450 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Checkout\Controller\Cart
|
||||
*/
|
||||
namespace Magento\Checkout\Controller;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Checkout\Model\Session as CheckoutSession;
|
||||
use Magento\Customer\Model\ResourceModel\CustomerRepository;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Request;
|
||||
use Magento\Customer\Model\Session as CustomerSession;
|
||||
use Magento\Sales\Model\ResourceModel\Order\Collection as OrderCollection;
|
||||
use Magento\Sales\Model\ResourceModel\Order\Item\Collection as OrderItemCollection;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class CartTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/** @var CheckoutSession */
|
||||
private $checkoutSession;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->checkoutSession = $this->_objectManager->get(CheckoutSession::class);
|
||||
$this->_objectManager->addSharedInstance($this->checkoutSession, CheckoutSession::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_objectManager->removeSharedInstance(CheckoutSession::class);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for \Magento\Checkout\Controller\Cart::configureAction() with simple product
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product.php
|
||||
*/
|
||||
public function testConfigureActionWithSimpleProduct()
|
||||
{
|
||||
/** @var $session CheckoutSession */
|
||||
$session = $this->_objectManager->create(CheckoutSession::class);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->_objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('simple');
|
||||
|
||||
$quoteItem = $this->_getQuoteItemIdByProductId($session->getQuote(), $product->getId());
|
||||
$this->assertNotNull($quoteItem, 'Cannot get quote item for simple product');
|
||||
|
||||
$this->dispatch(
|
||||
'checkout/cart/configure/id/' . $quoteItem->getId() . '/product_id/' . $quoteItem->getProduct()->getId()
|
||||
);
|
||||
$response = $this->getResponse();
|
||||
|
||||
$this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//button[@type="submit" and @title="Update Cart"]',
|
||||
$response->getBody()
|
||||
),
|
||||
'Response for simple product doesn\'t contain "Update Cart" button'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for \Magento\Checkout\Controller\Cart::configureAction() with simple product and custom option
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/cart_with_simple_product_and_custom_options.php
|
||||
*/
|
||||
public function testConfigureActionWithSimpleProductAndCustomOption()
|
||||
{
|
||||
/** @var Quote $quote */
|
||||
$quote = $this->getQuote('test_order_item_with_custom_options');
|
||||
$this->checkoutSession->setQuoteId($quote->getId());
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->_objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('simple_with_custom_options');
|
||||
|
||||
$quoteItem = $this->_getQuoteItemIdByProductId($quote, $product->getId());
|
||||
$this->assertNotNull($quoteItem, 'Cannot get quote item for simple product with custom option');
|
||||
|
||||
$this->dispatch(
|
||||
'checkout/cart/configure/id/' . $quoteItem->getId() . '/product_id/' . $quoteItem->getProduct()->getId()
|
||||
);
|
||||
$response = $this->getResponse();
|
||||
|
||||
$this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//button[@type="submit" and @title="Update Cart"]',
|
||||
$response->getBody()
|
||||
),
|
||||
'Response for simple product with custom option doesn\'t contain "Update Cart" button'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//input[contains(@class,"product-custom-option") and @type="text"]',
|
||||
$response->getBody()
|
||||
),
|
||||
'Response for simple product with custom option doesn\'t contain custom option input field'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for \Magento\Checkout\Controller\Cart::configureAction() with bundle product
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_bundle_product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testConfigureActionWithBundleProduct()
|
||||
{
|
||||
/** @var $session CheckoutSession */
|
||||
$session = $this->_objectManager->create(CheckoutSession::class);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->_objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('bundle-product');
|
||||
|
||||
$quoteItem = $this->_getQuoteItemIdByProductId($session->getQuote(), $product->getId());
|
||||
$this->assertNotNull($quoteItem, 'Cannot get quote item for bundle product');
|
||||
|
||||
$this->dispatch(
|
||||
'checkout/cart/configure/id/' . $quoteItem->getId() . '/product_id/' . $quoteItem->getProduct()->getId()
|
||||
);
|
||||
$response = $this->getResponse();
|
||||
|
||||
$this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//button[@type="submit" and @title="Update Cart"]',
|
||||
$response->getBody()
|
||||
),
|
||||
'Response for bundle product doesn\'t contain "Update Cart" button'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for \Magento\Checkout\Controller\Cart::configureAction() with downloadable product
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_downloadable_product.php
|
||||
*/
|
||||
public function testConfigureActionWithDownloadableProduct()
|
||||
{
|
||||
/** @var $session CheckoutSession */
|
||||
$session = $this->_objectManager->create(CheckoutSession::class);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->_objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('downloadable-product');
|
||||
|
||||
$quoteItem = $this->_getQuoteItemIdByProductId($session->getQuote(), $product->getId());
|
||||
$this->assertNotNull($quoteItem, 'Cannot get quote item for downloadable product');
|
||||
|
||||
$this->dispatch(
|
||||
'checkout/cart/configure/id/' . $quoteItem->getId() . '/product_id/' . $quoteItem->getProduct()->getId()
|
||||
);
|
||||
$response = $this->getResponse();
|
||||
|
||||
$this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//button[@type="submit" and @title="Update Cart"]',
|
||||
$response->getBody()
|
||||
),
|
||||
'Response for downloadable product doesn\'t contain "Update Cart" button'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id="downloadable-links-list"]',
|
||||
$response->getBody()
|
||||
),
|
||||
'Response for downloadable product doesn\'t contain links for download'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testUpdatePostAction()
|
||||
{
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->_objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('simple');
|
||||
|
||||
/** Preconditions */
|
||||
$customerFromFixture = 1;
|
||||
$productId = $product->getId();
|
||||
$originalQuantity = 1;
|
||||
$updatedQuantity = 2;
|
||||
/** @var $checkoutSession CheckoutSession */
|
||||
$checkoutSession = $this->_objectManager->create(CheckoutSession::class);
|
||||
$quoteItem = $this->_getQuoteItemIdByProductId($checkoutSession->getQuote(), $productId);
|
||||
|
||||
/** @var FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(FormKey::class);
|
||||
$postData = [
|
||||
'cart' => [$quoteItem->getId() => ['qty' => $updatedQuantity]],
|
||||
'update_cart_action' => 'update_qty',
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
];
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue($postData);
|
||||
/** @var $customerSession \Magento\Customer\Model\Session */
|
||||
$customerSession = $this->_objectManager->create(\Magento\Customer\Model\Session::class);
|
||||
$customerSession->setCustomerId($customerFromFixture);
|
||||
|
||||
$this->assertNotNull($quoteItem, 'Cannot get quote item for simple product');
|
||||
$this->assertEquals(
|
||||
$originalQuantity,
|
||||
$quoteItem->getQty(),
|
||||
"Precondition failed: invalid quote item quantity"
|
||||
);
|
||||
|
||||
/** Execute SUT */
|
||||
$this->dispatch('checkout/cart/updatePost');
|
||||
|
||||
/** Check results */
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $this->_objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load($checkoutSession->getQuote()->getId());
|
||||
$quoteItem = $this->_getQuoteItemIdByProductId($quote, $product->getId());
|
||||
$this->assertEquals($updatedQuantity, $quoteItem->getQty(), "Invalid quote item quantity");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote by reserved order id.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return Quote
|
||||
*/
|
||||
private function getQuote($reservedOrderId)
|
||||
{
|
||||
/** @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets \Magento\Quote\Model\Quote\Item from \Magento\Quote\Model\Quote by product id
|
||||
*
|
||||
* @param \Magento\Quote\Model\Quote $quote
|
||||
* @param string|int $productId
|
||||
*
|
||||
* @return \Magento\Quote\Model\Quote\Item|null
|
||||
*/
|
||||
private function _getQuoteItemIdByProductId($quote, $productId)
|
||||
{
|
||||
/** @var $quoteItems \Magento\Quote\Model\Quote\Item[] */
|
||||
$quoteItems = $quote->getAllItems();
|
||||
foreach ($quoteItems as $quoteItem) {
|
||||
if ($productId == $quoteItem->getProductId()) {
|
||||
return $quoteItem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for \Magento\Checkout\Controller\Cart::execute() with simple product
|
||||
*
|
||||
* @param string $area
|
||||
* @param string $expectedPrice
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @dataProvider addAddProductDataProvider
|
||||
*/
|
||||
public function testAddToCartSimpleProduct($area, $expectedPrice)
|
||||
{
|
||||
$formKey = $this->_objectManager->get(FormKey::class);
|
||||
$postData = [
|
||||
'qty' => '1',
|
||||
'product' => '1',
|
||||
'custom_price' => 1,
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
'isAjax' => 1
|
||||
];
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea($area);
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setPostValue($postData);
|
||||
|
||||
$quote = $this->_objectManager->create(\Magento\Checkout\Model\Cart::class);
|
||||
/** @var \Magento\Checkout\Controller\Cart\Add $controller */
|
||||
$controller = $this->_objectManager->create(\Magento\Checkout\Controller\Cart\Add::class, [$quote]);
|
||||
$controller->execute();
|
||||
|
||||
$this->assertStringContainsString(json_encode([]), $this->getResponse()->getBody());
|
||||
$items = $quote->getItems()->getItems();
|
||||
$this->assertIsArray($items, 'Quote doesn\'t have any items');
|
||||
$this->assertCount(1, $items, 'Expected quote items not equal to 1');
|
||||
$item = reset($items);
|
||||
$this->assertEquals(1, $item->getProductId(), 'Quote has more than one product');
|
||||
$this->assertEquals($expectedPrice, $item->getPrice(), 'Expected product price failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testAddToCartSimpleProduct
|
||||
*/
|
||||
public function addAddProductDataProvider()
|
||||
{
|
||||
return [
|
||||
'frontend' => ['frontend', 'expected_price' => 10],
|
||||
'adminhtml' => ['adminhtml', 'expected_price' => 1]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Checkout\Controller\Cart\Addgroup::execute()
|
||||
*
|
||||
* Test customer can add items to cart only if they belong to him.
|
||||
*
|
||||
* @param bool $loggedIn
|
||||
* @param string $request
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDataFixture Magento/Checkout/_files/order_items.php
|
||||
* @dataProvider reorderItemsDataProvider
|
||||
* @return void
|
||||
*/
|
||||
public function testReorderItems(bool $loggedIn, string $request)
|
||||
{
|
||||
// Make sure test starts without logged in customer.
|
||||
$customerSession = $this->_objectManager->get(CustomerSession::class);
|
||||
$customerSession->logout();
|
||||
|
||||
$checkoutSession = Bootstrap::getObjectManager()->get(Session::class);
|
||||
$expected = [];
|
||||
if ($loggedIn && $request == Request::METHOD_POST) {
|
||||
$customer = $this->_objectManager->create(CustomerRepository::class)->get('customer2@example.com');
|
||||
$customerSession->setCustomerDataObject($customer);
|
||||
$orderCollection = $this->_objectManager->create(OrderCollection::class);
|
||||
$orderCollection->addFieldToFilter('customer_id', $customer->getId());
|
||||
$orderItemCollection = $this->_objectManager->create(OrderItemCollection::class);
|
||||
$orderItemCollection->addFieldToFilter('order_id', ['in' => $orderCollection->getAllIds()]);
|
||||
$expected = $orderItemCollection->getColumnValues('product_id');
|
||||
}
|
||||
$this->prepareRequest($request);
|
||||
$this->dispatch('checkout/cart/addGroup');
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$checkoutSession->getQuote()->getItemsCollection()->getColumnValues('product_id')
|
||||
);
|
||||
|
||||
// Make sure test doesn't left logged in customer after execution.
|
||||
$customerSession->logout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testReorderItems.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function reorderItemsDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'logged_in' => false,
|
||||
'request_type' => Request::METHOD_POST,
|
||||
],
|
||||
[
|
||||
'logged_in' => false,
|
||||
'request_type' => Request::METHOD_GET,
|
||||
],
|
||||
[
|
||||
'logged_in' => true,
|
||||
'request_type' => Request::METHOD_POST,
|
||||
],
|
||||
[
|
||||
'logged_in' => true,
|
||||
'request_type' => Request::METHOD_GET,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare request for testReorderItems.
|
||||
*
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
private function prepareRequest(string $method)
|
||||
{
|
||||
/** @var OrderItemCollection $orderItems */
|
||||
$orderItems = $this->_objectManager->create(OrderItemCollection::class);
|
||||
/** @var FormKey $key */
|
||||
$key = $this->_objectManager->get(FormKey::class);
|
||||
$data = [
|
||||
'form_key' => $key->getFormKey(),
|
||||
'order_items' => $orderItems->getAllIds(),
|
||||
];
|
||||
$this->getRequest()->setMethod($method);
|
||||
switch ($method) {
|
||||
case Request::METHOD_POST:
|
||||
$this->getRequest()->setPostValue($data);
|
||||
break;
|
||||
case Request::METHOD_GET:
|
||||
default:
|
||||
$this->getRequest()->setParams($data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Model;
|
||||
|
||||
use Magento\Captcha\Model\DefaultModel;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Captcha\Helper\Data as CaptchaHelper;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\Customer\Model\Session as CustomerSession;
|
||||
|
||||
/**
|
||||
* Test CAPTCHA-based rate limiter.
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class CaptchaRateLimiterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var CaptchaRateLimiter
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var CaptchaHelper
|
||||
*/
|
||||
private $captchaHelper;
|
||||
|
||||
/**
|
||||
* @var HttpRequest;
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var CustomerSession
|
||||
*/
|
||||
private $customerSession;
|
||||
|
||||
/**
|
||||
* @var CustomerRepositoryInterface
|
||||
*/
|
||||
private $customerRepo;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->request = $objectManager->get(RequestInterface::class);
|
||||
$this->request->getServer()->set('REMOTE_ADDR', '127.0.0.1');
|
||||
$objectManager->removeSharedInstance(RemoteAddress::class);
|
||||
$this->captchaHelper = $objectManager->get(CaptchaHelper::class);
|
||||
$this->customerSession = $objectManager->get(CustomerSession::class);
|
||||
$this->customerRepo = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
$this->model = $objectManager->create(
|
||||
CaptchaRateLimiter::class,
|
||||
['captchaId' => 'payment_processing_request']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that limits work for logged-in customers.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*
|
||||
* @magentoConfigFixture default_store customer/captcha/enable 1
|
||||
* @magentoConfigFixture default_store customer/captcha/forms payment_processing_request
|
||||
* @magentoConfigFixture default_store customer/captcha/failed_attempts_login 2
|
||||
* @magentoConfigFixture default_store customer/captcha/failed_attempts_ip 10
|
||||
*/
|
||||
public function testLoggedInLimits(): void
|
||||
{
|
||||
//Logging in
|
||||
$customer = $this->customerRepo->get('customer@example.com');
|
||||
$this->customerSession->loginById($customer->getId());
|
||||
|
||||
$this->model->limit();
|
||||
$this->model->limit();
|
||||
try {
|
||||
$this->model->limit();
|
||||
$limited = false;
|
||||
} catch (LocalizedException $exception) {
|
||||
$limited = true;
|
||||
}
|
||||
$this->assertTrue($limited);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that limits work for guest.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @magentoConfigFixture default_store customer/captcha/enable 1
|
||||
* @magentoConfigFixture default_store customer/captcha/forms payment_processing_request
|
||||
* @magentoConfigFixture default_store customer/captcha/failed_attempts_login 10
|
||||
* @magentoConfigFixture default_store customer/captcha/failed_attempts_ip 2
|
||||
*/
|
||||
public function testGuestLimits(): void
|
||||
{
|
||||
$this->model->limit();
|
||||
$this->model->limit();
|
||||
try {
|
||||
$this->model->limit();
|
||||
$limited = false;
|
||||
} catch (LocalizedException $exception) {
|
||||
$limited = true;
|
||||
}
|
||||
$this->assertTrue($limited);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that CAPTCHA is validated.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @magentoConfigFixture default_store customer/captcha/enable 1
|
||||
* @magentoConfigFixture default_store customer/captcha/forms payment_processing_request
|
||||
* @magentoConfigFixture default_store customer/captcha/failed_attempts_login 10
|
||||
* @magentoConfigFixture default_store customer/captcha/failed_attempts_ip 2
|
||||
*/
|
||||
public function testCaptchaValidation(): void
|
||||
{
|
||||
$this->model->limit();
|
||||
$this->model->limit();
|
||||
try {
|
||||
$this->model->limit();
|
||||
$limited = false;
|
||||
} catch (LocalizedException $exception) {
|
||||
$limited = true;
|
||||
}
|
||||
//CAPTCHA is required
|
||||
$this->assertTrue($limited);
|
||||
|
||||
//Providing CAPTCHA value
|
||||
/** @var DefaultModel $captcha */
|
||||
$captcha = $this->captchaHelper->getCaptcha(CaptchaPaymentProcessingRateLimiter::CAPTCHA_FORM);
|
||||
$captcha->generate();
|
||||
$this->request->setPostValue(
|
||||
'captcha',
|
||||
[CaptchaPaymentProcessingRateLimiter::CAPTCHA_FORM => $captcha->getWord()]
|
||||
);
|
||||
$this->model->limit();
|
||||
//Providing CAPTCHA value in a header
|
||||
/** @var DefaultModel $captcha */
|
||||
$captcha = $this->captchaHelper->getCaptcha(CaptchaPaymentProcessingRateLimiter::CAPTCHA_FORM);
|
||||
$captcha->generate();
|
||||
$this->request->setPostValue(
|
||||
'captcha',
|
||||
[CaptchaPaymentProcessingRateLimiter::CAPTCHA_FORM => '']
|
||||
);
|
||||
$this->request->getHeaders()->addHeaderLine('X-Captcha', $captcha->getWord());
|
||||
$this->model->limit();
|
||||
|
||||
//Providing invalid CAPTCHA value.
|
||||
$this->request->setPostValue(
|
||||
'captcha',
|
||||
[CaptchaPaymentProcessingRateLimiter::CAPTCHA_FORM => 'invalid']
|
||||
);
|
||||
$this->request->getHeaders()->removeHeader($this->request->getHeaders()->get('X-Captcha'));
|
||||
try {
|
||||
$this->model->limit();
|
||||
$limited = false;
|
||||
} catch (LocalizedException $exception) {
|
||||
$limited = true;
|
||||
}
|
||||
//CAPTCHA was validated
|
||||
$this->assertTrue($limited);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Model;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Checkout\Model\Session as CheckoutSession;
|
||||
use Magento\Checkout\Model\SessionFactory as CheckoutSessionFactory;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Store\ExecuteInStoreContext;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for checkout cart model.
|
||||
*
|
||||
* @see \Magento\Checkout\Model\Cart
|
||||
* @magentoDbIsolation enabled
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class CartTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var CartFactory */
|
||||
private $cartFactory;
|
||||
|
||||
/** @var ProductInterfaceFactory */
|
||||
private $productFactory;
|
||||
|
||||
/** @var ProductRepositoryInterface */
|
||||
private $productRepository;
|
||||
|
||||
/** @var ExecuteInStoreContext */
|
||||
private $executeInStoreContext;
|
||||
|
||||
/** @var CheckoutSession */
|
||||
private $checkoutSession;
|
||||
|
||||
/** @var CartInterface */
|
||||
private $quote;
|
||||
|
||||
/** @var CartRepositoryInterface */
|
||||
private $quoteRepository;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->cartFactory = $this->objectManager->get(CartFactory::class);
|
||||
$this->productFactory = $this->objectManager->get(ProductInterfaceFactory::class);
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->productRepository->cleanCache();
|
||||
$this->executeInStoreContext = $this->objectManager->get(ExecuteInStoreContext::class);
|
||||
$this->checkoutSession = $this->objectManager->get(CheckoutSessionFactory::class)->create();
|
||||
$this->quoteRepository = $this->objectManager->get(CartRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if ($this->quote instanceof CartInterface) {
|
||||
$this->quoteRepository->delete($this->quote);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/set_product_min_in_cart.php
|
||||
* @magentoAppIsolation enabled
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddProductWithLowerQty(): void
|
||||
{
|
||||
$cart = $this->cartFactory->create();
|
||||
$this->expectException(LocalizedException::class);
|
||||
$this->expectExceptionMessage((string)__('The fewest you may purchase is %1', 3));
|
||||
$product = $this->productRepository->get('simple');
|
||||
$cart->addProduct($product->getId(), ['qty' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/set_product_min_in_cart.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddProductWithNoQty(): void
|
||||
{
|
||||
$cart = $this->cartFactory->create();
|
||||
$product = $this->productRepository->get('simple');
|
||||
$cart->addProduct($product->getId(), [])->save();
|
||||
$this->quote = $cart->getQuote();
|
||||
$this->assertCount(1, $cart->getItems());
|
||||
$this->assertEquals($product->getId(), $this->checkoutSession->getLastAddedProductId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddNotExistingProduct(): void
|
||||
{
|
||||
$product = $this->productFactory->create();
|
||||
$this->expectExceptionObject(
|
||||
new LocalizedException(__('The product wasn\'t found. Verify the product and try again.'))
|
||||
);
|
||||
$this->cartFactory->create()->addProduct($product);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddNotExistingProductId(): void
|
||||
{
|
||||
$this->expectExceptionObject(
|
||||
new LocalizedException(__('The product wasn\'t found. Verify the product and try again.'))
|
||||
);
|
||||
$this->cartFactory->create()->addProduct(989);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
|
||||
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddProductFromUnavailableWebsite(): void
|
||||
{
|
||||
$product = $this->productRepository->get('simple');
|
||||
$this->expectExceptionObject(
|
||||
new LocalizedException(__('The product wasn\'t found. Verify the product and try again.'))
|
||||
);
|
||||
$this->executeInStoreContext
|
||||
->execute('fixture_second_store', [$this->cartFactory->create(), 'addProduct'], $product->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddProductWithInvalidRequest(): void
|
||||
{
|
||||
$product = $this->productRepository->get('simple');
|
||||
$message = __('We found an invalid request for adding product to quote.');
|
||||
$this->expectExceptionObject(new LocalizedException($message));
|
||||
$this->cartFactory->create()->addProduct($product->getId(), '');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Model;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Customer\Model\Session as CustomerSession;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Checkout Session model test.
|
||||
*
|
||||
* @see \Magento\Checkout\Model\Session
|
||||
* @magentoDbIsolation enabled
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class SessionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var CustomerRepositoryInterface
|
||||
*/
|
||||
private $customerRepository;
|
||||
|
||||
/**
|
||||
* @var CustomerSession
|
||||
*/
|
||||
private $customerSession;
|
||||
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
private $checkoutSession;
|
||||
|
||||
/**
|
||||
* @var GetQuoteByReservedOrderId
|
||||
*/
|
||||
private $getQuoteByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var CartRepositoryInterface
|
||||
*/
|
||||
private $quoteRepository;
|
||||
|
||||
/**
|
||||
* @var CartInterface
|
||||
*/
|
||||
private $quote;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class);
|
||||
$this->customerSession = $this->objectManager->get(CustomerSession::class);
|
||||
$this->checkoutSession = $this->objectManager->get(Session::class);
|
||||
$this->getQuoteByReservedOrderId = $this->objectManager->get(GetQuoteByReservedOrderId::class);
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->productRepository->cleanCache();
|
||||
$this->quoteRepository = $this->objectManager->get(CartRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if ($this->quote instanceof CartInterface) {
|
||||
$this->quoteRepository->delete($this->quote);
|
||||
}
|
||||
$this->customerSession->setCustomerId(null);
|
||||
$this->checkoutSession->clearQuote();
|
||||
$this->checkoutSession->setCustomerData(null);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that quote items and totals are correct when product becomes unavailable.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
* @magentoAppIsolation enabled
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetQuoteWithUnavailableProduct(): void
|
||||
{
|
||||
$reservedOrderId = 'test01';
|
||||
$quoteGrandTotal = 10;
|
||||
$quote = $this->getQuoteByReservedOrderId->execute($reservedOrderId);
|
||||
$this->assertEquals(1, $quote->getItemsCount());
|
||||
$this->assertCount(1, $quote->getItems());
|
||||
$this->assertEquals($quoteGrandTotal, $quote->getShippingAddress()->getBaseGrandTotal());
|
||||
$product = $this->productRepository->get('simple');
|
||||
$product->setStatus(Status::STATUS_DISABLED);
|
||||
$this->productRepository->save($product);
|
||||
$this->checkoutSession->setQuoteId($quote->getId());
|
||||
$quote = $this->checkoutSession->getQuote();
|
||||
$this->assertEquals(0, $quote->getItemsCount());
|
||||
$this->assertEmpty($quote->getItems());
|
||||
$this->assertEquals(0, $quote->getShippingAddress()->getBaseGrandTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test covers case when quote is not yet initialized and customer data is set to checkout session model.
|
||||
*
|
||||
* Expected result - quote object should be loaded and customer data should be set to it.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetQuoteNotInitializedCustomerSet(): void
|
||||
{
|
||||
$customer = $this->customerRepository->getById(1);
|
||||
$this->checkoutSession->setCustomerData($customer);
|
||||
$quote = $this->checkoutSession->getQuote();
|
||||
$this->validateCustomerDataInQuote($quote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test covers case when quote is not yet initialized and customer data is set to customer session model.
|
||||
*
|
||||
* Expected result - quote object should be loaded and customer data should be set to it.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetQuoteNotInitializedCustomerLoggedIn(): void
|
||||
{
|
||||
$customer = $this->customerRepository->getById(1);
|
||||
$this->customerSession->setCustomerDataObject($customer);
|
||||
$quote = $this->checkoutSession->getQuote();
|
||||
$this->validateCustomerDataInQuote($quote);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetQuoteWithMismatchingSession(): void
|
||||
{
|
||||
$quote = $this->getQuoteByReservedOrderId->execute('test01');
|
||||
$this->checkoutSession->setQuoteId($quote->getId());
|
||||
$this->quote = $this->checkoutSession->getQuote();
|
||||
$this->assertEmpty($this->quote->getCustomerId());
|
||||
$this->assertNotEquals($quote->getId(), $this->quote->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tes merging of customer data into initialized quote object.
|
||||
*
|
||||
* Conditions:
|
||||
* 1. Quote without customer data is set to checkout session
|
||||
* 2. Customer without associated quote is set to checkout session
|
||||
*
|
||||
* Expected result:
|
||||
* Quote which is set to checkout session should contain customer data
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadCustomerQuoteCustomerWithoutQuote(): void
|
||||
{
|
||||
$this->quote = $this->checkoutSession->getQuote();
|
||||
$this->assertEmpty(
|
||||
$this->quote->getCustomerId(),
|
||||
'Precondition failed: Customer data must not be set to quote'
|
||||
);
|
||||
$this->assertEmpty(
|
||||
$this->quote->getCustomerEmail(),
|
||||
'Precondition failed: Customer data must not be set to quote'
|
||||
);
|
||||
self::assertEquals(
|
||||
'1',
|
||||
$this->quote->getCustomerIsGuest(),
|
||||
'Precondition failed: Customer must be as guest in quote'
|
||||
);
|
||||
$customer = $this->customerRepository->getById(1);
|
||||
$this->customerSession->setCustomerDataObject($customer);
|
||||
$this->quote = $this->checkoutSession->getQuote();
|
||||
$this->assertEmpty(
|
||||
$this->quote->getCustomerEmail(),
|
||||
'Precondition failed: Customer data must not be set to quote'
|
||||
);
|
||||
$this->checkoutSession->loadCustomerQuote();
|
||||
$this->quote = $this->checkoutSession->getQuote();
|
||||
$this->validateCustomerDataInQuote($this->quote);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetQuoteWithProductWithTierPrice(): void
|
||||
{
|
||||
$reservedOrderId = 'test01';
|
||||
$customerGroupId = 1;
|
||||
$tierPriceQty = 1;
|
||||
$tierPriceValue = 9;
|
||||
$product = $this->productRepository->get('simple');
|
||||
$tierPrice = $this->objectManager->get(ProductTierPriceInterface::class)
|
||||
->setCustomerGroupId($customerGroupId)
|
||||
->setQty($tierPriceQty)
|
||||
->setValue($tierPriceValue);
|
||||
$product->setTierPrices([$tierPrice]);
|
||||
$this->productRepository->save($product);
|
||||
$quote = $this->getQuoteByReservedOrderId->execute($reservedOrderId);
|
||||
$this->checkoutSession->setQuoteId($quote->getId());
|
||||
$quote = $this->checkoutSession->getQuote();
|
||||
$item = $quote->getItems()[0];
|
||||
$quoteProduct = $item->getProduct();
|
||||
$this->assertEquals(10, $quoteProduct->getTierPrice($tierPriceQty));
|
||||
$customer = $this->customerRepository->getById(1);
|
||||
$this->customerSession->setCustomerDataAsLoggedIn($customer);
|
||||
$quote = $this->checkoutSession->getQuote();
|
||||
$item = $quote->getItems()[0];
|
||||
$quoteProduct = $item->getProduct();
|
||||
$this->assertEquals($tierPriceValue, $quoteProduct->getTierPrice(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test covers case when quote is not yet initialized and customer is guest
|
||||
*
|
||||
* Expected result - quote object should be loaded with customer as guest
|
||||
*/
|
||||
public function testGetQuoteNotInitializedGuest()
|
||||
{
|
||||
$quote = $this->checkoutSession->getQuote();
|
||||
self::assertEquals('1', $quote->getCustomerIsGuest());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_customer_without_address.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMergeGuestQuoteWithCustomerQuote(): void
|
||||
{
|
||||
$guestQuote = $this->getQuoteByReservedOrderId->execute('test_order_with_simple_product_without_address');
|
||||
$customerQuote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address');
|
||||
$this->checkoutSession->setQuoteId($guestQuote->getId());
|
||||
$this->customerSession->setCustomerId(1);
|
||||
$updatedQuote = $this->checkoutSession->loadCustomerQuote()->getQuote();
|
||||
$this->assertNull($this->getQuoteByReservedOrderId->execute('test_order_with_simple_product_without_address'));
|
||||
$this->assertEquals($customerQuote->getId(), $updatedQuote->getId());
|
||||
$this->assertCount(2, $updatedQuote->getItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that quote has customer data specified in customer fixture.
|
||||
*
|
||||
* @param CartInterface $quote
|
||||
* @return void
|
||||
*/
|
||||
private function validateCustomerDataInQuote(CartInterface $quote): void
|
||||
{
|
||||
$customerIdFromFixture = 1;
|
||||
$customerEmailFromFixture = 'customer@example.com';
|
||||
$customerFirstNameFromFixture = 'John';
|
||||
$this->assertEquals(
|
||||
$customerEmailFromFixture,
|
||||
$quote->getCustomerEmail(),
|
||||
'Customer email was not set to Quote correctly.'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$customerIdFromFixture,
|
||||
$quote->getCustomerId(),
|
||||
'Customer ID was not set to Quote correctly.'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$customerFirstNameFromFixture,
|
||||
$quote->getCustomerFirstname(),
|
||||
'Customer first name was not set to Quote correctly.'
|
||||
);
|
||||
self::assertEquals(
|
||||
'0',
|
||||
$quote->getCustomerIsGuest(),
|
||||
'Customer should not be as guest in Quote.'
|
||||
);
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Checkout\Model;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Checkout\Api\Data\ShippingInformationInterface;
|
||||
use Magento\Checkout\Api\PaymentInformationManagementInterface;
|
||||
use Magento\Checkout\Api\ShippingInformationManagementInterface;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Quote\Api\CartItemRepositoryInterface;
|
||||
use Magento\Quote\Api\CartManagementInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterfaceFactory;
|
||||
use Magento\Quote\Api\Data\CartItemInterface;
|
||||
use Magento\Quote\Api\Data\PaymentInterface;
|
||||
use Magento\Quote\Api\ShipmentEstimationInterface;
|
||||
use Magento\Sales\Api\InvoiceOrderInterface;
|
||||
|
||||
/**
|
||||
* Shipping information managment test.
|
||||
*/
|
||||
class ShippingInformationManagementTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var CartManagementInterface */
|
||||
private $cartManagement;
|
||||
|
||||
/** @var CartItemRepositoryInterface */
|
||||
private $cartItemRepository;
|
||||
|
||||
/** @var CartItemInterface */
|
||||
private $cartItem;
|
||||
|
||||
/** @var ShippingInformationManagementInterface */
|
||||
private $shippingInformationManagement;
|
||||
|
||||
/** @var ShippingInformationInterface */
|
||||
private $shippingInformation;
|
||||
|
||||
/** @var CustomerRepositoryInterface */
|
||||
private $customerRepository;
|
||||
|
||||
/** @var AddressInterfaceFactory */
|
||||
private $apiAddressFactory;
|
||||
|
||||
/** @var ShipmentEstimationInterface */
|
||||
private $shipmentEstimation;
|
||||
|
||||
/** @var PaymentInformationManagementInterface */
|
||||
private $paymentInformationManagement;
|
||||
|
||||
/** @var PaymentInterface */
|
||||
private $payment;
|
||||
|
||||
/** @var InvoiceOrderInterface */
|
||||
private $invoiceOrder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->cartManagement = $objectManager->create(CartManagementInterface::class);
|
||||
$this->cartItemRepository = $objectManager->create(CartItemRepositoryInterface::class);
|
||||
$this->cartItem = $objectManager->create(CartItemInterface::class);
|
||||
$this->shippingInformationManagement = $objectManager->create(ShippingInformationManagementInterface::class);
|
||||
$this->shippingInformation = $objectManager->create(ShippingInformationInterface::class);
|
||||
$this->customerRepository = $objectManager->create(CustomerRepositoryInterface::class);
|
||||
$this->apiAddressFactory = $objectManager->create(AddressInterfaceFactory::class);
|
||||
$this->shipmentEstimation = $objectManager->create(ShipmentEstimationInterface::class);
|
||||
$this->paymentInformationManagement = $objectManager->create(PaymentInformationManagementInterface::class);
|
||||
$this->payment = $objectManager->create(PaymentInterface::class);
|
||||
$this->invoiceOrder = $objectManager->create(InvoiceOrderInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_virtual_in_stock.php
|
||||
*/
|
||||
public function testQuoteApiWithOnlyVirtualProducts()
|
||||
{
|
||||
$customer = $this->customerRepository->getById(1);
|
||||
|
||||
// Create empty quote
|
||||
$quoteId = $this->cartManagement->createEmptyCartForCustomer($customer->getId());
|
||||
|
||||
$cartItem = $this->cartItem
|
||||
->setSku('virtual-product')
|
||||
->setQty(1)
|
||||
->setQuoteId($quoteId);
|
||||
|
||||
// Add item to cart
|
||||
$this->cartItemRepository->save($cartItem);
|
||||
|
||||
$billingAddress = $shippingAddress = null;
|
||||
foreach ($customer->getAddresses() as $address) {
|
||||
$billingAddress = $address;
|
||||
$shippingAddress = $address;
|
||||
break;
|
||||
}
|
||||
|
||||
/** @var \Magento\Quote\Model\Quote\Address $apiBillingAddress */
|
||||
$apiBillingAddress = $this->apiAddressFactory->create();
|
||||
$apiBillingAddress->setRegion($billingAddress->getRegion())
|
||||
->setRegionId($billingAddress->getRegionId())
|
||||
->setCountryId($billingAddress->getCountryId())
|
||||
->setStreet($billingAddress->getStreet())
|
||||
->setPostcode($billingAddress->getPostcode())
|
||||
->setCity($billingAddress->getCity())
|
||||
->setFirstname($billingAddress->getFirstname())
|
||||
->setLastname($billingAddress->getLastname())
|
||||
->setEmail($customer->getEmail())
|
||||
->setTelephone($billingAddress->getTelephone());
|
||||
|
||||
/** @var \Magento\Quote\Model\Quote\Address $apiShippingAddress */
|
||||
$apiShippingAddress = $this->apiAddressFactory->create();
|
||||
$apiShippingAddress->setRegion($shippingAddress->getRegion())
|
||||
->setRegionId($shippingAddress->getRegionId())
|
||||
->setCountryId($shippingAddress->getCountryId())
|
||||
->setStreet($shippingAddress->getStreet())
|
||||
->setPostcode($shippingAddress->getPostcode())
|
||||
->setCity($shippingAddress->getCity())
|
||||
->setFirstname($shippingAddress->getFirstname())
|
||||
->setLastname($shippingAddress->getLastname())
|
||||
->setEmail($customer->getEmail())
|
||||
->setTelephone($shippingAddress->getTelephone());
|
||||
|
||||
// Estimate shipping
|
||||
$this->shipmentEstimation->estimateByExtendedAddress($quoteId, $apiShippingAddress);
|
||||
|
||||
$addressInformation = $this->shippingInformation
|
||||
->setBillingAddress($apiBillingAddress)
|
||||
->setShippingAddress($apiShippingAddress)
|
||||
->setShippingCarrierCode('flatrate')
|
||||
->setShippingMethodCode('flatrate');
|
||||
|
||||
// Set address information on quote
|
||||
$this->shippingInformationManagement->saveAddressInformation($quoteId, $addressInformation);
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Plugin\Model\Quote;
|
||||
|
||||
use Magento\Checkout\Model\Cart;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Quote\Model\BillingAddressManagement;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Address as QuoteAddress;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Checkout\Plugin\Model\Quote\ResetQuoteAddresses
|
||||
*/
|
||||
class ResetQuoteAddressesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @return void
|
||||
*/
|
||||
public function testAfterRemoveItem(): void
|
||||
{
|
||||
$this->login(1);
|
||||
/** @var Quote $quote */
|
||||
$quote = Bootstrap::getObjectManager()->create(Quote::class);
|
||||
$quote->load('test_order_with_virtual_product', 'reserved_order_id');
|
||||
/** @var QuoteAddress $quoteShippingAddress */
|
||||
$quoteBillingAddress = Bootstrap::getObjectManager()->create(QuoteAddress::class);
|
||||
$quoteBillingAddress->setRegion('CA')
|
||||
->setPostcode('90210')
|
||||
->setFirstname('a_unique_firstname')
|
||||
->setLastname('lastname')
|
||||
->setStreet('street')
|
||||
->setCity('Beverly Hills')
|
||||
->setEmail('admin@example.com')
|
||||
->setTelephone('1111111111')
|
||||
->setCountryId('US')
|
||||
->setAddressType('billing');
|
||||
|
||||
/** @var BillingAddressManagement $billingAddressManagement */
|
||||
$billingAddressManagement = Bootstrap::getObjectManager()->create(BillingAddressManagement::class);
|
||||
$billingAddressManagement->assign($quote->getId(), $quoteBillingAddress);
|
||||
/** @var Session $checkoutSession */
|
||||
$checkoutSession = Bootstrap::getObjectManager()->create(Session::class);
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
/** @var Cart $cart */
|
||||
$cart = Bootstrap::getObjectManager()->create(Cart::class);
|
||||
|
||||
$activeQuote = $cart->getQuote();
|
||||
// Dummy data is still persisted here. This is sufficient to check that it is removed
|
||||
$activeQuote->getExtensionAttributes()->setShippingAssignments(['test']);
|
||||
|
||||
$cart->removeItem($activeQuote->getAllVisibleItems()[0]->getId());
|
||||
$cart->save();
|
||||
|
||||
// Check that the shipping assignments were also unset
|
||||
$this->assertEmpty($activeQuote->getExtensionAttributes()->getShippingAssignments());
|
||||
|
||||
/** @var Quote $quote */
|
||||
$quote = Bootstrap::getObjectManager()->create(Quote::class);
|
||||
$quote->load('test_order_with_virtual_product', 'reserved_order_id');
|
||||
$quoteBillingAddressUpdated = $quote->getBillingAddress();
|
||||
$customer = $quote->getCustomer();
|
||||
|
||||
$this->assertEquals($quoteBillingAddressUpdated->getEmail(), $customer->getEmail());
|
||||
$this->assertEmpty($quoteBillingAddressUpdated->getCountryId());
|
||||
$this->assertEmpty($quoteBillingAddressUpdated->getRegionId());
|
||||
$this->assertEmpty($quoteBillingAddressUpdated->getRegion());
|
||||
$this->assertEmpty($quoteBillingAddressUpdated->getPostcode());
|
||||
$this->assertEmpty($quoteBillingAddressUpdated->getCity());
|
||||
}
|
||||
|
||||
private function login(int $customerId): void
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Session $session */
|
||||
$session = Bootstrap::getObjectManager()
|
||||
->get(\Magento\Customer\Model\Session::class);
|
||||
$session->loginById($customerId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\ViewModel;
|
||||
|
||||
use Magento\Framework\App\Config\MutableScopeConfigInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for clear shopping cart config
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class CartTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Cart
|
||||
*/
|
||||
private $cart;
|
||||
|
||||
/**
|
||||
* @var MutableScopeConfigInterface
|
||||
*/
|
||||
private $mutableScopeConfig;
|
||||
|
||||
/**
|
||||
* @var StoreManagerInterface
|
||||
*/
|
||||
private $storeManager;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = $this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->cart = $objectManager->get(Cart::class);
|
||||
$this->mutableScopeConfig = $objectManager->get(MutableScopeConfigInterface::class);
|
||||
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function testConfigClearShoppingCartEnabledWithWebsiteScopes()
|
||||
{
|
||||
// Assert not active by default
|
||||
$this->assertFalse($this->cart->isClearShoppingCartEnabled());
|
||||
|
||||
// Enable Clear Shopping Cart in default website scope
|
||||
$this->setClearShoppingCartEnabled(
|
||||
true,
|
||||
ScopeInterface::SCOPE_WEBSITE
|
||||
);
|
||||
|
||||
// Assert now active in default website scope
|
||||
$this->assertTrue($this->cart->isClearShoppingCartEnabled());
|
||||
|
||||
$defaultStore = $this->storeManager->getStore();
|
||||
$defaultWebsite = $defaultStore->getWebsite();
|
||||
$defaultWebsiteCode = $defaultWebsite->getCode();
|
||||
|
||||
$secondStore = $this->storeManager->getStore('fixture_second_store');
|
||||
$secondWebsite = $secondStore->getWebsite();
|
||||
$secondWebsiteCode = $secondWebsite->getCode();
|
||||
|
||||
// Change current store context to that of second website
|
||||
$this->storeManager->setCurrentStore($secondStore);
|
||||
|
||||
// Assert not active by default in second website
|
||||
$this->assertFalse($this->cart->isClearShoppingCartEnabled());
|
||||
|
||||
// Enable Clear Shopping Cart in second website scope
|
||||
$this->setClearShoppingCartEnabled(
|
||||
true,
|
||||
ScopeInterface::SCOPE_WEBSITE,
|
||||
$secondWebsiteCode
|
||||
);
|
||||
|
||||
// Assert now active in second website scope
|
||||
$this->assertTrue($this->cart->isClearShoppingCartEnabled());
|
||||
|
||||
// Disable Clear Shopping Cart in default website scope
|
||||
$this->setClearShoppingCartEnabled(
|
||||
false,
|
||||
ScopeInterface::SCOPE_WEBSITE,
|
||||
$defaultWebsiteCode
|
||||
);
|
||||
|
||||
// Assert still active in second website
|
||||
$this->assertTrue($this->cart->isClearShoppingCartEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set clear shopping cart enabled.
|
||||
*
|
||||
* @param bool $isActive
|
||||
* @param string $scope
|
||||
* @param string|null $scopeCode
|
||||
*/
|
||||
private function setClearShoppingCartEnabled(bool $isActive, string $scope, $scopeCode = null)
|
||||
{
|
||||
$this->mutableScopeConfig->setValue(
|
||||
'checkout/cart/enable_clear_shopping_cart',
|
||||
$isActive ? '1' : '0',
|
||||
$scope,
|
||||
$scopeCode
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(false)
|
||||
->setReservedOrderId('test_order_1')
|
||||
->save();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Customer\Model\CustomerRegistry;
|
||||
use Magento\Store\Api\StoreRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/second_store.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CustomerRegistry $customerRegistry */
|
||||
$customerRegistry = Bootstrap::getObjectManager()->create(CustomerRegistry::class);
|
||||
$customer = $customerRegistry->retrieve(1);
|
||||
/** @var StoreRepositoryInterface $storeRepository */
|
||||
$storeRepository = $objectManager->get(StoreRepositoryInterface::class);
|
||||
$store = $storeRepository->get('fixture_second_store');
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setStoreId($store->getId())
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(false)
|
||||
->setReservedOrderId('test_order_1_not_default_store')
|
||||
->setCustomerId($customer->getId())
|
||||
->save();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_1_not_default_store', 'reserved_order_id')->delete();
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/second_store_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Customer\Model\CustomerRegistry;
|
||||
use Magento\Store\Api\StoreRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/second_store.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var StoreRepositoryInterface $storeRepository */
|
||||
$storeRepository = $objectManager->get(StoreRepositoryInterface::class);
|
||||
$store = $storeRepository->get('fixture_second_store');
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setStoreId($store->getId())
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(false)
|
||||
->setReservedOrderId('test_order_1_not_default_store_guest')
|
||||
->save();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/second_store_rollback.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_1_not_default_store_guest', 'reserved_order_id')->delete();
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/second_website_with_two_stores.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$storeRepository = $objectManager->get(\Magento\Store\Api\StoreRepositoryInterface::class);
|
||||
$store = $storeRepository->get('fixture_second_store');
|
||||
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class)
|
||||
->setReservedOrderId('test_order_2')
|
||||
->setStoreId($store->getId())
|
||||
->setIsActive(true);
|
||||
$quoteRepository = $objectManager->get(\Magento\Quote\Api\CartRepositoryInterface::class);
|
||||
$quoteRepository->save($quote);
|
||||
|
||||
$quoteIdMask = $objectManager->create(\Magento\Quote\Model\QuoteIdMask::class)
|
||||
->setQuoteId($quote->getId())
|
||||
->setDataChanges(true);
|
||||
$quoteIdMaskResource = $objectManager->get(\Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask::class);
|
||||
$quoteIdMaskResource->save($quoteIdMask);
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_2', 'reserved_order_id')
|
||||
->delete();
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/second_website_with_two_stores_rollback.php');
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_1', 'reserved_order_id')->delete();
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
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/Downloadable/_files/product_downloadable.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/active_quote.php');
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('downloadable-product');
|
||||
|
||||
/** @var $linkCollection \Magento\Downloadable\Model\ResourceModel\Link\Collection */
|
||||
$linkCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Downloadable\Model\Link::class
|
||||
)->getCollection()->addProductToFilter(
|
||||
$product->getId()
|
||||
)->addTitleToResult(
|
||||
$product->getStoreId()
|
||||
)->addPriceToResult(
|
||||
$product->getStore()->getWebsiteId()
|
||||
);
|
||||
|
||||
/** @var $link \Magento\Downloadable\Model\Link */
|
||||
$link = $linkCollection->getFirstItem();
|
||||
|
||||
$requestInfo = new \Magento\Framework\DataObject(['qty' => 1, 'links' => [$link->getId()]]);
|
||||
|
||||
/** @var $cart \Magento\Checkout\Model\Cart */
|
||||
$cart = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Checkout\Model\Cart::class);
|
||||
$cart->setQuote($quote);
|
||||
$cart->addProduct($product, $requestInfo);
|
||||
$cart->save();
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->removeSharedInstance(\Magento\Checkout\Model\Session::class);
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Downloadable/_files/product_downloadable_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/active_quote_rollback.php');
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('_singleton/Magento\Checkout\Model\Session');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('_singleton/Magento_Checkout_Model_Cart');
|
||||
/** @var $cart \Magento\Checkout\Model\Cart */
|
||||
$cart = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Checkout\Model\Cart::class);
|
||||
|
||||
$cart->addProduct($product, $requestInfo);
|
||||
$cart->save();
|
||||
|
||||
$quoteItemId = $cart->getQuote()->getItemByProduct($product)->getId();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->register('product/quoteItemId', $quoteItemId);
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('_singleton/Magento\Checkout\Model\Session');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('_singleton/Magento_Checkout_Model_Cart');
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Option;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_with_custom_option_text_area.php');
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = Bootstrap::getObjectManager()
|
||||
->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple_with_custom_option_text_area');
|
||||
|
||||
$options = [];
|
||||
/** @var $option Option */
|
||||
foreach ($product->getOptions() as $option) {
|
||||
switch ($option->getGroupByType()) {
|
||||
case ProductCustomOptionInterface::OPTION_GROUP_SELECT:
|
||||
$value = key($option->getValues());
|
||||
break;
|
||||
default:
|
||||
$value = <<<EOT
|
||||
Test product simple with
|
||||
custom option text area
|
||||
with more 50 characters
|
||||
EOT;
|
||||
break;
|
||||
}
|
||||
$options[$option->getId()] = $value;
|
||||
}
|
||||
|
||||
$requestInfo = new DataObject(['qty' => 1, 'options' => $options]);
|
||||
|
||||
/** @var $cart \Magento\Checkout\Model\Cart */
|
||||
$quote = Bootstrap::getObjectManager()->create(Quote::class);
|
||||
$quote->setReservedOrderId('test_order_item_with_custom_option_text_area');
|
||||
$quote->addProduct($product, $requestInfo);
|
||||
$quote->save();
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->removeSharedInstance(Session::class);
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Option;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_with_custom_options.php');
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = Bootstrap::getObjectManager()
|
||||
->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple_with_custom_options');
|
||||
|
||||
$options = [];
|
||||
/** @var $option Option */
|
||||
foreach ($product->getOptions() as $option) {
|
||||
switch ($option->getGroupByType()) {
|
||||
case ProductCustomOptionInterface::OPTION_GROUP_SELECT:
|
||||
$value = key($option->getValues());
|
||||
break;
|
||||
default:
|
||||
$value = 'test';
|
||||
break;
|
||||
}
|
||||
$options[$option->getId()] = $value;
|
||||
}
|
||||
|
||||
$requestInfo = new DataObject(['qty' => 1, 'options' => $options]);
|
||||
|
||||
/** @var $cart \Magento\Checkout\Model\Cart */
|
||||
$quote = Bootstrap::getObjectManager()->create(Quote::class);
|
||||
$quote->setReservedOrderId('test_order_item_with_custom_options');
|
||||
$quote->addProduct($product, $requestInfo);
|
||||
$quote->save();
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->removeSharedInstance(Session::class);
|
||||
+41
@@ -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\Checkout\Model\Type\Onepage;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\Data\CartInterfaceFactory;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products_with_websites_and_stores.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
$customer = $customerRepository->get('customer@example.com');
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
/** @var CartInterface $quote */
|
||||
$quote = $objectManager->get(CartInterfaceFactory::class)->create();
|
||||
$quote->setStoreId($storeManager->getStore('fixture_second_store')->getId())
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(0)
|
||||
->setCustomer($customer)
|
||||
->setCheckoutMethod(Onepage::METHOD_CUSTOMER)
|
||||
->setReservedOrderId('test_order_on_second_website')
|
||||
->addProduct($productRepository->get('simple-2'), 1);
|
||||
$quoteRepository->save($quote);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var GetQuoteByReservedOrderId $getQuoteByReservedOrderId */
|
||||
$getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
|
||||
$quote = $getQuoteByReservedOrderId->execute('test_order_on_second_website');
|
||||
if ($quote !== null) {
|
||||
$quoteRepository->delete($quote);
|
||||
}
|
||||
|
||||
Resolver::getInstance()
|
||||
->requireDataFixture('Magento/Catalog/_files/products_with_websites_and_stores_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?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\Type\Onepage;
|
||||
use Magento\Customer\Api\AddressRepositoryInterface;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterfaceFactory;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\Data\CartInterfaceFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var AddressInterface $quoteShippingAddress */
|
||||
$quoteShippingAddress = $objectManager->get(AddressInterfaceFactory::class)->create();
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
/** @var AddressRepositoryInterface $addressRepository */
|
||||
$addressRepository = $objectManager->get(AddressRepositoryInterface::class);
|
||||
$quoteShippingAddress->importCustomerAddressData($addressRepository->getById(1));
|
||||
$customer = $customerRepository->getById(1);
|
||||
|
||||
/** @var CartInterface $quote */
|
||||
$quote = $objectManager->get(CartInterfaceFactory::class)->create();
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(0)
|
||||
->assignCustomerWithAddressChange($customer)
|
||||
->setShippingAddress($quoteShippingAddress)
|
||||
->setBillingAddress($quoteShippingAddress)
|
||||
->setCheckoutMethod(Onepage::METHOD_CUSTOMER)
|
||||
->setReservedOrderId('55555555')
|
||||
->setEmail($customer->getEmail());
|
||||
$quote->addProduct($productRepository->get('simple-1'), 55);
|
||||
$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
|
||||
$quote->getShippingAddress()->setCollectShippingRates(true);
|
||||
$quote->getShippingAddress()->collectShippingRates();
|
||||
$quote->getPayment()->setMethod('checkmo');
|
||||
$quoteRepository->save($quote);
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var GetQuoteByReservedOrderId $getQuoteByReservedOrderId */
|
||||
$getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
|
||||
$quote = $getQuoteByReservedOrderId->execute('55555555');
|
||||
if ($quote) {
|
||||
$quoteRepository->delete($quote);
|
||||
}
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_address_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Option;
|
||||
use Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile;
|
||||
use Magento\Catalog\Model\Product\Option\Value;
|
||||
use Magento\TestFramework\Catalog\Model\Product\Option\Type\File\ValidatorFileMock;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_with_options.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_with_uk_address.php');
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
/** @var Quote $quote */
|
||||
$quote = $objectManager->get(QuoteFactory::class)->create();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
|
||||
$customer = $customerRepository->get('customer_uk_address@test.com');
|
||||
$product = $productRepository->get('simple');
|
||||
$options = [];
|
||||
$dropDownValues = [];
|
||||
$iDate = 1;
|
||||
/** @var Option $option */
|
||||
foreach ($product->getOptions() as $option) {
|
||||
switch ($option->getGroupByType()) {
|
||||
case ProductCustomOptionInterface::OPTION_GROUP_SELECT:
|
||||
if ($option->getType() == ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN) {
|
||||
$dropDownValues = $option->getValues();
|
||||
$value = null;
|
||||
} elseif ($option->getType() == ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX) {
|
||||
$value = array_keys($option->getValues());
|
||||
} else {
|
||||
$value = (string)key($option->getValues());
|
||||
}
|
||||
break;
|
||||
case ProductCustomOptionInterface::OPTION_GROUP_DATE:
|
||||
$value = [
|
||||
'year' => 2013 + $iDate,
|
||||
'month' => 1 + $iDate,
|
||||
'day' => 1 + $iDate,
|
||||
'hour' => 10 + $iDate,
|
||||
'minute' => 30 + $iDate,
|
||||
];
|
||||
$iDate++;
|
||||
break;
|
||||
case ProductCustomOptionInterface::OPTION_GROUP_FILE:
|
||||
$value = null;
|
||||
break;
|
||||
default:
|
||||
$value = 'test';
|
||||
break;
|
||||
}
|
||||
$options[$option->getId()] = $value;
|
||||
}
|
||||
|
||||
$itemsOptions = [];
|
||||
/** @var Value $dropDownValue */
|
||||
foreach ($dropDownValues as $dropDownId => $dropDownValue) {
|
||||
$options[$dropDownValue->getOption()->getId()] = $dropDownId;
|
||||
$itemsOptions[$dropDownValue->getTitle()] = $options;
|
||||
}
|
||||
|
||||
$validatorFileMock = $objectManager->get(ValidatorFileMock::class)->getInstance();
|
||||
$objectManager->addSharedInstance($validatorFileMock, ValidatorFile::class);
|
||||
|
||||
$quote->setStoreId($storeManager->getStore()->getId())
|
||||
->assignCustomer($customer)
|
||||
->setReservedOrderId('customer_quote_product_custom_options');
|
||||
|
||||
/** @var DataObject $request */
|
||||
$requestInfo = $objectManager->create(DataObject::class);
|
||||
|
||||
foreach ($itemsOptions as $itemOptions) {
|
||||
$requestInfo->setData(['qty' => 1, 'options' => $itemOptions]);
|
||||
$product = clone $product;
|
||||
$quote->addProduct($product, $requestInfo);
|
||||
}
|
||||
|
||||
$quoteRepository->save($quote);
|
||||
$objectManager->removeSharedInstance(ValidatorFile::class);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/** @var ObjectManagerInterface $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
$quote = $objectManager->get(GetQuoteByReservedOrderId::class)->execute('customer_quote_product_custom_options');
|
||||
if ($quote !== null) {
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
$quoteRepository->delete($quote);
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_with_uk_address_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_with_options_rollback.php');
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Customer\Model\CustomerRegistry;
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$repository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
|
||||
$customer = $objectManager->create(\Magento\Customer\Model\Customer::class);
|
||||
$customerRegistry = $objectManager->get(CustomerRegistry::class);
|
||||
$customer->setWebsiteId(1)
|
||||
->setId(1)
|
||||
->setEmail('customer1@example.com')
|
||||
->setPassword('password')
|
||||
->setGroupId(1)
|
||||
->setStoreId(1)
|
||||
->setIsActive(1)
|
||||
->setFirstname('John')
|
||||
->setLastname('Smith')
|
||||
->setDefaultBilling(1)
|
||||
->setDefaultShipping(1);
|
||||
$customer->isObjectNew(true);
|
||||
$customer->save();
|
||||
|
||||
$customer->setWebsiteId(1)
|
||||
->setId(2)
|
||||
->setEmail('customer2@example.com')
|
||||
->setPassword('password')
|
||||
->setGroupId(1)
|
||||
->setStoreId(1)
|
||||
->setIsActive(1)
|
||||
->setFirstname('Jane')
|
||||
->setLastname('Smith')
|
||||
->setDefaultBilling(1)
|
||||
->setDefaultShipping(1);
|
||||
$customer->isObjectNew(true);
|
||||
$customer->save();
|
||||
|
||||
$customerRegistry->remove($customer->getId());
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* SalesRule 10% discount coupon
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\SalesRule\Model\RuleFactory $salesRule */
|
||||
$salesRuleFactory = $objectManager->get(\Magento\SalesRule\Model\RuleFactory::class);
|
||||
|
||||
/** @var \Magento\SalesRule\Model\Rule $salesRule */
|
||||
$salesRule = $salesRuleFactory->create();
|
||||
|
||||
$data = [
|
||||
'name' => 'Test Coupon',
|
||||
'is_active' => true,
|
||||
'website_ids' => [
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getWebsiteId()
|
||||
],
|
||||
'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID, 1],
|
||||
'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC,
|
||||
'coupon_code' => uniqid(),
|
||||
'simple_action' => \Magento\SalesRule\Model\Rule::BY_PERCENT_ACTION,
|
||||
'discount_amount' => 10,
|
||||
'discount_step' => 1
|
||||
];
|
||||
|
||||
$salesRule->loadPost($data)->setUseAutoGeneration(false)->save();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('Magento/Checkout/_file/discount_10percent');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)
|
||||
->register('Magento/Checkout/_file/discount_10percent', $salesRule->getRuleId());
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* SalesRule 10% discount coupon
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\SalesRule\Model\Rule $salesRule */
|
||||
$salesRule = $objectManager->create(\Magento\SalesRule\Model\Rule::class);
|
||||
|
||||
$data = [
|
||||
'name' => 'Test Coupon for General',
|
||||
'is_active' => true,
|
||||
'store_labels' => [0 => 'Test Coupon for General'],
|
||||
'website_ids' => [
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getWebsiteId()
|
||||
],
|
||||
'customer_group_ids' => [1],
|
||||
'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC,
|
||||
'coupon_code' => '2?ds5!2d',
|
||||
'simple_action' => \Magento\SalesRule\Model\Rule::BY_PERCENT_ACTION,
|
||||
'discount_amount' => 10,
|
||||
'discount_step' => 1
|
||||
];
|
||||
|
||||
$salesRule->loadPost($data)->setUseAutoGeneration(false)->save();
|
||||
$objectManager->get(
|
||||
\Magento\Framework\Registry::class
|
||||
)->unregister('Magento/Checkout/_file/discount_10percent_generalusers');
|
||||
$objectManager->get(\Magento\Framework\Registry::class)
|
||||
->register('Magento/Checkout/_file/discount_10percent_generalusers', $salesRule->getRuleId());
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* SalesRule 10% discount coupon
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var \Magento\SalesRule\Model\Rule $salesRule */
|
||||
$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\SalesRule\Model\Rule::class);
|
||||
/** @var int $salesRuleId */
|
||||
$salesRuleId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class)
|
||||
->registry('Magento/Checkout/_file/discount_10percent_generalusers');
|
||||
$salesRule->load($salesRuleId);
|
||||
$salesRule->delete();
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* SalesRule 10% discount coupon
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var \Magento\SalesRule\Model\Rule $salesRule */
|
||||
$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\SalesRule\Model\Rule::class);
|
||||
/** @var int $salesRuleId */
|
||||
$salesRuleId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class)
|
||||
->registry('Magento/Checkout/_file/discount_10percent');
|
||||
$salesRule->load($salesRuleId);
|
||||
$salesRule->delete();
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?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\Type\Onepage;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\Data\CartInterfaceFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/taxable_simple_product.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
$customer = $customerRepository->get('customer@example.com');
|
||||
|
||||
/** @var CartInterface $quote */
|
||||
$quote = $objectManager->get(CartInterfaceFactory::class)->create();
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(false)
|
||||
->setIsMultiShipping(0)
|
||||
->setCustomer($customer)
|
||||
->setCheckoutMethod(Onepage::METHOD_CUSTOMER)
|
||||
->setReservedOrderId('test_order_with_customer_inactive_quote')
|
||||
->addProduct($productRepository->get('taxable_product'), 1);
|
||||
$quoteRepository->save($quote);
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var GetQuoteByReservedOrderId $getQuoteByReservedOrderId */
|
||||
$getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
|
||||
$quote = $getQuoteByReservedOrderId->execute('test_order_with_customer_inactive_quote');
|
||||
if ($quote !== null) {
|
||||
$quoteRepository->delete($quote);
|
||||
}
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/taxable_simple_product_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/products.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/orders.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$order = Bootstrap::getObjectManager()->create(Order::class);
|
||||
$order1 = clone $order->loadByIncrementId('100000001');
|
||||
$order2 = clone $order->loadByIncrementId('100000002');
|
||||
$order3 = clone $order->loadByIncrementId('100000003');
|
||||
|
||||
/** @var Magento\Catalog\Model\ProductRepository $productRepository */
|
||||
$productRepository = $objectManager->create(Magento\Catalog\Model\ProductRepository::class);
|
||||
$product1 = $productRepository->get('Simple Product 1 sku');
|
||||
$product2 = $productRepository->get('Simple Product 2 sku');
|
||||
$product3 = $productRepository->get('Simple Product 3 sku');
|
||||
$product4 = $productRepository->get('Simple Product 4 sku');
|
||||
|
||||
//@codingStandardsIgnoreStart
|
||||
$productOptionValue = '{"info_buyRequest":{"uenc":"aHR0cDovL21hZ2VudG90MjIubG9jYWwvdGVzdC5odG1s","product":"%s","qty":1}}';
|
||||
//@codingStandardsIgnoreEnd
|
||||
|
||||
$orderItems = [
|
||||
[
|
||||
'item_id' => 1,
|
||||
'product_id' => $product1->getId(),
|
||||
'order_id' => $order1->getId(),
|
||||
'base_price' => 90,
|
||||
'price' => 90,
|
||||
'row_total' => 92,
|
||||
'product_type' => 'simple',
|
||||
'product_options' => sprintf($productOptionValue, $product1->getId())
|
||||
],
|
||||
[
|
||||
'item_id' => 2,
|
||||
'product_id' => $product2->getId(),
|
||||
'base_price' => 100,
|
||||
'order_id' => $order2->getId(),
|
||||
'price' => 100,
|
||||
'row_total' => 102,
|
||||
'product_type' => 'simple',
|
||||
'product_options' => sprintf($productOptionValue, $product2->getId())
|
||||
],
|
||||
[
|
||||
'item_id' => 3,
|
||||
'product_id' => $product3->getId(),
|
||||
'base_price' => 110,
|
||||
'order_id' => $order3->getId(),
|
||||
'price' => 110,
|
||||
'row_total' => 112,
|
||||
'product_type' => 'simple',
|
||||
'product_options' => sprintf($productOptionValue, $product3->getId())
|
||||
],
|
||||
[
|
||||
'item_id' => 4,
|
||||
'product_id' => $product4->getId(),
|
||||
'base_price' => 123,
|
||||
'order_id' => $order3->getId(),
|
||||
'price' => 123,
|
||||
'row_total' => 126,
|
||||
'product_type' => 'simple',
|
||||
'product_options' => sprintf($productOptionValue, $product4->getId())
|
||||
],
|
||||
];
|
||||
|
||||
/** @var $orderItem \Magento\Sales\Model\Order\Item */
|
||||
$orderItem = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\Order\Item::class
|
||||
);
|
||||
foreach ($orderItems as $orderItemData) {
|
||||
$orderItem->isObjectNew(true);
|
||||
/** @var array $orderItemData */
|
||||
$orderItem
|
||||
->setData($orderItemData)
|
||||
->save();
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/customers.php');
|
||||
|
||||
$addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php';
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$billingAddress = $objectManager->create(\Magento\Sales\Model\Order\Address::class, ['data' => $addressData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
|
||||
$payment = $objectManager->create(\Magento\Sales\Model\Order\Payment::class);
|
||||
$payment->setMethod('checkmo');
|
||||
$payment->setAdditionalInformation('last_trans_id', '11122');
|
||||
$payment->setAdditionalInformation('metadata', [
|
||||
'type' => 'free',
|
||||
'fraudulent' => false
|
||||
]);
|
||||
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
|
||||
$order->setIncrementId(
|
||||
'100000001'
|
||||
)->setState(
|
||||
\Magento\Sales\Model\Order::STATE_PROCESSING
|
||||
)->setStatus(
|
||||
$order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING)
|
||||
)->setSubtotal(
|
||||
100
|
||||
)->setGrandTotal(
|
||||
100
|
||||
)->setBaseSubtotal(
|
||||
100
|
||||
)->setBaseGrandTotal(
|
||||
100
|
||||
)->setCustomerIsGuest(
|
||||
true
|
||||
)->setCustomerId(
|
||||
null
|
||||
)->setCustomerEmail(
|
||||
'unknown@example.com'
|
||||
)->setBillingAddress(
|
||||
$billingAddress
|
||||
)->setShippingAddress(
|
||||
$shippingAddress
|
||||
)->setStoreId(
|
||||
$objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId()
|
||||
)->setPayment(
|
||||
$payment
|
||||
);
|
||||
$order->isObjectNew(true);
|
||||
$order->save();
|
||||
|
||||
|
||||
$order->setIncrementId(
|
||||
'100000002'
|
||||
)->setState(
|
||||
\Magento\Sales\Model\Order::STATE_PROCESSING
|
||||
)->setStatus(
|
||||
$order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING)
|
||||
)->setSubtotal(
|
||||
100
|
||||
)->setGrandTotal(
|
||||
100
|
||||
)->setBaseSubtotal(
|
||||
100
|
||||
)->setBaseGrandTotal(
|
||||
100
|
||||
)->setCustomerIsGuest(
|
||||
false
|
||||
)->setCustomerId(
|
||||
1
|
||||
)->setCustomerEmail(
|
||||
'customer1@example.com'
|
||||
)->setBillingAddress(
|
||||
$billingAddress
|
||||
)->setShippingAddress(
|
||||
$shippingAddress
|
||||
)->setStoreId(
|
||||
$objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId()
|
||||
)->setPayment(
|
||||
$payment
|
||||
);
|
||||
$order->isObjectNew(true);
|
||||
$order->save();
|
||||
|
||||
|
||||
$order->setIncrementId(
|
||||
'100000003'
|
||||
)->setState(
|
||||
\Magento\Sales\Model\Order::STATE_PROCESSING
|
||||
)->setStatus(
|
||||
$order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING)
|
||||
)->setSubtotal(
|
||||
100
|
||||
)->setGrandTotal(
|
||||
100
|
||||
)->setBaseSubtotal(
|
||||
100
|
||||
)->setBaseGrandTotal(
|
||||
100
|
||||
)->setCustomerIsGuest(
|
||||
false
|
||||
)->setCustomerId(
|
||||
2
|
||||
)->setCustomerEmail(
|
||||
'customer2@example.com'
|
||||
)->setBillingAddress(
|
||||
$billingAddress
|
||||
)->setShippingAddress(
|
||||
$shippingAddress
|
||||
)->setStoreId(
|
||||
$objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId()
|
||||
)->setPayment(
|
||||
$payment
|
||||
);
|
||||
$order->isObjectNew(true);
|
||||
$order->save();
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/simple_product.php');
|
||||
|
||||
/** @var $bundleProduct \Magento\Catalog\Model\Product */
|
||||
$bundleProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Catalog\Model\Product::class
|
||||
);
|
||||
$bundleProduct->setTypeId(
|
||||
\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE
|
||||
)->setId(
|
||||
3
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setName(
|
||||
'Bundle Product'
|
||||
)->setSku(
|
||||
'bundle-product'
|
||||
)->setDescription(
|
||||
'Description with <b>html tag</b>'
|
||||
)->setShortDescription(
|
||||
'Bundle'
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 0,
|
||||
'manage_stock' => 0,
|
||||
'use_config_enable_qty_increments' => 1,
|
||||
'use_config_qty_increments' => 1,
|
||||
'is_in_stock' => 0,
|
||||
]
|
||||
)->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Bundle Product Items',
|
||||
'default_title' => 'Bundle Product Items',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
'position' => 0,
|
||||
'option_id' => '',
|
||||
],
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 1, // fixture product
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'position' => 0,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 0.0,
|
||||
'option_id' => '',
|
||||
'selection_id' => '',
|
||||
'is_default' => 1,
|
||||
],
|
||||
],
|
||||
]
|
||||
)->setCanSaveBundleSelections(
|
||||
true
|
||||
)->setAffectBundleProductSelections(
|
||||
true
|
||||
)->save();
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->load($bundleProduct->getId());
|
||||
|
||||
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
|
||||
//Load options
|
||||
$typeInstance = $product->getTypeInstance();
|
||||
$typeInstance->setStoreFilter($product->getStoreId(), $product);
|
||||
$optionCollection = $typeInstance->getOptionsCollection($product);
|
||||
$selectionCollection = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);
|
||||
|
||||
$bundleOptions = [];
|
||||
$bundleOptionsQty = [];
|
||||
/** @var $option \Magento\Bundle\Model\Option */
|
||||
foreach ($optionCollection as $option) {
|
||||
/** @var $selection \Magento\Bundle\Model\Selection */
|
||||
$selection = $selectionCollection->getFirstItem();
|
||||
$bundleOptions[$option->getId()] = $selection->getSelectionId();
|
||||
$bundleOptionsQty[$option->getId()] = 1;
|
||||
}
|
||||
|
||||
$requestInfo = new \Magento\Framework\DataObject(
|
||||
['qty' => 1, 'bundle_option' => $bundleOptions, 'bundle_option_qty' => $bundleOptionsQty]
|
||||
);
|
||||
$product->setSkipCheckRequiredOption(true);
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/cart.php');
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/simple_product.php');
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->load(1);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product->setCanSaveCustomOptions(
|
||||
true
|
||||
)->setHasOptions(
|
||||
true
|
||||
);
|
||||
|
||||
$oldOptions = [
|
||||
[
|
||||
'id' => 1,
|
||||
'option_id' => 0,
|
||||
'previous_group' => 'text',
|
||||
'title' => 'Test Field',
|
||||
'type' => 'field',
|
||||
'is_require' => 1,
|
||||
'sort_order' => 0,
|
||||
'price' => 1,
|
||||
'price_type' => 'fixed',
|
||||
'sku' => '1-text',
|
||||
'max_characters' => 100,
|
||||
],
|
||||
];
|
||||
|
||||
$customOptions = [];
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory $customOptionFactory */
|
||||
$customOptionFactory = $objectManager->create(\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory::class);
|
||||
|
||||
foreach ($oldOptions as $option) {
|
||||
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterface $customOption */
|
||||
$customOption = $customOptionFactory->create(['data' => $option]);
|
||||
$customOption->setProductSku($product->getSku());
|
||||
|
||||
$customOptions[] = $customOption;
|
||||
}
|
||||
|
||||
$product->setOptions($customOptions)->save();
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->load(1);
|
||||
$optionId = $product->getOptions()[0]->getOptionId();
|
||||
|
||||
$requestInfo = new \Magento\Framework\DataObject(['qty' => 1, 'options' => [$optionId => 'test']]);
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/cart.php');
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/default_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/rollback_quote.php');
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product1 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product1->setTypeId(
|
||||
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setName(
|
||||
'Simple Product 1'
|
||||
)->setSku(
|
||||
'Simple Product 1 sku'
|
||||
)->setPrice(
|
||||
10
|
||||
)->setDescription(
|
||||
'Description with <b>html tag</b>'
|
||||
)->setMetaTitle(
|
||||
'meta title'
|
||||
)->setMetaKeyword(
|
||||
'meta keyword'
|
||||
)->setMetaDescription(
|
||||
'meta description'
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->setCategoryIds(
|
||||
[2]
|
||||
)->setStockData(
|
||||
['use_config_manage_stock' => 0]
|
||||
)->setCanSaveCustomOptions(
|
||||
true
|
||||
)->setHasOptions(
|
||||
true
|
||||
);
|
||||
|
||||
$product2 = clone $product1;
|
||||
$product2->setName('Simple Product 2')->setSku('Simple Product 2 sku')->save();
|
||||
$product3 = clone $product1;
|
||||
$product3->setName('Simple Product 3')->setSku('Simple Product 3 sku')->save();
|
||||
$product4 = clone $product1;
|
||||
$product4->setName('Simple Product 4')->setSku('Simple Product 4 sku')->save();
|
||||
$product1->save();
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setData(['store_id' => 1, 'is_active' => 0, 'is_multi_shipping' => 0]);
|
||||
$quote->save();
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
/** @var \Magento\Quote\Model\Quote\Address $quoteShippingAddress */
|
||||
$quoteShippingAddress = $objectManager->create(\Magento\Quote\Model\Quote\Address::class);
|
||||
|
||||
/** @var \Magento\Customer\Api\AccountManagementInterface $accountManagement */
|
||||
$accountManagement = $objectManager->create(\Magento\Customer\Api\AccountManagementInterface::class);
|
||||
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
|
||||
$customer = $customerRepository->getById(1);
|
||||
|
||||
/** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */
|
||||
$addressRepository = $objectManager->create(\Magento\Customer\Api\AddressRepositoryInterface::class);
|
||||
$quoteShippingAddress->importCustomerAddressData($addressRepository->getById(1));
|
||||
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setStoreId(
|
||||
1
|
||||
)->setIsActive(
|
||||
true
|
||||
)->setIsMultiShipping(
|
||||
false
|
||||
)->assignCustomerWithAddressChange(
|
||||
$customer
|
||||
)->setShippingAddress(
|
||||
$quoteShippingAddress
|
||||
)->setBillingAddress(
|
||||
$quoteShippingAddress
|
||||
)->setCheckoutMethod(
|
||||
'customer'
|
||||
)->setPasswordHash(
|
||||
$accountManagement->getPasswordHash('password')
|
||||
)->setReservedOrderId(
|
||||
'test_order_1'
|
||||
)->setCustomerEmail(
|
||||
'aaa@aaa.com'
|
||||
)->addProduct(
|
||||
$product,
|
||||
2
|
||||
);
|
||||
$quote->save();
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Api\CartManagementInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/quote_with_address_saved.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var CartManagementInterface $quoteManagement */
|
||||
$quoteManagement = $objectManager->get(CartManagementInterface::class);
|
||||
/** @var GetQuoteByReservedOrderId $getQuoteByReservedOrderId */
|
||||
$getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
|
||||
$quote = $getQuoteByReservedOrderId->execute('test_order_1');
|
||||
$quote->setIsActive(true);
|
||||
$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
|
||||
$quote->getShippingAddress()->setCollectShippingRates(true);
|
||||
$quote->getShippingAddress()->collectShippingRates();
|
||||
$quoteRepository->save($quote);
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?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/Checkout/_files/quote_with_address_saved_rollback.php');
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Customer\Api\AccountManagementInterface;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote\AddressFactory;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_with_addresses.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** Import Customer Address Data */
|
||||
$quoteShippingAddress = $objectManager->get(AddressFactory::class)->create();
|
||||
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
$customer = $customerRepository->get('customer_with_addresses@test.com');
|
||||
$addresses = $customer->getAddresses();
|
||||
$addressFirst = array_shift($addresses);
|
||||
$quoteShippingAddress->importCustomerAddressData($addressFirst);
|
||||
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$mainWebsite = $websiteRepository->get('base');
|
||||
|
||||
$accountManagement = $objectManager->create(AccountManagementInterface::class);
|
||||
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
$quote = $objectManager->get(QuoteFactory::class)->create();
|
||||
$quote->setStoreId($mainWebsite->getDefaultStore()->getId())
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(false)
|
||||
->assignCustomerWithAddressChange($customer)
|
||||
->setShippingAddress($quoteShippingAddress)
|
||||
->setBillingAddress($quoteShippingAddress)
|
||||
->setCheckoutMethod('customer')
|
||||
->setPasswordHash($accountManagement->getPasswordHash('password'))
|
||||
->setReservedOrderId('test_order_999')
|
||||
->setCustomerEmail('aaa2@aaa.com')
|
||||
->addProduct($product, 2);
|
||||
$quoteRepository->save($quote);
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?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\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_with_addresses_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', 'test_order_999')->create();
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)->getItems();
|
||||
$item = array_pop($items);
|
||||
$quoteRepository->delete($item);
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_address_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products_rollback.php');
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Save quote_with_address fixture
|
||||
*
|
||||
* The quote is not saved inside the original fixture. It is later saved inside child fixtures, but along with some
|
||||
* additional data which may break some tests.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
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/Checkout/_files/quote_with_address.php');
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
|
||||
$quoteRepository = \Magento\Framework\App\ObjectManager::getInstance()->get(
|
||||
\Magento\Quote\Api\CartRepositoryInterface::class
|
||||
);
|
||||
$quoteRepository->save($quote);
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Rollback for quote_with_address_saved.php fixture.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_1', 'reserved_order_id')->delete();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager->create(\Magento\Quote\Model\QuoteIdMask::class);
|
||||
$quoteIdMask->delete($quote->getId());
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/quote_with_address_rollback.php');
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_with_multiple_options.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->load(3);
|
||||
|
||||
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
|
||||
//Load options
|
||||
$typeInstance = $product->getTypeInstance();
|
||||
$typeInstance->setStoreFilter($product->getStoreId(), $product);
|
||||
$optionCollection = $typeInstance->getOptionsCollection($product);
|
||||
|
||||
$bundleOptions = [];
|
||||
$bundleOptionsQty = [];
|
||||
/** @var $option \Magento\Bundle\Model\Option */
|
||||
foreach ($optionCollection as $option) {
|
||||
$selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product);
|
||||
if ($option->isMultiSelection()) {
|
||||
$bundleOptions[$option->getId()] = array_column($selectionsCollection->toArray(), 'selection_id');
|
||||
} else {
|
||||
$bundleOptions[$option->getId()] = $selectionsCollection->getFirstItem()->getSelectionId();
|
||||
}
|
||||
$bundleOptionsQty[$option->getId()] = 1;
|
||||
}
|
||||
|
||||
$requestInfo = new \Magento\Framework\DataObject(
|
||||
['qty' => 1, 'bundle_option' => $bundleOptions, 'bundle_option_qty' => $bundleOptionsQty]
|
||||
);
|
||||
|
||||
/** @var $quote \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setStoreId(1)->setReservedOrderId('test_order_bundle')->save();
|
||||
$quote->addProduct($product, $requestInfo);
|
||||
$quote->save();
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Rollback for quote_with_address_saved.php fixture.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_with_multiple_options_rollback.php');
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_bundle', 'reserved_order_id')->delete();
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('bundle-product');
|
||||
|
||||
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
|
||||
//Load options
|
||||
$typeInstance = $product->getTypeInstance();
|
||||
$typeInstance->setStoreFilter($product->getStoreId(), $product);
|
||||
$optionCollection = $typeInstance->getOptionsCollection($product);
|
||||
$selectionCollection = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);
|
||||
|
||||
$bundleOptions = [];
|
||||
$bundleOptionsQty = [];
|
||||
/** @var $option \Magento\Bundle\Model\Option */
|
||||
foreach ($optionCollection as $option) {
|
||||
/** @var $selection \Magento\Bundle\Model\Selection */
|
||||
$selection = $selectionCollection->getFirstItem();
|
||||
$bundleOptions[$option->getId()] = $selection->getSelectionId();
|
||||
$bundleOptionsQty[$option->getId()] = 1;
|
||||
}
|
||||
|
||||
$requestInfo = new \Magento\Framework\DataObject(
|
||||
['qty' => 1, 'bundle_option' => $bundleOptions, 'bundle_option_qty' => $bundleOptionsQty]
|
||||
);
|
||||
|
||||
/** @var $cart \Magento\Checkout\Model\Cart */
|
||||
$cart = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Checkout\Model\Cart::class);
|
||||
$cart->addProduct($product, $requestInfo);
|
||||
$cart->getQuote()->setReservedOrderId('test_cart_with_bundle');
|
||||
$cart->save();
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->removeSharedInstance(\Magento\Checkout\Model\Session::class);
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/*
|
||||
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
|
||||
* bundled items should not contain products with required custom options.
|
||||
* However, if to create such a bundle product, it will be always out of stock.
|
||||
*/
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products_rollback.php');
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_cart_with_bundle', 'reserved_order_id');
|
||||
$quote->delete();
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Option;
|
||||
use Magento\Bundle\Model\Product\Type;
|
||||
use Magento\Bundle\Model\Selection;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Checkout\Model\Cart;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/bundle_product_with_dynamic_price.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Product $product */
|
||||
$product = $productRepository->get('bundle_product_with_dynamic_price');
|
||||
|
||||
/** @var $typeInstance Type */
|
||||
//Load options
|
||||
$typeInstance = $product->getTypeInstance();
|
||||
$typeInstance->setStoreFilter($product->getStoreId(), $product);
|
||||
$optionCollection = $typeInstance->getOptionsCollection($product);
|
||||
|
||||
$bundleOptions = [];
|
||||
$bundleOptionsQty = [];
|
||||
/** @var $option Option */
|
||||
foreach ($optionCollection as $option) {
|
||||
$selectionCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product);
|
||||
/** @var $selection Selection */
|
||||
$selection = $selectionCollection->getFirstItem();
|
||||
$bundleOptions[$option->getId()] = $selection->getSelectionId();
|
||||
$bundleOptionsQty[$option->getId()] = 1;
|
||||
}
|
||||
|
||||
$requestInfo = new DataObject(
|
||||
['qty' => 1, 'bundle_option' => $bundleOptions, 'bundle_option_qty' => $bundleOptionsQty]
|
||||
);
|
||||
|
||||
/** @var Cart $cart */
|
||||
$cart = $objectManager->create(Cart::class);
|
||||
$cart->addProduct($product, $requestInfo);
|
||||
$cart->getQuote()->setReservedOrderId('quote_with_bundle_product_with_dynamic_price');
|
||||
$cart->save();
|
||||
|
||||
$objectManager->removeSharedInstance(Session::class);
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
$quote = $objectManager->create(Quote::class);
|
||||
$quote->load('quote_with_bundle_product_with_dynamic_price', 'reserved_order_id')->delete();
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/bundle_product_with_dynamic_price_rollback.php');
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
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/Checkout/_files/quote_with_address.php');
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
|
||||
|
||||
/** @var $rate \Magento\Quote\Model\Quote\Address\Rate */
|
||||
$rate = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Quote\Model\Quote\Address\Rate::class
|
||||
);
|
||||
$rate->setCode('freeshipping_freeshipping');
|
||||
$rate->getPrice(1);
|
||||
|
||||
$quote->getShippingAddress()->setShippingMethod('freeshipping_freeshipping');
|
||||
$quote->getShippingAddress()->addShippingRate($rate);
|
||||
$quote->getPayment()->setMethod('checkmo');
|
||||
|
||||
$quote->collectTotals();
|
||||
$quote->save();
|
||||
$quote->getPayment()->setMethod('checkmo');
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Rollback for quote_with_check_payment.php fixture.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/default_rollback.php');
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('quote');
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_1', 'reserved_order_id')->delete();
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Save quote_with_coupon fixture
|
||||
*
|
||||
* The quote is not saved inside the original fixture. It is later saved inside child fixtures, but along with some
|
||||
* additional data which may break some tests.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
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/Checkout/_files/discount_10percent.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/quote_with_address_saved.php');
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$salesRuleFactory = $objectManager->get(\Magento\SalesRule\Model\RuleFactory::class);
|
||||
$salesRule = $salesRuleFactory->create();
|
||||
$salesRuleId = $objectManager->get(\Magento\Framework\Registry::class)
|
||||
->registry('Magento/Checkout/_file/discount_10percent');
|
||||
$salesRule->load($salesRuleId);
|
||||
$couponCode = $salesRule->getPrimaryCoupon()->getCode();
|
||||
|
||||
$quote->setCouponCode(trim($couponCode));
|
||||
$quote->collectTotals()->save();
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Rollback for quote_with_coupon_saved.php fixture.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_1', 'reserved_order_id')->delete();
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?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\Type\Onepage;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\Data\CartInterfaceFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
$customer = $customerRepository->get('customer@example.com');
|
||||
|
||||
/** @var CartInterface $quote */
|
||||
$quote = $objectManager->get(CartInterfaceFactory::class)->create();
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(0)
|
||||
->setCustomer($customer)
|
||||
->setCheckoutMethod(Onepage::METHOD_CUSTOMER)
|
||||
->setReservedOrderId('test_order_with_customer_without_address')
|
||||
->addProduct($productRepository->get('simple2'), 1);
|
||||
$quoteRepository->save($quote);
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var GetQuoteByReservedOrderId $getQuoteByReservedOrderId */
|
||||
$getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
|
||||
$quote = $getQuoteByReservedOrderId->execute('test_order_with_customer_without_address');
|
||||
if ($quote !== null) {
|
||||
$quoteRepository->delete($quote);
|
||||
}
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Downloadable/_files/product_downloadable.php');
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('downloadable-product');
|
||||
|
||||
/** @var $linkCollection \Magento\Downloadable\Model\ResourceModel\Link\Collection */
|
||||
$linkCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Downloadable\Model\Link::class
|
||||
)->getCollection()->addProductToFilter(
|
||||
$product->getId()
|
||||
)->addTitleToResult(
|
||||
$product->getStoreId()
|
||||
)->addPriceToResult(
|
||||
$product->getStore()->getWebsiteId()
|
||||
);
|
||||
|
||||
/** @var $link \Magento\Downloadable\Model\Link */
|
||||
$link = $linkCollection->getFirstItem();
|
||||
|
||||
$requestInfo = new \Magento\Framework\DataObject(['qty' => 1, 'links' => [$link->getId()]]);
|
||||
|
||||
/** @var $cart \Magento\Checkout\Model\Cart */
|
||||
$cart = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Checkout\Model\Cart::class);
|
||||
$cart->addProduct($product, $requestInfo);
|
||||
$cart->save();
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->removeSharedInstance(\Magento\Checkout\Model\Session::class);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Downloadable/_files/product_downloadable_rollback.php');
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Quote\Model\QuoteIdMask;
|
||||
use Magento\Quote\Model\QuoteIdMaskFactory;
|
||||
use Magento\Quote\Model\QuoteRepository;
|
||||
use Magento\TestFramework\Catalog\Model\Product\Option\Type\File\ValidatorFileMock;
|
||||
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/Checkout/_files/quote_with_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_with_options.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = $objectManager->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = $objectManager->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
|
||||
$options = [];
|
||||
/** @var $option \Magento\Catalog\Model\Product\Option */
|
||||
foreach ($product->getOptions() as $option) {
|
||||
switch ($option->getGroupByType()) {
|
||||
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE:
|
||||
$value = ['year' => 2013, 'month' => 8, 'day' => 9, 'hour' => 13, 'minute' => 35];
|
||||
break;
|
||||
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT:
|
||||
$value = key($option->getValues());
|
||||
break;
|
||||
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_FILE:
|
||||
$value = 'test.jpg';
|
||||
break;
|
||||
default:
|
||||
$value = 'test';
|
||||
break;
|
||||
}
|
||||
$options[$option->getId()] = $value;
|
||||
}
|
||||
|
||||
$requestInfo = new DataObject(['qty' => 1, 'options' => $options]);
|
||||
$validatorFile = $objectManager->get(ValidatorFileMock::class)->getInstance();
|
||||
$objectManager->addSharedInstance($validatorFile, ValidatorFile::class);
|
||||
|
||||
$quote->setReservedOrderId('test_order_item_with_items_and_custom_options');
|
||||
$quote->addProduct($product, $requestInfo);
|
||||
$quote->collectTotals();
|
||||
$objectManager->get(QuoteRepository::class)->save($quote);
|
||||
|
||||
/** @var QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = Bootstrap::getObjectManager()
|
||||
->create(QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->removeSharedInstance(\Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile::class);
|
||||
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_item_with_items_and_custom_options', 'reserved_order_id');
|
||||
$quoteId = $quote->getId();
|
||||
if ($quote->getId()) {
|
||||
$objectManager->get(\Magento\Quote\Model\QuoteRepository::class)->delete($quote);
|
||||
}
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/quote_with_address_rollback.php');
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Save quote_with_address fixture
|
||||
*
|
||||
* The quote is not saved inside the original fixture. It is later saved inside child fixtures, but along with some
|
||||
* additional data which may break some tests.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
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/Checkout/_files/quote_with_address.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = $objectManager->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = $objectManager->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(
|
||||
'simple'
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setName(
|
||||
'Simple Product One'
|
||||
)->setSku(
|
||||
'simple_one'
|
||||
)->setPrice(
|
||||
10
|
||||
)->setMetaTitle(
|
||||
'meta title'
|
||||
)->setMetaKeyword(
|
||||
'meta keyword'
|
||||
)->setMetaDescription(
|
||||
'meta description'
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->setStockData(
|
||||
['use_config_manage_stock' => 0]
|
||||
)->save();
|
||||
$quoteProduct = $product->load($product->getIdBySku('simple_one'));
|
||||
$quote->setReservedOrderId('test_order_item_with_items')
|
||||
->addProduct($product->load($product->getIdBySku('simple_one')), 1);
|
||||
$quote->collectTotals()->save();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$registry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_item_with_items', 'reserved_order_id');
|
||||
$quoteId = $quote->getId();
|
||||
if ($quote->getId()) {
|
||||
$quote->delete();
|
||||
}
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->load($product->getIdBySku('simple_one'));
|
||||
if ($product->getId()) {
|
||||
$product->delete();
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/quote_with_address_rollback.php');
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?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\Type\Onepage;
|
||||
use Magento\Customer\Api\AddressRepositoryInterface;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterfaceFactory;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\Data\CartInterfaceFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/simple_products_not_visible_individually.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var AddressInterface $quoteShippingAddress */
|
||||
$quoteShippingAddress = $objectManager->get(AddressInterfaceFactory::class)->create();
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
/** @var AddressRepositoryInterface $addressRepository */
|
||||
$addressRepository = $objectManager->get(AddressRepositoryInterface::class);
|
||||
$quoteShippingAddress->importCustomerAddressData($addressRepository->getById(1));
|
||||
$customer = $customerRepository->getById(1);
|
||||
|
||||
/** @var CartInterface $quote */
|
||||
$quote = $objectManager->get(CartInterfaceFactory::class)->create();
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(0)
|
||||
->assignCustomerWithAddressChange($customer)
|
||||
->setShippingAddress($quoteShippingAddress)
|
||||
->setBillingAddress($quoteShippingAddress)
|
||||
->setCheckoutMethod(Onepage::METHOD_CUSTOMER)
|
||||
->setReservedOrderId('test_order_with_not_visible_product')
|
||||
->setEmail($customer->getEmail())
|
||||
->addProduct($productRepository->get('simple_not_visible_1'), 1);
|
||||
|
||||
$quoteRepository->save($quote);
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var GetQuoteByReservedOrderId $getQuoteByReservedOrderId */
|
||||
$getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
|
||||
$quote = $getQuoteByReservedOrderId->execute('test_order_with_not_visible_product');
|
||||
if ($quote) {
|
||||
$quoteRepository->delete($quote);
|
||||
}
|
||||
|
||||
Resolver::getInstance()
|
||||
->requireDataFixture('Magento/Catalog/_files/simple_products_not_visible_individually_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_address_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
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/Checkout/_files/quote_with_address.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = $objectManager->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = $objectManager->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
|
||||
|
||||
/** @var \Magento\Framework\Serialize\Serializer\Json $serializer */
|
||||
$serializer = $objectManager->create(\Magento\Framework\Serialize\Serializer\Json::class);
|
||||
|
||||
$quote->setReservedOrderId(
|
||||
'test_order_1_with_payment'
|
||||
);
|
||||
|
||||
$paymentDetails = [
|
||||
'transaction_id' => 100500,
|
||||
'consumer_key' => '123123q',
|
||||
];
|
||||
|
||||
$quote->getPayment()
|
||||
->setMethod('checkmo')
|
||||
->setPoNumber('poNumber')
|
||||
->setCcOwner('tester')
|
||||
->setCcType('visa')
|
||||
->setCcExpYear(2014)
|
||||
->setCcExpMonth(1)
|
||||
->setAdditionalData($serializer->serialize($paymentDetails));
|
||||
|
||||
$quote->collectTotals()->save();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Rollback for quote_with_payment_saved.php fixture.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_1_with_payment', 'reserved_order_id')->delete();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager->create(\Magento\Quote\Model\QuoteIdMask::class);
|
||||
$quoteIdMask->delete($quote->getId());
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
$quote->setStoreId(1)->setIsActive(false)->setIsMultiShipping(false)->addProduct($product, 2);
|
||||
|
||||
$quote->getPayment()->setMethod('checkmo');
|
||||
|
||||
$quote->collectTotals();
|
||||
$quote->save();
|
||||
|
||||
$quote->getPayment()->setMethod('checkmo');
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/rollback_quote.php');
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Quote with simple product, shipping, billing addresses and shipping method fixture
|
||||
*
|
||||
* The quote is not saved inside the original fixture. It is later saved inside child fixtures, but along with some
|
||||
* additional data which may break some tests.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
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/Checkout/_files/quote_with_address_saved.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = $objectManager->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = $objectManager->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
|
||||
$rate = $objectManager->get(\Magento\Quote\Model\Quote\Address\Rate::class);
|
||||
|
||||
$shippingAddress = $quote->getShippingAddress();
|
||||
$shippingAddress->setShippingMethod('flatrate_flatrate')
|
||||
->setShippingDescription('Flat Rate - Fixed')
|
||||
->save();
|
||||
|
||||
$rate->setPrice(0)
|
||||
->setAddressId($shippingAddress->getId())
|
||||
->save();
|
||||
$shippingAddress->setBaseShippingAmount($rate->getPrice());
|
||||
$shippingAddress->setShippingAmount($rate->getPrice());
|
||||
$rate->delete();
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* Quote with simple product, shipping, billing addresses and shipping method fixture
|
||||
*
|
||||
* The quote is not saved inside the original fixture. It is later saved inside child fixtures, but along with some
|
||||
* additional data which may break some tests.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
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/Catalog/_files/categories_no_products.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/quote_with_shipping_method.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = $objectManager->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = $objectManager->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
|
||||
|
||||
$quote->load('test_order_1', 'reserved_order_id');
|
||||
$quote->removeAllItems();
|
||||
$quote->setReservedOrderId('test_order_item_with_items');
|
||||
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(
|
||||
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
|
||||
)->setId(
|
||||
333
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setStoreId(
|
||||
1
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setName(
|
||||
'Simple Product Cat Four'
|
||||
)->setSku(
|
||||
'simple_cat_3'
|
||||
)->setPrice(
|
||||
80
|
||||
)->setWeight(
|
||||
18
|
||||
)->setStockData(
|
||||
['use_config_manage_stock' => 0]
|
||||
)->setCategoryIds(
|
||||
[3]
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->save();
|
||||
|
||||
$quote->addProduct($product->load($product->getIdBySku('simple_cat_3')), 1);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(
|
||||
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
|
||||
)->setId(
|
||||
444
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setStoreId(
|
||||
1
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setName(
|
||||
'Simple Product Cat Five'
|
||||
)->setSku(
|
||||
'simple_cat_4'
|
||||
)->setPrice(
|
||||
15
|
||||
)->setWeight(
|
||||
18
|
||||
)->setStockData(
|
||||
['use_config_manage_stock' => 0]
|
||||
)->setCategoryIds(
|
||||
[4]
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->save();
|
||||
|
||||
$quote->addProduct($product->load($product->getIdBySku('simple_cat_4')), 1);
|
||||
|
||||
//save quote with id
|
||||
$quote->collectTotals()->save();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$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);
|
||||
|
||||
$productSkuList = ['simple_cat_3', 'simple_cat_4'];
|
||||
foreach ($productSkuList as $sku) {
|
||||
try {
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get($sku, true);
|
||||
if ($product->getId()) {
|
||||
$productRepository->delete($product);
|
||||
}
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
}
|
||||
|
||||
//Remove categories
|
||||
/** @var Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
|
||||
$collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Category\Collection::class);
|
||||
$collection
|
||||
->addAttributeToFilter('level', 2)
|
||||
->load()
|
||||
->delete();
|
||||
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_1', 'reserved_order_id')->delete();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager->create(\Magento\Quote\Model\QuoteIdMask::class);
|
||||
$quoteIdMask->delete($quote->getId());
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/quote_with_address_rollback.php');
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Rollback for quote_with_shipping_method.php fixture.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/quote_with_address_saved_rollback.php');
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products.php');
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('simple');
|
||||
|
||||
$requestInfo = new \Magento\Framework\DataObject(['qty' => 1]);
|
||||
|
||||
/** @var $cart \Magento\Checkout\Model\Cart */
|
||||
$cart = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Checkout\Model\Cart::class);
|
||||
$cart->addProduct($product, $requestInfo);
|
||||
$cart->save();
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->removeSharedInstance(\Magento\Checkout\Model\Session::class);
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple.php');
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
|
||||
$options = [];
|
||||
/** @var $option \Magento\Catalog\Model\Product\Option */
|
||||
foreach ($product->getOptions() as $option) {
|
||||
switch ($option->getGroupByType()) {
|
||||
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE:
|
||||
$value = ['year' => 2013, 'month' => 8, 'day' => 9, 'hour' => 13, 'minute' => 35];
|
||||
break;
|
||||
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT:
|
||||
$value = key($option->getValues());
|
||||
break;
|
||||
default:
|
||||
$value = 'test';
|
||||
break;
|
||||
}
|
||||
$options[$option->getId()] = $value;
|
||||
}
|
||||
|
||||
$requestInfo = new \Magento\Framework\DataObject(['qty' => 1, 'options' => $options]);
|
||||
|
||||
/** @var $cart \Magento\Checkout\Model\Cart */
|
||||
$cart = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Checkout\Model\Cart::class);
|
||||
$cart->addProduct($product, $requestInfo);
|
||||
$cart->save();
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->removeSharedInstance(\Magento\Checkout\Model\Session::class);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_image.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/quote_with_simple_product.php');
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->load(1)
|
||||
->setStoreId(0)
|
||||
->setImage('/m/a/magento_image.jpg')
|
||||
->setSmallImage('/m/a/magento_image.jpg')
|
||||
->setThumbnail('/m/a/magento_image.jpg')
|
||||
->setData('media_gallery', ['images' => [
|
||||
[
|
||||
'file' => '/m/a/magento_image.jpg',
|
||||
'position' => 1,
|
||||
'label' => 'Image Alt Text',
|
||||
'disabled' => 0,
|
||||
],
|
||||
]])->save();
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Rollback for quote_with_simple_product_and_image.php fixture.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_image_rollback.php');
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/simple_product.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(false)
|
||||
->setReservedOrderId('test_order_with_simple_product_without_address')
|
||||
->setEmail('store@example.com')
|
||||
->addProduct($product->load($product->getId()), 1);
|
||||
|
||||
$quote->collectTotals()->save();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Rollback for quote_with_payment_saved.php fixture.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_with_simple_product_without_address', 'reserved_order_id')->delete();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager->create(\Magento\Quote\Model\QuoteIdMask::class);
|
||||
$quoteIdMask->delete($quote->getId());
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Checkout/_files/simple_product_rollback.php');
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Checkout\Model\Type\Onepage;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\Data\CartInterfaceFactory;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = Bootstrap::getObjectManager()
|
||||
->create(ProductRepositoryInterface::class);
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var CartInterface $quote */
|
||||
$quote = $objectManager->get(CartInterfaceFactory::class)->create();
|
||||
$quote->setIsActive(true)
|
||||
->setStoreId(1)
|
||||
->setCheckoutMethod(Onepage::METHOD_GUEST)
|
||||
->setReservedOrderId('test_quote_with_simple_products');
|
||||
$quote->addProduct($productRepository->get('simple1'), 1);
|
||||
$quote->addProduct($productRepository->get('simple2'), 1);
|
||||
$quoteRepository->save($quote);
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?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;
|
||||
use Magento\Quote\Model\ResourceModel\Quote\Collection;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Framework\Registry;
|
||||
|
||||
/** @var Registry $registry */
|
||||
$registry = Bootstrap::getObjectManager()->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var $order Quote */
|
||||
$quoteCollection = Bootstrap::getObjectManager()->create(Collection::class);
|
||||
foreach ($quoteCollection as $quote) {
|
||||
$quote->delete();
|
||||
}
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?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\Type\Onepage;
|
||||
use Magento\Customer\Api\AddressRepositoryInterface;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterfaceFactory;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\Data\CartInterfaceFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/taxable_simple_product.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var AddressInterface $quoteShippingAddress */
|
||||
$quoteShippingAddress = $objectManager->get(AddressInterfaceFactory::class)->create();
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
|
||||
/** @var AddressRepositoryInterface $addressRepository */
|
||||
$addressRepository = $objectManager->get(AddressRepositoryInterface::class);
|
||||
$quoteShippingAddress->importCustomerAddressData($addressRepository->getById(1));
|
||||
$customer = $customerRepository->getById(1);
|
||||
|
||||
/** @var CartInterface $quote */
|
||||
$quote = $objectManager->get(CartInterfaceFactory::class)->create();
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(0)
|
||||
->assignCustomerWithAddressChange($customer)
|
||||
->setShippingAddress($quoteShippingAddress)
|
||||
->setBillingAddress($quoteShippingAddress)
|
||||
->setCheckoutMethod(Onepage::METHOD_CUSTOMER)
|
||||
->setReservedOrderId('test_order_with_taxable_product')
|
||||
->setEmail($customer->getEmail())
|
||||
->addProduct($productRepository->get('taxable_product'), 1);
|
||||
$quoteRepository->save($quote);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var GetQuoteByReservedOrderId $getQuoteByReservedOrderId */
|
||||
$getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
|
||||
$quote = $getQuoteByReservedOrderId->execute('test_order_with_taxable_product');
|
||||
if ($quote) {
|
||||
$quoteRepository->delete($quote);
|
||||
}
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/taxable_simple_product_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_address_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Customer\Model\CustomerRegistry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_virtual.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Quote\Model\Quote\Address $quoteShippingAddress */
|
||||
$quoteShippingAddress = $objectManager->create(
|
||||
\Magento\Quote\Model\Quote\Address::class
|
||||
);
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->create(
|
||||
\Magento\Customer\Api\CustomerRepositoryInterface::class
|
||||
);
|
||||
/** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */
|
||||
$addressRepository = $objectManager->create(
|
||||
\Magento\Customer\Api\AddressRepositoryInterface::class
|
||||
);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('virtual-product');
|
||||
$quoteShippingAddress->importCustomerAddressData($addressRepository->getById(1));
|
||||
/** @var CustomerRegistry $customerRegistry */
|
||||
$customerRegistry = Bootstrap::getObjectManager()->create(CustomerRegistry::class);
|
||||
$customer = $customerRegistry->retrieve(1);
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(false)
|
||||
->assignCustomerWithAddressChange($customerRepository->getById($customer->getId()))
|
||||
->setShippingAddress($quoteShippingAddress)
|
||||
->setBillingAddress($quoteShippingAddress)
|
||||
->setCheckoutMethod($customer->getMode())
|
||||
->setPasswordHash($customer->encryptPassword($customer->getPassword()))
|
||||
->setReservedOrderId('test_order_with_virtual_product')
|
||||
->setEmail('store@example.com')
|
||||
->addProduct($product->load($product->getId()), 1);
|
||||
|
||||
$quote->collectTotals()->save();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Rollback for quote_with_virtual_product_and_address.php fixture.
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_with_virtual_product', 'reserved_order_id')->delete();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager->create(\Magento\Quote\Model\QuoteIdMask::class);
|
||||
$quoteIdMask->delete($quote->getId());
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_address_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_virtual_rollback.php');
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_virtual.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('virtual-product');
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setStoreId(1)
|
||||
->setIsActive(true)
|
||||
->setIsMultiShipping(false)
|
||||
->setReservedOrderId('test_order_with_virtual_product_without_address')
|
||||
->setEmail('store@example.com')
|
||||
->setCustomerEmail('store@example.com')
|
||||
->addProduct(
|
||||
$product,
|
||||
1
|
||||
);
|
||||
|
||||
$quote->collectTotals()->save();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $objectManager
|
||||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
|
||||
->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId());
|
||||
$quoteIdMask->setDataChanges(true);
|
||||
$quoteIdMask->save();
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user