Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Api2] [Catalog] Product URL returned by REST Api is wrong store #4510

Open
Hanmac opened this issue Jan 27, 2025 · 0 comments · May be fixed by #4511
Open

[Api2] [Catalog] Product URL returned by REST Api is wrong store #4510

Hanmac opened this issue Jan 27, 2025 · 0 comments · May be fixed by #4511
Assignees
Labels
bug Component: Api2 Relates to Mage_Api2 Component: Catalog Relates to Mage_Catalog

Comments

@Hanmac
Copy link
Contributor

Hanmac commented Jan 27, 2025

Preconditions (*)

  1. 19.4.15 to 20.12+
  2. Mage_Api2 enabled

Steps to reproduce (*)

  1. Enable Guest in REST API2 and the Attribute that they can receive Product URL

Expected result (*)

  1. [Screenshots, logs or description]
  2. Correct URL

Actual result (*)

  1. [Screenshots, logs or description]
  2. Wrong Store

My Test URL
https://myserver/api/rest/products/sku?store=5

The JSON output:

{
  "entity_id": 1343,
  "type_id": "simple",
  "url": "https:\/\/myserver\/index.php\/admin\/catalog\/product\/view\/id\/1343\/"
}

see that it is returning admin because it ignores the store parameter or getDefaultStoreView
(it even ignores the adminhtml router in local.xml, but that is a different thing)

The problem is this piece:

$productData['url'] = $productHelper->getProductUrl($product->getId());

a few lines above, the WebsiteId is set from the store I used as parameter:

$product->setWebsiteId($this->_getStore()->getWebsiteId());

changing it to this solves the issue:

$productData['url'] = $product->getProductUrl();

@sreichel if you want, I can make an MR soon.

@Hanmac Hanmac added bug Component: Api2 Relates to Mage_Api2 Component: Catalog Relates to Mage_Catalog labels Jan 27, 2025
@Hanmac Hanmac linked a pull request Jan 27, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component: Api2 Relates to Mage_Api2 Component: Catalog Relates to Mage_Catalog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants