ltsecurityinc安防产品在线商城代码
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GroupedProduct\Block\Order\Email\Items\CreditMemo;
|
||||
|
||||
use Magento\Sales\Block\Order\Email\Items\DefaultItems;
|
||||
use Magento\Sales\Model\Order\Creditmemo;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Verify grouped product block will output correct data.
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class GroupedTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject.
|
||||
*
|
||||
* @var Grouped
|
||||
*/
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @var CreditMemo
|
||||
*/
|
||||
private $creditMemo;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->block = Bootstrap::getObjectManager()->get(Grouped::class);
|
||||
$this->creditMemo = Bootstrap::getObjectManager()->get(CreditMemo::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify, grouped block will output correct product sku and name.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/creditmemo_with_grouped_product.php
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
$creditMemo = $this->creditMemo->load('100000002', 'increment_id');
|
||||
$creditMemoItem = $creditMemo->getItemsCollection()->getFirstItem();
|
||||
$priceBlock = Bootstrap::getObjectManager()->create(DefaultItems::class);
|
||||
$this->block->setTemplate('Magento_Sales::email/items/creditmemo/default.phtml');
|
||||
$this->block->setItem($creditMemoItem);
|
||||
$this->block->getLayout()->setBlock('item_price', $priceBlock);
|
||||
$output = $this->block->toHtml();
|
||||
self::assertStringContainsString('SKU: simple_11', $output);
|
||||
self::assertStringContainsString('"product-name">Simple 11', $output);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GroupedProduct\Model\Inventory;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\CatalogInventory\Api\StockRegistryInterface;
|
||||
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
|
||||
/**
|
||||
* Test stock status parent product
|
||||
*/
|
||||
class ParentItemProcessorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test stock status parent product if children are out of stock
|
||||
*
|
||||
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped_with_simple_out_of_stock.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testOutOfStockParentProduct(): void
|
||||
{
|
||||
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Product $product */
|
||||
$product = $productRepository->get('simple_100000001');
|
||||
$product->setStockData(['qty' => 0, 'is_in_stock' => 0]);
|
||||
$productRepository->save($product);
|
||||
/** @var StockItemRepository $stockItemRepository */
|
||||
$stockItemRepository = $this->objectManager->create(StockItemRepository::class);
|
||||
/** @var StockRegistryInterface $stockRegistry */
|
||||
$stockRegistry = $this->objectManager->create(StockRegistryInterface::class);
|
||||
$stockItem = $stockRegistry->getStockItemBySku('grouped');
|
||||
$stockItem = $stockItemRepository->get($stockItem->getItemId());
|
||||
|
||||
$this->assertEquals(false, $stockItem->getIsInStock());
|
||||
}
|
||||
}
|
||||
+309
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\GroupedProduct\Model\Product\Type;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
||||
use Magento\Catalog\Test\Fixture\Virtual as VirtualProductFixture;
|
||||
use Magento\CatalogInventory\Model\Configuration;
|
||||
use Magento\Framework\App\Config\ReinitableConfigInterface;
|
||||
use Magento\Framework\App\Config\Value;
|
||||
use Magento\GroupedProduct\Test\Fixture\Product as GroupedProductFixture;
|
||||
use Magento\TestFramework\Fixture\AppArea;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
|
||||
class GroupedTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ReinitableConfigInterface
|
||||
*/
|
||||
private $reinitableConfig;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\Product\Type
|
||||
*/
|
||||
protected $_productType;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_productType = $this->objectManager->get(\Magento\Catalog\Model\Product\Type::class);
|
||||
$this->reinitableConfig = $this->objectManager->get(ReinitableConfigInterface::class);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->dropConfigValue(Configuration::XML_PATH_SHOW_OUT_OF_STOCK);
|
||||
}
|
||||
|
||||
public function testFactory()
|
||||
{
|
||||
$product = new \Magento\Framework\DataObject();
|
||||
$product->setTypeId(Grouped::TYPE_CODE);
|
||||
$type = $this->_productType->factory($product);
|
||||
$this->assertInstanceOf(Grouped::class, $type);
|
||||
}
|
||||
|
||||
#[
|
||||
AppArea('frontend'),
|
||||
DataFixture(ProductFixture::class, ['sku' => 'simple', 'name' => 'Simple Product', 'price' => 10], 'p1'),
|
||||
DataFixture(
|
||||
VirtualProductFixture::class,
|
||||
['sku' => 'virtual-product', 'name' => 'Virtual Product', 'price' => 10],
|
||||
'p2'
|
||||
),
|
||||
DataFixture(
|
||||
GroupedProductFixture::class,
|
||||
['sku' => 'gr1', 'product_links' => ['$p1$', ['sku' => '$p2.sku$', 'qty' => 2]]],
|
||||
'gr1'
|
||||
),
|
||||
]
|
||||
public function testGetAssociatedProducts()
|
||||
{
|
||||
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
|
||||
|
||||
/** @var Product $product */
|
||||
$product = $productRepository->get('gr1');
|
||||
$type = $product->getTypeInstance();
|
||||
$this->assertInstanceOf(Grouped::class, $type);
|
||||
|
||||
$associatedProducts = $type->getAssociatedProducts($product);
|
||||
$this->assertCount(2, $associatedProducts);
|
||||
|
||||
$this->assertProductInfo($associatedProducts[0]);
|
||||
$this->assertProductInfo($associatedProducts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
*/
|
||||
private function assertProductInfo($product)
|
||||
{
|
||||
$data = [
|
||||
'simple' => [
|
||||
'sku' => 'simple',
|
||||
'name' => 'Simple Product',
|
||||
'price' => '10.000000',
|
||||
'qty' => '1',
|
||||
'position' => '1'
|
||||
],
|
||||
'virtual-product' => [
|
||||
'sku' => 'virtual-product',
|
||||
'name' => 'Virtual Product',
|
||||
'price' => '10.000000',
|
||||
'qty' => '2',
|
||||
'position' => '2'
|
||||
]
|
||||
];
|
||||
$productId = $product->getSku();
|
||||
$this->assertEquals($data[$productId]['sku'], $product->getSku());
|
||||
$this->assertEquals($data[$productId]['name'], $product->getName());
|
||||
$this->assertEquals($data[$productId]['price'], $product->getPrice());
|
||||
$this->assertEquals($data[$productId]['qty'], $product->getQty());
|
||||
$this->assertEquals($data[$productId]['position'], $product->getPosition());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testPrepareProduct()
|
||||
{
|
||||
$buyRequest = $this->objectManager->create(
|
||||
\Magento\Framework\DataObject::class,
|
||||
['data' => ['value' => ['qty' => 2]]]
|
||||
);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('grouped-product');
|
||||
|
||||
/** @var Grouped $type */
|
||||
$type = $this->objectManager->get(Grouped::class);
|
||||
|
||||
$processModes = [
|
||||
Grouped::PROCESS_MODE_FULL,
|
||||
Grouped::PROCESS_MODE_LITE
|
||||
];
|
||||
$expectedData = [
|
||||
Grouped::PROCESS_MODE_FULL => [
|
||||
1 => '{"super_product_config":{"product_type":"grouped","product_id":"'
|
||||
. $product->getId() . '"}}',
|
||||
21 => '{"super_product_config":{"product_type":"grouped","product_id":"'
|
||||
. $product->getId() . '"}}',
|
||||
],
|
||||
Grouped::PROCESS_MODE_LITE => [
|
||||
$product->getId() => '{"value":{"qty":2}}',
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($processModes as $processMode) {
|
||||
$products = $type->processConfiguration($buyRequest, $product, $processMode);
|
||||
foreach ($products as $item) {
|
||||
$productId = $item->getId();
|
||||
$this->assertEquals(
|
||||
$expectedData[$processMode][$productId],
|
||||
$item->getCustomOptions()['info_buyRequest']->getValue(),
|
||||
"Wrong info_buyRequest data for product with id: $productId"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test adding grouped product to cart when one of subproducts is out of stock.
|
||||
*
|
||||
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped_with_out_of_stock.php
|
||||
* @magentoAppArea frontend
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @dataProvider outOfStockSubProductDataProvider
|
||||
* @param bool $outOfStockShown
|
||||
* @param array $data
|
||||
* @param array $expected
|
||||
*/
|
||||
public function testOutOfStockSubProduct(bool $outOfStockShown, array $data, array $expected)
|
||||
{
|
||||
$this->changeConfigValue(Configuration::XML_PATH_SHOW_OUT_OF_STOCK, $outOfStockShown);
|
||||
$buyRequest = new \Magento\Framework\DataObject($data);
|
||||
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Product $product */
|
||||
$product = $productRepository->get('grouped-product');
|
||||
/** @var Grouped $groupedProduct */
|
||||
$groupedProduct = $this->objectManager->get(Grouped::class);
|
||||
$actual = $groupedProduct->prepareForCartAdvanced($buyRequest, $product, Grouped::PROCESS_MODE_FULL);
|
||||
self::assertEquals(
|
||||
count($expected),
|
||||
count($actual)
|
||||
);
|
||||
/** @var Product $product */
|
||||
foreach ($actual as $product) {
|
||||
$sku = $product->getSku();
|
||||
self::assertEquals(
|
||||
$expected[$sku],
|
||||
$product->getCartQty(),
|
||||
"Failed asserting that Product Cart Quantity matches expected"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testOutOfStockSubProduct.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function outOfStockSubProductDataProvider()
|
||||
{
|
||||
return [
|
||||
'Out of stock product are shown #1' => [
|
||||
true,
|
||||
[
|
||||
'product' => 3,
|
||||
'qty' => 1,
|
||||
'super_group' => [
|
||||
1 => 4,
|
||||
21 => 5,
|
||||
],
|
||||
],
|
||||
[
|
||||
'virtual-product' => 5,
|
||||
'simple' => 4
|
||||
],
|
||||
],
|
||||
'Out of stock product are shown #2' => [
|
||||
true,
|
||||
[
|
||||
'product' => 3,
|
||||
'qty' => 1,
|
||||
'super_group' => [
|
||||
1 => 0,
|
||||
],
|
||||
],
|
||||
[
|
||||
'virtual-product' => 2.5, // This is a default quantity.
|
||||
],
|
||||
],
|
||||
'Out of stock product are hidden #1' => [
|
||||
false,
|
||||
[
|
||||
'product' => 3,
|
||||
'qty' => 1,
|
||||
'super_group' => [
|
||||
1 => 4,
|
||||
21 => 5,
|
||||
],
|
||||
],
|
||||
[
|
||||
'virtual-product' => 5,
|
||||
'simple' => 4,
|
||||
],
|
||||
],
|
||||
'Out of stock product are hidden #2' => [
|
||||
false,
|
||||
[
|
||||
'product' => 3,
|
||||
'qty' => 1,
|
||||
'super_group' => [
|
||||
1 => 0,
|
||||
],
|
||||
],
|
||||
[
|
||||
'virtual-product' => 2.5, // This is a default quantity.
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write config value to database.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $value
|
||||
* @param string $scope
|
||||
* @param int $scopeId
|
||||
*/
|
||||
private function changeConfigValue(string $path, string $value, string $scope = 'default', int $scopeId = 0)
|
||||
{
|
||||
$configValue = $this->objectManager->create(Value::class);
|
||||
$configValue->setPath($path)
|
||||
->setValue($value)
|
||||
->setScope($scope)
|
||||
->setScopeId($scopeId)
|
||||
->save();
|
||||
$this->reinitConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete config value from database.
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
private function dropConfigValue(string $path)
|
||||
{
|
||||
$configValue = $this->objectManager->create(Value::class);
|
||||
try {
|
||||
$configValue->load($path, 'path');
|
||||
$configValue->delete();
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
// do nothing
|
||||
}
|
||||
$this->reinitConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinit config.
|
||||
*/
|
||||
private function reinitConfig()
|
||||
{
|
||||
$this->reinitableConfig->reinit();
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GroupedProduct\Model\ProductLink;
|
||||
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\ProductLink\Data\ListCriteria;
|
||||
use Magento\Catalog\Model\ProductLink\ProductLinkQuery;
|
||||
use Magento\Catalog\Model\ProductRepository;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test grouped links.
|
||||
*/
|
||||
class GroupedProductLinkQueryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ProductLinkQuery
|
||||
*/
|
||||
private $query;
|
||||
|
||||
/**
|
||||
* @var ProductRepository
|
||||
*/
|
||||
private $productRepo;
|
||||
|
||||
/**
|
||||
* @var SearchCriteriaBuilder
|
||||
*/
|
||||
private $criteriaBuilder;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->query = $objectManager->get(ProductLinkQuery::class);
|
||||
$this->productRepo = $objectManager->get(ProductRepository::class);
|
||||
$this->criteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting links for a list of products.
|
||||
*
|
||||
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
|
||||
* @return void
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function testSearch(): void
|
||||
{
|
||||
$sku = 'grouped-product';
|
||||
//Generating criteria
|
||||
/** @var ListCriteria[] $criteriaList */
|
||||
$criteriaList = [
|
||||
new ListCriteria($sku, ['associated']),
|
||||
new ListCriteria($sku, ['related'])
|
||||
];
|
||||
|
||||
//Finding the list
|
||||
$result = $this->query->search($criteriaList);
|
||||
//Validating results
|
||||
//1st criteria
|
||||
$this->assertEmpty($result[0]->getError());
|
||||
$this->assertNotEmpty($result[0]->getResult());
|
||||
$this->assertCount(2, $result[0]->getResult());
|
||||
foreach ($result[0]->getResult() as $link) {
|
||||
$this->assertEquals($sku, $link->getSku());
|
||||
$this->assertEquals('associated', $link->getLinkType());
|
||||
$this->assertContains($link->getLinkedProductSku(), ['virtual-product', 'simple']);
|
||||
$this->assertNotEmpty($link->getExtensionAttributes()->getQty());
|
||||
}
|
||||
//2nd criteria
|
||||
$this->assertEmpty($result[1]->getError());
|
||||
$this->assertEmpty($result[1]->getResult());
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\GroupedProduct\Model\ResourceModel\Product\Indexer\Price;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
|
||||
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
|
||||
|
||||
/**
|
||||
* Test class for Magento\GroupedProduct\Model\ResourceModel\Product\Indexer\Price\Grouped
|
||||
*/
|
||||
class GroupedTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $productCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var Processor
|
||||
*/
|
||||
private $indexerProcessor;
|
||||
|
||||
/**
|
||||
* @var ProductTierPriceInterfaceFactory
|
||||
*/
|
||||
private $tierPriceFactory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
|
||||
$this->productCollectionFactory = Bootstrap::getObjectManager()->get(CollectionFactory::class);
|
||||
$this->indexerProcessor = Bootstrap::getObjectManager()->get(Processor::class);
|
||||
$this->tierPriceFactory = Bootstrap::getObjectManager()->get(ProductTierPriceInterfaceFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testReindex()
|
||||
{
|
||||
$simpleProductPrice = 15;
|
||||
$virtualProductPrice = 5;
|
||||
/** @var \Magento\Catalog\Model\Product $simpleProduct */
|
||||
$simpleProduct = $this->productRepository->get('simple', true);
|
||||
/** @var \Magento\Catalog\Model\Product $virtualProduct */
|
||||
$virtualProduct = $this->productRepository->get('virtual-product', true);
|
||||
$simpleProduct->setData('price', $simpleProductPrice);
|
||||
$virtualProduct->setData('price', $virtualProductPrice);
|
||||
$this->productRepository->save($simpleProduct);
|
||||
$this->productRepository->save($virtualProduct);
|
||||
$this->indexerProcessor->reindexAll();
|
||||
/** @var ProductCollection $collection */
|
||||
$collection = $this->productCollectionFactory->create();
|
||||
$collection->addPriceData()->addFieldToFilter(ProductInterface::SKU, 'grouped-product');
|
||||
/** @var \Magento\Catalog\Model\Product $item */
|
||||
$item = $collection->getFirstItem();
|
||||
$this->assertEquals($virtualProductPrice, $item->getData('min_price'));
|
||||
$this->assertEquals($simpleProductPrice, $item->getData('max_price'));
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\GroupedProduct\Model\ResourceModel\Product\Indexer\Stock;
|
||||
|
||||
class GroupedTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor
|
||||
*/
|
||||
protected $processor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->processor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\CatalogInventory\Model\Indexer\Stock\Processor::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
|
||||
*/
|
||||
public function testReindexAll()
|
||||
{
|
||||
$this->processor->reindexAll();
|
||||
|
||||
/** @var \Magento\Catalog\Model\CategoryFactory $categoryFactory */
|
||||
$categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Catalog\Model\CategoryFactory::class
|
||||
);
|
||||
$category = $categoryFactory->create()->load(2);
|
||||
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
|
||||
$productCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Catalog\Model\ResourceModel\Product\Collection::class
|
||||
);
|
||||
|
||||
$productCollection->addAttributeToSelect('name');
|
||||
$productCollection->addUrlRewrite($category->getId());
|
||||
$productCollection->joinField(
|
||||
'qty',
|
||||
'cataloginventory_stock_status',
|
||||
'qty',
|
||||
'product_id=entity_id',
|
||||
'{{table}}.stock_id=1',
|
||||
'left'
|
||||
);
|
||||
|
||||
$this->assertCount(3, $productCollection);
|
||||
|
||||
$expectedResult = [
|
||||
'Simple Product' => 22,
|
||||
'Virtual Product' => 10,
|
||||
'Grouped Product' => 0
|
||||
];
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
foreach ($productCollection as $product) {
|
||||
$this->assertEquals($expectedResult[$product->getName()], $product->getQty());
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\GroupedProduct\Model\ResourceModel\Product\Type\Grouped;
|
||||
|
||||
class AssociatedProductsCollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testGetColumnValues()
|
||||
{
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('grouped-product');
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->register('current_product', $product);
|
||||
|
||||
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\GroupedProduct\Model\ResourceModel\Product\Type\Grouped\AssociatedProductsCollection::class
|
||||
);
|
||||
|
||||
$resultData = $collection->getColumnValues('sku');
|
||||
$this->assertNotEmpty($resultData);
|
||||
|
||||
$expected = ['virtual-product', 'simple'];
|
||||
sort($expected);
|
||||
sort($resultData);
|
||||
$this->assertEquals($expected, $resultData);
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\GroupedProduct\Pricing\Price;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class FinalPriceTest
|
||||
*
|
||||
* @package Magento\GroupedProduct\Pricing\Price
|
||||
*/
|
||||
class FinalPriceTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testFinalPrice()
|
||||
{
|
||||
$productRepository = Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('grouped-product');
|
||||
|
||||
$this->assertEquals(10, $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testFinalPriceWithTierPrice()
|
||||
{
|
||||
$productRepository = Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var ProductTierPriceInterface $tierPrice */
|
||||
$tierPrice = Bootstrap::getObjectManager()->create(ProductTierPriceInterface::class);
|
||||
$tierPrice->setQty(1);
|
||||
$tierPrice->setCustomerGroupId(\Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL);
|
||||
$tierPrice->setValue(5);
|
||||
|
||||
/** @var $simpleProduct \Magento\Catalog\Api\Data\ProductInterface */
|
||||
$simpleProduct = $productRepository->get('simple');
|
||||
$simpleProduct->setTierPrices(
|
||||
[
|
||||
$tierPrice
|
||||
]
|
||||
);
|
||||
$productRepository->save($simpleProduct);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('grouped-product');
|
||||
$this->assertEquals(5, $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testFinalPriceWithSpecialPrice()
|
||||
{
|
||||
$productRepository = Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $simpleProduct \Magento\Catalog\Api\Data\ProductInterface */
|
||||
$simpleProduct = $productRepository->get('simple');
|
||||
$simpleProduct->setCustomAttribute('special_price', 6);
|
||||
$productRepository->save($simpleProduct);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $productRepository->get('grouped-product');
|
||||
$this->assertEquals(6, $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue());
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\GroupedProduct\Model\Product\Type\Grouped;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$product = Bootstrap::getObjectManager()->create(Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(Grouped::TYPE_CODE)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Grouped Product')
|
||||
->setSku('grouped-product')
|
||||
->setPrice(100)
|
||||
->setTaxClassId(0)
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 0, 'is_in_stock' => 1])
|
||||
->save();
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$registry = Bootstrap::getObjectManager()->get(Registry::class);
|
||||
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
try {
|
||||
$groupedProduct = $productRepository->get('grouped-product', false, null, true);
|
||||
$groupedProduct->delete();
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//already deleted
|
||||
}
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
@@ -0,0 +1,75 @@
|
||||
<?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_associated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_virtual_in_stock.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(
|
||||
\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setName(
|
||||
'Grouped Product'
|
||||
)->setSku(
|
||||
'grouped-product'
|
||||
)->setPrice(
|
||||
100
|
||||
)->setTaxClassId(
|
||||
0
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
);
|
||||
|
||||
$newLinks = [];
|
||||
$productLinkFactory = $objectManager->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $productLinkFactory->create();
|
||||
$linkedProduct = $productRepository->getById(1);
|
||||
$productLink->setSku($product->getSku())
|
||||
->setLinkType('associated')
|
||||
->setLinkedProductSku($linkedProduct->getSku())
|
||||
->setLinkedProductType($linkedProduct->getTypeId())
|
||||
->setPosition(1)
|
||||
->getExtensionAttributes()
|
||||
->setQty(1);
|
||||
$newLinks[] = $productLink;
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $productLinkFactory->create();
|
||||
$linkedProduct = $productRepository->getById(21);
|
||||
$productLink->setSku($product->getSku())
|
||||
->setLinkType('associated')
|
||||
->setLinkedProductSku($linkedProduct->getSku())
|
||||
->setLinkedProductType($linkedProduct->getTypeId())
|
||||
->setPosition(2)
|
||||
->getExtensionAttributes()
|
||||
->setQty(2);
|
||||
$newLinks[] = $productLink;
|
||||
$product->setProductLinks($newLinks);
|
||||
$product->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]);
|
||||
$productRepository->save($product);
|
||||
|
||||
/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */
|
||||
$categoryLinkManagement = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
|
||||
|
||||
$categoryLinkManagement->assignProductToCategories(
|
||||
$product->getSku(),
|
||||
[2]
|
||||
);
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/product_associated.php'
|
||||
);
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/product_virtual_in_stock.php'
|
||||
);
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
|
||||
/** @var WebsiteRepositoryInterface $repository */
|
||||
$repository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$websiteId = $repository->get('test')->getId();
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(
|
||||
\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setWebsiteIds(
|
||||
[$websiteId]
|
||||
)->setName(
|
||||
'Grouped Product'
|
||||
)->setSku(
|
||||
'grouped-product'
|
||||
)->setPrice(
|
||||
100
|
||||
)->setTaxClassId(
|
||||
0
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
);
|
||||
|
||||
$newLinks = [];
|
||||
$productLinkFactory = $objectManager->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $productLinkFactory->create();
|
||||
$linkedProduct = $productRepository->getById(1);
|
||||
$linkedProduct->setWebsiteIds([1, $websiteId])->save();
|
||||
$productLink->setSku($product->getSku())
|
||||
->setLinkType('associated')
|
||||
->setLinkedProductSku($linkedProduct->getSku())
|
||||
->setLinkedProductType($linkedProduct->getTypeId())
|
||||
->setPosition(1)
|
||||
->getExtensionAttributes()
|
||||
->setQty(1);
|
||||
$newLinks[] = $productLink;
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $productLinkFactory->create();
|
||||
$linkedProduct = $productRepository->getById(21);
|
||||
$linkedProduct->setWebsiteIds([1, $websiteId])->save();
|
||||
$productLink->setSku($product->getSku())
|
||||
->setLinkType('associated')
|
||||
->setLinkedProductSku($linkedProduct->getSku())
|
||||
->setLinkedProductType($linkedProduct->getTypeId())
|
||||
->setPosition(2)
|
||||
->getExtensionAttributes()
|
||||
->setQty(2);
|
||||
$newLinks[] = $productLink;
|
||||
$product->setProductLinks($newLinks);
|
||||
$product->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]);
|
||||
$productRepository->save($product);
|
||||
|
||||
/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */
|
||||
$categoryLinkManagement = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
|
||||
|
||||
$categoryLinkManagement->assignProductToCategories(
|
||||
$product->getSku(),
|
||||
[2]
|
||||
);
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
|
||||
*/
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Catalog\Api\ProductRepositoryInterface::class
|
||||
);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
try {
|
||||
$productRepository->deleteById('simple');
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//already deleted
|
||||
}
|
||||
|
||||
try {
|
||||
$productRepository->deleteById('virtual-product');
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//already deleted
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var $groupedProduct \Magento\Catalog\Model\Product */
|
||||
$productRepository->deleteById('grouped-product');
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//already deleted
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/product_associated.php'
|
||||
);
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/product_virtual_in_stock.php'
|
||||
);
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
|
||||
/** @var WebsiteRepositoryInterface $repository */
|
||||
$repository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$websiteId = $repository->get('test')->getId();
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(
|
||||
\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setWebsiteIds(
|
||||
[1, $websiteId]
|
||||
)->setName(
|
||||
'Grouped Product'
|
||||
)->setSku(
|
||||
'grouped-product'
|
||||
)->setPrice(
|
||||
100
|
||||
)->setTaxClassId(
|
||||
0
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
);
|
||||
|
||||
$newLinks = [];
|
||||
$productLinkFactory = $objectManager->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $productLinkFactory->create();
|
||||
$linkedProduct = $productRepository->getById(1);
|
||||
$linkedProduct->setWebsiteIds([1])->save();
|
||||
|
||||
$productLink->setSku($product->getSku())
|
||||
->setLinkType('associated')
|
||||
->setLinkedProductSku($linkedProduct->getSku())
|
||||
->setLinkedProductType($linkedProduct->getTypeId())
|
||||
->setPosition(1)
|
||||
->getExtensionAttributes()
|
||||
->setQty(1);
|
||||
$newLinks[] = $productLink;
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $productLinkFactory->create();
|
||||
$linkedProduct = $productRepository->getById(21);
|
||||
$linkedProduct->setWebsiteIds([$websiteId])->save();
|
||||
$productLink->setSku($product->getSku())
|
||||
->setLinkType('associated')
|
||||
->setLinkedProductSku($linkedProduct->getSku())
|
||||
->setLinkedProductType($linkedProduct->getTypeId())
|
||||
->setPosition(2)
|
||||
->getExtensionAttributes()
|
||||
->setQty(2);
|
||||
$newLinks[] = $productLink;
|
||||
$product->setProductLinks($newLinks);
|
||||
$product->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]);
|
||||
$productRepository->save($product);
|
||||
|
||||
/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */
|
||||
$categoryLinkManagement = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
|
||||
|
||||
$categoryLinkManagement->assignProductToCategories(
|
||||
$product->getSku(),
|
||||
[2]
|
||||
);
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
|
||||
*/
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Catalog\Api\ProductRepositoryInterface::class
|
||||
);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
try {
|
||||
$productRepository->deleteById('simple');
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//already deleted
|
||||
}
|
||||
|
||||
try {
|
||||
$productRepository->deleteById('virtual-product');
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//already deleted
|
||||
}
|
||||
|
||||
try {
|
||||
$productRepository->deleteById('grouped-product');
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//already deleted
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
|
||||
*/
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Catalog\Api\ProductRepositoryInterface::class
|
||||
);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
try {
|
||||
/** @var $simpleProduct \Magento\Catalog\Model\Product */
|
||||
$simpleProduct = $productRepository->get('simple', false, null, true);
|
||||
$simpleProduct->delete();
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//already deleted
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var $virtualProduct \Magento\Catalog\Model\Product */
|
||||
$virtualProduct = $productRepository->get('virtual-product', false, null, true);
|
||||
$virtualProduct->delete();
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//already deleted
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var $groupedProduct \Magento\Catalog\Model\Product */
|
||||
$groupedProduct = $productRepository->get('grouped-product', false, null, true);
|
||||
$groupedProduct->delete();
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//already deleted
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?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_associated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_virtual_in_stock.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_virtual_out_of_stock.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(
|
||||
\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setName(
|
||||
'Grouped Product'
|
||||
)->setSku(
|
||||
'grouped-product'
|
||||
)->setPrice(
|
||||
100
|
||||
)->setTaxClassId(
|
||||
0
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
);
|
||||
|
||||
$newLinks = [];
|
||||
$productLinkFactory = $objectManager->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
|
||||
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $productLinkFactory->create();
|
||||
$linkedProduct = $productRepository->getById(1);
|
||||
$productLink->setSku($product->getSku())
|
||||
->setLinkType('associated')
|
||||
->setLinkedProductSku($linkedProduct->getSku())
|
||||
->setLinkedProductType($linkedProduct->getTypeId())
|
||||
->setPosition(1)
|
||||
->getExtensionAttributes()
|
||||
->setQty(1);
|
||||
$newLinks[] = $productLink;
|
||||
|
||||
$subProductsSkus = ['virtual-product', 'virtual-product-out'];
|
||||
foreach ($subProductsSkus as $sku) {
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $productLinkFactory->create();
|
||||
$linkedProduct = $productRepository->get($sku);
|
||||
$productLink->setSku($product->getSku())
|
||||
->setLinkType('associated')
|
||||
->setLinkedProductSku($sku)
|
||||
->setLinkedProductType($linkedProduct->getTypeId())
|
||||
->getExtensionAttributes()
|
||||
->setQty(2.5);
|
||||
$newLinks[] = $productLink;
|
||||
}
|
||||
$product->setProductLinks($newLinks);
|
||||
$product->save();
|
||||
|
||||
/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */
|
||||
$categoryLinkManagement = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
|
||||
|
||||
$categoryLinkManagement->assignProductToCategories(
|
||||
$product->getSku(),
|
||||
[2]
|
||||
);
|
||||
+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/GroupedProduct/_files/product_grouped_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_virtual_out_of_stock_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_virtual_in_stock_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_associated_rollback.php');
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\GroupedProduct\Model\Product\Type\Grouped;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = Bootstrap::getObjectManager()
|
||||
->get(ProductRepositoryInterface::class);
|
||||
|
||||
$productLinkFactory = Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
|
||||
$productIds = ['11', '22'];
|
||||
|
||||
foreach ($productIds as $productId) {
|
||||
/** @var $product Product */
|
||||
$product = Bootstrap::getObjectManager()->create(Product::class);
|
||||
$product->setTypeId(Type::TYPE_SIMPLE)
|
||||
->setId($productId)
|
||||
->setWebsiteIds([1])
|
||||
->setAttributeSetId(4)
|
||||
->setName('Simple ' . $productId)
|
||||
->setSku('simple_' . $productId)
|
||||
->setPrice(100)
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1]);
|
||||
|
||||
$linkedProducts[] = $productRepository->save($product);
|
||||
}
|
||||
|
||||
/** @var $product Product */
|
||||
$product = Bootstrap::getObjectManager()->create(Product::class);
|
||||
|
||||
$product->setTypeId(Grouped::TYPE_CODE)
|
||||
->setId(1)
|
||||
->setWebsiteIds([1])
|
||||
->setAttributeSetId(4)
|
||||
->setName('Grouped Product')
|
||||
->setSku('grouped')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]);
|
||||
|
||||
foreach ($linkedProducts as $linkedProduct) {
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $productLinkFactory->create();
|
||||
$productLink->setSku($product->getSku())
|
||||
->setLinkType('associated')
|
||||
->setLinkedProductSku($linkedProduct->getSku())
|
||||
->setLinkedProductType($linkedProduct->getTypeId())
|
||||
->getExtensionAttributes()
|
||||
->setQty(1);
|
||||
$newLinks[] = $productLink;
|
||||
}
|
||||
|
||||
$product->setProductLinks($newLinks);
|
||||
|
||||
$productRepository->save($product);
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\GroupedProduct\Model\Product\Type\Grouped;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = Bootstrap::getObjectManager()
|
||||
->get(ProductRepositoryInterface::class);
|
||||
|
||||
$productLinkFactory = Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
|
||||
$productConfigs = [
|
||||
[
|
||||
'id' => '100000001',
|
||||
'stock_config' => ['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1]
|
||||
],
|
||||
[
|
||||
'id' => '100000002',
|
||||
'stock_config' => ['use_config_manage_stock' => 1, 'qty' => 0, 'is_qty_decimal' => 0, 'is_in_stock' => 0]
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($productConfigs as $productConfig) {
|
||||
/** @var $product Product */
|
||||
$product = Bootstrap::getObjectManager()->create(Product::class);
|
||||
$product->setTypeId(Type::TYPE_SIMPLE)
|
||||
->setId($productConfig['id'])
|
||||
->setWebsiteIds([1])
|
||||
->setAttributeSetId(4)
|
||||
->setName('Simple ' . $productConfig['id'])
|
||||
->setSku('simple_' . $productConfig['id'])
|
||||
->setPrice(100)
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData($productConfig['stock_config']);
|
||||
|
||||
$linkedProducts[] = $productRepository->save($product);
|
||||
}
|
||||
|
||||
/** @var $product Product */
|
||||
$product = Bootstrap::getObjectManager()->create(Product::class);
|
||||
|
||||
$product->setTypeId(Grouped::TYPE_CODE)
|
||||
->setId('100000003')
|
||||
->setWebsiteIds([1])
|
||||
->setAttributeSetId(4)
|
||||
->setName('Grouped Product')
|
||||
->setSku('grouped')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]);
|
||||
|
||||
foreach ($linkedProducts as $linkedProduct) {
|
||||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
|
||||
$productLink = $productLinkFactory->create();
|
||||
$productLink->setSku($product->getSku())
|
||||
->setLinkType('associated')
|
||||
->setLinkedProductSku($linkedProduct->getSku())
|
||||
->setLinkedProductType($linkedProduct->getTypeId())
|
||||
->getExtensionAttributes()
|
||||
->setQty(1);
|
||||
$newLinks[] = $productLink;
|
||||
}
|
||||
|
||||
$product->setProductLinks($newLinks);
|
||||
|
||||
$productRepository->save($product);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
$skuList = ['simple_100000001', 'simple_100000002', 'grouped'];
|
||||
foreach ($skuList as $sku) {
|
||||
try {
|
||||
$product = $productRepository->get($sku, false, null, true);
|
||||
|
||||
$stockStatus = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Status::class);
|
||||
$stockStatus->load($product->getData('entity_id'), 'product_id');
|
||||
$stockStatus->delete();
|
||||
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
$skuList = ['simple_11', 'simple_22', 'grouped'];
|
||||
foreach ($skuList as $sku) {
|
||||
try {
|
||||
$product = $productRepository->get($sku, false, null, true);
|
||||
|
||||
$stockStatus = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Status::class);
|
||||
$stockStatus->load($product->getEntityId(), 'product_id');
|
||||
$stockStatus->delete();
|
||||
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
Reference in New Issue
Block a user