why magento using other product's url key for url rewrite - magento

I am using magento 1.7. i am faceing strange problem. magento making duplicate product url with random number with wrong url key please my attached screenshot
I also empty table rewrite_urls and reindex urls but still i am getting wrong urls. please help me to solve this problem. if you are unable to view images in question then please click on links duplicate product urls and Product in admin panel
,
Let me make understand u with example
Like i have one product named "example" and url key is "example" Url will be
www.example.com/example
and now i have created new product "xyz and url key is "xyz" and url should be
www.example.com/xyz
but magento generating url
www.example.com/example-123

This seems to be a bug in 1.7.
If you have multiple simple products with the same url key as the configurable product (e.g. all names are the same), than magento always creates a new url rewrite on every index process.
Example:
First index:
myproducturl (config product)
myproducturl-id (simple product with its id appended, so far so good)
Second index:
myproducturl (config product)
myproducturl-randomnumber (simple product with random number, BAD)
myproducturl-id --> myproducturl-randomnumber (rewrite to the new url)
And on every new index process the last step will be repeated, so always a new random url key is generated.
If magento would check, that a url key with the id for that product already exists, this should be no problem.
After a few months, you will have a really big url_rewrite table, because nothing will be deleted and on every run, at least 1 record for every product with the same url key will be created.

I was able to eliminate the extra numbers at the end of the URLs by truncating the table "core_url_rewrites" (I made sure to make copy first) then reindexed it.

Related

Magento appending '-1' in Category URL Key in frontend

Magento is appending '-1' only to certain categories URL key despite not being defined by us like that in backend.
Eg. if URL key for category 'sample' is 'sample' .. in frontend its showing as '/sample-1'
It's not the case with all categories but 2 or 3 that too in desktop version alone. It's working fine in mobile version. What could be the issue?
There are few things that can cause this.
Duplicate Categories trying to use the same URL, upon reindex Magento will auto increment these values. To the next higher integer.
It's sometimes easy to miss.
Say you have the category "shoes" as a subcategory of "women"
The URL key created automatically for this category would be "/shoes"
Now say you have the category "shoes" as a subcategory of "men"
This category would automatically have the url key of "shoes" however because it already exists Magento will auto increment this key to "shoes-1"
Under a multi-store instance of Magento, you also can't have two categories with the same url keys even if they are part of different stores.
Additionally, Magento Enterprise 1.13 has a whole different problem with auto increments of URL Ids
What version of Magento are you running and is it a multi-store platform? I can provide further assistance from there.

Why does a category have a weird path defined in the Magento database?

My catalog_category_entity table has an entry for a category that does not appear anywhere in the admin area of the site, or in the front end.
It has a weird path: "/30" (30 is its entity_id). Every other category in every other Magento site I have access to starts its path with a number, not a slash.
It has entries through the rest of the EAV system in various places.
My suspicion is that someone ran a bad import, or other manual process, which left this category in the database, when really it should have been simply deleted.
Is this an anomaly, or is there a reason for this category to have a weird path?
Your suspicion is right. Most probably this is due to a bad import. Normally all paths look like this: 1/2/5/17. The path represents the ids of the categories starting from "root of all roots" (1) and continuing with all the parents and last is the category id. The path is used for displaying the categories in frontend and backend. That's why the category does not appear in any list.
If you have data on that category and you need it, just edit the path field and make it 1/2/30. 2 is the id of the root catalog so it may be different for you.
Then just increment the field children_count for the categories with id 1 and 2.
Back-up your db before trying this.

Products are not displaying in Frontend after import in Magento

I have imported products using System - Import/Export - Import option.
I can see my products in Admin panel, but not in Frontend.
I tried Re-indexing, cache clear, cache refresh, physical cache remove.
also checked product stock status, availability etc. Everything is ok.
But they are not displaying in frontend. I marked onething, If I open product that I imported using csv, just saved without any change, it starts displaying. But I have 100s of products. So I can't use this solution.
So please help me where I am going wrong in csv. below is my csv screenshot.
You need to ensure that the products are attached to a website.
This can be done via a bulk update:
Access the product listm select all
Alter attribute
Products information -> websites
It can also be done in the csv by using a "_product_websites" field and setting it to the website name or 'base'.
I forgot which CSV columns are mandatory but I do remember that if some are missing the importer does not tell you that but instead you get the behaviour that you are describing.
The simplest way to find out what is mandatory is to:
Fix bugs in Magento ImportExport module
Create a new product in admin
Check that the new product is visible on front-end
Export the new product with Magento ImportExport exporter
Delete created product
Import the previously exported product csv
Clear cache and reindex data
Check that product is visible on front-end (it should be)
Compare your CSV with the exported one and try to figure out what is missing from it
Try to import your CSV with added/fixed columns and add data untill the product is imported so that it is visible on front-end
This requires allot of trial and error...
The missing columns in my case had always the same value so if this will be the case with your problem as well you can simply extend CSV importer and hard code those values in there instead of fixing your CSV manually.
Since your product gets saved correctly if you open it in admin and save it you can also:
Import a product
Export that product
Open that product in admin and save it
Export newly saved product
Compare exported CSV-s where they differ
Fixing Magento ImportExport bugs:
First bug is that if you import multiple products the quantity informatino from the first product is used for all the products. To fix this you have to add $row = array(); right before $row['product_id'] = $this->_newSku[$rowData[self::COL_SKU]]['entity_id']; in Mage_ImportExport_Model_Import_Entity_Product::_saveStockItem() function.
The second bug causes Magento ImportExport module to return a foreign key constraint error when importing multiple products. Error happens because magento splits products data into multiple segments and if one product is located in two segments importer will delete data that was imported for the product in first segment before importing the second segment thereby causing database corruption (see this link for detailed explanation - this is where I got the solution below).
Note that removing foreign key constraint will not fix the problem but will instead make it worse since the database will contain corrupt data.
To fix it you have to change the code in Mage_ImportExport_Model_Import_Entity_Abstract::_saveValidatedBunches() function:
After if ($startNewBunch || !$source->valid()) { add
if ($startNewBunch && count($bunchRows) > 1) {
$arrKeys = array_keys($bunchRows);
$arrNew = array();
while(($tRow = array_pop($bunchRows))) {
$tKey = array_pop($arrKeys);
$arrNew[$tKey] = $tRow;
if ($tRow['sku']) {
break;
}
}
$nextRowBackup = array_reverse($arrNew, TRUE) + $nextRowBackup;
}
Hope this helps.
I had the same problem recently and I spent some time tring to figure it out...
Looks like magento needs a status flag for every product otherwise magento will not show it in the dashboard.
Solution : add a "status" column to your CSV file and set all the statuses to "Enabled"
(yes it's not a boolean. Just use the string inside the quotes as it is :)
I was stuck with the same problem, i then visited my var/export/export_all_products file, downloaded it again and uploaded the same back through import, logged out of my account and logged-in back, all products were back. This worked as a backup for me and i could see all the products back at the back-end.
Import as you have. If they are enabled, but not showing...
then you can fix this by clicking "select all" products in the "manage products" table and then "change status" and then select "enabled." This process might take a minute.
Visit your store and you should see your frontend with products.
Some kind of bug with the status/enabled setting.
You must have next fields in CSV
sku
_attribute_set
_type
_category
description
image
name
price
short_description
status
tax_class_id
thumbnail
visibility
weight
qty
_product_websites
is_in_stock
Please note that field is_in_stock is mandatory even if qty more then 1
In magento 2 we need to reindex in index management to display the products in frontend.
We can reindex through cmd.like the given example we need to enter magento file directory after that cmd php -f bin/magento indexer:reindex to reindex .
When I first started importing products via csv although I set the product to enabled, I figured out that even though it shows in the magento back end as enabled, it actually isnt - think its to do with setting the field contents as "1" or "0" rather than "enabled" or "disabled/null".
To get around this, after a import I simply selected all the products in the back end and change status to enabled - it fixes issue.
But, I do think if I simply changed the data in the csv import it would save me this minor in-convenience.

Magento - setting url key in csv leads to 404 page

I have a lot of products which need to be uploaded via csv in Magento. I have for example two attributes with values:
url_key
mypage
url_path
mypage.html
I have also tried the values the same, but when I upload them the products exist but always leads to an 404 error when trying to view their product page.
Is there somethig I'm missing out in the csv?
I'm using Magento 1.7
Thanks in advance.
Are you trying to have a different URL that the Product Name?
EG Product ABC, Magento would make the URL key product-abc and URL Path product-abc.html by default.
If that is your goal then you can leave those 2 columns blank on your import and Magento will apply this rule. Also be sure to re-index after you import.
Step 1 : Leave both column (url_key and url_path) empty and upload csv file
Step 2 : After succesful importing csv file, go to System -> Index Management :
Click on Select All and click on Submit.
It is very simple way. I tried and got result.

Magento creating invoice redirect to wrong url

When I create an invoice from the order in the backend, this on this url:
http://www.site.com/index.php/safe/sales_order_invoice/new/order_id/4372/
But when the Invoice is about to be created it goes to:
http://www.site.com/shop/safe/sales_order/view/order_id/4372/
You see the (Shop), which is mostly correct because the storefront is named that(We had 2 storefronts once) If I remove the (Shop) part from the url, I'm getting back to the correct page and it shows that the invoice was correctly created. This only happens from the Order itself. If I use Mass action to create invoices from the orders list, it's not giving me any problems.
If anyone else has the problem (Using multi stores)
Please check your database, core_config_data and see if web/secure/base_url etc. is redirecting to the right path. And make sure to check that it's doing so for the right store ID that is giving you the trouble.
My problem was that the secure path for one of my stores, was ruining it.
All works fine now!

Resources