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,68 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedProduct\Api;
use Magento\Catalog\Model\CustomOptions\CustomOptionProcessor;
use Magento\Framework\Webapi\Rest\Request;
use Magento\Quote\Model\Quote;
use Magento\TestFramework\TestCase\WebapiAbstract;
class CartItemRepositoryTest extends WebapiAbstract
{
const SERVICE_VERSION = 'V1';
const SERVICE_NAME = 'quoteCartItemRepositoryV1';
const RESOURCE_PATH = '/V1/carts/';
/**
* @var \Magento\TestFramework\ObjectManager
*/
protected $objectManager;
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
}
/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped_with_simple_out_of_stock.php
*/
public function testAddGroupedProductToCartThatHasAnOutOfStockItemInTheGroup()
{
$this->_markTestAsRestOnly();
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->objectManager->create(\Magento\Catalog\Model\Product::class)->load('100000003');
$productSku = $product->getSku();
/** @var Quote $quote */
$quote = $this->objectManager->create(Quote::class);
$quote->load('test_order_1', 'reserved_order_id');
$cartId = $quote->getId();
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $cartId . '/items',
'httpMethod' => Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'Save',
],
];
$requestData = [
'cartItem' => [
'sku' => $productSku,
'qty' => 1,
'quote_id' => $cartId,
],
];
$this->_webApiCall($serviceInfo, $requestData);
$this->assertTrue($quote->hasProductId('100000001'));
$this->assertFalse($quote->hasProductId('100000002'));
}
}
@@ -0,0 +1,61 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedProduct\Api;
/**
* @magentoAppIsolation enabled
*/
class ProductLinkManagementTest extends \Magento\TestFramework\TestCase\WebapiAbstract
{
const SERVICE_NAME = 'catalogProductLinkManagementV1';
const SERVICE_VERSION = 'V1';
const RESOURCE_PATH = '/V1/products/';
/**
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped.php
*/
public function testGetLinkedItemsByType()
{
$productSku = 'grouped-product';
$linkType = 'associated';
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $productSku . '/links/' . $linkType,
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'GetLinkedItemsByType',
],
];
$actual = $this->_webApiCall($serviceInfo, ['sku' => $productSku, 'type' => $linkType]);
$expected = [
[
'sku' => 'grouped-product',
'link_type' => 'associated',
'linked_product_sku' => 'simple',
'linked_product_type' => 'simple',
'position' => 1,
'extension_attributes' => ['qty' => 1]
],
[
'sku' => 'grouped-product',
'link_type' => 'associated',
'linked_product_sku' => 'virtual-product',
'linked_product_type' => 'virtual',
'position' => 2,
'extension_attributes' => ['qty' => 2]
],
];
$this->assertEquals($expected, $actual);
}
}
@@ -0,0 +1,287 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\GroupedProduct\Api;
use Magento\Catalog\Api\ProductLinkManagementInterface;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Webapi\Rest\Request;
use Magento\Indexer\Model\Config;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\WebapiAbstract;
class ProductLinkRepositoryTest extends WebapiAbstract
{
const SERVICE_NAME = 'catalogProductLinkRepositoryV1';
const SERVICE_VERSION = 'V1';
const RESOURCE_PATH = '/V1/products/';
const SERVICE_NAME_SEARCH = 'searchV1';
const RESOURCE_PATH_SEARCH = '/V1/search/';
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
protected $objectManager;
/**
* @var array
*/
private $indexersState;
/**
* @var mixed
*/
private $indexerRegistry;
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->indexerRegistry = $this->objectManager->get(IndexerRegistry::class);
}
/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_duplicated.php
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped.php
*/
public function testSave(): void
{
$productSku = 'grouped-product';
$linkType = 'associated';
$productData = [
'sku' => $productSku,
'link_type' => $linkType,
'linked_product_type' => 'simple',
'linked_product_sku' => 'simple-1',
'position' => 3,
'extension_attributes' => [
'qty' => (float)300.0000,
],
];
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $productSku . '/links',
'httpMethod' => Request::HTTP_METHOD_PUT,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'Save',
],
];
$this->_webApiCall($serviceInfo, ['entity' => $productData]);
/** @var ProductLinkManagementInterface $linkManagement */
$linkManagement = $this->objectManager->get(ProductLinkManagementInterface::class);
$actual = $linkManagement->getLinkedItemsByType($productSku, $linkType);
array_walk(
$actual,
function (&$item) {
$item = $item->__toArray();
}
);
$this->assertEquals($productData, $actual[2]);
}
/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_duplicated.php
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped.php
*/
public function testLinkWithScheduledIndex(): void
{
$this->setIndexScheduled();
$productSkuGrouped = 'grouped-product';
$productSimple = 'simple-1';
$linkType = 'associated';
$productData = [
'sku' => $productSkuGrouped,
'link_type' => $linkType,
'linked_product_type' => 'simple',
'linked_product_sku' => $productSimple,
'position' => 3,
'extension_attributes' => [
'qty' => (float)300.0000,
],
];
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $productSkuGrouped . '/links',
'httpMethod' => Request::HTTP_METHOD_PUT,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'Save',
],
];
$this->_webApiCall($serviceInfo, ['entity' => $productData]);
$searchCriteria = $this->buildSearchCriteria($productSimple);
$serviceInfo = $this->buildSearchServiceInfo($searchCriteria);
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
$this->assertArrayHasKey('search_criteria', $response);
$this->assertArrayHasKey('items', $response);
$this->assertGreaterThan(1, count($response['items']));
$this->assertGreaterThan(0, $response['items'][0]['id']);
$this->restoreIndexMode();
}
/**
* Verify empty out of stock grouped product is in stock after child has been added.
*
* @return void
* @magentoApiDataFixture Magento/GroupedProduct/_files/empty_grouped_product.php
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
*/
public function testGroupedProductIsInStockAfterAddChild(): void
{
$productSku = 'grouped-product';
self::assertFalse($this->isProductInStock($productSku));
$items = [
'sku' => $productSku,
'link_type' => 'associated',
'linked_product_type' => 'virtual',
'linked_product_sku' => 'virtual-product',
'position' => 3,
'extension_attributes' => [
'qty' => 1,
],
];
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $productSku . '/links',
'httpMethod' => Request::HTTP_METHOD_PUT,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'Save',
],
];
$this->_webApiCall($serviceInfo, ['entity' => $items]);
self::assertTrue($this->isProductInStock($productSku));
}
/**
* Verify in stock grouped product is out stock after children have been removed.
*
* @return void
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped_with_simple.php
*/
public function testGroupedProductIsOutOfStockAfterRemoveChild(): void
{
$productSku = 'grouped';
$childrenSkus = [
'simple_11',
'simple_22',
];
self::assertTrue($this->isProductInStock($productSku));
foreach ($childrenSkus as $childSku) {
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $productSku . '/links/associated/' . $childSku,
'httpMethod' => Request::HTTP_METHOD_DELETE,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'DeleteById',
],
];
$requestData = ['sku' => $productSku, 'type' => 'associated', 'linkedProductSku' => $childSku];
$this->_webApiCall($serviceInfo, $requestData);
}
self::assertFalse($this->isProductInStock($productSku));
}
/**
* Check product stock status.
*
* @param string $productSku
* @return bool
*/
private function isProductInStock(string $productSku): bool
{
$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/stockStatuses/' . $productSku,
'httpMethod' => Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => 'catalogInventoryStockRegistryV1',
'serviceVersion' => self::SERVICE_VERSION,
'operation' => 'catalogInventoryStockRegistryV1getStockStatusBySku',
],
];
$result = $this->_webApiCall($serviceInfo, ['productSku' => $productSku]);
return (bool)$result['stock_status'];
}
/**
* @param string $productSku
* @return array
*/
private function buildSearchCriteria(string $productSku): array
{
return [
'searchCriteria' => [
'request_name' => 'quick_search_container',
'filter_groups' => [
[
'filters' => [
[
'field' => 'search_term',
'value' => $productSku,
],
],
],
],
],
];
}
/**
* @param array $searchCriteria
* @return array
*/
private function buildSearchServiceInfo(array $searchCriteria): array
{
return [
'rest' => [
'resourcePath' => self::RESOURCE_PATH_SEARCH . '?' . http_build_query($searchCriteria),
'httpMethod' => Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => self::SERVICE_NAME_SEARCH,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME_SEARCH . 'Search',
],
];
}
private function setIndexScheduled(): void
{
$indexerListIds = $this->objectManager->get(Config::class)->getIndexers();
foreach ($indexerListIds as $indexerId) {
$indexer = $this->indexerRegistry->get($indexerId['indexer_id']);
$this->indexersState[$indexerId['indexer_id']] = $indexer->isScheduled();
$indexer->setScheduled(true);
}
}
private function restoreIndexMode(): void
{
foreach ($this->indexersState as $indexerId => $state) {
$this->indexerRegistry->get($indexerId)->setScheduled($state);
}
}
}
@@ -0,0 +1,64 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedProduct\Api;
use Magento\GroupedProduct\Model\ResourceModel\Product\Link;
class ProductLinkTypeListTest extends \Magento\TestFramework\TestCase\WebapiAbstract
{
const SERVICE_NAME = 'catalogProductLinkTypeListV1';
const SERVICE_VERSION = 'V1';
const RESOURCE_PATH = '/V1/products/';
public function testGetItems()
{
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . 'links/types',
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'GetItems',
],
];
$actual = $this->_webApiCall($serviceInfo);
/**
* Validate that product type links provided by Magento_GroupedProduct module are present
*/
$expectedItems = ['name' => 'associated', 'code' => Link::LINK_TYPE_GROUPED];
$this->assertContainsEquals($expectedItems, $actual);
}
public function testGetItemAttributes()
{
$linkType = 'associated';
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . 'links/' . $linkType . '/attributes',
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'GetItemAttributes',
],
];
$actual = $this->_webApiCall($serviceInfo, ['type' => $linkType]);
$expected = [
['code' => 'position', 'type' => 'int'],
['code' => 'qty', 'type' => 'decimal'],
];
$this->assertEquals($expected, $actual);
}
}
@@ -0,0 +1,238 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedProduct\Api;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\TestFramework\TestCase\WebapiAbstract;
class ProductRepositoryInterfaceTest extends WebapiAbstract
{
const SERVICE_NAME = 'catalogProductRepositoryV1';
const SERVICE_VERSION = 'V1';
const RESOURCE_PATH = '/V1/products';
/**
* Get Product
*
* @param $sku
* @return ProductInterface
*/
protected function getProduct($sku)
{
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . '/' . $sku,
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'Get',
],
];
$response = $this->_webApiCall($serviceInfo, ['sku' => $sku]);
return $response;
}
/**
* Update Product
*
* @param $product
* @return mixed
*/
protected function updateProduct($product)
{
$sku = $product[ProductInterface::SKU];
if (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) {
$product[ProductInterface::SKU] = null;
}
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . '/' . $sku,
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'Save',
],
];
$requestData = ['product' => $product];
$response = $this->_webApiCall($serviceInfo, $requestData);
return $response;
}
/**
* Save Product
*
* @param $product
* @return mixed
*/
protected function saveProduct($product)
{
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH,
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'Save',
],
];
$requestData = ['product' => $product];
return $this->_webApiCall($serviceInfo, $requestData);
}
/**
* Delete Product
*
* @param string $sku
* @return boolean
*/
protected function deleteProduct($sku)
{
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . '/' . $sku,
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'DeleteById',
],
];
return (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) ?
$this->_webApiCall($serviceInfo, ['sku' => $sku]) : $this->_webApiCall($serviceInfo);
}
public function testProductLinks()
{
// Create simple product
$productData = [
ProductInterface::SKU => "product_simple_500",
ProductInterface::NAME => "Product Simple 500",
ProductInterface::VISIBILITY => 4,
ProductInterface::TYPE_ID => 'simple',
ProductInterface::PRICE => 100,
ProductInterface::STATUS => 1,
ProductInterface::ATTRIBUTE_SET_ID => 4,
ProductInterface::EXTENSION_ATTRIBUTES_KEY => [
'stock_item' => $this->getStockItemData()
]
];
$this->saveProduct($productData);
// Create a group product
$productLinkData = ["sku" => "group_product_500", "link_type" => "associated",
"linked_product_sku" => "product_simple_500", "linked_product_type" => "simple",
"position" => 0, "extension_attributes" => ["qty" => 1]];
$productWithGroupData = [
ProductInterface::SKU => "group_product_500",
ProductInterface::NAME => "Group Product 500",
ProductInterface::VISIBILITY => 4,
ProductInterface::TYPE_ID => 'grouped',
ProductInterface::PRICE => 300,
ProductInterface::STATUS => 1,
ProductInterface::ATTRIBUTE_SET_ID => 4,
"product_links" => [$productLinkData]
];
$this->saveProduct($productWithGroupData);
$response = $this->getProduct("group_product_500");
$this->assertArrayHasKey('product_links', $response);
$links = $response['product_links'];
$this->assertCount(1, $links);
$this->assertEquals($productLinkData, $links[0]);
// update link information for Group Product
$productLinkData1 = ["sku" => "group_product_500", "link_type" => "associated",
"linked_product_sku" => "product_simple_500", "linked_product_type" => "simple",
"position" => 0, "extension_attributes" => ["qty" => 4]];
$productLinkData2 = ["sku" => "group_product_500", "link_type" => "upsell",
"linked_product_sku" => "product_simple_500", "linked_product_type" => "simple",
"position" => 0];
$productWithGroupData = [
ProductInterface::SKU => "group_product_500",
ProductInterface::NAME => "Group Product 500",
ProductInterface::VISIBILITY => 4,
ProductInterface::TYPE_ID => 'grouped',
ProductInterface::PRICE => 300,
ProductInterface::STATUS => 1,
ProductInterface::ATTRIBUTE_SET_ID => 4,
"product_links" => [$productLinkData1, $productLinkData2]
];
$this->saveProduct($productWithGroupData);
$response = $this->getProduct("group_product_500");
$this->assertArrayHasKey('product_links', $response);
$links = $response['product_links'];
$this->assertCount(2, $links);
$this->assertEquals($productLinkData1, $links[1]);
$this->assertEquals($productLinkData2, $links[0]);
// Remove link
$productWithNoLinkData = [
ProductInterface::SKU => "group_product_500",
ProductInterface::NAME => "Group Product 500",
ProductInterface::VISIBILITY => 4,
ProductInterface::TYPE_ID => 'grouped',
ProductInterface::PRICE => 300,
ProductInterface::STATUS => 1,
ProductInterface::ATTRIBUTE_SET_ID => 4,
"product_links" => []
];
$this->saveProduct($productWithNoLinkData);
$response = $this->getProduct("group_product_500");
$this->assertArrayHasKey('product_links', $response);
$links = $response['product_links'];
$this->assertEquals([], $links);
$this->deleteProduct("product_simple_500");
$this->deleteProduct("group_product_500");
}
/**
* @return array
*/
private function getStockItemData()
{
return [
StockItemInterface::IS_IN_STOCK => 1,
StockItemInterface::QTY => 100500,
StockItemInterface::IS_QTY_DECIMAL => 1,
StockItemInterface::SHOW_DEFAULT_NOTIFICATION_MESSAGE => 0,
StockItemInterface::USE_CONFIG_MIN_QTY => 0,
StockItemInterface::USE_CONFIG_MIN_SALE_QTY => 0,
StockItemInterface::MIN_QTY => 1,
StockItemInterface::MIN_SALE_QTY => 1,
StockItemInterface::MAX_SALE_QTY => 100,
StockItemInterface::USE_CONFIG_MAX_SALE_QTY => 0,
StockItemInterface::USE_CONFIG_BACKORDERS => 0,
StockItemInterface::BACKORDERS => 0,
StockItemInterface::USE_CONFIG_NOTIFY_STOCK_QTY => 0,
StockItemInterface::NOTIFY_STOCK_QTY => 0,
StockItemInterface::USE_CONFIG_QTY_INCREMENTS => 0,
StockItemInterface::QTY_INCREMENTS => 0,
StockItemInterface::USE_CONFIG_ENABLE_QTY_INC => 0,
StockItemInterface::ENABLE_QTY_INCREMENTS => 0,
StockItemInterface::USE_CONFIG_MANAGE_STOCK => 1,
StockItemInterface::MANAGE_STOCK => 1,
StockItemInterface::LOW_STOCK_DATE => null,
StockItemInterface::IS_DECIMAL_DIVIDED => 0,
StockItemInterface::STOCK_STATUS_CHANGED_AUTO => 0,
];
}
}