Guest User

Untitled

a guest
Oct 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. http://myhost.com/category-name/brand-name/product-name
  2.  
  3. class Vendor_Module_Model_Catalog_Product_Url extends Mage_Catalog_Model_Product_Url
  4. {
  5. /**
  6. * Format Key for URL
  7. *
  8. * @param string $str
  9. * @return string
  10. */
  11. public function formatUrlKey($str)
  12. {
  13. // added '/' character
  14. $urlKey = preg_replace('#[^0-9a-z/.]+#i', '-', Mage::helper('catalog/product_url')->format($str));
  15. $urlKey = strtolower($urlKey);
  16. $urlKey = trim($urlKey, '-');
  17.  
  18. return $urlKey;
  19. }
  20.  
  21. }
  22.  
  23. class Vendor_Module_Model_Catalog_Product_Attribute_Backend_Urlkey
  24. extends Mage_Catalog_Model_Product_Attribute_Backend_Urlkey
  25. {
  26. /**
  27. * Before save
  28. *
  29. * @param Varien_Object $object
  30. * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Urlkey
  31. * @overridden
  32. */
  33. public function beforeSave($object)
  34. {
  35. $attributeName = $this->getAttribute()->getName();
  36.  
  37. $urlKey = $object->getData($attributeName);
  38. if ($urlKey == '') {
  39. $urlKey = "{$object->getBrandName()}/{$object->getName()}";
  40. }
  41. $object->setData($attributeName, $object->formatUrlKey($urlKey));
  42.  
  43. return $this;
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment