-
- Georg Ringer

-
Total Posts: 58
Joined: 2008-07-04
Linz, Austria
|
Hi,
I did a 2nd module which could be interesting for core too!
It gives you the ability to link to product pages from anywhere by just knowing the SKU of the product!
The url would look like domain.tld/?sku=1234
If a product with this SKU is available, the user will be redirected to the page domain.tld/category/this-is-the-product-title.html
You can get the code on my website http://www.ringer.it/en/magento/code-snippets.html but I will post the current version here too:
<?php /** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * @category Cyberhouse * @package Cyberhouse_Catalog * @copyright Copyright (c) 2008 Georg Ringer cyberhouse.at * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */
// get the sku, string because a 0 as prefix would be skipped!! $sku = (string) $this->getRequest()->getParam('sku');
// if a sku is available if ($sku) { // try to get the product_id $resource = Mage::getSingleton('core/resource'); $read = $resource->getConnection('catalog_read'); $categoryProductTable = $resource->getTableName('catalog/product'); $productEntityIntTable = (string)Mage::getConfig() ->getTablePrefix() . 'catalog_product_entity '; $eavAttributeTable = $resource->getTableName('eav/attribute'); $select = $read->select() ->from($categoryProductTable) ->where('sku="'.$sku.'"'); // read the product id $row = $read->fetchRow($select); $product_id=$row['entity_id'];
// get the url $_product = Mage::getModel('catalog/product')->load($product_id); // if there is an active product if($_product->getStatus()==1) { $_categories = $_product->getCategoryIds(); $_category = Mage::getModel('catalog/category')->load($_categories[0]); $url = $this->getUrl($_category->getUrlPath()).$_product->getUrlPath().'.html'; // redirect to the product, 301 = permanent redirection header("Location:$url",TRUE,301); die(); } }
Plese tell me your opinion
Georg
|