ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
|
||||
/** @var $product Product */
|
||||
$product = $productRepository->get('simple-with-ftp', true);
|
||||
if ($product && $product->getId()) {
|
||||
$product->setFixedProductAttribute(
|
||||
array_merge(
|
||||
$product->getFixedProductAttribute() ?? [],
|
||||
[
|
||||
[
|
||||
'website_id' => 0,
|
||||
'country' => 'US',
|
||||
'state' => 1,
|
||||
'price' => 5.00,
|
||||
'delete' => ''
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
$productRepository->save($product);
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
|
||||
/** @var CartRepositoryInterface $cartRepository */
|
||||
$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class);
|
||||
|
||||
$product = $productRepository->get('simple-with-ftp');
|
||||
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_quote', 'reserved_order_id');
|
||||
$quote->addProduct($product, 2);
|
||||
$cartRepository->save($quote);
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Tax\Model\ClassModel as TaxClassModel;
|
||||
use Magento\Tax\Model\ResourceModel\TaxClass\CollectionFactory as TaxClassCollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple-with-ftp');
|
||||
|
||||
/** @var TaxClassCollectionFactory $taxClassCollectionFactory */
|
||||
$taxClassCollectionFactory = $objectManager->get(TaxClassCollectionFactory::class);
|
||||
$taxClassCollection = $taxClassCollectionFactory->create();
|
||||
|
||||
/** @var TaxClassModel $taxClass */
|
||||
$taxClassCollection->addFieldToFilter('class_type', TaxClassModel::TAX_CLASS_TYPE_PRODUCT);
|
||||
$taxClass = $taxClassCollection->getFirstItem();
|
||||
|
||||
$product->setCustomAttribute('tax_class_id', $taxClass->getClassId());
|
||||
$productRepository->save($product);
|
||||
Reference in New Issue
Block a user