Version Notes
This module has been tested and appears to work fine. If you notice any bugs, please report them to view-button@fishpig.co.uk and we will fix them ASAP.
Download this release
Release Info
Developer | Magento Core Team |
Extension | Fishpigs_View_Button |
Version | 0.1.0 |
Comparing to | |
See all releases |
Version 0.1.0
- app/code/community/Fishpig/ViewButton/Block/Abstract.php +52 -0
- app/code/community/Fishpig/ViewButton/Block/Catalog/Product.php +170 -0
- app/code/community/Fishpig/ViewButton/etc/config.xml +26 -0
- app/design/adminhtml/default/default/layout/view-button.xml +8 -0
- app/design/adminhtml/default/default/template/view-button/content.phtml +53 -0
- package.xml +18 -0
app/code/community/Fishpig/ViewButton/Block/Abstract.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
abstract class Fishpig_ViewButton_Block_Abstract extends Mage_Adminhtml_Block_Template
|
4 |
+
{
|
5 |
+
|
6 |
+
abstract public function shouldAddButton();
|
7 |
+
abstract public function getUrls();
|
8 |
+
|
9 |
+
public function __construct()
|
10 |
+
{
|
11 |
+
parent::__construct();
|
12 |
+
|
13 |
+
$this->setTemplate('view-button/content.phtml')
|
14 |
+
->setItemType('item');
|
15 |
+
}
|
16 |
+
|
17 |
+
public function getButtonId()
|
18 |
+
{
|
19 |
+
if (!$this->hasData('button_id')) {
|
20 |
+
$this->setData('button_id', 'fishpig.view-button');
|
21 |
+
}
|
22 |
+
|
23 |
+
return $this->getData('button_id');
|
24 |
+
}
|
25 |
+
|
26 |
+
public function getButtonHtml()
|
27 |
+
{
|
28 |
+
return addslashes('<button class="scalable form-button" type="button" id="'.$this->getButtonId().'"><span>View '.ucwords($this->getItemType()).'</span></button>');
|
29 |
+
}
|
30 |
+
|
31 |
+
public function getParam($key, $default = null)
|
32 |
+
{
|
33 |
+
return Mage::app()->getRequest()->getParam($key, $default);
|
34 |
+
}
|
35 |
+
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Get the Magento frontend base URL
|
39 |
+
*
|
40 |
+
* @return string
|
41 |
+
*/
|
42 |
+
public function getBaseUrl($store = null)
|
43 |
+
{
|
44 |
+
$url = rtrim(Mage::getStoreConfig('web/unsecure/base_url', $store), '/');
|
45 |
+
|
46 |
+
if (Mage::getStoreConfigFlag('web/seo/use_rewrites') == false) {
|
47 |
+
$url .= '/index.php';
|
48 |
+
}
|
49 |
+
|
50 |
+
return rtrim($url, '/');
|
51 |
+
}
|
52 |
+
}
|
app/code/community/Fishpig/ViewButton/Block/Catalog/Product.php
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Fishpig_ViewButton_Block_Catalog_Product extends Fishpig_ViewButton_Block_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
|
7 |
+
public function __construct()
|
8 |
+
{
|
9 |
+
parent::__construct();
|
10 |
+
$this->setItemType('product');
|
11 |
+
}
|
12 |
+
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Determines whether or not to add the View button
|
16 |
+
*
|
17 |
+
* @return bool
|
18 |
+
*/
|
19 |
+
public function shouldAddButton()
|
20 |
+
{
|
21 |
+
return (boolean) $this->getParam('id');
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Get all the possible URLs for the current product
|
26 |
+
*
|
27 |
+
* @return array
|
28 |
+
*/
|
29 |
+
public function getUrls()
|
30 |
+
{
|
31 |
+
$product = $this->getProduct();
|
32 |
+
|
33 |
+
if ($product instanceof Mage_Catalog_Model_Product) {
|
34 |
+
if ($this->canShow($product)) {
|
35 |
+
if ($this->_includeCategoryUrlKeys()) {
|
36 |
+
if ($categories = $this->_getCategoriesByIds($product->getCategoryIds())) {
|
37 |
+
return $this->_getProductUrls($product, $categories);
|
38 |
+
}
|
39 |
+
}
|
40 |
+
else {
|
41 |
+
return $this->_getProductUrl($product);
|
42 |
+
}
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
return array();
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Fetch the current product model
|
51 |
+
*
|
52 |
+
* @return null || Mage_Catalog_Model_Product
|
53 |
+
*/
|
54 |
+
public function getProduct()
|
55 |
+
{
|
56 |
+
//Mage::register('product', Mage::getModel('catalog/product')->load(6));
|
57 |
+
return Mage::registry('product');
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Determine whether or not the product can be shown at all
|
62 |
+
*
|
63 |
+
* @param Mage_Catalog_Model_Product $product
|
64 |
+
* @return bool
|
65 |
+
*/
|
66 |
+
public function canShow(Mage_Catalog_Model_Product $product)
|
67 |
+
{
|
68 |
+
return in_array($product->getVisibility(), array(2,4)) && $product->getStatus() == 1;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Returns true if product URL's have category URL key's included
|
73 |
+
*
|
74 |
+
* @return bool
|
75 |
+
*/
|
76 |
+
protected function _includeCategoryUrlKeys()
|
77 |
+
{
|
78 |
+
return Mage::getStoreConfigFlag('catalog/seo/product_use_categories');
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Gets a collection of category models
|
83 |
+
*
|
84 |
+
* @param array $categoryIds
|
85 |
+
* @return null || Mage_Catalog_Model_Mysql_Category_Collection
|
86 |
+
*/
|
87 |
+
protected function _getCategoriesByIds(array $categoryIds)
|
88 |
+
{
|
89 |
+
if (count($categoryIds) > 0) {
|
90 |
+
$categories = Mage::getResourceModel('catalog/category_collection')
|
91 |
+
->addAttributeToSelect('*')
|
92 |
+
->addFieldToFilter('entity_id', array('in' => $categoryIds));
|
93 |
+
|
94 |
+
if (count($categories) > 0) {
|
95 |
+
return $categories;
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
return null;
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Get an array of product URL's using the category collection provided
|
104 |
+
* It is assumed that the product is a member of all categories in the collection
|
105 |
+
*
|
106 |
+
* @param Mage_Catalog_Model_Product $product
|
107 |
+
* @param $categories
|
108 |
+
* @return array
|
109 |
+
*/
|
110 |
+
protected function _getProductUrls(Mage_Catalog_Model_Product $product, $categories)
|
111 |
+
{
|
112 |
+
$urls = array();
|
113 |
+
|
114 |
+
foreach($categories as $category) {
|
115 |
+
$url = $this->_getProductUrl($product, $category);
|
116 |
+
|
117 |
+
if (!in_array($url, $urls)) {
|
118 |
+
$urls[] = $url;
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
return $urls;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Get a product URL
|
127 |
+
* Optional param $category will add the category URL keys onto the URL
|
128 |
+
*
|
129 |
+
* @param Mage_Catalog_Model_Product $product
|
130 |
+
* @param mixed $category
|
131 |
+
* @return string;
|
132 |
+
*/
|
133 |
+
protected function _getProductUrl(Mage_Catalog_Model_Product $product, $category = null)
|
134 |
+
{
|
135 |
+
if ($category instanceof Mage_Catalog_Model_Category) {
|
136 |
+
$parts = array($product->getUrlKey());
|
137 |
+
|
138 |
+
while($category->getLevel() >= 2) {
|
139 |
+
$parts[] = $category->getUrlKey();
|
140 |
+
|
141 |
+
if ($category->getParentId()) {
|
142 |
+
$category = $category->getParentCategory();
|
143 |
+
}
|
144 |
+
else {
|
145 |
+
break;
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
$parts[] = $this->getBaseUrl();
|
150 |
+
|
151 |
+
return implode(DS, array_reverse($parts)).$this->_getProductUrlSuffix();
|
152 |
+
}
|
153 |
+
|
154 |
+
return $this->getBaseUrl() . '/' . $product->getUrlKey().$this->_getProductUrlSuffix();
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Get's the URL suffix for the product (EG. .html)
|
159 |
+
*
|
160 |
+
* @return string
|
161 |
+
*/
|
162 |
+
protected function _getProductUrlSuffix()
|
163 |
+
{
|
164 |
+
return Mage::getStoreConfig('catalog/seo/product_url_suffix');
|
165 |
+
}
|
166 |
+
|
167 |
+
}
|
168 |
+
|
169 |
+
|
170 |
+
|
app/code/community/Fishpig/ViewButton/etc/config.xml
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Fishpig_ViewButton>
|
5 |
+
<version>0.1.0</version>
|
6 |
+
</Fishpig_ViewButton>
|
7 |
+
</modules>
|
8 |
+
|
9 |
+
<global>
|
10 |
+
<blocks>
|
11 |
+
<viewButton>
|
12 |
+
<class>Fishpig_ViewButton_Block</class>
|
13 |
+
</viewButton>
|
14 |
+
</blocks>
|
15 |
+
</global>
|
16 |
+
|
17 |
+
<adminhtml>
|
18 |
+
<layout>
|
19 |
+
<updates>
|
20 |
+
<viewButton>
|
21 |
+
<file>view-button.xml</file>
|
22 |
+
</viewButton>
|
23 |
+
</updates>
|
24 |
+
</layout>
|
25 |
+
</adminhtml>
|
26 |
+
</config>
|
app/design/adminhtml/default/default/layout/view-button.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout>
|
3 |
+
<adminhtml_catalog_product_edit>
|
4 |
+
<reference name="content">
|
5 |
+
<block type="viewButton/catalog_product" name="preview_button.catalog.product"/>
|
6 |
+
</reference>
|
7 |
+
</adminhtml_catalog_product_edit>
|
8 |
+
</layout>
|
app/design/adminhtml/default/default/template/view-button/content.phtml
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Fishpig
|
4 |
+
*
|
5 |
+
* http://fishpig.co.uk
|
6 |
+
*
|
7 |
+
*/
|
8 |
+
?>
|
9 |
+
<?php if ($this->shouldAddButton()): ?>
|
10 |
+
<?php $urls = $this->getUrls() ?>
|
11 |
+
<?php if (count($urls) > 0): ?>
|
12 |
+
<script type="text/javascript">
|
13 |
+
//<![CDATA[
|
14 |
+
document.observe("dom:loaded", function() {
|
15 |
+
var backBtn = $$('.content-header .form-buttons button')[0];
|
16 |
+
if (backBtn.id) {
|
17 |
+
backBtn.insert({after : '<?php echo $this->getButtonHtml() ?>'});
|
18 |
+
|
19 |
+
$('<?php echo $this->getButtonId() ?>').observe('click', function() {
|
20 |
+
$('fish-url-box').show();
|
21 |
+
return false;
|
22 |
+
});
|
23 |
+
|
24 |
+
$('<?php echo $this->getButtonId() ?>_close').observe('click', function () {
|
25 |
+
$('fish-url-box').hide();
|
26 |
+
return false;
|
27 |
+
});
|
28 |
+
}
|
29 |
+
});
|
30 |
+
//]]>
|
31 |
+
</script>
|
32 |
+
<div id="fish-url-box" style="display:none; height:100%; left:0; position:fixed; top: 0; width:100%;">
|
33 |
+
<div class="dimmer" style="background:#000; height:100%; opacity:.4; position:fixed; width:100%; "></div>
|
34 |
+
<div class="entry-edit" style="margin: 100px auto; position:relative; width:720px; z-index:2;">
|
35 |
+
<div class="entry-edit-head">
|
36 |
+
<h4 style="padding-top:4px;">You can view this <?php echo ucwords($this->getItemType()) ?> at any of the following URL's:</h4>
|
37 |
+
<div class="form-buttons">
|
38 |
+
<button type="button" id="<?php echo $this->getButtonId() ?>_close"><span>Close</span></button>
|
39 |
+
</div>
|
40 |
+
</div>
|
41 |
+
<div class="fieldset">
|
42 |
+
<div class="hor-scroll">
|
43 |
+
<ul>
|
44 |
+
<?php foreach($urls as $url): ?>
|
45 |
+
<li><a href="<?php echo $url ?>" target="fish_view"><?php echo $url ?></li>
|
46 |
+
<?php endforeach; ?>
|
47 |
+
</ul>
|
48 |
+
</div>
|
49 |
+
</div>
|
50 |
+
</div>
|
51 |
+
</div>
|
52 |
+
<?php endif; ?>
|
53 |
+
<?php endif; ?>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Fishpigs_View_Button</name>
|
4 |
+
<version>0.1.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Adds a button to the product admin page, which when pressed, displays link to all of the URL's the product is viewable on</summary>
|
10 |
+
<description>This module adds a button the the product edit page in the Magento admin. When clicked, a small javascript popup is displayed listing all of the valid URL's for that product. Not only does provide you with an easy way to view a product from the backend, it also shows you how many different URL's your product is accessible from.</description>
|
11 |
+
<notes>This module has been tested and appears to work fine. If you notice any bugs, please report them to view-button@fishpig.co.uk and we will fix them ASAP.</notes>
|
12 |
+
<authors><author><name>fishpig</name><user>auto-converted</user><email>ben@fishpig.co.uk</email></author></authors>
|
13 |
+
<date>2010-08-30</date>
|
14 |
+
<time>18:55:53</time>
|
15 |
+
<contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="view-button.xml" hash="c55ad5371c0c75050eed32941d392a18"/></dir><dir name="template"><dir name="view-button"><file name="content.phtml" hash="83c4f844f3f44cb8baaa5c8c44127bea"/></dir></dir></dir></dir></dir></target><target name="magecommunity"><dir name="Fishpig"><dir name="ViewButton"><dir name="Block"><dir name="Catalog"><file name="Product.php" hash="f9b6d156dd72ab0280fc41999ee03541"/></dir><file name="Abstract.php" hash="550a2044933d08fcc68e0880647c1ae3"/></dir><dir name="etc"><file name="config.xml" hash="ab0af9e38a0629647e7d54dd25676dc1"/></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies/>
|
18 |
+
</package>
|