Querying the Name, URL of a Product in Magento 1

Getting a Product URL Potentially confusing because of the 3 methods you could use, all of them in Mage_Catalog_Model_Product:
public function getUrlPath ($ category = null) public function getUrlInStore ($ params = array ()) public function getProductUrl ($ useSid = null)

The best way to explain it is simply to show the results of multiple calls. Given a product whose URL key is mondrian-large-coffee-table-set-multicolour in the field of http: //made.local, the results are:

$ product-> getUrlPath (); 'mondrian-large-coffee-table-set-multicolour' $ product-> getUrlPath ($ category); 'tables / mondrian-large-coffee-table-set-multicolour' // you can not stop this method adding ___store to the URL, even by setting _store_to_url to false $ product-> getUrlInStore (); 'http: //made.local/tables/mondrian-large-coffee-table-set-multicolour? ___ store = default' // you can not stop this method adding ___store to the URL, even by setting _store_to_url to false // note - see the "using _ignore_category" section below for an arguable bug with this $ product-> getUrlInStore (array ('_ ignore_category' => true)); 'http: //made.local/mondrian-large-coffee-table-set-multicolour? ___ store = default' $ product-> getProductUrl (); 'http: //made.local/tables/mondrian-large-coffee-table-set-multicolour' $ product-> getProductUrl (true); 'http: //made.local/tables/mondrian-large-coffee-table-set-multicolour'

Example showing loading of product object by ID

$ product = Mage :: getModel ('catalog / product') -> load ($ id_product); $ message = '<a href ='. $ product-> getUrlPath (). '> Click Here:'. $ product-> getName (). '</a>';

Rate This Article!

Click on the stars to give a note of 1 to 5.

1 star2 stars3 stars4 stars5 stars (No Ratings Yet)
Loading ...

Doubts? Make a comment below or send us a message by clicking here.

Your email address will not be published. Required fields are marked with *