Add custom product attribute to URL product viewCustom URL rewrite for reviews in MagentoMagento EE Create Custom Redirect for old URLAutomatic URL rewrite after deleting a productHow Can I Customize Magento Default URL (Product URL and Category URL)Custom module url rewriteHow to delete and regenerate URL rewrites in Magento 2?Magento 2 : Product URL rewrite issueShop by Brand/Manufacturer custom URL in M1How to add a custom attribute value to product url in Magento 2Url Rewrite Issue in product duplication

If Melisandre foresaw another character closing blue eyes, why did she follow Stannis?

Is balancing necessary on a full-wheel change?

If 1. e4 c6 is considered as a sound defense for black, why is 1. c3 so rare?

Why is Arya visibly scared in the library in S8E3?

Packet sniffer for MacOS Mojave and above

Why is Thanos so tough at the beginning of "Avengers: Endgame"?

What is the word which sounds like "shtrass"?

Floor tile layout process?

Binary Numbers Magic Trick

How did Captain America use this power?

Entropy as a function of temperature: is temperature well defined?

Power LED from 3.3V Power Pin without Resistor

Copy line and insert it in a new position with sed or awk

LT Spice Voltage Output

Can PCs use nonmagical armor and weapons looted from monsters?

Historically, were women trained for obligatory wars? Or did they serve some other military function?

Can a cyclic Amine form an Amide?

Any examples of headwear for races with animal ears?

Password expiration with Password manager

Would "lab meat" be able to feed a much larger global population

How to implement float hashing with approximate equality

Unexpected email from Yorkshire Bank

How to get SEEK accessing converted ID via view

How did Arya get back her dagger from Sansa?



Add custom product attribute to URL product view


Custom URL rewrite for reviews in MagentoMagento EE Create Custom Redirect for old URLAutomatic URL rewrite after deleting a productHow Can I Customize Magento Default URL (Product URL and Category URL)Custom module url rewriteHow to delete and regenerate URL rewrites in Magento 2?Magento 2 : Product URL rewrite issueShop by Brand/Manufacturer custom URL in M1How to add a custom attribute value to product url in Magento 2Url Rewrite Issue in product duplication






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have created an EAV entity (that represents the brand) which can be associated to a product as an attribute.
Now, I would like to add the name of the brand to the product view URL.
I would like something like this:



http://myhost.com/category-name/brand-name/product-name


Is there a way to extend the url rewrite for products view?










share|improve this question




























    0















    I have created an EAV entity (that represents the brand) which can be associated to a product as an attribute.
    Now, I would like to add the name of the brand to the product view URL.
    I would like something like this:



    http://myhost.com/category-name/brand-name/product-name


    Is there a way to extend the url rewrite for products view?










    share|improve this question
























      0












      0








      0








      I have created an EAV entity (that represents the brand) which can be associated to a product as an attribute.
      Now, I would like to add the name of the brand to the product view URL.
      I would like something like this:



      http://myhost.com/category-name/brand-name/product-name


      Is there a way to extend the url rewrite for products view?










      share|improve this question














      I have created an EAV entity (that represents the brand) which can be associated to a product as an attribute.
      Now, I would like to add the name of the brand to the product view URL.
      I would like something like this:



      http://myhost.com/category-name/brand-name/product-name


      Is there a way to extend the url rewrite for products view?







      url-rewrite product-view ce-1.9.2.2 product-urls






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 25 '16 at 17:43









      gianis6gianis6

      7351435




      7351435




















          1 Answer
          1






          active

          oldest

          votes


















          0














          In order to create url key with "/" sign you need to override Mage_Catalog_Model_Product_Url's formatUrlKey() method.

          You can do it like so:



          class Vendor_Module_Model_Catalog_Product_Url extends Mage_Catalog_Model_Product_Url

          /**
          * Format Key for URL
          *
          * @param string $str
          * @return string
          */
          public function formatUrlKey($str)

          // added '/' character
          $urlKey = preg_replace('#[^0-9a-z/.]+#i', '-', Mage::helper('catalog/product_url')->format($str));
          $urlKey = strtolower($urlKey);
          $urlKey = trim($urlKey, '-');

          return $urlKey;





          You can override beforeSave() method of the Backend Model of Catalog Product Urlkey attribute as following:



          class Vendor_Module_Model_Catalog_Product_Attribute_Backend_Urlkey
          extends Mage_Catalog_Model_Product_Attribute_Backend_Urlkey

          /**
          * Before save
          *
          * @param Varien_Object $object
          * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Urlkey
          * @overridden
          */
          public function beforeSave($object)

          $attributeName = $this->getAttribute()->getName();

          $urlKey = $object->getData($attributeName);
          if ($urlKey == '')
          $urlKey = "$object->getBrandName()/$object->getName()";

          $object->setData($attributeName, $object->formatUrlKey($urlKey));

          return $this;





          Now while product is being saved, if url key empty it will automatically create an 'brand-name/name' like url. If it comes to category name it is a matter of magento configuration to or not to add category name at the begining of URL address.




          Alternatively check out this free extension, it does exactly what you require:
          https://www.magentocommerce.com/magento-connect/custom-product-urls-seo.html






          share|improve this answer

























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f103529%2fadd-custom-product-attribute-to-url-product-view%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            In order to create url key with "/" sign you need to override Mage_Catalog_Model_Product_Url's formatUrlKey() method.

            You can do it like so:



            class Vendor_Module_Model_Catalog_Product_Url extends Mage_Catalog_Model_Product_Url

            /**
            * Format Key for URL
            *
            * @param string $str
            * @return string
            */
            public function formatUrlKey($str)

            // added '/' character
            $urlKey = preg_replace('#[^0-9a-z/.]+#i', '-', Mage::helper('catalog/product_url')->format($str));
            $urlKey = strtolower($urlKey);
            $urlKey = trim($urlKey, '-');

            return $urlKey;





            You can override beforeSave() method of the Backend Model of Catalog Product Urlkey attribute as following:



            class Vendor_Module_Model_Catalog_Product_Attribute_Backend_Urlkey
            extends Mage_Catalog_Model_Product_Attribute_Backend_Urlkey

            /**
            * Before save
            *
            * @param Varien_Object $object
            * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Urlkey
            * @overridden
            */
            public function beforeSave($object)

            $attributeName = $this->getAttribute()->getName();

            $urlKey = $object->getData($attributeName);
            if ($urlKey == '')
            $urlKey = "$object->getBrandName()/$object->getName()";

            $object->setData($attributeName, $object->formatUrlKey($urlKey));

            return $this;





            Now while product is being saved, if url key empty it will automatically create an 'brand-name/name' like url. If it comes to category name it is a matter of magento configuration to or not to add category name at the begining of URL address.




            Alternatively check out this free extension, it does exactly what you require:
            https://www.magentocommerce.com/magento-connect/custom-product-urls-seo.html






            share|improve this answer





























              0














              In order to create url key with "/" sign you need to override Mage_Catalog_Model_Product_Url's formatUrlKey() method.

              You can do it like so:



              class Vendor_Module_Model_Catalog_Product_Url extends Mage_Catalog_Model_Product_Url

              /**
              * Format Key for URL
              *
              * @param string $str
              * @return string
              */
              public function formatUrlKey($str)

              // added '/' character
              $urlKey = preg_replace('#[^0-9a-z/.]+#i', '-', Mage::helper('catalog/product_url')->format($str));
              $urlKey = strtolower($urlKey);
              $urlKey = trim($urlKey, '-');

              return $urlKey;





              You can override beforeSave() method of the Backend Model of Catalog Product Urlkey attribute as following:



              class Vendor_Module_Model_Catalog_Product_Attribute_Backend_Urlkey
              extends Mage_Catalog_Model_Product_Attribute_Backend_Urlkey

              /**
              * Before save
              *
              * @param Varien_Object $object
              * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Urlkey
              * @overridden
              */
              public function beforeSave($object)

              $attributeName = $this->getAttribute()->getName();

              $urlKey = $object->getData($attributeName);
              if ($urlKey == '')
              $urlKey = "$object->getBrandName()/$object->getName()";

              $object->setData($attributeName, $object->formatUrlKey($urlKey));

              return $this;





              Now while product is being saved, if url key empty it will automatically create an 'brand-name/name' like url. If it comes to category name it is a matter of magento configuration to or not to add category name at the begining of URL address.




              Alternatively check out this free extension, it does exactly what you require:
              https://www.magentocommerce.com/magento-connect/custom-product-urls-seo.html






              share|improve this answer



























                0












                0








                0







                In order to create url key with "/" sign you need to override Mage_Catalog_Model_Product_Url's formatUrlKey() method.

                You can do it like so:



                class Vendor_Module_Model_Catalog_Product_Url extends Mage_Catalog_Model_Product_Url

                /**
                * Format Key for URL
                *
                * @param string $str
                * @return string
                */
                public function formatUrlKey($str)

                // added '/' character
                $urlKey = preg_replace('#[^0-9a-z/.]+#i', '-', Mage::helper('catalog/product_url')->format($str));
                $urlKey = strtolower($urlKey);
                $urlKey = trim($urlKey, '-');

                return $urlKey;





                You can override beforeSave() method of the Backend Model of Catalog Product Urlkey attribute as following:



                class Vendor_Module_Model_Catalog_Product_Attribute_Backend_Urlkey
                extends Mage_Catalog_Model_Product_Attribute_Backend_Urlkey

                /**
                * Before save
                *
                * @param Varien_Object $object
                * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Urlkey
                * @overridden
                */
                public function beforeSave($object)

                $attributeName = $this->getAttribute()->getName();

                $urlKey = $object->getData($attributeName);
                if ($urlKey == '')
                $urlKey = "$object->getBrandName()/$object->getName()";

                $object->setData($attributeName, $object->formatUrlKey($urlKey));

                return $this;





                Now while product is being saved, if url key empty it will automatically create an 'brand-name/name' like url. If it comes to category name it is a matter of magento configuration to or not to add category name at the begining of URL address.




                Alternatively check out this free extension, it does exactly what you require:
                https://www.magentocommerce.com/magento-connect/custom-product-urls-seo.html






                share|improve this answer















                In order to create url key with "/" sign you need to override Mage_Catalog_Model_Product_Url's formatUrlKey() method.

                You can do it like so:



                class Vendor_Module_Model_Catalog_Product_Url extends Mage_Catalog_Model_Product_Url

                /**
                * Format Key for URL
                *
                * @param string $str
                * @return string
                */
                public function formatUrlKey($str)

                // added '/' character
                $urlKey = preg_replace('#[^0-9a-z/.]+#i', '-', Mage::helper('catalog/product_url')->format($str));
                $urlKey = strtolower($urlKey);
                $urlKey = trim($urlKey, '-');

                return $urlKey;





                You can override beforeSave() method of the Backend Model of Catalog Product Urlkey attribute as following:



                class Vendor_Module_Model_Catalog_Product_Attribute_Backend_Urlkey
                extends Mage_Catalog_Model_Product_Attribute_Backend_Urlkey

                /**
                * Before save
                *
                * @param Varien_Object $object
                * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Urlkey
                * @overridden
                */
                public function beforeSave($object)

                $attributeName = $this->getAttribute()->getName();

                $urlKey = $object->getData($attributeName);
                if ($urlKey == '')
                $urlKey = "$object->getBrandName()/$object->getName()";

                $object->setData($attributeName, $object->formatUrlKey($urlKey));

                return $this;





                Now while product is being saved, if url key empty it will automatically create an 'brand-name/name' like url. If it comes to category name it is a matter of magento configuration to or not to add category name at the begining of URL address.




                Alternatively check out this free extension, it does exactly what you require:
                https://www.magentocommerce.com/magento-connect/custom-product-urls-seo.html







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jun 17 '16 at 7:52









                7ochem

                5,88493770




                5,88493770










                answered Jun 17 '16 at 7:41









                Marcin KlauzaMarcin Klauza

                11




                11



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f103529%2fadd-custom-product-attribute-to-url-product-view%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form