Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Builder Class Reference

Public Member Functions

 __construct (ProductFactory $productFactory, Logger $logger, Registry $registry, WysiwygModel\Config $wysiwygConfig, StoreFactory $storeFactory=null, ProductRepositoryInterface $productRepository=null)
 
 build (RequestInterface $request)
 

Protected Attributes

 $productFactory
 
 $logger
 
 $registry
 
 $wysiwygConfig
 
 $storeFactory
 

Detailed Description

Definition at line 18 of file Builder.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ProductFactory  $productFactory,
Logger  $logger,
Registry  $registry,
WysiwygModel\Config  $wysiwygConfig,
StoreFactory  $storeFactory = null,
ProductRepositoryInterface  $productRepository = null 
)

Constructor

Parameters
ProductFactory$productFactory
Logger$logger
Registry$registry
WysiwygModel\Config$wysiwygConfig
StoreFactory | null$storeFactory
ProductRepositoryInterface | null$productRepository

Definition at line 60 of file Builder.php.

67  {
68  $this->productFactory = $productFactory;
69  $this->logger = $logger;
70  $this->registry = $registry;
71  $this->wysiwygConfig = $wysiwygConfig;
73  ->get(\Magento\Store\Model\StoreFactory::class);
74  $this->productRepository = $productRepository ?: \Magento\Framework\App\ObjectManager::getInstance()
75  ->get(ProductRepositoryInterface::class);
76  }

Member Function Documentation

◆ build()

build ( RequestInterface  $request)

Build product based on user request

Parameters
RequestInterface$request
Returns
\Magento\Catalog\Model\Product
Exceptions

Definition at line 85 of file Builder.php.

86  {
87  $productId = (int) $request->getParam('id');
88  $storeId = $request->getParam('store', 0);
89  $attributeSetId = (int) $request->getParam('set');
90  $typeId = $request->getParam('type');
91 
92  if ($productId) {
93  try {
94  $product = $this->productRepository->getById($productId, true, $storeId);
95  } catch (\Exception $e) {
96  $product = $this->createEmptyProduct(ProductTypes::DEFAULT_TYPE, $attributeSetId, $storeId);
97  $this->logger->critical($e);
98  }
99  } else {
100  $product = $this->createEmptyProduct($typeId, $attributeSetId, $storeId);
101  }
102 
103  $store = $this->storeFactory->create();
104  $store->load($storeId);
105 
106  $this->registry->register('product', $product);
107  $this->registry->register('current_product', $product);
108  $this->registry->register('current_store', $store);
109 
110  $this->wysiwygConfig->setStoreId($storeId);
111 
112  return $product;
113  }

Field Documentation

◆ $logger

$logger
protected

Definition at line 28 of file Builder.php.

◆ $productFactory

$productFactory
protected

Definition at line 23 of file Builder.php.

◆ $registry

$registry
protected

Definition at line 33 of file Builder.php.

◆ $storeFactory

$storeFactory
protected

Definition at line 43 of file Builder.php.

◆ $wysiwygConfig

$wysiwygConfig
protected

Definition at line 38 of file Builder.php.


The documentation for this class was generated from the following file: