|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/*** |
|
4
|
|
|
* NOTICE OF LICENSE |
|
5
|
|
|
* |
|
6
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
7
|
|
|
* that is bundled with this package in the file LICENSE.txt. |
|
8
|
|
|
* It is also available through the world-wide-web at this URL: |
|
9
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
10
|
|
|
* |
|
11
|
|
|
* @category Magento Extensions |
|
12
|
|
|
* @package Toonvd_Recentlyviewed |
|
13
|
|
|
* @copyright Copyright (c) 2016 Toon Van Dooren |
|
14
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
15
|
|
|
* @author Toon Van Dooren <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class Toonvd_Recentlyviewed_Block_Options extends Mage_Core_Block_Template |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var Mage_Catalog_Model_Product |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $product; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Initializes product object if it exists |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct() |
|
28
|
|
|
{ |
|
29
|
|
|
if (is_object(Mage::registry("current_product")) && |
|
30
|
|
|
!is_object($this->product) |
|
31
|
|
|
) { |
|
32
|
|
|
$this->product = Mage::registry("current_product"); |
|
33
|
|
|
} |
|
34
|
|
|
parent::__construct(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Gets recently viewed block title. |
|
39
|
|
|
* |
|
40
|
|
|
* @return mixed |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getListBlockTitle() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->helper("toonvd_recentlyviewed")->__("Recently Viewed Products"); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Returns scope type and current scope id. |
|
49
|
|
|
* |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getDesiredScopeAndId() |
|
53
|
|
|
{ |
|
54
|
|
|
$desiredScope = $this->getConfig('catalog/recently_products/scope'); |
|
55
|
|
|
|
|
56
|
|
|
switch ($desiredScope) { |
|
57
|
|
|
case 'website': |
|
58
|
|
|
$currentScopeId = Mage::app()->getStore()->getWebsite()->getId(); |
|
59
|
|
|
break; |
|
60
|
|
|
case 'group': |
|
61
|
|
|
$currentScopeId = Mage::app()->getStore()->getGroup()->getId(); |
|
62
|
|
|
break; |
|
63
|
|
|
default: |
|
64
|
|
|
$currentScopeId = Mage::app()->getStore()->getId(); |
|
65
|
|
|
break; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $desiredScope . $currentScopeId; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Fetches the product url for images and links. |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getProductUrl() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->helper("catalog/product")->getProductUrl($this->product); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Fetches the product image. |
|
83
|
|
|
* |
|
84
|
|
|
* @return Mage_Catalog_Helper_Image |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getProductImage() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->helper("catalog/image")->init($this->product, "thumbnail")->resize(50, |
|
89
|
|
|
50)->setWatermarkSize("30x10"); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Fetches the product name the core way. |
|
94
|
|
|
* |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getProductName() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->helper("catalog/output")->productAttribute($this->product, $this->product->getName(), "name"); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Fetches the product id. |
|
104
|
|
|
* |
|
105
|
|
|
* @return mixed |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getProductId() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->product->getId(); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Fetches max recently viewed list length. |
|
114
|
|
|
* |
|
115
|
|
|
* @return mixed |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getMaxLength() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->getConfig('catalog/recently_products/viewed_count'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Gets configuration by path. |
|
124
|
|
|
* |
|
125
|
|
|
* @param $configPath |
|
126
|
|
|
* @return mixed |
|
127
|
|
|
*/ |
|
128
|
|
|
protected function getConfig($configPath) |
|
129
|
|
|
{ |
|
130
|
|
|
$config = Mage::getStoreConfig($configPath); |
|
131
|
|
|
return $config; |
|
132
|
|
|
} |
|
133
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.