Completed
Push — feature/varnish-cache-busting ( 0fb5cd )
by Steven
03:32
created

View::getProductViewUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
     * Route frontname used in URL
18
     */
19
    const ROUTE = "personalised";
20
21
    /**
22
     * @var \Magento\Framework\Registry
23
     */
24
    protected $_coreRegistry;
25
26
    /**
27
     * View constructor.
28
     * @param Context $context
29
     */
30
    public function __construct(Context $context)
31
    {
32
        $this->_coreRegistry = $context->getRegistry();
33
        parent::__construct($context, $data = []);
34
    }
35
36
    /**
37
     * Get current product instance
38
     *
39
     * @return mixed
40
     */
41
    public function getProduct()
42
    {
43
        return $this->_coreRegistry->registry('current_product');
44
    }
45
46
    /**
47
     * Get the current products ID for recording the product view
48
     *
49
     * @return mixed
50
     */
51
    public function getProductId()
52
    {
53
        return $this->getProduct()->getId();
54
    }
55
56
    /**
57
     * Build product view URL for making AJAX calls
58
     *
59
     * @return string
60
     */
61
    public function getProductViewUrl()
62
    {
63
        return $this->getBaseUrl() . self::ROUTE . "/products/productView/id/" . $this->getProductId();
64
    }
65
}
66