Post by wenza8 » Fri Apr 01, 2016 4:56 pm

Hi, I know oc 1.5 is old but I'm still can not move on ;D

So, I need a help. I want to make a button link in admin product list that will open a blank product detail in frontpage with seo url. I can do this using this in .tpl but this is not what I want because this is not seo url

<a target="_blank" href="../index.php?route=product/product&product_id=<?php echo $product_name['product_id']; ?>"><?php echo $product_name['text']; ?></a>

I've successfully make the frontpage become seo url, so the only problem is the link from admin page.

Any help please?

Newbie

Posts

Joined
Mon May 04, 2015 9:48 pm

Post by oc-extensions » Sat Apr 02, 2016 7:44 am

Hi,

In product list you can use keyword;

Assuming that SEO url is enabled then in area:

Code: Select all

$this->data['products'][] = array(
	'product_id' => $result['product_id'],
	'name'       => $result['name'],
         ..................................
        'front_product_url' => HTTP_CATALOG . $result['keyword'],               
	'action'     => $action
);
Now in tpl file, you can create new button

Code: Select all

<a href="<?php echo $product['front_product_url']; ?>" target="_blank"> View product in front store </a>

Image | Extensions and Custom Development


User avatar
Active Member

Posts

Joined
Fri Jan 06, 2012 11:31 pm

Post by wenza8 » Mon Apr 04, 2016 10:51 am

Hi oc-extension, thank for the help.
I've tried it but there is an error Notice: Undefined index: keyword
Did I miss something?

Newbie

Posts

Joined
Mon May 04, 2015 9:48 pm

Post by oc-extensions » Mon Apr 04, 2016 3:57 pm

Hi,

Change like this:
'front_product_url' => $this->model_catalog_product->getProductFrontURL($result['product_id']),
Then in admin/model/catalog/product.php define new function

Code: Select all

private function getProductKeyword($product_id) {
     $sql = "SELECT keyword FROM " . DB_PREFIX . "url_alias WHERE query = 'product_id=" . (int)$product_id . "'";
     $query = $this->db->query($sql);
    
     if ($query->num_rows) {
         return $query->row['keyword'];
     }

     return false;
}

public function getProductFrontURL($product_id) {
     $keyword = $this->getProductKeyword($product_id);

     $product_url = HTTP_CATALOG;

     if ($keyword) {
         $product_url .= $keyword;
     } else {
         $product_url .= 'index.php?route=product/product&product_id=' . $product_id;
     }
     
     return $product_url;
}
Of course you can get keyword directly in getProducts function ........

Image | Extensions and Custom Development


User avatar
Active Member

Posts

Joined
Fri Jan 06, 2012 11:31 pm

Post by wenza8 » Tue Apr 05, 2016 10:51 am

Thanks a lot oc-extension :D

Newbie

Posts

Joined
Mon May 04, 2015 9:48 pm
Who is online

Users browsing this forum: No registered users and 71 guests