|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +use Magento\Catalog\Api\ProductRepositoryInterface; |
| 8 | +use Magento\Catalog\Model\Product; |
| 9 | +use Magento\Catalog\Model\Product\Attribute\Source\Status; |
| 10 | +use Magento\Catalog\Model\Product\Visibility; |
| 11 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | +use Magento\TestFramework\Workaround\Override\Fixture\Resolver; |
| 14 | + |
| 15 | +Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_boolean_attribute.php'); |
| 16 | + |
| 17 | +/** @var $objectManager \Magento\Framework\ObjectManagerInterface */ |
| 18 | +$objectManager = Bootstrap::getObjectManager(); |
| 19 | + |
| 20 | +$productRepository = $objectManager->get(ProductRepositoryInterface::class); |
| 21 | +try { |
| 22 | + $productRepository->get('fulltext-1'); |
| 23 | +} catch (NoSuchEntityException $e) { |
| 24 | + /** @var $productFirst Product */ |
| 25 | + $productFirst = $objectManager->create(Product::class); |
| 26 | + $productFirst->setTypeId('simple') |
| 27 | + ->setAttributeSetId(4) |
| 28 | + ->setWebsiteIds([1]) |
| 29 | + ->setName('A') |
| 30 | + ->setSku('fulltext-1') |
| 31 | + ->setPrice(10) |
| 32 | + ->setMetaTitle('first meta title') |
| 33 | + ->setMetaKeyword('first meta keyword') |
| 34 | + ->setMetaDescription('first meta description') |
| 35 | + ->setVisibility(Visibility::VISIBILITY_BOTH) |
| 36 | + ->setStatus(Status::STATUS_ENABLED) |
| 37 | + ->setStockData(['use_config_manage_stock' => 0]) |
| 38 | + ->setBooleanAttribute(1) |
| 39 | + ->save(); |
| 40 | +} |
| 41 | + |
| 42 | +try { |
| 43 | + $productRepository->get('fulltext-2'); |
| 44 | +} catch (NoSuchEntityException $e) { |
| 45 | + /** @var $productSecond Product */ |
| 46 | + $productSecond = $objectManager->create(Product::class); |
| 47 | + $productSecond->setTypeId('simple') |
| 48 | + ->setAttributeSetId(4) |
| 49 | + ->setWebsiteIds([1]) |
| 50 | + ->setName('B') |
| 51 | + ->setSku('fulltext-2') |
| 52 | + ->setPrice(20) |
| 53 | + ->setMetaTitle('second meta title') |
| 54 | + ->setMetaKeyword('second meta keyword') |
| 55 | + ->setMetaDescription('second meta description') |
| 56 | + ->setVisibility(Visibility::VISIBILITY_BOTH) |
| 57 | + ->setStatus(Status::STATUS_ENABLED) |
| 58 | + ->setStockData(['use_config_manage_stock' => 0]) |
| 59 | + ->setBooleanAttribute(1) |
| 60 | + ->save(); |
| 61 | +} |
| 62 | + |
| 63 | +try { |
| 64 | + $productRepository->get('fulltext-3'); |
| 65 | +} catch (NoSuchEntityException $e) { |
| 66 | + /** @var $productThird Product */ |
| 67 | + $productThird = $objectManager->create(Product::class); |
| 68 | + $productThird->setTypeId('simple') |
| 69 | + ->setAttributeSetId(4) |
| 70 | + ->setWebsiteIds([1]) |
| 71 | + ->setName('C') |
| 72 | + ->setSku('fulltext-3') |
| 73 | + ->setPrice(20) |
| 74 | + ->setMetaTitle('third meta title') |
| 75 | + ->setMetaKeyword('third meta keyword') |
| 76 | + ->setMetaDescription('third meta description') |
| 77 | + ->setVisibility(Visibility::VISIBILITY_BOTH) |
| 78 | + ->setStatus(Status::STATUS_ENABLED) |
| 79 | + ->setStockData(['use_config_manage_stock' => 0]) |
| 80 | + ->setBooleanAttribute(1) |
| 81 | + ->save(); |
| 82 | +} |
| 83 | + |
| 84 | +try { |
| 85 | + $productRepository->get('fulltext-4'); |
| 86 | +} catch (NoSuchEntityException $e) { |
| 87 | + /** @var $productFourth Product */ |
| 88 | + $productFourth = $objectManager->create(Product::class); |
| 89 | + $productFourth->setTypeId('simple') |
| 90 | + ->setAttributeSetId(4) |
| 91 | + ->setWebsiteIds([1]) |
| 92 | + ->setName('a') |
| 93 | + ->setSku('fulltext-4') |
| 94 | + ->setPrice(20) |
| 95 | + ->setMetaTitle('fourth meta title') |
| 96 | + ->setMetaKeyword('fourth meta keyword') |
| 97 | + ->setMetaDescription('fourth meta description') |
| 98 | + ->setUrlKey('aa') |
| 99 | + ->setVisibility(Visibility::VISIBILITY_BOTH) |
| 100 | + ->setStatus(Status::STATUS_ENABLED) |
| 101 | + ->setStockData(['use_config_manage_stock' => 0]) |
| 102 | + ->setBooleanAttribute(0) |
| 103 | + ->save(); |
| 104 | +} |
| 105 | + |
| 106 | +try { |
| 107 | + $productRepository->get('fulltext-5'); |
| 108 | +} catch (NoSuchEntityException $e) { |
| 109 | + /** @var $productFifth Product */ |
| 110 | + $productFifth = $objectManager->create(Product::class); |
| 111 | + $productFifth->setTypeId('simple') |
| 112 | + ->setAttributeSetId(4) |
| 113 | + ->setWebsiteIds([1]) |
| 114 | + ->setName('b') |
| 115 | + ->setSku('fulltext-5') |
| 116 | + ->setPrice(20) |
| 117 | + ->setMetaTitle('fifth meta title') |
| 118 | + ->setMetaKeyword('fifth meta keyword') |
| 119 | + ->setMetaDescription('fifth meta description') |
| 120 | + ->setUrlKey('bb') |
| 121 | + ->setVisibility(Visibility::VISIBILITY_BOTH) |
| 122 | + ->setStatus(Status::STATUS_ENABLED) |
| 123 | + ->setStockData(['use_config_manage_stock' => 0]) |
| 124 | + ->setBooleanAttribute(0) |
| 125 | + ->save(); |
| 126 | +} |
0 commit comments