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

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

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?