init
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(42)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle_product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setPriceType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC)
|
||||
->setShipmentType(0);
|
||||
|
||||
$productRepository->save($product);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$registry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle_product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/CatalogRule/_files/catalog_rule_10_off_not_logged.php');
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_rollback.php'
|
||||
);
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/CatalogRule/_files/catalog_rule_10_off_not_logged_rollback.php'
|
||||
);
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$productRepository
|
||||
->get('bundle_product')
|
||||
->setSpecialPrice(50)
|
||||
->save();
|
||||
|
||||
$productRepository
|
||||
->get('simple2')
|
||||
->setSpecialPrice(2.5)
|
||||
->save();
|
||||
|
||||
$productRepository
|
||||
->get('simple5')
|
||||
->setSpecialPrice(9.9)
|
||||
->save();
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Bundle/_files/PriceCalculator/dynamic_bundle_product_rollback.php'
|
||||
);
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(42)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle_product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setPriceType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)
|
||||
->setPrice(110.0)
|
||||
->setShipmentType(0);
|
||||
|
||||
$productRepository->save($product);
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$registry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle_product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/CatalogRule/_files/catalog_rule_10_off_not_logged.php');
|
||||
+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/Bundle/_files/PriceCalculator/fixed_bundle_product_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/CatalogRule/_files/catalog_rule_10_off_not_logged_rollback.php'
|
||||
);
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/fixed_bundle_product.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$productRepository
|
||||
->get('bundle_product')
|
||||
->setSpecialPrice(50)
|
||||
->save();
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/PriceCalculator/fixed_bundle_product_rollback.php');
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Checkbox Options')
|
||||
->setSku('bundle-product-checkbox-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Checkbox Options',
|
||||
'default_title' => 'Checkbox Options',
|
||||
'type' => 'checkbox',
|
||||
'required' => 0,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -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\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-checkbox-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Checkbox Required Option')
|
||||
->setSku('bundle-product-checkbox-required-option')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Checkbox Options',
|
||||
'default_title' => 'Checkbox Options',
|
||||
'type' => 'checkbox',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-checkbox-required-option', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Checkbox Required Options')
|
||||
->setSku('bundle-product-checkbox-required-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Checkbox Options',
|
||||
'default_title' => 'Checkbox Options',
|
||||
'type' => 'checkbox',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -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\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-checkbox-required-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Dropdown options')
|
||||
->setSku('bundle-product-dropdown-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Dropdown Options',
|
||||
'default_title' => 'Dropdown Options',
|
||||
'type' => 'select',
|
||||
'required' => 0,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -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\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-dropdown-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Dropdown Required options')
|
||||
->setSku('bundle-product-dropdown-required-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Dropdown Options',
|
||||
'default_title' => 'Dropdown Options',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => 'simple-1',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -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\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-dropdown-required-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Multiselect Options')
|
||||
->setSku('bundle-product-multiselect-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Multiselect Options',
|
||||
'default_title' => 'Multiselect Options',
|
||||
'type' => 'multi',
|
||||
'required' => 0,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -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\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-multiselect-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Multiselect Required Option')
|
||||
->setSku('bundle-product-multiselect-required-option')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Multiselect Options',
|
||||
'default_title' => 'Multiselect Options',
|
||||
'type' => 'multi',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-multiselect-required-option', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Multiselect Required Options')
|
||||
->setSku('bundle-product-multiselect-required-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Multiselect Options',
|
||||
'default_title' => 'Multiselect Options',
|
||||
'type' => 'multi',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -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\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-multiselect-required-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Radio Options')
|
||||
->setSku('bundle-product-radio-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Radio Options',
|
||||
'default_title' => 'Radio Options',
|
||||
'type' => 'radio',
|
||||
'required' => 0,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -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\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-radio-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Radio Required Option')
|
||||
->setSku('bundle-product-radio-required-option')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Radio Options',
|
||||
'default_title' => 'Radio Options',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-radio-required-option', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$baseWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$productRepository->cleanCache();
|
||||
$product = $productRepository->get('simple-1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
/** @var ProductFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$baseWebsiteId])
|
||||
->setName('Bundle Product Radio Required Options')
|
||||
->setSku('bundle-product-radio-required-options')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Radio Options',
|
||||
'default_title' => 'Radio Options',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-radio-required-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
|
||||
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
|
||||
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\CatalogInventory\Model\Stock\Item;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var Item $stockItem */
|
||||
$stockItem = $objectManager->create(Item::class);
|
||||
$stockItem->load(10, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId(10);
|
||||
}
|
||||
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
$stockItem->setIsInStock(1);
|
||||
$stockItem->save();
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product With Single dropdown option')
|
||||
->setSku('bundle-product-single-dropdown-option')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Drop Down Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 0,
|
||||
'position' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 1.00,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1,
|
||||
'option_id' => 1,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!$optionData['delete']) {
|
||||
$option = $objectManager->create(OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!$linkData['delete']) {
|
||||
$link = $objectManager->create(LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
if (isset($linkData['selection_can_change_qty'])) {
|
||||
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
|
||||
}
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$productRepository->save($product, true);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-single-dropdown-option', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $exception) {
|
||||
$logger = $objectManager->get(LoggerInterface::class);
|
||||
$logger->log($exception->getCode(), $exception->getMessage());
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
<?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/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$productIds = range(10, 12, 1);
|
||||
foreach ($productIds as $productId) {
|
||||
/** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
|
||||
$stockItem = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Item::class);
|
||||
$stockItem->load($productId, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId($productId);
|
||||
}
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
$stockItem->setIsInStock(1);
|
||||
$stockItem->save();
|
||||
}
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product With Two dropdown options')
|
||||
->setSku('bundle-product-two-dropdown-options')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// "Drop-down" option
|
||||
[
|
||||
'title' => 'Drop Down Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 0,
|
||||
'position' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'title' => 'Drop Down Option 2',
|
||||
'default_title' => 'Option 2',
|
||||
'type' => 'select',
|
||||
'required' => 0,
|
||||
'position' => 2,
|
||||
'delete' => '',
|
||||
]
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 1.00,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 2.00,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_price_value' => 1.00,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 2.00,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
]
|
||||
],
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
if (isset($linkData['selection_can_change_qty'])) {
|
||||
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
|
||||
}
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$productRepository->save($product, true);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-two-dropdown-options', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\CatalogInventory\Model\Stock\Item;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/multiple_products_with_disabled_virtual_product.php'
|
||||
);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$productIds = range(101, 104, 1);
|
||||
|
||||
foreach ($productIds as $productId) {
|
||||
/** @var Item $stockItem */
|
||||
$stockItem = $objectManager->create(Item::class);
|
||||
$stockItem->load($productId, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId($productId);
|
||||
}
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
if ($productId == 104) {
|
||||
$stockItem->setQty(0);
|
||||
$stockItem->setIsInStock(0);
|
||||
} else {
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsInStock(1);
|
||||
}
|
||||
$stockItem->save();
|
||||
}
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setId(3)
|
||||
->setCategoryIds([565])
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// Required "Drop-down" option 1
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'position' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
// Required "Drop-down" option 2
|
||||
[
|
||||
'title' => 'Option 2',
|
||||
'default_title' => 'Option 2',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'position' => 2,
|
||||
'delete' => '',
|
||||
]
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 101,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 102,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 103,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 104,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 101,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
],
|
||||
[
|
||||
'product_id' => 102,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
],
|
||||
[
|
||||
'product_id' => 103,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$product->save();
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/multiple_products_with_disabled_virtual_product_rollback.php'
|
||||
);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = Bootstrap::getObjectManager()->get(Registry::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
//delete bundle product
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product');
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $exception) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
/** @var Magento\Catalog\Api\Data\ProductInterface $bundleProduct */
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product With Dynamic Price')
|
||||
->setSku('bundle_product_with_dynamic_price')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 0,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(null)
|
||||
->setWeightType(0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
[
|
||||
'title' => 'Option 2',
|
||||
'default_title' => 'Option 2',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'selection_qty' => 1,
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'selection_qty' => 1,
|
||||
],
|
||||
]
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -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\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle_product_with_dynamic_price', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//product already deleted.
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
|
||||
* bundled items should not contain products with required custom options.
|
||||
* However, if to create such a bundle product, it will be always out of stock.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/simple_products_not_visible_individually.php');
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$sampleProduct = $productRepository->get('simple_not_visible_1');
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId('bundle')
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setWeight(2)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product-1')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(0)
|
||||
->setPriceType(0)
|
||||
->setShipmentType(0)
|
||||
->setPrice(10.0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Bundle Product Items',
|
||||
'default_title' => 'Bundle Product Items',
|
||||
'type' => 'select', 'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
]
|
||||
)
|
||||
->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => $sampleProduct->getId(),
|
||||
'selection_price_value' => 2.75,
|
||||
'selection_qty' => 2,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
/** @var \Magento\Bundle\Api\Data\LinkInterface$link */
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
if (isset($linkData['selection_can_change_qty'])) {
|
||||
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
|
||||
}
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
|
||||
$productRepository->save($product, true);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
|
||||
* bundled items should not contain products with required custom options.
|
||||
* However, if to create such a bundle product, it will be always out of stock.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/simple_products_not_visible_individually_rollback.php'
|
||||
);
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product-1', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
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\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/three_simple_products_with_tier_price.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
|
||||
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle_with_tier_price_selections')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(null)
|
||||
->setWeightType(0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
[
|
||||
'sku' => 'simple_1',
|
||||
'selection_qty' => 3,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple_2',
|
||||
'selection_qty' => 3,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple_3',
|
||||
'selection_qty' => 3,
|
||||
],
|
||||
]
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
|
||||
$productRepository->save($bundleProduct);
|
||||
+33
@@ -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\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()
|
||||
->requireDataFixture('Magento/Catalog/_files/three_simple_products_with_tier_price_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
try {
|
||||
$product = $productRepository->get('bundle_with_tier_price_selections', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\CategoryLinkManagementInterface;
|
||||
use Magento\Catalog\Helper\DefaultCategory;
|
||||
use Magento\TestFramework\Catalog\Model\GetCategoryByName;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/bundle_product_dropdown_options.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var GetCategoryByName $getCategoryByName */
|
||||
$getCategoryByName = $objectManager->create(GetCategoryByName::class);
|
||||
$category = $getCategoryByName->execute('Category 1');
|
||||
/** @var CategoryLinkManagementInterface $categoryLinkManagement */
|
||||
$categoryLinkManagement = $objectManager->create(CategoryLinkManagementInterface::class);
|
||||
/** @var DefaultCategory $categoryHelper */
|
||||
$categoryHelper = $objectManager->get(DefaultCategory::class);
|
||||
$categoryLinkManagement->assignProductToCategories('bundle-product', [2, $category->getId()]);
|
||||
$categoryLinkManagement->assignProductToCategories(
|
||||
'bundle-product-dropdown-options',
|
||||
[$categoryHelper->getId(), $category->getId()]
|
||||
);
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/bundle_product_dropdown_options_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_rollback.php');
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
|
||||
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\Data\ProductExtensionFactory;
|
||||
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\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$defaultWebsiteId = $websiteRepository->get('base')->getId();
|
||||
/** @var ProductExtensionFactory $extensionAttributesFactory */
|
||||
$extensionAttributesFactory = $objectManager->get(ProductExtensionFactory::class);
|
||||
/** @var OptionInterfaceFactory $optionFactory */
|
||||
$optionFactory = $objectManager->get(OptionInterfaceFactory::class);
|
||||
/** @var LinkInterfaceFactory $linkFactory */
|
||||
$linkFactory = $objectManager->get(LinkInterfaceFactory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple1');
|
||||
$product2 = $productRepository->get('simple2');
|
||||
$product3 = $productRepository->get('simple3');
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle_product')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setWeightType(0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'multi',
|
||||
'required' => 1,
|
||||
],
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => $product->getId(),
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'product_id' => $product2->getId(),
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'product_id' => $product3->getId(),
|
||||
'sku' => $product3->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$options = [];
|
||||
foreach ($bundleProduct->getBundleOptionsData() as $key => $optionData) {
|
||||
$option = $optionFactory->create(['data' => $optionData]);
|
||||
$option->setSku($bundleProduct->getSku());
|
||||
$option->setOptionId(null);
|
||||
$links = [];
|
||||
foreach ($bundleProduct->getBundleSelectionsData()[$key] as $linkData) {
|
||||
$link = $linkFactory->create(['data' => $linkData]);
|
||||
$links[] = $link;
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
$extensionAttributes = $bundleProduct->getExtensionAttributes() ?: $extensionAttributesFactory->create();
|
||||
$extensionAttributes->setBundleProductOptions($options);
|
||||
$bundleProduct->setExtensionAttributes($extensionAttributes);
|
||||
$productRepository->save($bundleProduct);
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle_product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\CategoryRepositoryInterface;
|
||||
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Api\Data\CategoryInterfaceFactory;
|
||||
use Magento\Catalog\Helper\DefaultCategory;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\CatalogRule\Api\CatalogRuleRepositoryInterface;
|
||||
use Magento\CatalogRule\Api\Data\RuleInterface;
|
||||
use Magento\CatalogRule\Api\Data\RuleInterfaceFactory;
|
||||
use Magento\CatalogRule\Model\Indexer\IndexBuilder;
|
||||
use Magento\CatalogRule\Model\Rule\Condition\Combine;
|
||||
use Magento\CatalogRule\Model\Rule\Condition\Product;
|
||||
use Magento\Customer\Model\Group;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_with_different_price_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CategoryInterfaceFactory $categoryFactory */
|
||||
$categoryFactory = $objectManager->get(CategoryInterfaceFactory::class);
|
||||
/** @var CategoryRepositoryInterface $categoryRepository */
|
||||
$categoryRepository = $objectManager->get(CategoryRepositoryInterface::class);
|
||||
/** @var DefaultCategory $categoryHelper */
|
||||
$categoryHelper = $objectManager->get(DefaultCategory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
$product = $productRepository->get('simple1000');
|
||||
$product2 = $productRepository->get('simple1001');
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var RuleInterfaceFactory $catalogRuleFactory */
|
||||
$catalogRuleFactory = $objectManager->get(RuleInterfaceFactory::class);
|
||||
/** @var CatalogRuleRepositoryInterface $catalogRuleRepository */
|
||||
$catalogRuleRepository = $objectManager->get(CatalogRuleRepositoryInterface::class);
|
||||
/** @var IndexBuilder $indexBuilder */
|
||||
$indexBuilder = $objectManager->get(IndexBuilder::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
|
||||
|
||||
$category = $categoryFactory->create();
|
||||
$category->isObjectNew(true);
|
||||
$category->setName('Category with bundle product and rule')
|
||||
->setParentId($categoryHelper->getId())
|
||||
->setIsActive(true)
|
||||
->setPosition(1);
|
||||
$category = $categoryRepository->save($category);
|
||||
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('dynamic_bundle_product_with_catalog_rule')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(null)
|
||||
->setWeightType(0)
|
||||
->setCategoryIds([$category->getId()])
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
[
|
||||
'sku' => $product->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => $product2->getSku(),
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
]
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
|
||||
$productRepository->save($bundleProduct);
|
||||
|
||||
$ruleData = [
|
||||
RuleInterface::NAME => 'Rule for bundle product',
|
||||
RuleInterface::IS_ACTIVE => 1,
|
||||
'website_ids' => [$defaultWebsiteId],
|
||||
'customer_group_ids' => Group::NOT_LOGGED_IN_ID,
|
||||
RuleInterface::DISCOUNT_AMOUNT => 50,
|
||||
RuleInterface::SIMPLE_ACTION => 'by_percent',
|
||||
'conditions' => [
|
||||
'1' => [
|
||||
'type' => Combine::class,
|
||||
'aggregator' => 'all',
|
||||
'value' => '1',
|
||||
],
|
||||
'1--1' => [
|
||||
'type' => Product::class,
|
||||
'attribute' => 'category_ids',
|
||||
'operator' => '==',
|
||||
'value' => $category->getId(),
|
||||
],
|
||||
],
|
||||
];
|
||||
$catalogRule = $catalogRuleFactory->create();
|
||||
$catalogRule->loadPost($ruleData);
|
||||
$catalogRuleRepository->save($catalogRule);
|
||||
$indexBuilder->reindexFull();
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\CategoryRepositoryInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\CatalogRule\Api\CatalogRuleRepositoryInterface;
|
||||
use Magento\CatalogRule\Model\Indexer\IndexBuilder;
|
||||
use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Catalog\Model\GetCategoryByName;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/category_with_different_price_products_rollback.php'
|
||||
);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CategoryRepositoryInterface $categoryRepository */
|
||||
$categoryRepository = $objectManager->get(CategoryRepositoryInterface::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
/** @var GetCategoryByName $getCategoryByName */
|
||||
$getCategoryByName = $objectManager->create(GetCategoryByName::class);
|
||||
/** @var CollectionFactory $ruleCollectionFactory */
|
||||
$ruleCollectionFactory = $objectManager->get(CollectionFactory::class);
|
||||
/** @var CatalogRuleRepositoryInterface $ruleRepository */
|
||||
$ruleRepository = $objectManager->get(CatalogRuleRepositoryInterface::class);
|
||||
/** @var IndexBuilder $indexBuilder */
|
||||
$indexBuilder = $objectManager->get(IndexBuilder::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('dynamic_bundle_product_with_catalog_rule', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//product already deleted.
|
||||
}
|
||||
|
||||
$category = $getCategoryByName->execute('Category with bundle product and rule');
|
||||
|
||||
try {
|
||||
$categoryRepository->delete($category);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//category already deleted.
|
||||
}
|
||||
|
||||
$ruleCollection = $ruleCollectionFactory->create();
|
||||
$ruleCollection->addFieldToFilter('name', 'Rule for bundle product');
|
||||
$ruleCollection->setPageSize(1);
|
||||
$catalogRule = $ruleCollection->getFirstItem();
|
||||
|
||||
try {
|
||||
$ruleRepository->delete($catalogRule);
|
||||
} catch (Exception $ex) {
|
||||
//Nothing to remove
|
||||
}
|
||||
|
||||
$indexBuilder->reindexFull();
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$productIds = [10, 11, 12];
|
||||
foreach ($productIds as $productId) {
|
||||
/** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
|
||||
$stockItem = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Item::class);
|
||||
$stockItem->load($productId, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId($productId);
|
||||
}
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
$stockItem->setIsInStock(1);
|
||||
$stockItem->save();
|
||||
}
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(0)
|
||||
->setPrice(10.0)
|
||||
->setSpecialPrice(10)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// Required "Drop-down" option
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 2.75,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 6.75,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$tierPriceFactory = $objectManager->get(ProductTierPriceInterfaceFactory::class);
|
||||
/** @var $tierPriceExtensionAttributesFactory */
|
||||
$tierPriceExtensionAttributesFactory = $objectManager->create(ProductTierPriceExtensionFactory::class);
|
||||
$tierPriceExtensionAttribute = $tierPriceExtensionAttributesFactory->create()->setPercentageValue(10);
|
||||
$tierPrices[] = $tierPriceFactory->create(
|
||||
[
|
||||
'data' => [
|
||||
'customer_group_id' => \Magento\Customer\Model\Group::CUST_GROUP_ALL,
|
||||
'qty' => 2
|
||||
]
|
||||
]
|
||||
)->setExtensionAttributes($tierPriceExtensionAttribute);
|
||||
$product->setTierPrices($tierPrices);
|
||||
$product->save();
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_with_multiple_options_rollback.php');
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
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\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_with_different_price_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
|
||||
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('dynamic_bundle_product_with_special_price')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(null)
|
||||
->setSpecialPrice(75)
|
||||
->setWeightType(0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
[
|
||||
'sku' => 'simple1000',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple1001',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
]
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
|
||||
$productRepository->save($bundleProduct);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/category_with_different_price_products_rollback.php'
|
||||
);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('dynamic_bundle_product_with_special_price', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//product already deleted.
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\Customer\Model\Group;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_with_different_price_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductTierPriceInterfaceFactory $tierPriceFactory */
|
||||
$tierPriceFactory = $objectManager->get(ProductTierPriceInterfaceFactory::class);
|
||||
/** @var $tierPriceExtensionAttributesFactory */
|
||||
$tierPriceExtensionAttributesFactory = $objectManager->get(ProductTierPriceExtensionFactory::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
|
||||
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('dynamic_bundle_product_with_tier_price')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(null)
|
||||
->setWeightType(0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
[
|
||||
'sku' => 'simple1000',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple1001',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
]
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
|
||||
|
||||
$tierPriceExtensionAttribute = $tierPriceExtensionAttributesFactory->create(
|
||||
[
|
||||
'data' => [
|
||||
'website_id' => 0,
|
||||
'percentage_value' => 25,
|
||||
]
|
||||
]
|
||||
);
|
||||
$tierPrices[] = $tierPriceFactory->create(
|
||||
[
|
||||
'data' => [
|
||||
'customer_group_id' => Group::CUST_GROUP_ALL,
|
||||
'qty' => 1,
|
||||
]
|
||||
]
|
||||
)->setExtensionAttributes($tierPriceExtensionAttribute);
|
||||
$bundleProduct->setTierPrices($tierPrices);
|
||||
$productRepository->save($bundleProduct);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/category_with_different_price_products_rollback.php'
|
||||
);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('dynamic_bundle_product_with_tier_price', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//product already deleted.
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
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\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_with_different_price_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var StoreManagerInterface $storeManager */
|
||||
$storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
|
||||
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('dynamic_bundle_product_without_discounts')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setSkuType(0)
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPrice(null)
|
||||
->setWeightType(0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
[
|
||||
'sku' => 'simple1000',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple1001',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
]
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
|
||||
$productRepository->save($bundleProduct);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture(
|
||||
'Magento/Catalog/_files/category_with_different_price_products_rollback.php'
|
||||
);
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('dynamic_bundle_product_without_discounts', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//product already deleted.
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId('bundle')
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setPriceType(0)
|
||||
->setShipmentType(1)
|
||||
->setWeightType(0)
|
||||
->setDescription('description')
|
||||
->setPrice(99);
|
||||
|
||||
$productRepository->save($product);
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
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\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$defaultWebsiteId = $websiteRepository->get('base')->getId();
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('fixed_bundle_product_with_special_price')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setPriceView(1)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_FIXED)
|
||||
->setPrice(50.0)
|
||||
->setSpecialPrice(80)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 10,
|
||||
'selection_price_type' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 25,
|
||||
'selection_price_type' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 25,
|
||||
'selection_price_type' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('fixed_bundle_product_with_special_price', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
|
||||
use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Customer\Model\Group;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var ProductTierPriceInterfaceFactory $tierPriceFactory */
|
||||
$tierPriceFactory = $objectManager->get(ProductTierPriceInterfaceFactory::class);
|
||||
/** @var $tierPriceExtensionAttributesFactory */
|
||||
$tierPriceExtensionAttributesFactory = $objectManager->get(ProductTierPriceExtensionFactory::class);
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$defaultWebsiteId = $websiteRepository->get('base')->getId();
|
||||
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('fixed_bundle_product_with_tier_price')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setPriceView(1)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_FIXED)
|
||||
->setPrice(50.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 10,
|
||||
'selection_price_type' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 25,
|
||||
'selection_price_type' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 25,
|
||||
'selection_price_type' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
|
||||
$tierPriceExtensionAttribute = $tierPriceExtensionAttributesFactory->create(
|
||||
[
|
||||
'data' => [
|
||||
'website_id' => 0,
|
||||
'percentage_value' => 25,
|
||||
]
|
||||
]
|
||||
);
|
||||
$tierPrices[] = $tierPriceFactory->create(
|
||||
[
|
||||
'data' => [
|
||||
'customer_group_id' => Group::CUST_GROUP_ALL,
|
||||
'qty' => 1,
|
||||
]
|
||||
]
|
||||
)->setExtensionAttributes($tierPriceExtensionAttribute);
|
||||
$bundleProduct->setTierPrices($tierPrices);
|
||||
$productRepository->save($bundleProduct);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('fixed_bundle_product_with_tier_price', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
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\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var PrepareBundleLinks $prepareBundleLinks */
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$defaultWebsiteId = $websiteRepository->get('base')->getId();
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setName('Bundle Product')
|
||||
->setSku('fixed_bundle_product_without_discounts')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
]
|
||||
)
|
||||
->setPriceView(1)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(Price::PRICE_TYPE_FIXED)
|
||||
->setPrice(50.0)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
|
||||
|
||||
$bundleOptionsData = [
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$bundleSelectionsData = [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 10,
|
||||
'selection_price_type' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple2',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 25,
|
||||
'selection_price_type' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
[
|
||||
'sku' => 'simple3',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 25,
|
||||
'selection_price_type' => 0,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
];
|
||||
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, [$bundleSelectionsData]);
|
||||
$productRepository->save($bundleProduct);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var Registry $registry */
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('fixed_bundle_product_without_discounts', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
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\TestFramework\Bundle\Model\PrepareBundleLinks;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->setTypeId(Type::TYPE_BUNDLE)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle_product')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(0)
|
||||
->setPriceType(Price::PRICE_TYPE_FIXED)
|
||||
->setPrice(110.0)
|
||||
->setShipmentType(0);
|
||||
|
||||
$optionData = [
|
||||
[
|
||||
'title' => 'Test Option',
|
||||
'default_title' => 'Test Option',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
];
|
||||
$selectionData = [
|
||||
[
|
||||
'sku' => 'simple1',
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 0,
|
||||
'selection_price_type' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
],
|
||||
];
|
||||
$product = $prepareBundleLinks->execute($product, $optionData, [$selectionData]);
|
||||
$productRepository->save($product);
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$registry = $objectManager->get(Registry::class);
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle_product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// Required "Drop-down" option
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
// Required "Radio Buttons" option
|
||||
[
|
||||
'title' => 'Option 2',
|
||||
'default_title' => 'Option 2',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
// Required "Checkbox" option
|
||||
[
|
||||
'title' => 'Option 3',
|
||||
'default_title' => 'Option 3',
|
||||
'type' => 'checkbox',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
// Required "Multiple Select" option
|
||||
[
|
||||
'title' => 'Option 4',
|
||||
'default_title' => 'Option 4',
|
||||
'type' => 'multi',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
// Non-required "Multiple Select" option
|
||||
[
|
||||
'title' => 'Option 5',
|
||||
'default_title' => 'Option 5',
|
||||
'type' => 'multi',
|
||||
'required' => 0,
|
||||
'delete' => '',
|
||||
]
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 10,
|
||||
'selection_can_change_qty' => 0,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 10,
|
||||
'selection_can_change_qty' => 0,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 12,
|
||||
'selection_qty' => 10,
|
||||
'selection_can_change_qty' => 0,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 10,
|
||||
'selection_can_change_qty' => 0,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 10,
|
||||
'selection_can_change_qty' => 0,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
],
|
||||
[
|
||||
'product_id' => 13,
|
||||
'selection_qty' => 10,
|
||||
'selection_can_change_qty' => 0,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 10,
|
||||
'delete' => '',
|
||||
'option_id' => 3
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 10,
|
||||
'delete' => '',
|
||||
'option_id' => 3
|
||||
],
|
||||
[
|
||||
'product_id' => 14,
|
||||
'selection_qty' => 10,
|
||||
'selection_can_change_qty' => 0,
|
||||
'delete' => '',
|
||||
'option_id' => 3
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 13,
|
||||
'selection_qty' => 10,
|
||||
'delete' => '',
|
||||
'option_id' => 4
|
||||
],
|
||||
[
|
||||
'product_id' => 14,
|
||||
'selection_qty' => 10,
|
||||
'delete' => '',
|
||||
'option_id' => 4
|
||||
],
|
||||
[
|
||||
'product_id' => 12,
|
||||
'selection_qty' => 10,
|
||||
'selection_can_change_qty' => 0,
|
||||
'delete' => '',
|
||||
'option_id' => 4
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 10,
|
||||
'delete' => '',
|
||||
'option_id' => 5
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 10,
|
||||
'delete' => '',
|
||||
'option_id' => 5
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
|
||||
$productRepository->save($product, true);
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/multiple_products_rollback.php');
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product');
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
@@ -0,0 +1,163 @@
|
||||
<?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\Api\Data\ProductInterfaceFactory;
|
||||
use Magento\Catalog\Model\Product\Type as ProductType;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Msrp\Model\Product\Attribute\Source\Type;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductInterfaceFactory $productFactory */
|
||||
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$defaultWebsiteId = $websiteRepository->get('base')->getId();
|
||||
$product = $productFactory->create();
|
||||
$product->setTypeId(ProductType::TYPE_SIMPLE)
|
||||
->setId(10)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setName('Simple Product')
|
||||
->setSku('simple1')
|
||||
->setTaxClassId(2)
|
||||
->setDescription('description')
|
||||
->setShortDescription('short description')
|
||||
->setOptionsContainer('container1')
|
||||
->setMsrpDisplayActualPriceType(Type::TYPE_IN_CART)
|
||||
->setPrice(10)
|
||||
->setWeight(1)
|
||||
->setMetaTitle('meta title')
|
||||
->setMetaKeyword('meta keyword')
|
||||
->setMetaDescription('meta description')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setCategoryIds([])
|
||||
->setStockData([
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
'manage_stock' => 1,
|
||||
]);
|
||||
$productRepository->save($product);
|
||||
|
||||
$product2 = $productFactory->create();
|
||||
$product2->setTypeId(ProductType::TYPE_SIMPLE)
|
||||
->setId(11)
|
||||
->setAttributeSetId($product2->getDefaultAttributeSetId())
|
||||
->setName('Simple Product2')
|
||||
->setSku('simple2')
|
||||
->setTaxClassId(2)
|
||||
->setDescription('description')
|
||||
->setShortDescription('short description')
|
||||
->setOptionsContainer('container1')
|
||||
->setMsrpDisplayActualPriceType(Type::TYPE_ON_GESTURE)
|
||||
->setPrice(20)
|
||||
->setWeight(1)
|
||||
->setMetaTitle('meta title')
|
||||
->setMetaKeyword('meta keyword')
|
||||
->setMetaDescription('meta description')
|
||||
->setVisibility(Visibility::VISIBILITY_IN_CATALOG)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setCategoryIds([])
|
||||
->setStockData([
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 50,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
'manage_stock' => 1,
|
||||
]);
|
||||
$productRepository->save($product2);
|
||||
|
||||
$product3 = $productFactory->create();
|
||||
$product3->setTypeId(ProductType::TYPE_SIMPLE)
|
||||
->setId(12)
|
||||
->setAttributeSetId($product3->getDefaultAttributeSetId())
|
||||
->setName('Simple Product 3')
|
||||
->setSku('simple3')
|
||||
->setTaxClassId(0)
|
||||
->setDescription('description')
|
||||
->setShortDescription('short description')
|
||||
->setPrice(30)
|
||||
->setWeight(1)
|
||||
->setVisibility(Visibility::VISIBILITY_IN_CATALOG)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setCategoryIds([])
|
||||
->setStockData([
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 140,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
'manage_stock' => 1,
|
||||
]);
|
||||
$productRepository->save($product3);
|
||||
|
||||
$product4 = $productFactory->create();
|
||||
$product4->setTypeId(ProductType::TYPE_SIMPLE)
|
||||
->setId(13)
|
||||
->setAttributeSetId($product4->getDefaultAttributeSetId())
|
||||
->setName('Simple Product 4')
|
||||
->setSku('simple4')
|
||||
->setTaxClassId(0)
|
||||
->setDescription('description')
|
||||
->setShortDescription('short description')
|
||||
->setOptionsContainer('container1')
|
||||
->setMsrpDisplayActualPriceType(Type::TYPE_IN_CART)
|
||||
->setPrice(13)
|
||||
->setWeight(12)
|
||||
->setMetaTitle('meta title')
|
||||
->setMetaKeyword('meta keyword')
|
||||
->setMetaDescription('meta description')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setCategoryIds([])
|
||||
->setStockData([
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 20,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
'manage_stock' => 1,
|
||||
]);
|
||||
$productRepository->save($product4);
|
||||
|
||||
$product5 = $productFactory->create();
|
||||
$product5->setTypeId(ProductType::TYPE_SIMPLE)
|
||||
->setId(14)
|
||||
->setAttributeSetId($product5->getDefaultAttributeSetId())
|
||||
->setName('Simple Product 5')
|
||||
->setSku('simple5')
|
||||
->setTaxClassId(0)
|
||||
->setDescription('description')
|
||||
->setShortDescription('short description')
|
||||
->setOptionsContainer('container1')
|
||||
->setMsrpDisplayActualPriceType(Type::TYPE_IN_CART)
|
||||
->setPrice(14)
|
||||
->setWeight(10)
|
||||
->setMetaTitle('meta title')
|
||||
->setMetaKeyword('meta keyword')
|
||||
->setMetaDescription('meta description')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setWebsiteIds([$defaultWebsiteId])
|
||||
->setCategoryIds([])
|
||||
->setStockData([
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 15,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
'manage_stock' => 1,
|
||||
]);
|
||||
$productRepository->save($product5);
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
foreach (['simple1', 'simple2', 'simple3', 'simple4', 'simple5'] as $sku) {
|
||||
try {
|
||||
$product = $productRepository->get($sku, false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
|
||||
//Product already removed
|
||||
}
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_with_multiple_options.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php';
|
||||
|
||||
$billingAddress = $objectManager->create(\Magento\Sales\Model\Order\Address::class, ['data' => $addressData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
|
||||
$payment = $objectManager->create(\Magento\Sales\Model\Order\Payment::class);
|
||||
$payment->setMethod('checkmo');
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->load(3);
|
||||
|
||||
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
|
||||
$typeInstance = $product->getTypeInstance();
|
||||
$typeInstance->setStoreFilter($product->getStoreId(), $product);
|
||||
$optionCollection = $typeInstance->getOptionsCollection($product);
|
||||
|
||||
$bundleOptions = [];
|
||||
$bundleOptionsQty = [];
|
||||
foreach ($optionCollection as $option) {
|
||||
/** @var $option \Magento\Bundle\Model\Option */
|
||||
$selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product);
|
||||
if ($option->isMultiSelection()) {
|
||||
$bundleOptions[$option->getId()] = array_column($selectionsCollection->toArray(), 'selection_id');
|
||||
} else {
|
||||
$bundleOptions[$option->getId()] = $selectionsCollection->getFirstItem()->getSelectionId();
|
||||
}
|
||||
$bundleOptionsQty[$option->getId()] = 1;
|
||||
}
|
||||
|
||||
$requestInfo = [
|
||||
'product' => $product->getId(),
|
||||
'bundle_option' => $bundleOptions,
|
||||
'bundle_option_qty' => $bundleOptionsQty,
|
||||
'qty' => 1,
|
||||
'custom_price' => 300,
|
||||
];
|
||||
|
||||
/** @var \Magento\Sales\Model\Order\Item $orderItem */
|
||||
$orderItem = $objectManager->create(\Magento\Sales\Model\Order\Item::class);
|
||||
$orderItem->setProductId($product->getId());
|
||||
$orderItem->setQtyOrdered(1);
|
||||
$orderItem->setBasePrice($product->getPrice());
|
||||
$orderItem->setPrice($product->getPrice());
|
||||
$orderItem->setRowTotal($product->getPrice());
|
||||
$orderItem->setProductType($product->getTypeId());
|
||||
$orderItem->setProductOptions([
|
||||
'info_buyRequest' => $requestInfo,
|
||||
'bundle_options' => [
|
||||
[
|
||||
'value' => [['title' => $product->getName()]]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->setIncrementId('100000001');
|
||||
$order->setState(\Magento\Sales\Model\Order::STATE_NEW);
|
||||
$order->setStatus($order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_NEW));
|
||||
$order->setCustomerIsGuest(true);
|
||||
$order->setCustomerEmail('customer@null.com');
|
||||
$order->setCustomerFirstname('firstname');
|
||||
$order->setCustomerLastname('lastname');
|
||||
$order->setBillingAddress($billingAddress);
|
||||
$order->setShippingAddress($shippingAddress);
|
||||
$order->setAddresses([$billingAddress, $shippingAddress]);
|
||||
$order->setPayment($payment);
|
||||
$order->addItem($orderItem);
|
||||
$order->setStoreId($objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId());
|
||||
$order->setSubtotal(100);
|
||||
$order->setBaseSubtotal(100);
|
||||
$order->setBaseGrandTotal(100);
|
||||
$order->save();
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_with_multiple_options_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/default_rollback.php');
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Sales\Api\Data\OrderInterfaceFactory;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/order_item_with_bundle_and_options.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_product.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$order = $objectManager->get(OrderInterfaceFactory::class)->create()->loadByIncrementId('100000001');
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple333');
|
||||
/** @var \Magento\Sales\Model\Order\Item $orderItem */
|
||||
$orderItem = $objectManager->create(\Magento\Sales\Model\Order\Item::class);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$orderItem->setProductId($product->getId())->setQtyOrdered(1);
|
||||
$orderItem->setBasePrice($product->getPrice());
|
||||
$orderItem->setPrice($product->getPrice());
|
||||
$orderItem->setRowTotal($product->getPrice());
|
||||
$orderItem->setProductType('simple');
|
||||
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order->addItem($orderItem);
|
||||
$order->save();
|
||||
+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/Bundle/_files/product_with_multiple_options_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/category_product_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/default_rollback.php');
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Model\Option;
|
||||
use Magento\Bundle\Model\Product\Type as BundleProductType;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Checkout\Model\Cart;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Quote\Api\CartManagementInterface;
|
||||
use Magento\Quote\Model\Quote\Address;
|
||||
use Magento\Quote\Model\Quote\Payment;
|
||||
use Magento\Quote\Model\QuoteManagement;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/two_bundle_products_with_separate_shipping.php');
|
||||
$addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php';
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)
|
||||
->setAddressType('shipping')
|
||||
->setShippingMethod('flatrate_flatrate');
|
||||
|
||||
/** @var Payment $payment */
|
||||
$payment = $objectManager->create(Payment::class);
|
||||
$payment->setMethod('checkmo');
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
|
||||
$bundleProduct = $productRepository->get('bundle-product-separate-shipping-1');
|
||||
$bundleProduct2 = $productRepository->get('bundle-product-separate-shipping-2');
|
||||
$selectionProducts = [
|
||||
$bundleProduct->getId() => [10, 12],
|
||||
$bundleProduct2->getId() => [11, 13],
|
||||
];
|
||||
|
||||
/** @var Cart $cart */
|
||||
$cart = $objectManager->create(Cart::class);
|
||||
|
||||
foreach ([$bundleProduct, $bundleProduct2] as $product) {
|
||||
|
||||
/** @var BundleProductType $typeInstance */
|
||||
$typeInstance = $product->getTypeInstance();
|
||||
$typeInstance->setStoreFilter($product->getStoreId(), $product);
|
||||
$optionCollection = $typeInstance->getOptionsCollection($product);
|
||||
|
||||
$bundleOptions = [];
|
||||
$bundleOptionsQty = [];
|
||||
$optionsData = [];
|
||||
|
||||
/** @var Option $option */
|
||||
foreach ($optionCollection as $option) {
|
||||
$selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product);
|
||||
$selectionIds = $selectionProducts[$product->getId()];
|
||||
$selectionsCollection->addIdFilter($selectionIds);
|
||||
|
||||
foreach ($selectionIds as $productId) {
|
||||
$selection = $selectionsCollection->getItemByColumnValue('product_id', $productId);
|
||||
if ($selection !== null) {
|
||||
$bundleOptions[$option->getId()] = $selection->getSelectionId();
|
||||
$optionsData[$option->getId()] = $selection->getProductId();
|
||||
$bundleOptionsQty[$option->getId()] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$requestInfo = [
|
||||
'product' => $product->getId(),
|
||||
'bundle_option' => $bundleOptions,
|
||||
'bundle_option_qty' => $bundleOptionsQty,
|
||||
'qty' => 1,
|
||||
];
|
||||
|
||||
$cart->addProduct($product, $requestInfo);
|
||||
}
|
||||
|
||||
$cart->getQuote()
|
||||
->setReservedOrderId('order_bundle_separately_shipped')
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress)
|
||||
->setCheckoutMethod(CartManagementInterface::METHOD_GUEST)
|
||||
->setPayment($payment);
|
||||
$cart->save();
|
||||
|
||||
/** @var QuoteManagement $quoteManager */
|
||||
$quoteManager = $objectManager->get(QuoteManagement::class);
|
||||
$orderId = $quoteManager->placeOrder($cart->getQuote()->getId());
|
||||
|
||||
$objectManager->removeSharedInstance(Session::class);
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/default_rollback.php');
|
||||
+241
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Api\Data\LinkInterface;
|
||||
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
|
||||
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
|
||||
use Magento\Bundle\Model\Option;
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Bundle\Model\Product\Type;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Sales\Api\OrderPaymentRepositoryInterface as PaymentFactory;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Address;
|
||||
use Magento\Sales\Model\Order\Item;
|
||||
use Magento\Sales\Model\Order\ItemFactory;
|
||||
use Magento\Sales\Model\OrderFactory;
|
||||
use Magento\Sales\Model\OrderRepository;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products.php');
|
||||
|
||||
/** @var ObjectManagerInterface $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$sampleProduct = $productRepository->get('simple');
|
||||
$secondSampleProduct = $productRepository->get('custom-design-simple-product');
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $productFactory->create();
|
||||
$product->setTypeId(Type::TYPE_CODE)
|
||||
->setId(3)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setPriceType(Price::PRICE_TYPE_FIXED)
|
||||
->setShipmentType(AbstractType::SHIPMENT_SEPARATELY)
|
||||
->setPrice(10.0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Bundle Product Items',
|
||||
'default_title' => 'Bundle Product Items',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'title' => 'Bundle Product Items Option 2',
|
||||
'default_title' => 'Bundle Product Items Option 2',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
],
|
||||
)
|
||||
->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => $sampleProduct->getId(),
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => $secondSampleProduct->getId(),
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->get(OptionInterfaceFactory::class)->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
/** @var LinkInterface $link */
|
||||
$link = $objectManager->get(LinkInterfaceFactory::class)->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
if (isset($linkData['selection_can_change_qty'])) {
|
||||
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
|
||||
}
|
||||
$link->setPriceType($linkData['selection_price_type']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$productRepository->save($product);
|
||||
|
||||
$addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php';
|
||||
|
||||
$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
|
||||
$paymentFactory = $objectManager->get(PaymentFactory::class);
|
||||
$payment = $paymentFactory->create()->setMethod('checkmo');
|
||||
|
||||
$product = $productRepository->getById(3);
|
||||
|
||||
/** @var $typeInstance Type */
|
||||
$typeInstance = $product->getTypeInstance();
|
||||
$typeInstance->setStoreFilter($product->getStoreId(), $product);
|
||||
$optionCollection = $typeInstance->getOptionsCollection($product);
|
||||
|
||||
$bundleOptions = [];
|
||||
$bundleOptionsQty = [];
|
||||
$optionsData = [];
|
||||
foreach ($optionCollection as $option) {
|
||||
/** @var $option Option */
|
||||
$selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product);
|
||||
if ($option->isMultiSelection()) {
|
||||
$optionsData[$option->getId()] = array_column($selectionsCollection->toArray(), 'product_id');
|
||||
$bundleOptions[$option->getId()] = array_column($selectionsCollection->toArray(), 'selection_id');
|
||||
} else {
|
||||
$bundleOptions[$option->getId()] = $selectionsCollection->getFirstItem()->getSelectionId();
|
||||
$optionsData[$option->getId()] = $selectionsCollection->getFirstItem()->getProductId();
|
||||
}
|
||||
$bundleOptionsQty[$option->getId()] = 1;
|
||||
}
|
||||
|
||||
$requestInfo = [
|
||||
'product' => $product->getId(),
|
||||
'bundle_option' => $bundleOptions,
|
||||
'bundle_option_qty' => $bundleOptionsQty,
|
||||
'qty' => 1,
|
||||
];
|
||||
|
||||
$orderItemFactory = $objectManager->get(ItemFactory::class);
|
||||
$orderItems = [];
|
||||
/** @var Item $orderItem */
|
||||
$orderItem = $orderItemFactory->create();
|
||||
$orderItem->setProductId($product->getId());
|
||||
$orderItem->setQtyOrdered(1);
|
||||
$orderItem->setBasePrice($product->getPrice());
|
||||
$orderItem->setPrice($product->getPrice());
|
||||
$orderItem->setRowTotal($product->getPrice());
|
||||
$orderItem->setProductType($product->getTypeId());
|
||||
$orderItem->setSku($product->getSku());
|
||||
$orderItem->setProductOptions([
|
||||
'info_buyRequest' => $requestInfo,
|
||||
'shipment_type' => AbstractType::SHIPMENT_SEPARATELY
|
||||
]);
|
||||
|
||||
$orderItems[] = $orderItem;
|
||||
|
||||
foreach ($optionsData as $optionId => $productId) {
|
||||
/** @var $selectedProduct Product */
|
||||
$selectedProduct = $productRepository->getById($productId);
|
||||
|
||||
/** @var Item $orderItem */
|
||||
$orderItem = $orderItemFactory->create();
|
||||
$orderItem->setProductId($productId);
|
||||
$orderItem->setQtyOrdered(1);
|
||||
$orderItem->setBasePrice($selectedProduct->getPrice());
|
||||
$orderItem->setPrice($selectedProduct->getPrice());
|
||||
$orderItem->setRowTotal($selectedProduct->getPrice());
|
||||
$orderItem->setProductType($selectedProduct->getTypeId());
|
||||
$orderItem->setSku($selectedProduct->getSku());
|
||||
$orderItem->setProductOptions([
|
||||
'info_buyRequest' => $requestInfo,
|
||||
'shipment_type' => AbstractType::SHIPMENT_SEPARATELY
|
||||
]);
|
||||
$orderItem->setParentItem($orderItems[0]);
|
||||
$orderItems[] = $orderItem;
|
||||
}
|
||||
|
||||
$orderFactory = $objectManager->get(OrderFactory::class);
|
||||
$orderRepository = $objectManager->get(OrderRepository::class);
|
||||
/** @var Order $order */
|
||||
$order = $orderFactory->create();
|
||||
$order->setIncrementId('100000001');
|
||||
$order->setState(Order::STATE_NEW);
|
||||
$order->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_NEW));
|
||||
$order->setCustomerIsGuest(true);
|
||||
$order->setCustomerEmail('customer@null.com');
|
||||
$order->setCustomerFirstname('firstname');
|
||||
$order->setCustomerLastname('lastname');
|
||||
$order->setBillingAddress($billingAddress);
|
||||
$order->setShippingAddress($shippingAddress);
|
||||
$order->setAddresses([$billingAddress, $shippingAddress]);
|
||||
$order->setPayment($payment);
|
||||
|
||||
foreach ($orderItems as $item) {
|
||||
$order->addItem($item);
|
||||
}
|
||||
|
||||
$order->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId());
|
||||
$order->setSubtotal(100);
|
||||
$order->setBaseSubtotal(100);
|
||||
$order->setBaseGrandTotal(100);
|
||||
$orderRepository->save($order);
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/default_rollback.php');
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Bundle\Api\Data\LinkInterface;
|
||||
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
|
||||
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
|
||||
use Magento\Bundle\Model\Option;
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Bundle\Model\Product\Type;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\Catalog\Model\ProductFactory;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Sales\Api\OrderPaymentRepositoryInterface as PaymentFactory;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Address;
|
||||
use Magento\Sales\Model\Order\Item;
|
||||
use Magento\Sales\Model\Order\ItemFactory;
|
||||
use Magento\Sales\Model\OrderFactory;
|
||||
use Magento\Sales\Model\OrderRepository;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products.php');
|
||||
|
||||
/** @var ObjectManagerInterface $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$sampleProduct = $productRepository->get('simple');
|
||||
$secondSampleProduct = $productRepository->get('custom-design-simple-product');
|
||||
$productFactory = $objectManager->get(ProductFactory::class);
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $productFactory->create();
|
||||
$product->setTypeId(Type::TYPE_CODE)
|
||||
->setId(3)
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setPriceType(Price::PRICE_TYPE_FIXED)
|
||||
->setShipmentType(AbstractType::SHIPMENT_TOGETHER)
|
||||
->setPrice(10.0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Bundle Product Items',
|
||||
'default_title' => 'Bundle Product Items',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
[
|
||||
'title' => 'Bundle Product Items Option 2',
|
||||
'default_title' => 'Bundle Product Items Option 2',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
],
|
||||
)
|
||||
->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => $sampleProduct->getId(),
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => $secondSampleProduct->getId(),
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->get(OptionInterfaceFactory::class)->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
/** @var LinkInterface $link */
|
||||
$link = $objectManager->get(LinkInterfaceFactory::class)->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
if (isset($linkData['selection_can_change_qty'])) {
|
||||
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
|
||||
}
|
||||
$link->setPriceType($linkData['selection_price_type']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$productRepository->save($product);
|
||||
|
||||
$addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php';
|
||||
|
||||
$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
|
||||
$paymentFactory = $objectManager->get(PaymentFactory::class);
|
||||
$payment = $paymentFactory->create()->setMethod('checkmo');
|
||||
|
||||
$product = $productRepository->getById(3);
|
||||
|
||||
/** @var $typeInstance Type */
|
||||
$typeInstance = $product->getTypeInstance();
|
||||
$typeInstance->setStoreFilter($product->getStoreId(), $product);
|
||||
$optionCollection = $typeInstance->getOptionsCollection($product);
|
||||
|
||||
$bundleOptions = [];
|
||||
$bundleOptionsQty = [];
|
||||
$optionsData = [];
|
||||
foreach ($optionCollection as $option) {
|
||||
/** @var $option Option */
|
||||
$selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product);
|
||||
if ($option->isMultiSelection()) {
|
||||
$optionsData[$option->getId()] = array_column($selectionsCollection->toArray(), 'product_id');
|
||||
$bundleOptions[$option->getId()] = array_column($selectionsCollection->toArray(), 'selection_id');
|
||||
} else {
|
||||
$bundleOptions[$option->getId()] = $selectionsCollection->getFirstItem()->getSelectionId();
|
||||
$optionsData[$option->getId()] = $selectionsCollection->getFirstItem()->getProductId();
|
||||
}
|
||||
$bundleOptionsQty[$option->getId()] = 1;
|
||||
}
|
||||
|
||||
$requestInfo = [
|
||||
'product' => $product->getId(),
|
||||
'bundle_option' => $bundleOptions,
|
||||
'bundle_option_qty' => $bundleOptionsQty,
|
||||
'qty' => 1,
|
||||
];
|
||||
|
||||
$orderItemFactory = $objectManager->get(ItemFactory::class);
|
||||
$orderItems = [];
|
||||
/** @var Item $orderItem */
|
||||
$orderItem = $orderItemFactory->create();
|
||||
$orderItem->setProductId($product->getId());
|
||||
$orderItem->setQtyOrdered(1);
|
||||
$orderItem->setBasePrice($product->getPrice());
|
||||
$orderItem->setPrice($product->getPrice());
|
||||
$orderItem->setRowTotal($product->getPrice());
|
||||
$orderItem->setProductType($product->getTypeId());
|
||||
$orderItem->setSku($product->getSku());
|
||||
$orderItem->setProductOptions([
|
||||
'info_buyRequest' => $requestInfo,
|
||||
'bundle_options' => [['value' => [['title' => $sampleProduct->getSku()]]]],
|
||||
]);
|
||||
|
||||
$orderItems[] = $orderItem;
|
||||
|
||||
foreach ($optionsData as $optionId => $productId) {
|
||||
/** @var $selectedProduct Product */
|
||||
$selectedProduct = $productRepository->getById($productId);
|
||||
|
||||
/** @var Item $orderItem */
|
||||
$orderItem = $orderItemFactory->create();
|
||||
$orderItem->setProductId($productId);
|
||||
$orderItem->setQtyOrdered(1);
|
||||
$orderItem->setBasePrice($selectedProduct->getPrice());
|
||||
$orderItem->setPrice($selectedProduct->getPrice());
|
||||
$orderItem->setRowTotal($selectedProduct->getPrice());
|
||||
$orderItem->setProductType($selectedProduct->getTypeId());
|
||||
$orderItem->setSku($selectedProduct->getSku());
|
||||
$orderItem->setProductOptions(['info_buyRequest' => $requestInfo]);
|
||||
$orderItem->setParentItem($orderItems[0]);
|
||||
$orderItems[] = $orderItem;
|
||||
}
|
||||
|
||||
$orderFactory = $objectManager->get(OrderFactory::class);
|
||||
$orderRepository = $objectManager->get(OrderRepository::class);
|
||||
/** @var Order $order */
|
||||
$order = $orderFactory->create();
|
||||
$order->setIncrementId('100000001');
|
||||
$order->setState(Order::STATE_NEW);
|
||||
$order->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_NEW));
|
||||
$order->setCustomerIsGuest(true);
|
||||
$order->setCustomerEmail('customer@null.com');
|
||||
$order->setCustomerFirstname('firstname');
|
||||
$order->setCustomerLastname('lastname');
|
||||
$order->setBillingAddress($billingAddress);
|
||||
$order->setShippingAddress($shippingAddress);
|
||||
$order->setAddresses([$billingAddress, $shippingAddress]);
|
||||
$order->setPayment($payment);
|
||||
|
||||
foreach ($orderItems as $item) {
|
||||
$order->addItem($item);
|
||||
}
|
||||
|
||||
$order->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId());
|
||||
$order->setSubtotal(100);
|
||||
$order->setBaseSubtotal(100);
|
||||
$order->setBaseGrandTotal(100);
|
||||
$orderRepository->save($order);
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/default_rollback.php');
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/*
|
||||
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
|
||||
* bundled items should not contain products with required custom options.
|
||||
* However, if to create such a bundle product, it will be always out of stock.
|
||||
*/
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products.php');
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$sampleProduct = $productRepository->get('simple');
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId('bundle')
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setWeight(2)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(1)
|
||||
->setShipmentType(0)
|
||||
->setPrice(10.0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Bundle Product Items',
|
||||
'default_title' => 'Bundle Product Items',
|
||||
'type' => 'select', 'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
]
|
||||
)
|
||||
->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => $sampleProduct->getId(),
|
||||
'selection_price_value' => 2.75,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'selection_price_type' => 0
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
/** @var \Magento\Bundle\Api\Data\LinkInterface$link */
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
if (isset($linkData['selection_can_change_qty'])) {
|
||||
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
|
||||
}
|
||||
$link->setPriceType($linkData['selection_price_type']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
|
||||
$productRepository->save($product, true);
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/*
|
||||
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
|
||||
* bundled items should not contain products with required custom options.
|
||||
* However, if to create such a bundle product, it will be always out of stock.
|
||||
*/
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products.php');
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$sampleProduct = $productRepository->get('simple');
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId('bundle')
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setWeight(2)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(1)
|
||||
->setShipmentType(0)
|
||||
->setPrice(10.0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Bundle Product Items',
|
||||
'default_title' => 'Bundle Product Items',
|
||||
'type' => 'select', 'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
]
|
||||
)
|
||||
->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => $sampleProduct->getId(),
|
||||
'selection_price_value' => 2.75,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
/** @var \Magento\Bundle\Api\Data\LinkInterface$link */
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
if (isset($linkData['selection_can_change_qty'])) {
|
||||
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
|
||||
}
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
|
||||
$productRepository->save($product, true);
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/*
|
||||
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
|
||||
* bundled items should not contain products with required custom options.
|
||||
* However, if to create such a bundle product, it will be always out of stock.
|
||||
*/
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products_rollback.php');
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product.php');
|
||||
|
||||
/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */
|
||||
$categoryLinkManagement = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
|
||||
|
||||
$categoryLinkManagement->assignProductToCategories(
|
||||
'bundle-product',
|
||||
[2]
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Bundle/_files/product_rollback.php');
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
/*
|
||||
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
|
||||
* bundled items should not contain products with required custom options.
|
||||
* However, if to create such a bundle product, it will be always out of stock.
|
||||
*/
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products_rollback.php');
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product', false, null, true);
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
<?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/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
$productIds = range(10, 12, 1);
|
||||
foreach ($productIds as $productId) {
|
||||
$product = $productRepository->getById($productId, true, null, true);
|
||||
if ((int) $product->getStatus() === \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED) {
|
||||
$product->unlockAttribute('status')
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
|
||||
$product->save();
|
||||
}
|
||||
/** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
|
||||
$stockItem = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Item::class);
|
||||
$stockItem->load($productId, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId($productId);
|
||||
}
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
$stockItem->setIsInStock(1);
|
||||
$stockItem->save();
|
||||
}
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// Required "Drop-down" option
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'position' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
// Required "Radio Buttons" option
|
||||
[
|
||||
'title' => 'Option 2',
|
||||
'default_title' => 'Option 2',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'position' => 2,
|
||||
'delete' => '',
|
||||
],
|
||||
// Required "Checkbox" option
|
||||
[
|
||||
'title' => 'Option 3',
|
||||
'default_title' => 'Option 3',
|
||||
'type' => 'checkbox',
|
||||
'required' => 1,
|
||||
'position' => 3,
|
||||
'delete' => '',
|
||||
],
|
||||
// Required "Multiple Select" option
|
||||
[
|
||||
'title' => 'Option 4',
|
||||
'default_title' => 'Option 4',
|
||||
'type' => 'multi',
|
||||
'required' => 1,
|
||||
'position' => 4,
|
||||
'delete' => '',
|
||||
],
|
||||
// Non-required "Multiple Select" option
|
||||
[
|
||||
'title' => 'Option 5',
|
||||
'default_title' => 'Option 5',
|
||||
'type' => 'multi',
|
||||
'required' => 0,
|
||||
'position' => 5,
|
||||
'delete' => '',
|
||||
]
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 3,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 3,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 4,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 4,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 5,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 5,
|
||||
'selection_price_type' => 0,
|
||||
'selection_price_value' => 5
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$link->setPriceType($linkData['selection_price_type']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$product->save();
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
<?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/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$productIds = range(10, 12, 1);
|
||||
foreach ($productIds as $productId) {
|
||||
/** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
|
||||
$stockItem = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Item::class);
|
||||
$stockItem->load($productId, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId($productId);
|
||||
}
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
$stockItem->setIsInStock(1);
|
||||
$stockItem->save();
|
||||
}
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceView(1)
|
||||
->setSkuType(1)
|
||||
->setWeightType(1)
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// Required "Drop-down" option
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 2.75,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_price_value' => 6.75,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
]
|
||||
]
|
||||
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$link->setPrice($linkData['selection_price_value']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$product->save();
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->load(3);
|
||||
if ($product->getId()) {
|
||||
$product->delete();
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
<?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/multiple_products.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$productIds = range(10, 12, 1);
|
||||
foreach ($productIds as $productId) {
|
||||
/** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
|
||||
$stockItem = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Item::class);
|
||||
$stockItem->load($productId, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId($productId);
|
||||
}
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
$stockItem->setIsInStock(1);
|
||||
$stockItem->save();
|
||||
}
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setWebsiteIds([1])
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setPriceView(1)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// Required "Drop-down" option
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'position' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
// Required "Radio Buttons" option
|
||||
[
|
||||
'title' => 'Option 2',
|
||||
'default_title' => 'Option 2',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'position' => 2,
|
||||
'delete' => '',
|
||||
],
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 0,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 0,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
if (isset($linkData['selection_can_change_qty'])) {
|
||||
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
|
||||
}
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$product->save();
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product');
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$productIds = range(10, 12, 1);
|
||||
foreach ($productIds as $productId) {
|
||||
/** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
|
||||
$stockItem = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Item::class);
|
||||
$stockItem->load($productId, 'product_id');
|
||||
|
||||
if (!$stockItem->getProductId()) {
|
||||
$stockItem->setProductId($productId);
|
||||
}
|
||||
$stockItem->setUseConfigManageStock(1);
|
||||
$stockItem->setQty(1000);
|
||||
$stockItem->setIsQtyDecimal(0);
|
||||
$stockItem->setIsInStock(1);
|
||||
$stockItem->save();
|
||||
}
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
|
||||
->setId(3)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
|
||||
->setPriceType(1)
|
||||
->setPrice(10.0)
|
||||
->setShipmentType(0)
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
// Required "Drop-down" option
|
||||
[
|
||||
'title' => 'Option 1',
|
||||
'default_title' => 'Option 1',
|
||||
'type' => 'select',
|
||||
'required' => 1,
|
||||
'position' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
// Required "Radio Buttons" option
|
||||
[
|
||||
'title' => 'Option 2',
|
||||
'default_title' => 'Option 2',
|
||||
'type' => 'radio',
|
||||
'required' => 1,
|
||||
'position' => 2,
|
||||
'delete' => '',
|
||||
]
|
||||
]
|
||||
)->setBundleSelectionsData(
|
||||
[
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 1
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'selection_can_change_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 2
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 3
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 3
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 4
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 4
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'product_id' => 10,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 5
|
||||
],
|
||||
[
|
||||
'product_id' => 11,
|
||||
'selection_qty' => 1,
|
||||
'delete' => '',
|
||||
'option_id' => 5
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
if ($product->getBundleOptionsData()) {
|
||||
$options = [];
|
||||
foreach ($product->getBundleOptionsData() as $key => $optionData) {
|
||||
if (!(bool)$optionData['delete']) {
|
||||
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
|
||||
->create(['data' => $optionData]);
|
||||
$option->setSku($product->getSku());
|
||||
$option->setOptionId(null);
|
||||
|
||||
$links = [];
|
||||
$bundleLinks = $product->getBundleSelectionsData();
|
||||
if (!empty($bundleLinks[$key])) {
|
||||
foreach ($bundleLinks[$key] as $linkData) {
|
||||
if (!(bool)$linkData['delete']) {
|
||||
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
|
||||
->create(['data' => $linkData]);
|
||||
$linkProduct = $productRepository->getById($linkData['product_id']);
|
||||
$link->setSku($linkProduct->getSku());
|
||||
$link->setQty($linkData['selection_qty']);
|
||||
$links[] = $link;
|
||||
}
|
||||
}
|
||||
$option->setProductLinks($links);
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
$extension = $product->getExtensionAttributes();
|
||||
$extension->setBundleProductOptions($options);
|
||||
$product->setExtensionAttributes($extension);
|
||||
}
|
||||
$product->save();
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product');
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product');
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var $productFactory Magento\Catalog\Model\ProductFactory */
|
||||
$productFactory = $objectManager->create(\Magento\Catalog\Model\ProductFactory::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
/** @var $bundleProduct \Magento\Catalog\Model\Product */
|
||||
$bundleProduct = $productFactory->create();
|
||||
$bundleProduct->setTypeId('bundle')
|
||||
->setAttributeSetId($product->getDefaultAttributeSetId())
|
||||
->setWebsiteIds([1])
|
||||
->setPriceType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC)
|
||||
->setPriceView(1)
|
||||
->setName('Bundle Product')
|
||||
->setSku('bundle-product')
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData([
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 1,
|
||||
])
|
||||
->setBundleOptionsData(
|
||||
[
|
||||
[
|
||||
'title' => 'Bundle Product Items',
|
||||
'default_title' => 'Bundle Product Items',
|
||||
'type' => 'checkbox',
|
||||
'required' => 1,
|
||||
'delete' => '',
|
||||
],
|
||||
]
|
||||
)
|
||||
->setBundleSelectionsData(
|
||||
[[['product_id' => $product->getId(), 'selection_qty' => 1, 'delete' => '']]]
|
||||
);
|
||||
$productRepository->save($bundleProduct);
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_rollback.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
try {
|
||||
$product = $productRepository->get('bundle-product');
|
||||
$productRepository->delete($product);
|
||||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
|
||||
//Product already removed
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user