Magento 1 - Removing numbers in url key/product url - url

As you may know, if you have products that share a url key, the url key will have a digit appended to it:
i.e
http://www.example.com/main-category/sub-category/product-name-**6260**.html
How do I find the source of that 6260 (which is one of the #'s appended to my urls)? I tried product id, sku, I cannot find the source of it. The reason I ask is because if I can find it, I can create a string replace function to flush it out of url's before I echo them on certain product listing pages.
Thanks.

Before we get to the location in code where this happens, be advised you're entering a world of pain.
There's no simple rule as to how those numbers are generated. There's cases where it's the store ID, there's cases where it's the simple product ID. There's cases where it's neither
Even if there was, it's common for not-from-scratch Magento sites to contain custom functionality that changes this
Ultimately, since Magento's human readable/SEO-friendly URLs are located in the core_url_rewrite table, it's possible for people to insert arbitrary text
Warnings of doom aside, the Model you're looking for is Mage::getSingleton('catalog/url'). This contains most of the logic for generating Magento Catalog and product rewrites. All of these methods end by passing the request path through the getUnusedPath method.
#File: app/code/core/Mage/Catalog/Model/Url.php
public function getUnusedPath($storeId, $requestPath, $idPath)
{
//...
}
This method contains the logic for for creating a unique number on the end of the URL. Tracing this in its entirely is beyond the scope of a Stack Overflow post, but this line in particular is enlightening/disheartening.
$lastRequestPath = $this->getResource()
->getLastUsedRewriteRequestIncrement($match[1], $match[4], $storeId);
if ($lastRequestPath) {
$match[3] = $lastRequestPath;
}
return $match[1]
. (isset($match[3]) ? ($match[3]+1) : '1')
. $match[4];
In particular, these two lines
$match[3] = $lastRequestPath;
//...
. (isset($match[3]) ? ($match[3]+1) : '1')
//...
In case it's not obvious, there are cases where Magento will automatically append a 1 to a URL, and then continue to increment it. This makes the generation of those URLs dependent on system state when they were generated — there's no simple rule.
Other lines of interest in this file are
if (strpos($idPath, 'product') !== false) {
$suffix = $this->getProductUrlSuffix($storeId);
} else {
$suffix = $this->getCategoryUrlSuffix($storeId);
}
This $suffix will be used on the end of the URL as well, so those methods are worth investigating.
If all you're trying to do is remove numbers from the URL, you might be better off with a regular expression or some explode/implode string jiggering.

I have little to no idea why this works but this worked for me. Most probably because it makes urls non-unique. Magento ver. 1.7.0.2 had suddenly started adding numbers as suffixes to my new products' names, even if their url keys and names were different from the old products. On a hunch, I went to System -> Configuration -> Catalog -> Search Engine Optimizations -> Product URL Suffix and changed the default .html to -prod.html. I guess you could change it to any suffix you wanted to. Then I re-indexed my website, refreshed cache, and presto! All the numbers were gone from the product urls. The product urls now all have the format custom-product-name-prod.html. The canonical tag also shows custom-product-name-prod.html so I'm double happy.
Don't know if it'll work for others, but I hope it does. Do note that I did have old and new products with duplicate URLs and that I had disabled old products before doing this procedure. So if you have 2 products with the same url key and both are enabled, then this may NOT work for you.

There's a problem! As you look in the edit product you can see the link is correct but on your store the url is different.
Step 1: Edit the URL and add SS to the end of the custom url. Press
Save. \product-namess.html
Step 2: Go to Catalog -> URL Rewrite
Step 3: Narrow Down the Criteria to Include Only The Problem Situation.
Press Search.
Step 4: Download Jib Bit Mouse Recorder / Macro
Recorder. Its Free I pay.
Step 5: Edit the First Rewrite. Press
Delete and OK.
Step 6: Press Record on JitBit. Edit the 1st Rewrite.
Delete. OK. Press Stop.
Step 7: Drop Down Next to Play Select X
Times. Write the Number of Records. Press OK.
Step 8: Watch the
Program Delete All the Records for You.
Step 9: Catalog -> Manage
Products. Remove the SS from the end of the custom URL. Do not check
create redirect. Fixed.
Mine was 279 records of changing that product. So it took about an hour.

Related

I want to Understand - URL Parameter Showing me different prices

Please help me understand how this is happening:
I am monitoring one of my competitor's website products. But something strange happened and I am bit confused how this is possible.
Please see the urls below which leads to same product but showing me different prices.
https://www.werko.com.au/product/genuine-fuji-xerox-cwaa0751-waste-toner-bottle/
Price - $33.00
https://www.werko.com.au/product/genuine-fuji-xerox-cwaa0751-waste-toner-bottle/?gclid=EAIaIQobChMI5unSyImD3wIVRBSPCh2y3QNcEAsYASABEgJBpvD_BwE
Price - $31.57
If "?gclid=EAIaIQobChMI5unSyImD3wIVRBSPCh2y3QNcEAsYAS ABEgJBpvD_BwE" portion is of URL is added to any product URL it will show me the edited prices otherwise the old prices. How this is happening?
It's just a GET parameter (Query string) and the webpage is generated (on the server by the script) depending on it. The value itself (part after =) is just a random string here.
Edit: actually it's the Google Click ID which they also use to change the price. So if the Click ID is present, the price is lowered.

How do you print different templates in netsuite?

I am trying to find the correct template and id to use for a hotprint of an advanced pdf template of an Item Fulfillment.
The hot print url is (with the id bolded) https://system.na3.netsuite.com/app/accounting/print/hotprint.nl?regular=T&sethotprinter=T&id=7600&label=Packing%20Slip&printtype=packingslip&trantype=itemship&orgtrantype=TrnfrOrd&auxtrans=7605
For some reason only certain id=# seems to affect the outcome and the ids I have got to work for two different templates don't match the Custom Transaction Forms ID or the Advanced pdf script id. (example most ids=template 1, while 168,4954, and seemingly random other ids=template 2) I am very confused on how netsuite resolves the hot print url as it normally doesn't include the template= part though I have seen others use it for invoice print urls.
The parameters at the end of the url (the stuff after the ?) are used by Netsuite to control settings used by the webpage which prints the PDFs for you.
In this case, &id=##### refers to the internal id of the document you are printing. You can see this by going to the document, right clicking, selecting inspect, and typing nlapiGetRecordId() into the console. When you click Print, you should see that same number after &id=#####.
&template=### refers to the template you are printing. If you go to Customization -> Forms -> Advanced PDF/HTML Templates, you'll notice a Script ID field in the table. If you substitute the correct Script ID in for the number in &template=###, you'll notice you generate the same PDF. This Script ID acts the same as the number that was previously there.
The reason you're seeing unusual results when you change those numbers is because you're mismatching a record with a template not built for it. So it won't print exactly right, but will sometimes execute anyways.
Anyways, this sort of parameter scheme is a similar scheme to how Suitelets and Restlets work, so in the future, you might experience this sort of thing again.
EDIT: For those reading this in the future, please read the comments.
To customize a packing slip and return form:
If you are printing packing slips and need some customization, you can use a custom invoice form when printing packing slips. For example, you can customize an invoice form to hide the fulfilled item tax rate and amount, and the order total. Then, when you print the packing slip using the custom form through mass print, choose the the packing slip shows the customized information.

How to rewrite prestashop friendly urls? (not the htaccess file but url for each product)

For some reason in my shop some of the friendly urls are mixed up. For example I have a product with name "White wine glass 280 ml" and the friendly url is "250-red-wine-glass-300-ml.html". If I go to product edit page and select SEO and click generate URL than the url is corect and all is fine but I don't want to do that for each product in shop.
How can I do that for all the products at once?
I tried finding where are the urls stored in db to delete them and hope presta would autognerate them but I couldn't find where they are saved.
You have to do an override of Dispatcher.php class or use hookModulesRoutes in a Module.
Just create overrides/classes/Dispatcher.php and modify original methods/variable to get what you want to achieve here. You will have to modify how pages are grabed by PHP/Prestashop by altering the script getting the (for exemple) product ID and make a search inside your products url_rewrite to get the good one.
Honestly this is a tought job and lots of modules available are doing it very well, you should have a look as some are very cheap (less than 20$).

List all links present in a given website

I'd need a suggestion on the most effective way to list all links in a website. I am able to do it with either php vb and I have tried to do it with scrapy, but my problem is that with the first 2 it is not enough inputting the address of the website, I actually have to scrape the following links in my code, and with scrapy I have tried to list all susequent links in the page, but the spider seems never ending the research.
In otehr words I'd need to find out a way to input a website adress returning all links present in that website. I'd need to do that for a school project and I was thinking to do a small research on the retailing industry so I'd need to list up to 20 000 results for a given website.
any suggestions?
Scrapy is a perfect choice here. Use CrawlSpider with LinkExtractor.
The following spider would follow and gather all links on the website. Since there is an OffsiteMiddleware enabled by default - you would not get links from other domains.
from scrapy.item import Field, Item
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors import LinkExtractor
class SampleItem(Item):
link = Field()
class SampleSpider(CrawlSpider):
name = "sample_spider"
allowed_domains = ["domain.com"]
start_urls = ["http://domain.com"]
rules = (
Rule(LinkExtractor(), callback='parse_page', follow=True),
)
def parse_page(self, response):
item = SampleItem()
item['link'] = response.url
return item
If you want to limit the number of links and stop the spider after getting n links, use Close Spider extension and set CLOSESPIDER_ITEMCOUNT setting:
CLOSESPIDER_ITEMCOUNT
An integer which specifies a number of items. If the spider scrapes
more than that amount if items and those items are passed by the item
pipeline, the spider will be closed with the reason
closespider_itemcount. If zero (or non set), spiders won’t be closed
by number of passed items.
In your case you can also use CLOSESPIDER_PAGECOUNT setting instead.
Hope that helps.

opencart: product url after homepage and after category

I am using opencart 1.5.6.
Products on homepage (or somewhere else then the category) link to /product while when cicked from a category page it goed /category/product.
This means google thinks there's duplicate content, I don't like that so how can I solve this(so the url's are allways /categorie(/subcat)/product?
I would like all other pages also to have a clean seo url but when I installed the following extentions there happened nothing:
www.opencart.com/index.php?route=extension/extension/info&extension_id=15557&filter_search=seo%20url&filter_license=0&sort=e.downloaded&order=DESC&page=3
www.opencart.com/index.php?route=extension/extension/info&extension_id=15516
The url of the site:
http://publiekgeheim.com
You don't have to worry for duplicate content. As I can see you have the "canonical" link tag in the <head> of your products so you are ok. This tag tells search engines which url is the "correct" one and that the others are just produced by plugins, categorization, etc. So there is no duplicate content.
In opencart, unless you want to code and make scenarios and change your workflow the best way to generate the canonical tag is as is done now. That is, www.example.com/product . The reason is that the way opencart produces urls such as http://publiekgeheim.com/lingerie/Esprit/Esprit-Feel-Sexy-String, where the category path is included, is really unreliable. Eg, the following url http://publiekgeheim.com/stackoverflow/Goerge/wtf/Esprit-Feel-Sexy-String will also lead you to the product page!
If you still want to do it your way you will have to change this line in catalog/product/product.php:
$this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
And this is where the pain starts. You can use the getCategories method in catalog/model/catalog/product.php and get the categories where the product belongs to. But which one do you want to display? If you only assign one category to your products you are lucky. But if not? In a store of mine I even often assign a product in 2 categories that are essentially the same but belong to different parent categories in order to help users find the product more easily (since opencart doesn't allow putting links (to categories) as menu items in the top menu). If I wanted to follow your approach I would need to either use some extensions that allow me to put links in the top menu, but which create empty, duplicate categories in my sitemaps or use some mega menu that will totally replace the default top menu. And then new problems will arise. So, you see that depending on your use case it gets more and more complex.
And even if you manage to get past this (by for example choosing a random or the first category that is returned, or by assigning from now on a product only to one category) how are you going to find the parent categories in order to display the full path in the url? There is no such method in opencart and coding this is really ugly and will add at least 3 more db queries to the product page (I tried to calculate how many db queries are needed in order to produce the default opencart page and I counted at least 10).
So, all in all, and to avoid having tricky situations stick to the default canonicals unless you come up with a strict policy on how you upload and display products and some clever code.
Those extensions should work. Check your vqmod errors and compatibility.
I've sat with this problem for a couple of days now and have finally figured it out. 1.5.6.4
category/product instead of /product when linking from HOME and Related Products.
1. In /catalog/controller/module/showintabs.php
AFTER:
if ($this->config->get('config_review_status')) {
$rating = $result['rating'];
} else {
$rating = false;
}
ADD:
$categories = $this->model_catalog_product->getCategories($result['product_id']);
if(isset($categories[0]) && !empty($categories[0])){
$path = $categories[0]['category_id'];
}else{
$path = '';
}
AND in $products[] = array right below it
CHANGE:
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
TO
'href' => $this->url->link('product/product', 'path=' . $path . '&product_id=' . $result['product_id']),
2. In /catalog/controller/product/product.php
AFTER
if ($this->config->get('config_review_status')) {
$rating = (int)$result['rating'];
} else {
$rating = false;
}
ADD
$categories = $this->model_catalog_product->getCategories($result['product_id']);
if(isset($categories[0]) && !empty($categories[0])){
$path = $categories[0]['category_id'];
}else{
$path = '';
}
AND in $this->data['products'][] = array( right below it
CHANGE:
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
TO
'href' => $this->url->link('product/product', 'path=' . $path . '&product_id=' . $result['product_id']),

Resources