View::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Richdynamix\PersonalisedProducts\Block\Product;
4
5
use \Magento\Catalog\Block\Product\Context;
6
7
/**
8
 * Class View
9
 *
10
 * @category  Richdynamix
11
 * @package   PersonalisedProducts
12
 * @author    Steven Richardson ([email protected]) @mage_gizmo
13
 */
14
class View extends \Magento\Framework\View\Element\Template
15
{
16
    /**
17
     * @var \Magento\Framework\Registry
18
     */
19
    protected $_coreRegistry;
20
21
    /**
22
     * View constructor.
23
     * @param Context $context
24
     */
25
    public function __construct(Context $context)
26
    {
27
        $this->_coreRegistry = $context->getRegistry();
28
        parent::__construct($context, $data = []);
29
    }
30
31
    /**
32
     * Get current product instance
33
     *
34
     * @return mixed
35
     */
36
    public function getProduct()
37
    {
38
        return $this->_coreRegistry->registry('current_product');
39
    }
40
41
    /**
42
     * Get the current products ID for recording the product view
43
     *
44
     * @return mixed
45
     */
46
    public function getProductId()
47
    {
48
        return $this->getProduct()->getId();
49
    }
50
51
    /**
52
     * Build product view URL for making AJAX calls
53
     *
54
     * @return string
55
     */
56
    public function getProductViewUrl()
57
    {
58
        return $this->getBaseUrl() . "personalised/products/productView/id/" . $this->getProductId();
59
    }
60
}
61