9 use Magento\Bundle\Api\Data\LinkInterfaceFactory;
10 use Magento\Bundle\Api\Data\OptionInterfaceFactory;
15 use Magento\Catalog\Model\ProductFactory;
31 private $productFactory;
36 private $optionFactory;
50 ProductFactory $productFactory,
52 OptionInterfaceFactory $optionFactory,
53 LinkInterfaceFactory $linkFactory
55 $this->fixture = $fixture;
57 $this->optionFactory = $optionFactory;
66 $product = $this->getProductTemplate(
67 $this->fixture[
'attribute_set_id']
83 $bundleProductsPerOption = $this->fixture[
'_bundle_products_per_option'];
84 $bundleVariationSkuPattern = $this->fixture[
'_bundle_variation_sku_pattern'];
85 $productRandomizerNumber = crc32(random_int(1, PHP_INT_MAX));
90 'name' =>
'template name' . $productRandomizerNumber,
91 'url_key' =>
'template-url' . $productRandomizerNumber,
92 'sku' =>
'template_sku_bundle' . $productRandomizerNumber,
97 'category_ids' => isset($this->fixture[
'category_ids']) ? [2] :
null,
99 'description' =>
'description',
100 'short_description' =>
'short description',
102 'price_type' => \
Magento\Bundle\Model\
Product\Price::PRICE_TYPE_FIXED,
105 'use_config_manage_stock' => 1,
107 'is_qty_decimal' => 0,
110 'can_save_bundle_selections' =>
true,
111 'affect_bundle_product_selections' =>
true,
116 $bundleProductOptions = [];
119 $option = $this->optionFactory->create([
'data' => [
120 'title' =>
'Bundle Product Items ' .
$i,
121 'default_title' =>
'Bundle Product Items ' .
$i,
131 for ($linkN = 1; $linkN <= $bundleProductsPerOption; $linkN++) {
133 $link = $this->linkFactory->create([
'data' => [
134 'sku' => sprintf($bundleVariationSkuPattern, $variationN),
136 'can_change_qty' => 1,
137 'position' => $linkN - 1,
141 'is_default' => $linkN === 1,
146 $bundleProductOptions[] =
$option;
150 $extension->setBundleProductOptions($bundleProductOptions);
154 $bundleSelections = array_map(
function (
$option) {
155 return array_map(
function (
$link) {
156 return $link->getData();
157 },
$option->getProductLinks());
158 }, $bundleProductOptions);
__construct(ProductFactory $productFactory, array $fixture, OptionInterfaceFactory $optionFactory, LinkInterfaceFactory $linkFactory)