hello i nee dto customize my opencart manual invoice in admin.
id like to add disbaled products and enabled to my invoice. but only admin in administration can make it.
i tried to change this file:
system/library/cart/cart.php and in line 41
i replaced the line 41 query to
if (isset($this->session->data['api_id'])) {
$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_store p2s LEFT JOIN " . DB_PREFIX . "product p ON (p2s.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2s.product_id = '" . (int)$cart['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
} else {
$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_store p2s LEFT JOIN " . DB_PREFIX . "product p ON (p2s.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2s.product_id = '" . (int)$cart['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");
}
but its keepeing blocking me to add disabled products on admin manual invoice cart.
To check if admin is logged in use condition
if (isset($this->session->data['user_id']) && !empty($this->session- >data['user_token'])) {
// admin sql
}else{
// stock sql
}
The code below uses 2 tables "category_path" and "category_description" to get id=>name of all categories and sub-categories. Im bad at mySql, so I would appreciate if you help me.
In this function I need to also get values of 'cat_name' column FROM THE OTHER (third) table named 'category'
https://i.stack.imgur.com/1PC4A.jpg
public function getCategories($data = array()) {
$sql = "SELECT cp.category_id AS category_id,
GROUP_CONCAT(cd1.name ORDER BY cp.level SEPARATOR ' > ') AS name,
c1.parent_id, c1.sort_order
FROM " . DB_PREFIX . "category_path cp
LEFT JOIN " . DB_PREFIX . "category c1 ON (cp.category_id = c1.category_id)
LEFT JOIN " . DB_PREFIX . "category c2 ON (cp.path_id = c2.category_id)
LEFT JOIN " . DB_PREFIX . "category_description cd1 ON (cp.path_id = cd1.category_id)
LEFT JOIN " . DB_PREFIX . "category_description cd2 ON (cp.category_id = cd2.category_id)
WHERE cd1.language_id = '" . (int)$this->config->get('config_language_id') . "'
AND cd2.language_id = '" . (int)$this->config->get('config_language_id') . "'";
You are already using that category table in the first join and you gave it an alias of c1 so
SELECT cp.category_id AS category_id, c1.cat_name,
. . .
. . .
Tried to combine another query to my existing queries but failed.
Here is the working query without LEFT JOIN
$order_query = $this->db->query("SELECT * FROM " . DB_PREFIX .
"order_items WHERE order_id = '" . (int)$order_id . "'");
Below is the one tried to combined (not working)
$order_query = $this->db->query("SELECT * FROM " . DB_PREFIX .
"order_items WHERE order_id = '" . (int)$order_id . "'" LEFT JOIN .
DB_PREFIX ."item_description WHERE item_id= '" . (int)$item_id . "'"
);
Any idea where did i do wrong ?
You need to construct the join statement correctly. The WHERE clauses come in later.
$prefix = DB_PREFIX;
$sql = "
SELECT oi.* FROM {$prefix}order_items AS oi
LEFT JOIN {$prefix}item_description AS itd
ON oi.item_id = itd.item_id
WHERE oi.order_id = ?
AND itd.item_id = ?
";
$this->db->query($sql, [$order_id, $item_id]);
You can try this code
$order_query = $this->db->query("SELECT oi.* FROM " . DB_PREFIX ."order_items oi
LEFT JOIN ".DB_PREFIX ."item_description des on oi.order_id = des.order_id
WHERE oi.order_id = '" . (int)$order_id . "' and
des.item_id= '" . (int)$item_id . "'");
I've been trying to fix this PHP MySQL query all afternoon and am losing my mind! the following query works!:
$sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, o.shipping_code, o.total, o.channel, o.currency_code, o.currency_value, o.date_added, o.date_modified, c.image,
cg.name AS cgroup, CONCAT(o.payment_address_1, '<br>', o.payment_city, ', ', o.payment_zone, ' ', o.payment_postcode) AS address, o.telephone AS phone, o.email AS email,
(SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') .
"') AS order_status FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "customer` c ON(o.customer_id=c.customer_id) LEFT JOIN `" . DB_PREFIX . "customer_group_description`
cg ON(c.customer_group_id=cg.customer_group_id)";
but when I try to add the following to it it breaks.
(SELECT action FROM " . DB_PREFIX . "donate_history h LEFT JOIN " . DB_prefix . "order od ON (h.customer_id = od.customer_id)),
I dont if Im writing it right. I've rewritten it, removed parts, tried to make as simple as possible, but I can't fix it. This is what I've been trying :
$sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, o.shipping_code, o.total, o.channel, o.currency_code, o.currency_value, o.date_added, o.date_modified, c.image,
cg.name AS cgroup, CONCAT(o.payment_address_1, '<br>', o.payment_city, ', ', o.payment_zone, ' ', o.payment_postcode) AS address, o.telephone AS phone, o.email AS email,
(SELECT action FROM " . DB_PREFIX . "donate_history h LEFT JOIN " . DB_prefix . "order od ON (h.customer_id = od.customer_id)),
(SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') .
"') AS order_status FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "customer` c ON(o.customer_id=c.customer_id) LEFT JOIN `" . DB_PREFIX . "customer_group_description`
cg ON(c.customer_group_id=cg.customer_group_id)";
Looks like your new subquery you tried adding didn't have an alias.
SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, o.shipping_code, o.total, o.channel, o.currency_code, o.currency_value,
o.date_added, o.date_modified, c.image, cg.name AS cgroup, CONCAT(o.payment_address_1, '<br>', o.payment_city, ', ', o.payment_zone, ' ', o.payment_postcode) AS address,
o.telephone AS phone, o.email AS email,
(SELECT action
FROM " . DB_PREFIX . "donate_history h
LEFT JOIN " . DB_prefix . "order od
ON (h.customer_id = od.customer_id)) AS donate_history,
(SELECT os.name
FROM " . DB_PREFIX . "order_status os
WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') .
"') AS order_status
FROM `" . DB_PREFIX . "order` o
LEFT JOIN `" . DB_PREFIX . "customer` c
ON(o.customer_id=c.customer_id)
LEFT JOIN `" . DB_PREFIX . "customer_group_description` cg
ON(c.customer_group_id=cg.customer_group_id)
I have written sql code using group by and order by but in here order by not working can any one help me
SELECT " . DB_PREFIX . "leaderboard_scores.* , SUM(" . DB_PREFIX . "leaderboard_scores.score) as total_score, " . DB_PREFIX . "customer.firstname,
" . DB_PREFIX . "customer.lastname
FROM " . DB_PREFIX . "leaderboard_scores
JOIN " . DB_PREFIX . "customer ON " . DB_PREFIX . "leaderboard_scores.philips_store_id = " . DB_PREFIX . "customer.customer_id
GROUP BY " . DB_PREFIX . "leaderboard_scores.phi_store_id
ORDER BY " . DB_PREFIX . "leaderboard_scores.week DESC
This query work without php errors but given middle rows without giving top weeks. weeks store using times stamp
actual query
SELECT rc_leaderboard_scores.* , SUM(rc_leaderboard_scores.score)
as total_score, rc_customer.firstname, rc_customer.lastname
FROM rc_leaderboard_scores
JOIN rc_customer
ON rc_leaderboard_scores.phi_store_id = rc_customer.customer_id
GROUP BY rc_leaderboard_scores.phi_store_id
ORDER BY rc_leaderboard_scores.week DESC
If you need to return the last record for every customer, you need a JOIN with a subquery that returns MAX(week) for every customer id:
SELECT
rc_leaderboard_scores.*,
m.total_score,
rc_customer.firstname,
rc_customer.lastname
FROM
(SELECT phi_store_id,
MAX(`week`) as max_week,
SUM(score) as total_score,
FROM rc_leaderboard_scores
GROUP BY phi_store_id) m
INNER JOIN
rc_leaderboard_scores
ON rc_leaderboard_scores.phi_store_id = m.phi_store_id
AND rc_leaderboard_scores.`week` = m.max_week
INNER JOIN
rc_customer ON m.phi_store_id = rc_customer.customer_id