ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,149 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
namespace Amasty\SortingGraphQl\Test\GraphQl;
use Amasty\Sorting\Model\Indexer\Summary;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;
class SortingAmFeaturedWidgetTest extends GraphQlAbstract
{
private const MAIN_RESPONSE_KEY = 'amfeaturedWidget';
/**
* @var Summary
*/
private $summary;
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
protected function setUp(): void
{
parent::setUp();
$objectManager = Bootstrap::getObjectManager();
$this->summary = $objectManager->get(Summary::class);
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
}
/**
* @group amasty_sorting
*
* @magentoApiDataFixture Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_products.php
*/
public function testSortingAmFeaturedWidget(): void
{
$this->summary->reindexAll();
// get main product data
$productSku = 'am_sort_simple_5';
$product = $this->productRepository->get($productSku);
$productId = (int)$product->getId();
$productName = $product->getName();
$productUrl = $product->getUrlKey();
$productPrice = (int)$product->getPrice();
$variables = [
'sortBy' => 'price',
'amsortingSortOrder' => 'desc',
'productsCount' => 4,
'conditions' => "[]",
'showPager' => false,
'productsPerPage' => 5,
'currentPage' => 3
];
$assertArrayItem = [
'id' => $productId,
'sku' => $productSku,
'productUrl' => '/' . $productUrl . '.html',
'thumbnail' => [
'label' => $productName
],
'name' => $productName,
'price_range' => [
'maximum_price' => [
'final_price' => [
'value' => $productPrice
]
],
'minimum_price' => [
'final_price' => [
'value' => $productPrice
]
]
],
'isSalable' => true,
'hasRequiredOptions' => false
];
$response = $this->graphQlQuery($this->getQuery(), $variables);
$this->assertArrayHasKey(self::MAIN_RESPONSE_KEY, $response);
$this->assertCount(4, $response[self::MAIN_RESPONSE_KEY]);
$this->assertResponseFields($response[self::MAIN_RESPONSE_KEY][1], $assertArrayItem);
$this->assertArrayHasKey('addToCartUrl', $response[self::MAIN_RESPONSE_KEY][1]);
$this->assertArrayHasKey('addToCompareParams', $response[self::MAIN_RESPONSE_KEY][1]);
}
private function getQuery(): string
{
return <<<'QUERY'
query AmFeaturedWidget (
$sortBy: String!,
$amsortingSortOrder: String!,
$productsCount: Int!,
$conditions: String!,
$showPager: Boolean,
$productsPerPage: Int,
$currentPage: Int
) {
amfeaturedWidget (
sortBy:$sortBy
amsortingSortOrder:$amsortingSortOrder
productsCount:$productsCount
conditions:$conditions
showPager:$showPager
productsPerPage:$productsPerPage
currentPage:$currentPage
) {
id
sku
productUrl
thumbnail {
label
}
name
price_range {
maximum_price {
final_price {
value
}
}
minimum_price {
final_price {
value
}
}
}
isSalable
hasRequiredOptions
addToCartUrl
addToCompareParams
}
}
QUERY;
}
}
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
namespace Amasty\SortingGraphQl\Test\GraphQl;
use Magento\TestFramework\TestCase\GraphQlAbstract;
class SortingAmOrderListTest extends GraphQlAbstract
{
private const MAIN_RESPONSE_KEY = 'amOrderList';
/**
* @group amasty_sorting
*/
public function testSortingAmOrderList(): void
{
$assertArrayItem = [
'attribute' => 'price',
'id' => 'price',
'sortDirection' => 'ASC',
'text' => 'Price'
];
$response = $this->graphQlQuery($this->getQuery());
$this->assertArrayHasKey(self::MAIN_RESPONSE_KEY, $response);
$this->assertGreaterThanOrEqual(1, count($response[self::MAIN_RESPONSE_KEY]));
$havePriceAttr = false;
foreach ($response[self::MAIN_RESPONSE_KEY] as $attr) {
if ($attr['attribute'] == 'price') {
$this->assertResponseFields($attr, $assertArrayItem);
$havePriceAttr = true;
break;
}
}
$this->assertTrue($havePriceAttr, 'List of orders not contains default attribute "Price".');
}
private function getQuery(): string
{
return <<<QUERY
query {
amOrderList {
attribute
id
sortDirection
text
}
}
QUERY;
}
}
@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
namespace Amasty\SortingGraphQl\Test\GraphQl;
use Magento\TestFramework\TestCase\GraphQlAbstract;
class SortingDefaultSortingTest extends GraphQlAbstract
{
private const MAIN_RESPONSE_KEY = 'defaultSorting';
/**
* @group amasty_sorting
*
* @magentoConfigFixture default_store amsorting/default_sorting/category_1 price
*/
public function testSortingDefaultSortingCategory(): void
{
$assertResponse = [
[
'attribute' => 'price',
'id' => 'price',
'sortDirection' => 'ASC',
'text' => 'Price'
]
];
$response = $this->graphQlQuery($this->getQueryCategory());
$this->assertArrayHasKey(self::MAIN_RESPONSE_KEY, $response);
$this->assertResponseFields($response[self::MAIN_RESPONSE_KEY], $assertResponse);
}
/**
* @group amasty_sorting
*
* @magentoConfigFixture default_store amsorting/default_sorting/search_1 name
*/
public function testSortingDefaultSortingSearch(): void
{
$assertResponse = [
[
'attribute' => 'name',
'id' => 'name',
'sortDirection' => 'ASC',
'text' => 'Product Name'
]
];
$response = $this->graphQlQuery($this->getQuerySearch());
$this->assertArrayHasKey(self::MAIN_RESPONSE_KEY, $response);
$this->assertResponseFields($response[self::MAIN_RESPONSE_KEY], $assertResponse);
}
private function getQueryCategory(): string
{
return <<<QUERY
query {
defaultSorting(pageType:CATEGORY) {
attribute
id
sortDirection
text
}
}
QUERY;
}
private function getQuerySearch(): string
{
return <<<QUERY
query {
defaultSorting(pageType:SEARCH) {
attribute
id
sortDirection
text
}
}
QUERY;
}
}
@@ -0,0 +1,358 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
namespace Amasty\SortingGraphQl\Test\GraphQl;
use Amasty\Sorting\Model\Indexer\Summary;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;
use Magento\Framework\Shell;
class SortingProductsTest extends GraphQlAbstract
{
private const MAIN_RESPONSE_KEY = 'products';
private const MAIN_SEARCH_WORD = 'Amasty';
/**
* @var Summary
*/
private $summary;
/**
* @var Shell
*/
private $shell;
protected function setUp(): void
{
parent::setUp();
$objectManager = Bootstrap::getObjectManager();
$this->summary = $objectManager->get(Summary::class);
$this->shell = Bootstrap::getObjectManager()->get(Shell::class);
}
/**
* @group amasty_sorting
*
* @magentoApiDataFixture Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_products.php
* @magentoApiDataFixture Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_wishlist.php
* @magentoApiDataFixture Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_wishlist_second.php
*/
public function testSortingProductsWished(): void
{
$this->summary->reindexAll();
$this->reindexCatalogProducts();
$assertArrayItems = [
'items' => [
[
'sku' => 'am_sort_virtual_1'
],
[
'sku' => 'am_sort_simple_4'
],
[
'sku' => 'am_sort_virtual_4'
],
]
];
$response = $this->graphQlQuery($this->getQueryWished(self::MAIN_SEARCH_WORD));
$this->assertArrayHasKey(self::MAIN_RESPONSE_KEY, $response);
$this->assertResponseFields($response[self::MAIN_RESPONSE_KEY], $assertArrayItems);
}
/**
* @group amasty_sorting
*
* @magentoApiDataFixture Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_products.php
*/
public function testSortingProductsPrice(): void
{
$this->summary->reindexAll();
$this->reindexCatalogProducts();
$assertArrayItems = [
'items' => [
[
'sku' => 'am_sort_virtual_1'
],
[
'sku' => 'am_sort_simple_1'
],
[
'sku' => 'am_sort_virtual_5'
],
]
];
$response = $this->graphQlQuery($this->getQueryPriceAsc(self::MAIN_SEARCH_WORD));
$this->assertArrayHasKey(self::MAIN_RESPONSE_KEY, $response);
$this->assertResponseFields($response[self::MAIN_RESPONSE_KEY], $assertArrayItems);
}
/**
* @group amasty_sorting
*
* @magentoApiDataFixture Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_products.php
*/
public function testSortingProductsNew(): void
{
$this->summary->reindexAll();
$this->reindexCatalogProducts();
$assertArrayItems = [
'items' => [
[
'sku' => 'am_sort_virtual_1'
],
[
'sku' => 'am_sort_virtual_4'
],
[
'sku' => 'am_sort_virtual_3'
],
]
];
$response = $this->graphQlQuery($this->getQueryNew(self::MAIN_SEARCH_WORD));
$this->assertArrayHasKey(self::MAIN_RESPONSE_KEY, $response);
$this->assertResponseFields($response[self::MAIN_RESPONSE_KEY], $assertArrayItems);
}
/**
* @group amasty_sorting
*
* @magentoApiDataFixture Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_customer_order.php
*/
public function testSortingProductsBestsellers(): void
{
$this->summary->reindexAll();
$this->reindexCatalogProducts();
$assertArrayItems = [
'items' => [
[
'sku' => 'am_sort_simple_4'
],
[
'sku' => 'am_sort_virtual_2'
],
[
'sku' => 'am_sort_virtual_1'
],
]
];
$response = $this->graphQlQuery($this->getQueryBestsellers(self::MAIN_SEARCH_WORD));
$this->assertArrayHasKey(self::MAIN_RESPONSE_KEY, $response);
$this->assertResponseFields($response[self::MAIN_RESPONSE_KEY], $assertArrayItems);
}
/**
* @group amasty_sorting
*
* @magentoApiDataFixture Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_customer_order.php
*/
public function testSortingProductsRevenue(): void
{
$this->summary->reindexAll();
$this->reindexCatalogProducts();
$assertArrayItems = [
'items' => [
[
'sku' => 'am_sort_simple_4'
],
[
'sku' => 'am_sort_virtual_2'
],
[
'sku' => 'am_sort_virtual_1'
],
]
];
$response = $this->graphQlQuery($this->getQueryRevenue(self::MAIN_SEARCH_WORD));
$this->assertArrayHasKey(self::MAIN_RESPONSE_KEY, $response);
$this->assertResponseFields($response[self::MAIN_RESPONSE_KEY], $assertArrayItems);
}
/**
* @group amasty_sorting
*
* @magentoApiDataFixture Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_customer_order.php
*/
public function testSortingProductsOtherSorts(): void
{
$this->summary->reindexAll();
$this->reindexCatalogProducts();
$assertArrayItems = [
'items' => [
[
'sku' => 'am_sort_virtual_1'
],
[
'sku' => 'am_sort_simple_1'
],
[
'sku' => 'am_sort_virtual_5'
],
]
];
$response = $this->graphQlQuery($this->getQueryOtherSorts(self::MAIN_SEARCH_WORD));
$this->assertArrayHasKey(self::MAIN_RESPONSE_KEY, $response);
$this->assertResponseFields($response[self::MAIN_RESPONSE_KEY], $assertArrayItems);
}
private function getQueryWished(string $search): string
{
return <<<QUERY
query {
products (
search: "$search"
pageSize: 3
sort: {
wished:DESC
}
) {
items {
sku
}
}
}
QUERY;
}
private function getQueryNew(string $search): string
{
return <<<QUERY
query {
products (
search: "$search"
pageSize: 3
sort: {
new:DESC
}
) {
items {
sku
}
}
}
QUERY;
}
private function getQueryPriceAsc(string $search): string
{
return <<<QUERY
query {
products (
search: "$search"
pageSize: 3
sort: {
price_desc:ASC
}
) {
items {
sku
}
}
}
QUERY;
}
private function getQueryBestsellers(string $search): string
{
return <<<QUERY
query {
products (
search: "$search"
pageSize: 3
sort: {
bestsellers:DESC
}
) {
items {
sku
}
}
}
QUERY;
}
private function getQueryRevenue(string $search): string
{
return <<<QUERY
query {
products (
search: "$search"
pageSize: 3
sort: {
revenue:DESC
}
) {
items {
sku
}
}
}
QUERY;
}
private function getQueryOtherSorts(string $search): string
{
return <<<QUERY
query {
products (
search: "$search"
pageSize: 3
sort: {
rating_summary:ASC
reviews_count:ASC
most_viewed:ASC
saving:ASC
price_asc:ASC
}
) {
items {
sku
}
}
}
QUERY;
}
private function reindexCatalogProducts():void
{
$indexes = [
'catalogrule_rule',
'catalogsearch_fulltext',
'catalog_category_product',
'catalog_product_attribute',
'inventory',
'catalog_product_price',
'cataloginventory_stock'
];
$parameters = implode(' ', $indexes);
$appDir = dirname(Bootstrap::getInstance()->getAppTempDir());
$this->shell->execute("php -f {$appDir}/bin/magento indexer:reindex {$parameters}");
}
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
Resolver::getInstance()->requireDataFixture(
'Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_customer_quote_for_order.php'
);
$objectManager = Bootstrap::getObjectManager();
/** @var CartRepositoryInterface $quoteRepository */
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
/** @var CartManagementInterface $quoteManagement */
$quoteManagement = $objectManager->get(CartManagementInterface::class);
/** @var CustomerRepositoryInterface $customerRepository */
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
$customer = $customerRepository->get('customer_with_addresses@test.com');
$quote = $quoteRepository->getActiveForCustomer($customer->getId());
$quoteManagement->placeOrder($quote->getId());
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
use Magento\Framework\Registry;
use Magento\Sales\Api\Data\OrderInterfaceFactory;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
$objectManager = Bootstrap::getObjectManager();
/** @var Registry $registry */
$registry = $objectManager->get(Registry::class);
/** @var OrderRepositoryInterface $orderRepository */
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
/** @var OrderInterfaceFactory $orderFactory */
$orderFactory = $objectManager->get(OrderInterfaceFactory::class);
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);
$order = $orderFactory->create()->loadByIncrementId('123456789');
if ($order->getId()) {
$orderRepository->delete($order);
}
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);
Resolver::getInstance()->requireDataFixture(
'Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_customer_quote_for_order_rollback.php'
);
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Checkout\Model\Type\Onepage;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
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_with_addresses.php');
Resolver::getInstance()->requireDataFixture('Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_products.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);
/** @var SearchCriteriaBuilder $searchCriteria */
$searchCriteria = $objectManager->get(SearchCriteriaBuilder::class);
$productRepository->cleanCache();
$searchCriteriaAddress = $searchCriteria->addFilter('postcode', '75477')
->addFilter('city', 'CityM')
->addFilter('country_id', 'US')
->addFilter('firstname', 'John')
->addFilter('street', 'CustomerAddress1')
->create();
$address = $addressRepository->getList($searchCriteriaAddress)->getItems()[0];
$quoteShippingAddress->importCustomerAddressData($address);
$customer = $customerRepository->get('customer_with_addresses@test.com');
/** @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('123456789')
->setEmail($customer->getEmail());
$quote->addProduct($productRepository->get('am_sort_simple_4'), 3);
$quote->addProduct($productRepository->get('am_sort_virtual_2'), 1);
$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getShippingAddress()->collectShippingRates();
$quote->getPayment()->setMethod('checkmo');
$quoteRepository->save($quote);
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
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('123456789');
if ($quote) {
$quoteRepository->delete($quote);
}
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_with_addresses_rollback.php');
Resolver::getInstance()->requireDataFixture('Amasty_SortingGraphQl::Test/GraphQl/_files/am_sort_products_rollback.php');
@@ -0,0 +1,148 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Api\Data\CategoryInterfaceFactory;
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\Product\Type;
use Magento\Catalog\Model\Product\Visibility;
use Magento\TestFramework\Helper\Bootstrap;
$objectManager = Bootstrap::getObjectManager();
/** @var ProductInterfaceFactory $productFactory */
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
/** @var CategoryInterfaceFactory $categoryFactory */
$categoryFactory = $objectManager->get(CategoryInterfaceFactory::class);
/** @var CategoryRepositoryInterface $categoryRepository */
$categoryRepository = $objectManager->get(CategoryRepositoryInterface::class);
// create first category
$category = $categoryFactory->create();
$category->isObjectNew(true);
$category->setName('Am Category Sorting One Test')
->setIsActive(true)
->setPosition(1);
$category = $categoryRepository->save($category);
$categoryId = $category->getId();
// create second category
$categorySecond = $categoryFactory->create();
$categorySecond->isObjectNew(true);
$categorySecond->setName('Am Category Sorting Second Test')
->setIsActive(true)
->setPosition(1);
$categorySecond = $categoryRepository->save($categorySecond);
$categorySecondId = $categorySecond->getId();
// create products data array
$productsData = [
[
'sku' => 'am_sort_simple_1',
'category' => [$categoryId],
'type' => Type::TYPE_SIMPLE,
'name' => 'Amasty Simple Product 1',
'price' => 1000
],
[
'sku' => 'am_sort_simple_2',
'category' => [$categorySecondId],
'type' => Type::TYPE_SIMPLE,
'name' => 'Amasty Simple Product 2',
'price' => 1200
],
[
'sku' => 'am_sort_simple_3',
'category' => [$categoryId],
'type' => Type::TYPE_SIMPLE,
'name' => 'Amasty Simple Product 3',
'price' => 1200
],
[
'sku' => 'am_sort_simple_4',
'category' => [$categorySecondId],
'type' => Type::TYPE_SIMPLE,
'name' => 'Amasty Simple Product 4',
'price' => 2000
],
[
'sku' => 'am_sort_simple_5',
'category' => [$categoryId],
'type' => Type::TYPE_SIMPLE,
'name' => 'Amasty Simple Product 5',
'price' => 5000
],
[
'sku' => 'am_sort_virtual_5',
'category' => [$categorySecondId],
'type' => Type::TYPE_VIRTUAL,
'name' => 'Amasty Virtual Product 1',
'price' => 1000
],
[
'sku' => 'am_sort_virtual_2',
'category' => [$categoryId],
'type' => Type::TYPE_VIRTUAL,
'name' => 'Amasty Virtual Product 2',
'price' => 2500
],
[
'sku' => 'am_sort_virtual_3',
'category' => [$categorySecondId],
'type' => Type::TYPE_VIRTUAL,
'name' => 'Amasty Virtual Product 3',
'price' => 2500
],
[
'sku' => 'am_sort_virtual_4',
'category' => [$categoryId],
'type' => Type::TYPE_VIRTUAL,
'name' => 'Amasty Virtual Product 4',
'price' => 50000
],
[
'sku' => 'am_sort_virtual_1',
'category' => [$categorySecondId],
'type' => Type::TYPE_VIRTUAL,
'name' => 'Amasty Virtual Product 5',
'price' => 800
]
];
// create products
foreach ($productsData as $productData) {
$product = $productFactory->create();
$product->setTypeId($productData['type'])
->setAttributeSetId($product->getDefaultAttributeSetId())
->setWebsiteIds([1])
->setName($productData['name'])
->setSku($productData['sku'])
->setPrice(10)
->setVisibility(Visibility::VISIBILITY_BOTH)
->setStatus(Status::STATUS_ENABLED)
->setPrice($productData['price'])
->setStockData(
[
'use_config_manage_stock' => 1,
'qty' => 100,
'is_qty_decimal' => 0,
'is_in_stock' => 1,
]
)
->setCategoryIds($productData['category']);
$productRepository->save($product);
}
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Registry;
use Magento\TestFramework\Catalog\Model\GetCategoryByName;
use Magento\TestFramework\Helper\Bootstrap;
$objectManager = Bootstrap::getObjectManager();
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
/** @var Registry $registry */
$registry = $objectManager->get(Registry::class);
/** @var CategoryRepositoryInterface $categoryRepository */
$categoryRepository = $objectManager->get(CategoryRepositoryInterface::class);
/** @var GetCategoryByName $getCategoryByName */
$getCategoryByName = $objectManager->create(GetCategoryByName::class);
$currentArea = $registry->registry('isSecureArea');
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);
// get categories
$category = $getCategoryByName->execute('Am Category Sorting One Test');
$categorySecond = $getCategoryByName->execute('Am Category Sorting Second Test');
// delete categories
try {
$categoryRepository->delete($category);
$categoryRepository->delete($categorySecond);
} catch (NoSuchEntityException $e) {
// category already deleted.
}
// products sku data array
$skus = [
'am_sort_simple_1',
'am_sort_simple_2',
'am_sort_simple_3',
'am_sort_simple_4',
'am_sort_simple_5',
'am_sort_virtual_1',
'am_sort_virtual_2',
'am_sort_virtual_3',
'am_sort_virtual_4',
'am_sort_virtual_5'
];
// delete products
try {
foreach ($skus as $sku) {
$productRepository->delete($productRepository->get($sku));
}
} catch (NoSuchEntityException $e) {
// product already deleted.
}
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', $currentArea);
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Wishlist\Model\WishlistFactory;
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_with_addresses.php');
$objectManager = Bootstrap::getObjectManager();
/** @var CustomerRepositoryInterface $customerRepository */
$customerRepository = Bootstrap::getObjectManager()->create(CustomerRepositoryInterface::class);
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
/** @var WishlistFactory $wishlistFactory */
$wishlistFactory = $objectManager->get(WishlistFactory::class);
$customer = $customerRepository->get('customer_with_addresses@test.com');
$productOne = $productRepository->get('am_sort_simple_4');
$productTwo = $productRepository->get('am_sort_virtual_1');
$wishlist = $wishlistFactory->create();
$wishlist->loadByCustomerId($customer->getId(), true);
$wishlist->addNewItem($productOne);
$wishlist->addNewItem($productTwo);
$wishlist->save();
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_with_addresses_rollback.php');
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Wishlist\Model\WishlistFactory;
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_with_uk_address.php');
$objectManager = Bootstrap::getObjectManager();
/** @var CustomerRepositoryInterface $customerRepository */
$customerRepository = Bootstrap::getObjectManager()->create(CustomerRepositoryInterface::class);
/** @var ProductRepositoryInterface $productRepository */
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
/** @var WishlistFactory $wishlistFactory */
$wishlistFactory = $objectManager->get(WishlistFactory::class);
$customer = $customerRepository->get('customer_uk_address@test.com');
$product = $productRepository->get('am_sort_virtual_1');
$wishlist = $wishlistFactory->create();
$wishlist->loadByCustomerId($customer->getId(), true);
$wishlist->addNewItem($product);
$wishlist->save();
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Amasty Improved Sorting GraphQl for Magento 2 (System)
*/
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_with_uk_address_rollback.php');