Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Product Class Reference
Inheritance diagram for Product:
Action AbstractAction ActionInterface Delete Edit Index JsonProductInfo MassDelete MassUpdateStatus MassVisibleIn NewAction Pending Post ProductGrid RatingItems ReviewGrid Save ListAction ListAjax Post View

Public Member Functions

 __construct (\Magento\Framework\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Customer\Model\Session $customerSession, \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository, \Psr\Log\LoggerInterface $logger, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Review\Model\ReviewFactory $reviewFactory, \Magento\Review\Model\RatingFactory $ratingFactory, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Framework\Session\Generic $reviewSession, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator)
 
 dispatch (RequestInterface $request)
 
- Public Member Functions inherited from Action
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getActionFlag ()
 
- Public Member Functions inherited from AbstractAction
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getRequest ()
 
 getResponse ()
 
- Public Member Functions inherited from ActionInterface
 execute ()
 

Protected Member Functions

 initProduct ()
 
 loadProduct ($productId)
 
- Protected Member Functions inherited from Action
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _redirect ($path, $arguments=[])
 

Protected Attributes

 $coreRegistry = null
 
 $customerSession
 
 $reviewSession
 
 $categoryRepository
 
 $logger
 
 $productRepository
 
 $reviewFactory
 
 $ratingFactory
 
 $catalogDesign
 
 $storeManager
 
 $formKeyValidator
 
- Protected Attributes inherited from Action
 $_objectManager
 
 $_sessionNamespace
 
 $_eventManager
 
 $_actionFlag
 
 $_redirect
 
 $_view
 
 $_url
 
 $messageManager
 
- Protected Attributes inherited from AbstractAction
 $_request
 
 $_response
 
 $resultRedirectFactory
 
 $resultFactory
 

Additional Inherited Members

- Data Fields inherited from ActionInterface
const FLAG_NO_DISPATCH = 'no-dispatch'
 
const FLAG_NO_POST_DISPATCH = 'no-postDispatch'
 
const FLAG_NO_DISPATCH_BLOCK_EVENT = 'no-beforeGenerateLayoutBlocksDispatch'
 
const PARAM_NAME_BASE64_URL = 'r64'
 
const PARAM_NAME_URL_ENCODED = 'uenc'
 

Detailed Description

Review controller

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 18 of file Product.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Action\Context  $context,
\Magento\Framework\Registry  $coreRegistry,
\Magento\Customer\Model\Session  $customerSession,
\Magento\Catalog\Api\CategoryRepositoryInterface  $categoryRepository,
\Psr\Log\LoggerInterface  $logger,
\Magento\Catalog\Api\ProductRepositoryInterface  $productRepository,
\Magento\Review\Model\ReviewFactory  $reviewFactory,
\Magento\Review\Model\RatingFactory  $ratingFactory,
\Magento\Catalog\Model\Design  $catalogDesign,
\Magento\Framework\Session\Generic  $reviewSession,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\Data\Form\FormKey\Validator  $formKeyValidator 
)
Parameters
\Magento\Framework\App\Action\Context$context
\Magento\Framework\Registry$coreRegistry
\Magento\Customer\Model\Session$customerSession
\Magento\Catalog\Api\CategoryRepositoryInterface$categoryRepository
\Psr\Log\LoggerInterface$logger
\Magento\Catalog\Api\ProductRepositoryInterface$productRepository
\Magento\Review\Model\ReviewFactory$reviewFactory
\Magento\Review\Model\RatingFactory$ratingFactory
\Magento\Catalog\Model\Design$catalogDesign
\Magento\Framework\Session\Generic$reviewSession
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\Data\Form\FormKey\Validator$formKeyValidator@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 112 of file Product.php.

125  {
126  $this->storeManager = $storeManager;
127  $this->coreRegistry = $coreRegistry;
128  $this->customerSession = $customerSession;
129  $this->reviewSession = $reviewSession;
130  $this->categoryRepository = $categoryRepository;
131  $this->logger = $logger;
132  $this->productRepository = $productRepository;
133  $this->reviewFactory = $reviewFactory;
134  $this->ratingFactory = $ratingFactory;
135  $this->catalogDesign = $catalogDesign;
136  $this->formKeyValidator = $formKeyValidator;
137 
138  parent::__construct($context);
139  }

Member Function Documentation

◆ dispatch()

dispatch ( RequestInterface  $request)

Dispatch request

Parameters
RequestInterface$request
Returns
\Magento\Framework\App\ResponseInterface

Definition at line 147 of file Product.php.

148  {
149  $allowGuest = $this->_objectManager->get(\Magento\Review\Helper\Data::class)->getIsGuestAllowToWrite();
150  if (!$request->isDispatched()) {
151  return parent::dispatch($request);
152  }
153 
154  if (!$allowGuest && $request->getActionName() == 'post' && $request->isPost()) {
155  if (!$this->customerSession->isLoggedIn()) {
156  $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
157  $this->customerSession->setBeforeAuthUrl($this->_url->getUrl('*/*/*', ['_current' => true]));
158  $this->reviewSession->setFormData(
159  $request->getPostValue()
160  )->setRedirectUrl(
161  $this->_redirect->getRefererUrl()
162  );
163  $this->getResponse()->setRedirect(
164  $this->_objectManager->get(\Magento\Customer\Model\Url::class)->getLoginUrl()
165  );
166  }
167  }
168 
169  return parent::dispatch($request);
170  }
_redirect($path, $arguments=[])
Definition: Action.php:167

◆ initProduct()

initProduct ( )
protected

Initialize and check product

Returns
\Magento\Catalog\Model\Product|bool

Definition at line 177 of file Product.php.

178  {
179  $this->_eventManager->dispatch('review_controller_product_init_before', ['controller_action' => $this]);
180  $categoryId = (int)$this->getRequest()->getParam('category', false);
181  $productId = (int)$this->getRequest()->getParam('id');
182 
183  $product = $this->loadProduct($productId);
184  if (!$product) {
185  return false;
186  }
187 
188  if ($categoryId) {
189  $category = $this->categoryRepository->get($categoryId);
190  $this->coreRegistry->register('current_category', $category);
191  }
192 
193  try {
194  $this->_eventManager->dispatch('review_controller_product_init', ['product' => $product]);
195  $this->_eventManager->dispatch(
196  'review_controller_product_init_after',
197  ['product' => $product, 'controller_action' => $this]
198  );
199  } catch (\Magento\Framework\Exception\LocalizedException $e) {
200  $this->logger->critical($e);
201  return false;
202  }
203 
204  return $product;
205  }

◆ loadProduct()

loadProduct (   $productId)
protected

Load product model with data by passed id. Return false if product was not loaded or has incorrect status.

Parameters
int$productId
Returns
bool|CatalogProduct

Definition at line 214 of file Product.php.

215  {
216  if (!$productId) {
217  return false;
218  }
219 
220  try {
221  $product = $this->productRepository->getById($productId);
222 
223  if (!in_array($this->storeManager->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
224  throw new NoSuchEntityException();
225  }
226 
227  if (!$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) {
228  throw new NoSuchEntityException();
229  }
230  } catch (NoSuchEntityException $noEntityException) {
231  return false;
232  }
233 
234  $this->coreRegistry->register('current_product', $product);
235  $this->coreRegistry->register('product', $product);
236 
237  return $product;
238  }

Field Documentation

◆ $catalogDesign

$catalogDesign
protected

Definition at line 81 of file Product.php.

◆ $categoryRepository

$categoryRepository
protected

Definition at line 46 of file Product.php.

◆ $coreRegistry

$coreRegistry = null
protected

Definition at line 25 of file Product.php.

◆ $customerSession

$customerSession
protected

Definition at line 32 of file Product.php.

◆ $formKeyValidator

$formKeyValidator
protected

Definition at line 95 of file Product.php.

◆ $logger

$logger
protected

Definition at line 53 of file Product.php.

◆ $productRepository

$productRepository
protected

Definition at line 60 of file Product.php.

◆ $ratingFactory

$ratingFactory
protected

Definition at line 74 of file Product.php.

◆ $reviewFactory

$reviewFactory
protected

Definition at line 67 of file Product.php.

◆ $reviewSession

$reviewSession
protected

Definition at line 39 of file Product.php.

◆ $storeManager

$storeManager
protected

Definition at line 88 of file Product.php.


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