Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Synchronize Class Reference
Inheritance diagram for Synchronize:
Action AbstractAction ActionInterface

Public Member Functions

 __construct (Context $context, Synchronizer $synchronizer, JsonFactory $jsonFactory)
 
 execute ()
 
- 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 ()
 

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'
 
- Protected Member Functions inherited from Action
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _redirect ($path, $arguments=[])
 
- Protected Attributes inherited from Action
 $_objectManager
 
 $_sessionNamespace
 
 $_eventManager
 
 $_actionFlag
 
 $_redirect
 
 $_view
 
 $_url
 
 $messageManager
 
- Protected Attributes inherited from AbstractAction
 $_request
 
 $_response
 
 $resultRedirectFactory
 
 $resultFactory
 

Detailed Description

Synchronizes Product Frontend Actions with database

Definition at line 15 of file Synchronize.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Context  $context,
Synchronizer  $synchronizer,
JsonFactory  $jsonFactory 
)
Parameters
Context$context
Synchronizer$synchronizer
JsonFactory$jsonFactory

Definition at line 37 of file Synchronize.php.

41  {
42  parent::__construct($context);
43  $this->context = $context;
44  $this->synchronizer = $synchronizer;
45  $this->jsonFactory = $jsonFactory;
46  }

Member Function Documentation

◆ execute()

execute ( )

This is handle for synchronizing between frontend and backend product actions:

  • visit product page (recently_viewed)
  • compare products (recently_compared)
  • etc... It comes in next format: [ 'type_id' => 'recently_*', 'ids' => [ 'product_id' => "$id", 'added_at' => "JS_TIMESTAMP" ] ]

Execute action based on request and return resultNote: Request will be added as operation argument in future

Returns
\Magento\Framework\Controller\ResultInterface|ResponseInterface
Exceptions

Implements ActionInterface.

Definition at line 64 of file Synchronize.php.

65  {
66  $resultJson = $this->jsonFactory->create();
67 
68  try {
69  $productsData = $this->getRequest()->getParam('ids', []);
70  $typeId = $this->getRequest()->getParam('type_id', null);
71  $this->synchronizer->syncActions($productsData, $typeId);
72  } catch (\Exception $e) {
73  $resultJson->setStatusHeader(
74  \Zend\Http\Response::STATUS_CODE_400,
75  \Zend\Http\AbstractMessage::VERSION_11,
76  'Bad Request'
77  );
78  }
79 
80  return $resultJson->setData([]);
81  }
$productsData
Definition: products.php:19

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