Stock Status in email order opencart - opencart

Hello my opencart version in 1.5.6.4
I am trying to make stock status to appear in email order.
I tried this on catalog/model/checkout.order.php
$order_product_info = $this->db->query("SELECT * FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product['product_id'] . "'");
'stock' => $order_product_info->row['stock_status_id'],
and in /template/mail/order.tpl
I have this
<?php echo $product['stock']; ?>
It is almost working but it appears as an id at the email. like (product_name) 5. But not appear status name...
5 s an example of stosck_status_is
Any idea on how to make it appear as text like "Available"

after you got an stosck_status_id you should retrieve from oc_stock_status table a name where the stosck_status_id is.
$order_product_status = $this->db->query("SELECT * FROM " . DB_PREFIX . "stock_status WHERE stosck_status_id = '" . (int)$order_product_info->row['stock_status_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
'stock_name' => $order_product_status->row['name'],

Related

Opencart search product model without full string

Opencart doesn't show me if I don't write the full name of the model. I want to search without the full name of the model.
public_html/catalog/model/catalog/product.php
LINE 140:
$sql .= " OR LCASE(p.model) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "%'";
LINE: 497:
$sql .= " OR LCASE(p.model) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "%'";

How to add SKU to Invoices

In OpenCart 3.0.2.0, I'm trying to get the Invoices pages to display the "SKU" variable for each product. The variable is in the database, along with other product data, but for some ungodly reason, OpenCart doesn't have an option to display it. You can display the product name, price, stock availability, etc, but not the SKU.
Does anyone know how to do this specifically in OC 3? They've switched from PHP to Twig for the templates, and I'm not sure what I'm doing wrong but the method I was using in OC 2.0 is NOT working in 3.0.
If you want SKU in order_invoice in admin side then, you have to modify as below:
admin/model/sale/order.php
find :
public function getOrderProducts($order_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
return $query->rows;
}
replace :
public function getOrderProducts($order_id) {
$query = $this->db->query("SELECT op.*,p.sku FROM " . DB_PREFIX . "order_product op LEFT JOIN " . DB_PREFIX . "product p on op.product_id = p.product_id WHERE order_id = '" . (int)$order_id . "'");
return $query->rows;
}
admin/controller/sale/order.php
in
`public function invoice()`
find:
`$product_data[] = array(
'name' => $product['name'],`
add after that :
`'sku' => $product['sku'],`
in admin/view/sale/order_invoice.twig
add:
`{{ product.sku }}`
So you have to fetch sku from product table first which is not available in default order invoice page.
Are you talking about it appearing in admin/view/sale/order_invoice.twig?
If so, first modify admin/controller/sale/order.php at around line 518:
foreach ($products as $product) {
$data['order_products'][] = array(
'product_id' => $product['product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']),
'quantity' => $product['quantity'],
'price' => $product['price'],
'total' => $product['total'],
'reward' => $product['reward']
);
}
include somewhere there (like after the model line, let's say), a line with:
'sku' => $product['sku'],
Then in admin/view/sale/order_invoice.twig add where ever you want it to appear with:
{{ product.sku }}
You'll have to stylize it or make a column for it as you see fit of course. Hopefully, this points you in the right direction.

I need to change the name of an text documente through a cicle

I need that this code create text documents but i need that the name change every time i create a new text document, an example will be that when execute the code it will create a text document named " aventura-1.txt " then why execute again and the name will be " aventura-2.txt" so on too " aventura-n.txt" How i can do that.?
sorry for my bad english btw, this is the code which i have.
import os
def adventure_path ( nombre_aventura) :
if not os. path . isdir (" aventuras ") :
os. mkdir (" aventuras ")
return " aventuras/ %s" %nombre_aventura
archivo = open ( adventure_path ("aventura-n.txt") ,"w")
print "hi"
print "bye"
archivo . close ()
You may use this code that I wrote once and tweaked a little for you...
It will:
check each file in a specific folder
split the names of these files at "." and "-", so we'll be able to catch only the number part of your .txt name (i'm assuming you'll have a specific folder that contains ONLY "aventura-n.txt" named like files)
add this number to a list
get the max value of the numbers list
add +1 to get the next version number
Code:
import os
nums = []
for item in os.listdir('path_to_folder'):
a = item.split(".")[0]
b = a.split("-")[1]
c = int(b)
nums.append(c)
next_num = max(nums) + 1
print next_num

Can't assign modules to System->Design->Layouts->Product in Opencart v.1.5.6.1

Opencart: v.1.5.6.1
Theme: Journal v.2.1.2 (http://themeforest.net/item/journal-premium-responsive-opencart-theme/4260361)
Apache: v.2.2.26
MySQL: v.5.5.36
php: v.5.4.22
I am trying to assign the Category module to
Layout: Product
Position: Column Right (or Left it doesn't matter)
It works in all other Layouts (Home, Information, Manufacturer etc) except from Product.
I changed to the Default Opencart theme and it doesn't work either!
Something is messed up with Product Layout !??! I thought of that, so I created a CustomProduct Layout (just like the original Product Layout) and...
Catalog -> Products -> Edit-A-Product -> Design -> Layout Override: CustomProduct
guess what... It worked!
No changes to Opencart's core files are made. Everything is vQmod (theme, extensions).
I have removed my vQmods (just in case I was doing something wrong)... still it doesn't work.
In catalog/controller/common/column_right.php line 38 I added...
echo $layout_id;
The value returned is id=4 (Default Layout). Shouldn't that be id=2 (Product Layout)?
Also, the value of the key "category_module" from table oc_setting...
a:1:{i:0;a:4:{s:9:"layout_id";s:1:"2";s:8:"position";s:12:"column_right";s:6:"status";s:1:"1";s:10:"sort_order";s:1:"1";}}
I thought it was something simple and I just couldn't see it. Now I have 2 days trying to figure out what has happened!
Any suggestions ?!
Because I had downloaded Opencart v.1.5.6.1 before its public release, I didn't had the correct file for catalog/model/catalog/product.php
I had this...
public function getProductLayoutId($product_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
if ($query->num_rows) {
return $query->row['layout_id'];
} else {
return $this->config->get('config_layout_id');
}
}
instead of this...
public function getProductLayoutId($product_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
if ($query->num_rows) {
return $query->row['layout_id'];
} else {
return false;
}
}
All credits go to user http://www.opencart-hellas.gr/memberlist.php?mode=viewprofile&u=2
Read all here http://www.opencart-hellas.gr/viewtopic.php?f=8&t=47 (it is in Greek).

Opencart list categories inside manufacturers

I have searched for hours but could not find an answer to this, or a module to help.
We are building a store and our client needs the ability to navigate the store by manufacturer. Is there any way that the manufacturer page can list the categories and subcategories.
There seems two ways to do it.
Add brands while adding categories in admin section.
Get all categories inside the brands by join operation while viewing the manufacturer.
Are there any modules available to link up categories with manufacturers so that I can display categories inside the manufacturer page.
Or the only way is to query all the products inside the manufacturer and get the categories out of it... I guess it is not a good solution.
So any suggestions would be a great help.
Thanks.
I figured a way to find the categories that belongs to a manufacturer. The second options seems better.
Here is the function that I added to catalog/model/catalog/manufacturer.php
public function getManufacturerCategories($manufacturer_id) {
$query = $this->db->query("
SELECT
DISTINCT c.category_id,cd.name
FROM
". DB_PREFIX . "manufacturer m
LEFT JOIN ". DB_PREFIX. "product p ON (m.manufacturer_id = p.manufacturer_id)
LEFT JOIN ". DB_PREFIX. "product_to_category p2c ON (p2c.product_id = p.product_id)
LEFT JOIN ". DB_PREFIX. "category c ON (c.category_id = p2c.category_id)
LEFT JOIN ". DB_PREFIX. "category_description cd ON (cd.category_id = p2c.category_id)
WHERE
p.status = 1
AND m.manufacturer_id = '".(int)$manufacturer_id."'
AND c.status= 1
");
return $query->rows;
}
Here is the output array
stdClass Object (
[row] => Array
(
[category_id] => 20
[name] => Desktops
)
[rows] => Array
(
[0] => Array
(
[category_id] => 20
[name] => Desktops
)
[1] => Array
(
[category_id] => 24
[name] => Phones & PDAs
)
)
[num_rows] => 2 )