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
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
add a comment |
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
add a comment |
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
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
url
edited 47 mins ago
Teja Bhagavan Kollepara
3,00641949
3,00641949
asked Mar 24 '17 at 17:42
mikejwmikejw
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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;
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
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
add a comment |
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;
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
add a comment |
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;
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;
edited Mar 24 '17 at 18:15
answered Mar 24 '17 at 18:06
Amit Bera♦Amit 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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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