1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Richdynamix\PersonalisedProducts\Controller\Products; |
4
|
|
|
|
5
|
|
|
use \Magento\Framework\App\Action\Action; |
6
|
|
|
use \Magento\Framework\Controller\Result\JsonFactory; |
7
|
|
|
use \Magento\Framework\App\Action\Context; |
8
|
|
|
use \Richdynamix\PersonalisedProducts\Model\ProductView as ProductViewModel; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ProductView |
12
|
|
|
* |
13
|
|
|
* @category Richdynamix |
14
|
|
|
* @package PersonalisedProducts |
15
|
|
|
* @author Steven Richardson ([email protected]) @mage_gizmo |
16
|
|
|
*/ |
17
|
|
|
class ProductView extends Action { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var JsonFactory |
21
|
|
|
*/ |
22
|
|
|
protected $_resultJsonFactory; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* ProductView constructor. |
26
|
|
|
* @param Context $context |
27
|
|
|
* @param JsonFactory $resultJsonFactory |
28
|
|
|
* @param ProductViewModel $productView |
29
|
|
|
*/ |
30
|
|
|
public function __construct( |
31
|
|
|
Context $context, |
32
|
|
|
JsonFactory $resultJsonFactory, |
33
|
|
|
ProductViewModel $productView |
34
|
|
|
) { |
35
|
|
|
$this->_resultJsonFactory = $resultJsonFactory; |
36
|
|
|
$this->_productView = $productView; |
37
|
|
|
parent::__construct($context); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return $this |
42
|
|
|
*/ |
43
|
|
|
public function execute() |
44
|
|
|
{ |
45
|
|
|
$result = $this->_resultJsonFactory->create(); |
46
|
|
|
|
47
|
|
|
$productId = $this->getRequest()->getParam('id'); |
48
|
|
|
if (empty($productId)) { |
49
|
|
|
return $result->setData(['error' => true, 'message' => 'Product ID has not been supplied']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$pageViewResult = $this->_productView->processViews($productId); |
53
|
|
|
|
54
|
|
|
if (!$pageViewResult) { |
55
|
|
|
return $result->setData(['error' => true, 'message' => 'There was an error processing the product view.']); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $result->setData(['success' => true, 'message' => 'Product view logged in PredictionIO']); |
59
|
|
|
} |
60
|
|
|
} |