Pragmatically disable payment method if not in specific zone opencart - php

How would i disable 'Cash On Delivery' payment method in opencart 2.x checkout if the selected address is from a zone_id that i don't want
I don't know the specific variable to do the logic; I have tried adding the logic below but it does not work
if (($this->config->get('cod_geo_zone_id')) == 1736) {
$status = true;
} else {
$status = false;
}
The complete code is as below in: catalog\model\payment\cod.php
<?php
class ModelPaymentCOD extends Model {
public function getMethod($address, $total) {
$this->load->language('payment/cod');
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('cod_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
if ($this->config->get('cod_total') > 0 && $this->config->get('cod_total') > $total) {
$status = false;
} elseif (!$this->config->get('cod_geo_zone_id')) {
$status = true;
} elseif ($query->num_rows) {
$status = true;
}
else {
$status = false;
}
if (($this->config->get('cod_geo_zone_id')) == 1736) {
$status = true;
} else {
$status = false;
}
/*$zonex = $address['zone_id'];
if ($zonex == 1736) {
$status = false;
}*/
$method_data = array();
if ($status) {
$method_data = array(
'code' => 'cod',
'title' => $this->language->get('text_title'),
'terms' => '',
'sort_order' => $this->config->get('cod_sort_order')
);
}
return $method_data;
}
}
Any help will be appreciated

Related

delete one row in foreach

I'm using php CRM that the following code exports the list of all users in database (this list is shown by admin users)
foreach ($rResult as $aRow) {
$row = array();
for ($i = 0; $i < count($aColumns); $i++) {
if (strpos($aColumns[$i], 'as') !== false && !isset($aRow[$aColumns[$i]])) {
$_data = $aRow[strafter($aColumns[$i], 'as ')];
} else {
$_data = $aRow[$aColumns[$i]];
}
if ($aColumns[$i] == 'last_login') {
if ($_data != null) {
$_data = time_ago($_data);
} else {
$_data = 'Never';
}
} elseif ($aColumns[$i] == 'active') {
$checked = '';
if ($aRow['active'] == 1) {
$checked = 'checked';
}
$_data = '<div class="onoffswitch">
<input type="checkbox" data-switch-url="'.admin_url().'staff/change_staff_status" name="onoffswitch" class="onoffswitch-checkbox" id="c_'.$aRow['staffid'].'" data-id="'.$aRow['staffid'].'" ' . $checked . '>
<label class="onoffswitch-label" for="c_'.$aRow['staffid'].'"></label>
</div>';
// For exporting
$_data .= '<span class="hide">' . ($checked == 'checked' ? _l('is_active_export') : _l('is_not_active_export')) . '</span>';
} elseif ($aColumns[$i] == 'firstname') {
$_data = '<a href="' . admin_url('staff/profile/' . $aRow['staffid']) . '">' . staff_profile_image($aRow['staffid'], array(
'staff-profile-image-small'
)) . '</a>';
$_data .= ' ' . $aRow['firstname'] . ' ' . $aRow['lastname'] . '';
} elseif ($aColumns[$i] == 'email') {
$_data = '' . $_data . '';
} else {
if (strpos($aColumns[$i], 'date_picker_') !== false) {
$_data = (strpos($_data, ' ') !== false ? _dt($_data) : _d($_data));
}
}
$row[] = $_data;
}
$options = icon_btn('staff/member/' . $aRow['staffid'], 'pencil-square-o');
if (has_permission('staff', '', 'delete') && $output['iTotalRecords'] > 1 && $aRow['staffid'] != get_staff_user_id()) {
$options .= icon_btn('#', 'remove', 'btn-danger', array(
'onclick'=>'delete_staff_member('.$aRow['staffid'].'); return false;',
));
}
$row[] = $options;
$output['aaData'][] = $row;
}
Ther are 5 admin in the database;
I want to hide one user with staffid = 1 as a backdoor.
How can I delete row with this staffid ?
(I'm not familiar with PHP coding)
Thanks
You can add an if() condition like below:-
foreach ($rResult as $aRow) {
if($aRow['staffid'] !=1){
//complete code inside if
}
}
Note:- I assume that $aRow have staffid as an index

Blockchain suddenly stopped working

[Bitcoin stopped generating bitcoin address, It used to work 2 days before, Suddenly it stopped working. I think blockchain had made changes. Please help. I saw blockchain was upgrading. so They might have made some changes.
<?php
/**
*
* # EvolutionScript FULL DECODED & NULLED
*
* # Version : 5.1
* # Author : MTIMER
* # Release on : 2014-09-01
* # Website : http://www.mtimer.net
*
**/
if (!defined("EvolutionScript")) {
exit("Hacking attempt...");
}
if ($_SESSION['logged'] != "yes") {
header("location: ./");
exit();
}
$blockchain_root = "https://blockchain.info/";
if (is_numeric($input->g['order'])) {
$orderid = $db->real_escape_string($input->gc['order']);
$chk = $db->fetchOne("SELECT COUNT(id) AS NUM FROM blockchain_requests WHERE id=" . $orderid . "
AND user_id=" . $user_info['id']);
if ($chk == 0) {
header("location: ./?view=account");
exit();
}
else {
$bc_address = $db->fetchOne("SELECT account FROM gateways WHERE id=8");
$order = $db->fetchRow("SELECT * FROM blockchain_requests WHERE id=" . $orderid);
$timeleft = TIMENOW - 10800;
if ($order['bc_address'] == "" || $order['date'] < $timeleft) {
$callback_url = $settings['site_url'] . "modules/gateways/bcstatus.php?order=" .
$order['id'] . "&secret=" . $order['code'] . "&membership=" . $order['membership'];
$response = json_decode(file_get_contents($blockchain_root . "api/receive?
method=create&callback=" . urlencode($callback_url) . "&address=" . $bc_address));
$account_address = $response->input_address;
$db->query("UPDATE blockchain_requests SET bc_address='" . $account_address . "',
date=" . TIMENOW . (" WHERE id=" . $order['id']));
}
else {
$account_address = $order['bc_address'];
}
require SMARTYLOADER;
$smarty->assign("amount", $order['btc_amount']);
$smarty->assign("account", $account_address);
$smarty->assign("blockchain_root", $blockchain_root);
$smarty->assign("file_name", "blockchain.tpl");
$smarty->display("account.tpl");
exit();
}
}
if (is_numeric($input->p['amount']) && isset($input->p['type'])) {
$amount = number_format($input->pc['amount'], 2, ".", "");
if ($input->p['type'] == "deposit") {
$minimum_deposit = $db->fetchOne("SELECT min_deposit FROM gateways WHERE id=8");
if ($amount < $minimum_deposit) {
exit("Error");
}
}
$upgrade_id = (!is_numeric($input->p['membership']) ? 0 : $input->p['membership']);
$btc_amount = file_get_contents($blockchain_root . "tobtc?currency=USD&value=" . $amount);
$data = array("user_id" => $user_info['id'], "amount" => $amount, "btc_amount" => $btc_amount, "type"
=> $input->pc['type'], "membership" => $upgrade_id, "code" => substr(md5("block" . TIMENOW . "bc"), 4, 15),
"date" => TIMENOW);
$db->insert("blockchain_requests", $data);
$orderid = $db->lastInsertId();
header("location: ./?view=blockchain&order=" . $orderid);
exit();
return 1;
}
header("location: ./?view=account");
exit();
?>

Add text shipping value in Opencart

We provide emailed quotes after an order is recieved in OpenCart. How can I add a field to show TBC instead of £0.00 in OpenCart. We use X-Shipping for our 4 delivery options:
Is this possible?
Here is the PHP code for the catalog side
<?php
class ModelShippingXshipping extends Model {
function getQuote($address) {
$this->load->language('shipping/xshipping');
$method_data = array();
$quote_data = array();
for($i=1;$i<=12;$i++)
{
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('xshipping_geo_zone_id'.$i) . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
if (!$this->config->get('xshipping_geo_zone_id'.$i)) {
$status = true;
} elseif ($query->num_rows) {
$status = true;
} else {
$status = false;
}
if (!$this->config->get('xshipping_status'.$i)) {
$status = false;
}
if (!$this->config->get('xshipping_name'.$i)) {
$status = false;
}
$shipping_cost=$this->config->get('xshipping_cost'.$i);
$free_shipping_cost=(float)$this->config->get('xshipping_free'.$i);
if(empty($free_shipping_cost))$free_shipping_cost=0;
if ($this->cart->getSubTotal() >= $free_shipping_cost && $free_shipping_cost!=0) {
$shipping_cost = 0;
}
if ($status) {
$quote_data['xshipping'.$i] = array(
'code' => 'xshipping'.'.xshipping'.$i,
'title' => $this->config->get('xshipping_name'.$i),
'cost' => $shipping_cost,
'tax_class_id' => $this->config->get('xshipping_tax_class_id'.$i),
'text' => $this->currency->format($this->tax->calculate($shipping_cost, $this->config->get('xshipping_tax_class_id'.$i), $this->config->get('config_tax')))
);
}
}
if(!$quote_data) return array();
$method_data = array(
'code' => 'xshipping',
'title' => $this->language->get('text_title'),
'quote' => $quote_data,
'sort_order' => $this->config->get('xshipping_sort_order'),
'error' => ''
);
return $method_data;
}
}
?>

Undefined offset: 0 (Oscommerce bm.categories.php)

I have an issue with a file in oscommerce. In a customized bm_categories.php file I get a error:
Notice: Undefined offset: 0 in xxx\includes\modules\boxes\bm_categories.php on line 52
Here is the code.
I have marked Line 52 with : //THIS IS LINE 52//
I really hope someone can give me a hint.
Here is the code:
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2010 osCommerce
Released under the GNU General Public License
Modfied by Kevin Neufeld
Date: Novemeber 16, 2010
Released as contributions: Decenber 9th, 2010
*/
class bm_categories {
var $code = 'bm_categories';
var $group = 'boxes';
var $title;
var $description;
var $sort_order;
var $enabled = false;
function bm_categories() {
$this->title = MODULE_BOXES_CATEGORIES_TITLE;
$this->description = MODULE_BOXES_CATEGORIES_DESCRIPTION;
if ( defined('MODULE_BOXES_CATEGORIES_STATUS') ) {
$this->sort_order = MODULE_BOXES_CATEGORIES_SORT_ORDER;
$this->enabled = (MODULE_BOXES_CATEGORIES_STATUS == 'True');
$this->group = ((MODULE_BOXES_CATEGORIES_CONTENT_PLACEMENT == 'Left Column') ? 'boxes_column_left' : 'boxes_column_right');
}
}
function tep_show_category($counter) {
global $tree, $categories_string, $cPath_array, $pCounter; //added $pCounter
//additional Variables
//$pCounter is also globally defined and initialized in getData() and gets changed at the end of this function
$nCounter = $tree[$counter]['next_id'];
//Get item Levels
if($pCounter == 0){
$pLevel = 0;
}else{
$pLevel = $tree[$pCounter]['level'];
}
$cLevel = $tree[$counter]['level'];
//<---- THIS IS LINE 52 ------>//
$nLevel = $tree[$nCounter]['level'];
//Start of UnsortedList <ul> if Category level > 0
if($cLevel > 0){
if($cLevel != $pLevel){
$categories_string .= '<ul class="level ' . $cLevel . '">';
}
}
//Start of ListItem <li> and determines if List Item is Current
if (isset($cPath_array) && in_array($counter, $cPath_array)) {
if($cLevel == 0){
$categories_string .= '<li id="current" class=" active item'.$counter.'"><a href="';
}else{
$categories_string .= '<li class="item'.$counter.'"><a href="';
}
}else{
$categories_string .= '<li class="item'.$counter.'"><a href="';
}
//Gets and inserts URL path for link
if ($tree[$counter]['parent'] == 0) {
$cPath_new = 'cPath=' . $counter;
} else {
$cPath_new = 'cPath=' . $tree[$counter]['path'];
}
$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';
//Gets CatgoryCounts if Set in Admin -- Seperator is also located here
if (SHOW_COUNTS == 'true') {
$products_in_category = tep_count_products_in_category($counter);
if ($products_in_category > 0) {
$showCount_string = '<span class="countSeperator"> » </span><span class="showCounts">[' . $products_in_category . ']</span>';
}
}
//Start of Span <span> around Category Name
if (isset($cPath_array) && in_array($counter, $cPath_array)) {
$categories_string .= '<span class="itemParentName">' . $tree[$counter]['name'] . '</span></a>';
} else {
$categories_string .= '<span class="itemName">'. $tree[$counter]['name'] . '</span></a></li>';
}
//This is used to determin the level and place the correct number of closing tags
if($cLevel > 0){
if ($cLevel > $nLevel){
$j = abs($cLevel - $nLevel);
$categories_string .= str_repeat('</ul></li>', $j);
}elseif ($nCounter == false){
$categories_string .= str_repeat('</ul></li>', $tree[$counter]['level']);
}
}
$pCounter = $counter;
if ($tree[$counter]['next_id'] != false) {
$this->tep_show_category($tree[$counter]['next_id']);
}
}
function getData() {
global $categories_string, $tree, $languages_id, $cPath, $cPath_array, $pCounter; //added $pCounter
$pCounter = 0; //initialize $pCounter
$categories_string = '';
$tree = array();
$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_status = 1 and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
while ($categories = tep_db_fetch_array($categories_query)) {
$tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
'parent' => $categories['parent_id'],
'level' => 0,
'path' => $categories['categories_id'],
'next_id' => false);
if (isset($parent_id)) {
$tree[$parent_id]['next_id'] = $categories['categories_id'];
}
$parent_id = $categories['categories_id'];
if (!isset($first_element)) {
$first_element = $categories['categories_id'];
}
}
if (tep_not_null($cPath)) {
$new_path = '';
reset($cPath_array);
while (list($key, $value) = each($cPath_array)) {
unset($parent_id);
unset($first_id);
$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_status = 1 and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
if (tep_db_num_rows($categories_query)) {
$new_path .= $value;
while ($row = tep_db_fetch_array($categories_query)) {
$tree[$row['categories_id']] = array('name' => ''.$row['categories_name'],
'parent' => $row['parent_id'],
'level' => $key+1,
'path' => $new_path . '_' . $row['categories_id'],
'next_id' => false);
if (isset($parent_id)) {
$tree[$parent_id]['next_id'] = $row['categories_id'];
}
$parent_id = $row['categories_id'];
if (!isset($first_id)) {
$first_id = $row['categories_id'];
}
$last_id = $row['categories_id'];
}
$tree[$last_id]['next_id'] = $tree[$value]['next_id'];
$tree[$value]['next_id'] = $first_id;
$new_path .= '_';
} else {
break;
}
}
}
$this->tep_show_category($first_element);
$data = '<div id="categoryBoxContainer" class="ui-widget infoBoxContainer">' .
' <div class="ui-widget-header infoBoxHeading">' . MODULE_BOXES_CATEGORIES_BOX_TITLE . '</div>' .
' <div class="ui-widget-content infoBoxContents" style="background-color:#f5f5f5; border:none;"><ul class="menu">' . $categories_string . '</ul></div>' .
'</div>';
return $data;
}
function execute() {
global $SID, $oscTemplate;
if ((USE_CACHE == 'true') && empty($SID)) {
$output = tep_cache_categories_box();
} else {
$output = $this->getData();
}
$oscTemplate->addBlock($output, $this->group);
}
function isEnabled() {
return $this->enabled;
}
function check() {
return defined('MODULE_BOXES_CATEGORIES_STATUS');
}
function install() {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Categories Module', 'MODULE_BOXES_CATEGORIES_STATUS', 'True', 'Do you want to add the module to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_BOXES_CATEGORIES_CONTENT_PLACEMENT', 'Left Column', 'Should the module be loaded in the left or right column?', '6', '1', 'tep_cfg_select_option(array(\'Left Column\', \'Right Column\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_BOXES_CATEGORIES_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
}
function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array('MODULE_BOXES_CATEGORIES_STATUS', 'MODULE_BOXES_CATEGORIES_CONTENT_PLACEMENT', 'MODULE_BOXES_CATEGORIES_SORT_ORDER');
}
}
?>
Do this. if $tree has index 0 then get its value else set it to empty string or whatever you want
$nLevel = isset($tree[$nCounter]['level']) ? $tree[$nCounter]['level'] : '';
It means, that your array has no key with the value 0. Check the $tree array:
var_dump( $tree );
and see what's inside there.
Seems, that:
$nCounter = $tree[$counter]['next_id'];
has no value in it; might id be, that there is no next_id ? If so, then check with isset before posting it:
$nLevel = (isset($tree[$nCounter]['level']) ? $tree[$nCounter]['level'] : '');
or add the same check when setting nCounter:
$nCounter = (isset($tree[$counter]['next_id']) ? $tree[$counter]['next_id'] : 0);

How can I create custom SEO-friendly URLs in OpenCart?

How can you customize system URLs in OpenCart? For example, I would like http://example.com/index.php?route=checkout/cart to be displayed as http://example.com/cart
I know OpenCart provides SEO URLs for products, categories, manufacturers and information pages, but it doesn't look like there is anything built-in (at least prior to version 1.5.0) for anything else.
It turns out this can be done with a relatively simple change to a single file. No .htaccess rewrite rules, simply patch the catalog/controller/common/seo_url.php file and add your pretty URLs to an existing database table.
The patch to seo_url.php:
Index: catalog/controller/common/seo_url.php
===================================================================
--- catalog/controller/common/seo_url.php (old)
+++ catalog/controller/common/seo_url.php (new)
## -48,7 +42,12 ##
$this->request->get['route'] = 'product/manufacturer/product';
} elseif (isset($this->request->get['information_id'])) {
$this->request->get['route'] = 'information/information';
- }
+ } else {
+ $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($this->request->get['_route_']) . "'");
+ if ($query->num_rows) {
+ $this->request->get['route'] = $query->row['query'];
+ }
+ }
if (isset($this->request->get['route'])) {
return $this->forward($this->request->get['route']);
## -88,7 +87,15 ##
}
unset($data[$key]);
- }
+ } else {
+ $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($data['route']) . "'");
+
+ if ($query->num_rows) {
+ $url .= '/' . $query->row['keyword'];
+
+ unset($data[$key]);
+ }
+ }
}
}
There are two edits required. The first extends the index() function to look in the url_alias table for any keyword matching $this->request->get['_route_'].
The second extends the rewrite() function to look in the url_alias table for all routes, not just those for products, manufacturers, and information pages.
Adding entries to the database:
INSERT INTO `url_alias` (`url_alias_id`, `query`, `keyword`) VALUES
(NULL, 'checkout/cart', 'cart');
That's it. http://example.com/cart should return the same thing that http://example.com/index.php?route=checkout/cart does, and OpenCart should recognize $this->url->link('checkout/cart'); and return a link to the pretty URL http://example.com/cart
I'm using Opencart version 1.5.5.1 and this is the exact code that worked for me:
<?php
class ControllerCommonSeoUrl extends Controller {
/* SEO Custom URL */
private $url_list = array (
'common/home' => '',
'checkout/cart' => 'cart',
'account/register' => 'register',
'account/wishlist' => 'wishlist',
'checkout/checkout' => 'checkout',
'account/login' => 'login',
'product/special' => 'special',
'affiliate/account' => 'affiliate',
'checkout/voucher' => 'voucher',
'product/manufacturer' => 'brand',
'account/newsletter' => 'newsletter',
'account/order' => 'order',
'account/account' => 'account',
'information/contact' => 'contact',
'account/return/insert' => 'return',
'information/sitemap' => 'sitemap',
);
/* SEO Custom URL */
public function index() {
// Add rewrite to url class
if ($this->config->get('config_seo_url')) {
$this->url->addRewrite($this);
}
// Decode URL
if (isset($this->request->get['_route_'])) {
$parts = explode('/', $this->request->get['_route_']);
foreach ($parts as $part) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
if ($query->num_rows) {
$url = explode('=', $query->row['query']);
if ($url[0] == 'product_id') {
$this->request->get['product_id'] = $url[1];
}
if ($url[0] == 'category_id') {
if (!isset($this->request->get['path'])) {
$this->request->get['path'] = $url[1];
} else {
$this->request->get['path'] .= '_' . $url[1];
}
}
if ($url[0] == 'manufacturer_id') {
$this->request->get['manufacturer_id'] = $url[1];
}
if ($url[0] == 'information_id') {
$this->request->get['information_id'] = $url[1];
}
} else {
$this->request->get['route'] = 'error/not_found';
}
}
/* SEO Custom URL */
if ( $_s = $this->setURL($this->request->get['_route_']) ) {
$this->request->get['route'] = $_s;
}/* SEO Custom URL */
if (isset($this->request->get['product_id'])) {
$this->request->get['route'] = 'product/product';
} elseif (isset($this->request->get['path'])) {
$this->request->get['route'] = 'product/category';
} elseif (isset($this->request->get['manufacturer_id'])) {
$this->request->get['route'] = 'product/manufacturer/info';
} elseif (isset($this->request->get['information_id'])) {
$this->request->get['route'] = 'information/information';
}
if (isset($this->request->get['route'])) {
return $this->forward($this->request->get['route']);
}
}
}
public function rewrite($link) {
$url_info = parse_url(str_replace('&', '&', $link));
$url = '';
$data = array();
parse_str($url_info['query'], $data);
foreach ($data as $key => $value) {
if (isset($data['route'])) {
if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
} elseif ($key == 'path') {
$categories = explode('_', $value);
foreach ($categories as $category) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
}
}
unset($data[$key]);
}
/* SEO Custom URL */
if( $_u = $this->getURL($data['route']) ){
$url .= $_u;
unset($data[$key]);
}/* SEO Custom URL */
}
}
if ($url) {
unset($data['route']);
$query = '';
if ($data) {
foreach ($data as $key => $value) {
$query .= '&' . $key . '=' . $value;
}
if ($query) {
$query = '?' . trim($query, '&');
}
}
return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
} else {
return $link;
}
}
/* SEO Custom URL */
public function getURL($route) {
if( count($this->url_list) > 0) {
foreach ($this->url_list as $key => $value) {
if($route == $key) {
return '/'.$value;
}
}
}
return false;
}
public function setURL($_route) {
if( count($this->url_list) > 0 ){
foreach ($this->url_list as $key => $value) {
if($_route == $value) {
return $key;
}
}
}
return false;
}/* SEO Custom URL */
}
?>
A simple "no code" method is to install vQmod.
Instructions here:
vQmod install wiki
And then upload the xml file available in this Opencart forum thread to the vqmod/xml/ folder.
The xml contains a relatively easy to read script that maps the urls similar to the two answers above, but without modifying core files. So site updates will not kill it.
Put this near the top of your index.php file. It was the only solution that worked for me.
switch($_SERVER["REQUEST_URI"])
{
case '/old-url': $three01 = "/new-url"; break;
}
if($three01)
{
header("HTTP/1.1 301 Moved Permanently"); header("Location: ".$three01); exit;
}
vQmod xml file
<modification>
<id>Seo All Alias</id>
<version>1.0</version>
<vqmver>2.1.7</vqmver>
<author>noname</author>
<file name="catalog/controller/common/seo_url.php">
<operation>
<search position="after" offset="2"><![CDATA[
$this->request->get['route'] = 'information/information';
]]></search>
<add><![CDATA[
else {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($this->request->get['_route_']) . "'");
if ($query->num_rows) {
$this->request->get['route'] = $query->row['query'];
}
}
]]></add>
</operation>
<operation>
<search position="after" offset="1" index="2"><![CDATA[
unset($data[$key]);
]]></search>
<add><![CDATA[
else {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($data['route']) . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
}
]]></add>
</operation>
</file>
OpenCart SEO for OpenCart 1.5.X free :)
You can use as you wish. Category Name / ID / ID for quicker SEO resolving
<?php
class ControllerCommonSeoUrl extends Controller {
/* SEO Custom URL */
private $url_list = array (
'common/home' => 'home',
'checkout/cart' => 'cart',
'account/register' => 'register',
'account/wishlist' => 'wishlist',
'checkout/checkout' => 'checkout',
'account/login' => 'login',
'product/special' => 'special',
'affiliate/account' => 'affiliate',
'checkout/voucher' => 'voucher',
'product/manufacturer' => 'brand',
'account/newsletter' => 'newsletter',
'account/order' => 'order',
'account/account' => 'account',
'information/contact' => 'contact',
'account/return/insert' => 'return/insert',
'information/sitemap' => 'sitemap',
);
/* SEO Custom URL */
public function index() {
// Add rewrite to url class
if ($this->config->get('config_seo_url')) {
$this->url->addRewrite($this);
}
// Decode URL
if (isset($this->request->get['_route_'])) {
$parts = explode('/', $this->request->get['_route_']);
if ( count($parts) > 1 ) {
if ($parts[1] == 'category'){
$this->request->get['path'] = $parts[2];
for ( $i = 3 ; $i < count($parts); $i++) {
$this->request->get['path'] .= '_' . $parts[$i];
}
}elseif( $parts[1] == 'item' ) {
$this->request->get['product_id'] = $parts[2];
}
}
foreach ($parts as $part) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
if ($query->num_rows) {
$url = explode('=', $query->row['query']);
if ($url[0] == 'product_id') {
$this->request->get['product_id'] = $url[1];
}
if ($url[0] == 'category_id') {
if (!isset($this->request->get['path'])) {
$this->request->get['path'] = $url[1];
} else {
$this->request->get['path'] .= '_' . $url[1];
}
}
if ($url[0] == 'manufacturer_id') {
$this->request->get['manufacturer_id'] = $url[1];
}
if ($url[0] == 'information_id') {
$this->request->get['information_id'] = $url[1];
}
} else {
$this->request->get['route'] = 'error/not_found';
}
}
/* SEO Custom URL */
if ( $_s = $this->setURL($this->request->get['_route_']) ) {
$this->request->get['route'] = $_s;
}/* SEO Custom URL */
if (isset($this->request->get['product_id'])) {
$this->request->get['route'] = 'product/product';
} elseif (isset($this->request->get['path'])) {
$this->request->get['route'] = 'product/category';
} elseif (isset($this->request->get['manufacturer_id'])) {
$this->request->get['route'] = 'product/manufacturer/product';
} elseif (isset($this->request->get['information_id'])) {
$this->request->get['route'] = 'information/information';
}
if (isset($this->request->get['route'])) {
return $this->forward($this->request->get['route']);
}
}
}
public function rewrite($link) {
if ($this->config->get('config_seo_url')) {
$url_data = parse_url(str_replace('&', '&', $link));
$url = '';
$data = array();
parse_str($url_data['query'], $data);
foreach ($data as $key => $value) {
if (isset($data['route'])) {
if ( (($data['route'] == 'product/manufacturer/product' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");
if ($query->num_rows) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
}
} elseif( $key == 'product_id' ) {
$url = '/shop/item/'.$value;
unset($data[$key]);
}elseif ($key == 'path') {
$categories = explode('_', $value);
$url = '/shop/category';
foreach ($categories as $category) {
$url .= '/'.$category;
}
unset($data[$key]);
}//
/* SEO Custom URL */
if( $_u = $this->getURL($data['route']) ){
$url .= $_u;
unset($data[$key]);
}/* SEO Custom URL */
}
}
if ($url) {
unset($data['route']);
$query = '';
if ($data) {
foreach ($data as $key => $value) {
$query .= '&' . $key . '=' . $value;
}
if ($query) {
$query = '?' . trim($query, '&');
}
}
return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
} else {
return $link;
}
} else {
return $link;
}
}
/* SEO Custom URL */
public function getURL($route) {
if( count($this->url_list) > 0) {
foreach ($this->url_list as $key => $value) {
if($route == $key) {
return '/'.$value;
}
}
}
return false;
}
public function setURL($_route) {
if( count($this->url_list) > 0 ){
foreach ($this->url_list as $key => $value) {
if($_route == $value) {
return $key;
}
}
}
return false;
}/* SEO Custom URL */
}
?>
Depending on the level of customization you need, there are a few extensions available, including free ones.
This one works both on OpenCart 1.5 and OpenCart 2 and seems quite customizable. However it does not support customization of hardcoded URL parts like "checkout/cart" or "account/wishlist".
Here is a vQmod for OpenCart 2.0 (might work with 1.5, not tested) which applies to the forementioned extension and allows to change these hardcoded strings into whatever you want, and support multilanguage websites.
E.g. "checkout/cart" will become "cart" for English, "panier" for French, etc.
here is a free Extension that adds custom SEO URLs, as well as lets you manage multi-langauge URLs, 404s, export/import, and bulk edit.
SEO Module URL
Hey, before you click down, check the extension. It is my extension, I know that it is coded properly and it does exactly what the user asks for and much more and it is FREE.
I really hope it helps someone.

Categories