सबसे पहले मैं कहना चाहता हूं कि यह एक अच्छा सवाल है। मुझे सब निकाल दिया गया।
यह यूआरएल प्रबंधन के साथ काम करता है लेकिन यह एक प्रकार का ड्रैग है। बहुत ज्यादा कार्य।
उदाहरण के लिए मैंने इसे यूआरएल प्रबंधन में जोड़ा।
Type : Custom
Store: Select any store here - if you have more you have to do this process for each one
ID Path: TAG_23
Request Path: tag/camera
Target Path: tag/product/list/tagId/23
Redirect: No
सहेजा गया। अब ROOT/tag/camera
पर कॉल करते समय मुझे 'कैमरा' के साथ टैग किए गए प्रोडक्ट्स दिखाई देते हैं।
लेकिन निश्चित रूप से यह जाने का तरीका नहीं है। यदि आपके पास 10 से अधिक टैग हैं तो आप ऊब जाते हैं।
तो विचार एक मॉड्यूल बनाना है जो Magento को tag/something
जैसे टैग पहचानने देगा और टैग के लिए लिंक को उसी प्रारूप में बदल देगा, इसलिए आपको बहुत से टेम्पलेट्स को संपादित नहीं करना होगा।
मैंने मॉड्यूल Easylife_Tag
नाम दिया। आपको इसके लिए निम्नलिखित फाइलों की आवश्यकता है।
app/etc/modules/Easylife_Tag.xml
- घोषणा फ़ाइल
<?xml version="1.0"?>
<config>
<modules>
<Easylife_Tag>
<codePool>local</codePool>
<active>true</active>
<depends>
<Mage_Tag />
</depends>
</Easylife_Tag>
</modules>
</config>
app/code/local/Easylife/Tag/etc/config.xml
- विन्यास फाइल
<?xml version="1.0"?>
<config>
<modules>
<Easylife_Tag>
<version>1.0.0</version>
</Easylife_Tag>
</modules>
<global>
<events>
<controller_front_init_routers><!-- add a custom router to recognize urls like tag/something -->
<observers>
<easylife_tag>
<class>Easylife_Tag_Controller_Router</class>
<method>initControllerRouters</method>
</easylife_tag>
</observers>
</controller_front_init_routers>
</events>
<models>
<tag>
<rewrite>
<tag>Easylife_Tag_Model_Tag</tag><!-- rewrite the tag model to change the url of the tags to tag/something -->
</rewrite>
</tag>
<tag_resource>
<rewrite>
<tag>Easylife_Tag_Model_Resource_Tag</tag> <!-- rewrite the tag resource model - see below why is needed -->
</rewrite>
</tag_resource>
</models>
</global>
</config>
app/code/local/Easylife/Tag/Model/Tag.php
- फिर से लिखा टैग मॉडल
<?php
class Easylife_Tag_Model_Tag extends Mage_Tag_Model_Tag {
//change the url from `tag/product/list/tagId/23` to `tag/camera`
public function getTaggedProductsUrl() {
return Mage::getUrl('', array('_direct' => 'tag/'.$this->getName()));
}
}
app/code/local/Easylife/Tag/Model/Resource/Tag.php
- फिर से लिखा टैग संसाधन मॉडल
<?php
class Easylife_Tag_Model_Resource_Tag extends Mage_Tag_Model_Resource_Tag {
//by default, when loading a tag by name magento does not load the store ids it is allowed in
//this method loads also the store ids
public function loadByName($model, $name){
parent::loadByName($model, $name);
if ($model->getId()) {
$this->_afterLoad($model);
}
else {
return false;
}
}
}
app/code/local/Easylife/Tag/Controller/Router.php
- कस्टम रूटर - इनलाइन
<?php
class Easylife_Tag_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract{
public function initControllerRouters($observer){
$front = $observer->getEvent()->getFront();
$front->addRouter('easylife_tag', $this);
return $this;
}
public function match(Zend_Controller_Request_Http $request){
//if magento is not installed redirect to install
if (!Mage::isInstalled()) {
Mage::app()->getFrontController()->getResponse()
->setRedirect(Mage::getUrl('install'))
->sendResponse();
exit;
}
//get the url key
$urlKey = trim($request->getPathInfo(), '/');
//explode by slash
$parts = explode('/', $urlKey);
//if there are not 2 parts (tag/something) in the url we don't care about it.
//return false and let the rest of the application take care of the url.
if (count($parts) != 2) {
return false;
}
//if the first part of the url key is not 'tag' we don't care about it
//return false and let the rest of the application take care of the url
if ($parts[0] != 'tag') {
return false;
}
$tagName = $parts[1]; //tag name
//load the tag model
$tag = Mage::getModel('tag/tag')->loadByName($tagName);
//if there is no tag with this name available in the current store just do nothing
if(!$tag->getId() || !$tag->isAvailableInStore()) {
return false;
}
//but if the tag is valid
//say to magento that the request should be mapped to `tag/product/list/tagId/ID_HERE` - the original url
$request->setModuleName('tag')
->setControllerName('product')
->setActionName('list')
->setParam('tagId', $tag->getId());
$request->setAlias(
Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
$urlKey
);
return true;
}
}
यह है कि टिप्पणियों को देखने। कैश साफ़ करें और इसे जाने दें।
[संपादित करें]।
You can find the full extension here। केवल अंतर यह है कि यह ऊपर वर्णित अनुसार स्थानीय के बजाय community
कोड पूल का उपयोग करता है।
मारियस, आप एक Magento भगवान –
@ डेविडविल्किन्स इसे काट लें। आप मुझे शर्मिंदा कर रहे हैं। :) – Marius
आपने 'setAlias (...' अंत में भाग को खोजने का प्रबंधन कैसे किया? Magento के पास कोई स्वचालित परीक्षण नहीं है, क्या इस तरह की चीजें पकड़ने के लिए आपके द्वारा चलाए गए मैन्युअल परीक्षणों का एक विशिष्ट सेट है? ईमानदारी से , मुझे नहीं पता कि Magento में सुरक्षित कोड कैसे करें, और यह एक, बस मेरे दिमाग को उड़ा दिया। – shampoo