Trouble getting product URLsMagento: 'Use categories path for product URL’s to no' - Will the old URLs be auto redirected?Magento invalid product urlsMultistore - Prevent product from having multiple urlsLayered Navigation - altering URLsgetting product URL by IDduplicated content, product URLsRegenerate product URLs for new storeConfigurable product with different URLS for simpleURL Rewrite issue - category/sub-category/product urls not workingMagento 2 Duplicate Product URLs Problem

Do I have to take mana from my deck or hand when tapping this card?

Would a primitive species be able to learn English from reading books alone?

Can you describe someone as luxurious? As in someone who likes luxurious things?

Output visual diagram of picture

Do native speakers use "ultima" and "proxima" frequently in spoken English?

Extract substring according to regexp with sed or grep

How can I, as DM, avoid the Conga Line of Death occurring when implementing some form of flanking rule?

Weird lines in Microsoft Word

How do you justify more code being written by following clean code practices?

Reasons for having MCU pin-states default to pull-up/down out of reset

Are all namekians brothers?

Mortal danger in mid-grade literature

What is this high flying aircraft over Pennsylvania?

Center page as a whole without centering each element individually

I keep switching characters, how do I stop?

Showing mass murder in a kid's book

Calculate Pi using Monte Carlo

Is there a distance limit for minecart tracks?

Should I be concerned about student access to a test bank?

How do I prevent inappropriate ads from appearing in my game?

Why does a 97 / 92 key piano exist by Bosendorfer?

Is there a POSIX way to shutdown a UNIX machine?

Why is indicated airspeed rather than ground speed used during the takeoff roll?

Hashing password to increase entropy



Trouble getting product URLs


Magento: 'Use categories path for product URL’s to no' - Will the old URLs be auto redirected?Magento invalid product urlsMultistore - Prevent product from having multiple urlsLayered Navigation - altering URLsgetting product URL by IDduplicated content, product URLsRegenerate product URLs for new storeConfigurable product with different URLS for simpleURL Rewrite issue - category/sub-category/product urls not workingMagento 2 Duplicate Product URLs Problem













0















After looking at various methods, the following code is almost getting what I want:



 $product = Mage::getModel('catalog/product')->load($product_id);
$site_url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$product_url = '';
$cats = $product->getCategoryIds();
if (sizeof($cats))
$category = Mage::getModel('catalog/category')->load((int) $cats[0]);
$product_url = $site_url.$product->getUrlPath($category);



This returns: http://magento.dev/men/shirts/french-cuff-cotton-twill-oxford-570.html.



However this produces a 404.



570 is not the ID that corresponds to this product so I'm wondering where it's coming from.










share|improve this question




























    0















    After looking at various methods, the following code is almost getting what I want:



     $product = Mage::getModel('catalog/product')->load($product_id);
    $site_url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
    $product_url = '';
    $cats = $product->getCategoryIds();
    if (sizeof($cats))
    $category = Mage::getModel('catalog/category')->load((int) $cats[0]);
    $product_url = $site_url.$product->getUrlPath($category);



    This returns: http://magento.dev/men/shirts/french-cuff-cotton-twill-oxford-570.html.



    However this produces a 404.



    570 is not the ID that corresponds to this product so I'm wondering where it's coming from.










    share|improve this question


























      0












      0








      0








      After looking at various methods, the following code is almost getting what I want:



       $product = Mage::getModel('catalog/product')->load($product_id);
      $site_url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
      $product_url = '';
      $cats = $product->getCategoryIds();
      if (sizeof($cats))
      $category = Mage::getModel('catalog/category')->load((int) $cats[0]);
      $product_url = $site_url.$product->getUrlPath($category);



      This returns: http://magento.dev/men/shirts/french-cuff-cotton-twill-oxford-570.html.



      However this produces a 404.



      570 is not the ID that corresponds to this product so I'm wondering where it's coming from.










      share|improve this question
















      After looking at various methods, the following code is almost getting what I want:



       $product = Mage::getModel('catalog/product')->load($product_id);
      $site_url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
      $product_url = '';
      $cats = $product->getCategoryIds();
      if (sizeof($cats))
      $category = Mage::getModel('catalog/category')->load((int) $cats[0]);
      $product_url = $site_url.$product->getUrlPath($category);



      This returns: http://magento.dev/men/shirts/french-cuff-cotton-twill-oxford-570.html.



      However this produces a 404.



      570 is not the ID that corresponds to this product so I'm wondering where it's coming from.







      url






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 47 mins ago









      Teja Bhagavan Kollepara

      3,00641949




      3,00641949










      asked Mar 24 '17 at 17:42









      mikejwmikejw

      1




      1




















          1 Answer
          1






          active

          oldest

          votes


















          0














          Instead of using $product_url = $site_url.$product->getUrlPath($category); those.



          You use below code




           $product = Mage::getModel('catalog/product')->load($product_id);
          $product_url = '';
          $cats = $product->getCategoryIds();
          if (sizeof($cats))
          $category = Mage::getModel('catalog/category')->load((int) $cats[0]);
          if($category->getId())
          $product->setCategory($category);


          $product_url = $product->getProductUrl();



          Or via ProductCollection with addUrlRewrite() function:




          $product = Mage::getModel('catalog/product')->load($product_id);
          $product_url = $product->getProductUrl();
          $cats = $product->getCategoryIds();

          if (sizeof($cats))
          $collection = Mage::getResourceModel('catalog/product_collection');
          $collection->addIdFilter($product->getId());
          if($collection->getSize() >= 1):
          /* Add addUrlRewrite for add category url with product */
          $collection->addUrlRewrite((int)$cats[0]);
          $ProductWithCategory = $collection->getFirstItem();
          $product_url = $ProductWithCategory->getProductUrl();
          endif;







          share|improve this answer

























          • Thanks Amit. The first recommendation worked and produced the url: magento.dev/index.php/catalog/product/view/id/402/s/… The second solution didn't seem to do what was expected. It produced the URL: magento.dev/index.php/catalog/product/view/id/402 This seems less "url-rewritten" than the first one. It seems insane but I'm now seriously considering sticking with my original method but doing a REGEX replace on the ID to produce the correct URL. Only by doing this horrible hack will I get the URL that the front-end uses.

            – mikejw
            Mar 27 '17 at 9:53












          • Please do indexing from shell check and check the result

            – Amit Bera
            Mar 27 '17 at 9:57












          • Hi Amit, I've successfully run "php indexer.php --reindex" and "php indexer.php --reindex all". This has no impact on the results I'm getting.

            – mikejw
            Mar 27 '17 at 10:11










          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%2f166106%2ftrouble-getting-product-urls%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














          Instead of using $product_url = $site_url.$product->getUrlPath($category); those.



          You use below code




           $product = Mage::getModel('catalog/product')->load($product_id);
          $product_url = '';
          $cats = $product->getCategoryIds();
          if (sizeof($cats))
          $category = Mage::getModel('catalog/category')->load((int) $cats[0]);
          if($category->getId())
          $product->setCategory($category);


          $product_url = $product->getProductUrl();



          Or via ProductCollection with addUrlRewrite() function:




          $product = Mage::getModel('catalog/product')->load($product_id);
          $product_url = $product->getProductUrl();
          $cats = $product->getCategoryIds();

          if (sizeof($cats))
          $collection = Mage::getResourceModel('catalog/product_collection');
          $collection->addIdFilter($product->getId());
          if($collection->getSize() >= 1):
          /* Add addUrlRewrite for add category url with product */
          $collection->addUrlRewrite((int)$cats[0]);
          $ProductWithCategory = $collection->getFirstItem();
          $product_url = $ProductWithCategory->getProductUrl();
          endif;







          share|improve this answer

























          • Thanks Amit. The first recommendation worked and produced the url: magento.dev/index.php/catalog/product/view/id/402/s/… The second solution didn't seem to do what was expected. It produced the URL: magento.dev/index.php/catalog/product/view/id/402 This seems less "url-rewritten" than the first one. It seems insane but I'm now seriously considering sticking with my original method but doing a REGEX replace on the ID to produce the correct URL. Only by doing this horrible hack will I get the URL that the front-end uses.

            – mikejw
            Mar 27 '17 at 9:53












          • Please do indexing from shell check and check the result

            – Amit Bera
            Mar 27 '17 at 9:57












          • Hi Amit, I've successfully run "php indexer.php --reindex" and "php indexer.php --reindex all". This has no impact on the results I'm getting.

            – mikejw
            Mar 27 '17 at 10:11















          0














          Instead of using $product_url = $site_url.$product->getUrlPath($category); those.



          You use below code




           $product = Mage::getModel('catalog/product')->load($product_id);
          $product_url = '';
          $cats = $product->getCategoryIds();
          if (sizeof($cats))
          $category = Mage::getModel('catalog/category')->load((int) $cats[0]);
          if($category->getId())
          $product->setCategory($category);


          $product_url = $product->getProductUrl();



          Or via ProductCollection with addUrlRewrite() function:




          $product = Mage::getModel('catalog/product')->load($product_id);
          $product_url = $product->getProductUrl();
          $cats = $product->getCategoryIds();

          if (sizeof($cats))
          $collection = Mage::getResourceModel('catalog/product_collection');
          $collection->addIdFilter($product->getId());
          if($collection->getSize() >= 1):
          /* Add addUrlRewrite for add category url with product */
          $collection->addUrlRewrite((int)$cats[0]);
          $ProductWithCategory = $collection->getFirstItem();
          $product_url = $ProductWithCategory->getProductUrl();
          endif;







          share|improve this answer

























          • Thanks Amit. The first recommendation worked and produced the url: magento.dev/index.php/catalog/product/view/id/402/s/… The second solution didn't seem to do what was expected. It produced the URL: magento.dev/index.php/catalog/product/view/id/402 This seems less "url-rewritten" than the first one. It seems insane but I'm now seriously considering sticking with my original method but doing a REGEX replace on the ID to produce the correct URL. Only by doing this horrible hack will I get the URL that the front-end uses.

            – mikejw
            Mar 27 '17 at 9:53












          • Please do indexing from shell check and check the result

            – Amit Bera
            Mar 27 '17 at 9:57












          • Hi Amit, I've successfully run "php indexer.php --reindex" and "php indexer.php --reindex all". This has no impact on the results I'm getting.

            – mikejw
            Mar 27 '17 at 10:11













          0












          0








          0







          Instead of using $product_url = $site_url.$product->getUrlPath($category); those.



          You use below code




           $product = Mage::getModel('catalog/product')->load($product_id);
          $product_url = '';
          $cats = $product->getCategoryIds();
          if (sizeof($cats))
          $category = Mage::getModel('catalog/category')->load((int) $cats[0]);
          if($category->getId())
          $product->setCategory($category);


          $product_url = $product->getProductUrl();



          Or via ProductCollection with addUrlRewrite() function:




          $product = Mage::getModel('catalog/product')->load($product_id);
          $product_url = $product->getProductUrl();
          $cats = $product->getCategoryIds();

          if (sizeof($cats))
          $collection = Mage::getResourceModel('catalog/product_collection');
          $collection->addIdFilter($product->getId());
          if($collection->getSize() >= 1):
          /* Add addUrlRewrite for add category url with product */
          $collection->addUrlRewrite((int)$cats[0]);
          $ProductWithCategory = $collection->getFirstItem();
          $product_url = $ProductWithCategory->getProductUrl();
          endif;







          share|improve this answer















          Instead of using $product_url = $site_url.$product->getUrlPath($category); those.



          You use below code




           $product = Mage::getModel('catalog/product')->load($product_id);
          $product_url = '';
          $cats = $product->getCategoryIds();
          if (sizeof($cats))
          $category = Mage::getModel('catalog/category')->load((int) $cats[0]);
          if($category->getId())
          $product->setCategory($category);


          $product_url = $product->getProductUrl();



          Or via ProductCollection with addUrlRewrite() function:




          $product = Mage::getModel('catalog/product')->load($product_id);
          $product_url = $product->getProductUrl();
          $cats = $product->getCategoryIds();

          if (sizeof($cats))
          $collection = Mage::getResourceModel('catalog/product_collection');
          $collection->addIdFilter($product->getId());
          if($collection->getSize() >= 1):
          /* Add addUrlRewrite for add category url with product */
          $collection->addUrlRewrite((int)$cats[0]);
          $ProductWithCategory = $collection->getFirstItem();
          $product_url = $ProductWithCategory->getProductUrl();
          endif;








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 24 '17 at 18:15

























          answered Mar 24 '17 at 18:06









          Amit BeraAmit Bera

          59.3k1575177




          59.3k1575177












          • Thanks Amit. The first recommendation worked and produced the url: magento.dev/index.php/catalog/product/view/id/402/s/… The second solution didn't seem to do what was expected. It produced the URL: magento.dev/index.php/catalog/product/view/id/402 This seems less "url-rewritten" than the first one. It seems insane but I'm now seriously considering sticking with my original method but doing a REGEX replace on the ID to produce the correct URL. Only by doing this horrible hack will I get the URL that the front-end uses.

            – mikejw
            Mar 27 '17 at 9:53












          • Please do indexing from shell check and check the result

            – Amit Bera
            Mar 27 '17 at 9:57












          • Hi Amit, I've successfully run "php indexer.php --reindex" and "php indexer.php --reindex all". This has no impact on the results I'm getting.

            – mikejw
            Mar 27 '17 at 10:11

















          • Thanks Amit. The first recommendation worked and produced the url: magento.dev/index.php/catalog/product/view/id/402/s/… The second solution didn't seem to do what was expected. It produced the URL: magento.dev/index.php/catalog/product/view/id/402 This seems less "url-rewritten" than the first one. It seems insane but I'm now seriously considering sticking with my original method but doing a REGEX replace on the ID to produce the correct URL. Only by doing this horrible hack will I get the URL that the front-end uses.

            – mikejw
            Mar 27 '17 at 9:53












          • Please do indexing from shell check and check the result

            – Amit Bera
            Mar 27 '17 at 9:57












          • Hi Amit, I've successfully run "php indexer.php --reindex" and "php indexer.php --reindex all". This has no impact on the results I'm getting.

            – mikejw
            Mar 27 '17 at 10:11
















          Thanks Amit. The first recommendation worked and produced the url: magento.dev/index.php/catalog/product/view/id/402/s/… The second solution didn't seem to do what was expected. It produced the URL: magento.dev/index.php/catalog/product/view/id/402 This seems less "url-rewritten" than the first one. It seems insane but I'm now seriously considering sticking with my original method but doing a REGEX replace on the ID to produce the correct URL. Only by doing this horrible hack will I get the URL that the front-end uses.

          – mikejw
          Mar 27 '17 at 9:53






          Thanks Amit. The first recommendation worked and produced the url: magento.dev/index.php/catalog/product/view/id/402/s/… The second solution didn't seem to do what was expected. It produced the URL: magento.dev/index.php/catalog/product/view/id/402 This seems less "url-rewritten" than the first one. It seems insane but I'm now seriously considering sticking with my original method but doing a REGEX replace on the ID to produce the correct URL. Only by doing this horrible hack will I get the URL that the front-end uses.

          – mikejw
          Mar 27 '17 at 9:53














          Please do indexing from shell check and check the result

          – Amit Bera
          Mar 27 '17 at 9:57






          Please do indexing from shell check and check the result

          – Amit Bera
          Mar 27 '17 at 9:57














          Hi Amit, I've successfully run "php indexer.php --reindex" and "php indexer.php --reindex all". This has no impact on the results I'm getting.

          – mikejw
          Mar 27 '17 at 10:11





          Hi Amit, I've successfully run "php indexer.php --reindex" and "php indexer.php --reindex all". This has no impact on the results I'm getting.

          – mikejw
          Mar 27 '17 at 10: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%2f166106%2ftrouble-getting-product-urls%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

          Disable / Remove link to Product Items in Cart Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How can I limit products that can be bought / added to cart?Remove item from cartHide “Add to Cart” button if specific products are already in cart“Prettifying” the custom options in cart pageCreate link in cart sidebar to view all added items After limit reachedLink products together in checkout/cartHow to Get product from cart and add it againHide action-edit on cart page if simple productRemoving Cart items - ObserverRemove wishlist items when added to cart

          Helsingin valtaus Sisällysluettelo Taustaa | Yleistä sotatoimista | Osapuolet | Taistelut Helsingin ympäristössä | Punaisten antautumissuunnitelma | Taistelujen kulku Helsingissä | Valtauksen jälkeen | Tappiot | Muistaminen | Kirjallisuutta | Lähteet | Aiheesta muualla | NavigointivalikkoTeoksen verkkoversioTeoksen verkkoversioGoogle BooksSisällissota Helsingissä päättyi tasan 95 vuotta sittenSaksalaisten ylivoima jyräsi punaisen HelsinginSuomalaiset kuvaavat sotien jälkiä kaupungeissa – katso kuvat ja tarinat tutuilta kulmiltaHelsingin valtaus 90 vuotta sittenSaksalaiset valtasivat HelsinginHyökkäys HelsinkiinHelsingin valtaus 12.–13.4. 1918Saksalaiset käyttivät ihmiskilpiä Helsingin valtauksessa 1918Teoksen verkkoversioTeoksen verkkoversioSaksalaiset hyökkäävät Etelä-SuomeenTaistelut LeppävaarassaSotilaat ja taistelutLeppävaara 1918 huhtikuussa. KapinatarinaHelsingin taistelut 1918Saksalaisten voitonparaati HelsingissäHelsingin valtausta juhlittiinSaksalaisten Helsinki vuonna 1918Helsingin taistelussa kaatuneet valkokaartilaisetHelsinkiin haudatut taisteluissa kaatuneet punaiset12.4.1918 Helsingin valtauksessa saksalaiset apujoukot vapauttavat kaupunginVapaussodan muistomerkkejä Helsingissä ja pääkaupunkiseudullaCrescendo / Vuoden 1918 Kansalaissodan uhrien muistomerkkim

          Adjektiivitarina Tarinan tekeminen | Esimerkki: ennen | Esimerkki: jälkeen | Navigointivalikko