Opencart search product model without full string - opencart

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'])) . "%'";

Related

Stock Status in email order 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'],

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.

RegEx PowerShell match

I have the following website http://www.shazam.com/charts/top-100/australia which displays songs, I want to capture the songs using RegEx & PowerShell. The PowerShell code below is what I have so far:
$ie = New-Object -comObject InternetExplorer.Application
$ie.navigate('http://www.shazam.com/charts/top-100/australia')
Start-Sleep -Seconds 10
$null = $ie.Document.body.innerhtml -match 'data-chart-position="1"(.|\n)*data-track-title=.*content="(.*)"><a href(.|\n)*data-track-artist=\W\W>(.|\n)*<meta\scontent="(.*)"\sitemprop';$shazam01artist = $matches[5];$shazam01title = $matches[2]
data-chart-position
data-track-title
data-track-artist
Each of the songs listed have the 3 values (above) associated with each of them, I want to capture the Artist & Title for each song based on the different chart positions (numbers). So a regular expression to find the actual chart position, then the trailing Artist & Title.
If I run the RegEx separately for Artist & Title (code below), it finds them, however it only finds the first Artist & Title. I need to find the Artist & Title for each song based on the different chart position.
$null = $ie.Document.body.innerhtml -match 'data-track-artist=\W\W>(.|\n)*<meta\scontent="(.*)"\sitemprop';$shazam01artist = $matches[2]
$null = $ie.Document.body.innerhtml -match 'data-track-title=.*content="(.*)"><a href';$shazam01title = $matches[1]
$shazam01artist
$shazam01title
Using regex to parse partial HTML is an absolute nightmare, you might want to reconsider that approach.
Invoke-WebRequest returns a property called ParsedHtml, that contains a reference to a pre-parsed HTMLDocument object. Use that instead:
# Fetch the document
$Top100Response = Invoke-WebRequest -Uri 'http://www.shazam.com/charts/top-100/australia'
# Select all the "article" elements that contain charted tracks
$Top100Entries = $Top100Response.ParsedHtml.getElementsByTagName("article") |Where-Object {$_.className -eq 'ti__container'}
# Iterate over each article
$Top100 = foreach($Entry in $Top100Entries){
$Properties = #{
# Collect the chart position from the article element
Position = $Entry.getAttribute('data-chart-position',0)
}
# Iterate over the inner paragraphs containing the remaining details
$Entry.getElementsByTagName('p') |ForEach-Object {
if($_.className -eq 'ti__artist') {
# the ti__artist paragraph contains a META element that holds the artist name
$Properties['Artist'] = $_.getElementsByTagName('META').item(0).getAttribute('content',0)
} elseif ($_.className -eq 'ti__title') {
# the ti__title paragraph stores the title name directly in the content attribute
$Properties['Title'] = $_.getAttribute('content',0)
}
}
# Create a psobject based on the details we just collected
New-Object -TypeName psobject -Property $Properties
}
Now, let's see how Tay-Tay's doing down under:
PS C:\> $Top100 |Where-Object { $_.Artist -match "Taylor Swift" }
Position Title Artist
-------- ----- ------
42 Bad Blood Taylor Swift Feat. Kendrick Lamar
Sweet!

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).

Line chart of all data type string? A timeline?

I want to make a chart of city council members in my city over time. I envision this as kind of being like a line chart. The x axis would be years. There are nine city council seats, so there would be nine straight lines, and each would show who was city council member over time (perhaps through different colored line segments or by showing their names onMouseOver). Perhaps this is like a time line.
When I graph the city's budget, since both the years and city budget are type "number," this classic line graph works out nicely.
For this new graph, I am passing all of the data types "string" since they are peoples' names, and Google Charts API is giving the error: "Data column(s) for axis #0 cannot be of type string"
How can I make this chart? (I not only want to graph numeric data like budget surplus or deficit or number of robberies, but relate [in another chart] who was in charge at that time.)
In PHP, I queried my mySQL database and produced a JSON object in the format Google Chart API needs to receive to make horizontal lines over time that show names onHover like this:
$conn = mysql_connect("x","y","z");
mysql_select_db("a",$conn);
$sql = "SELECT year,d_mayor,d_council1,d_council2,d_council3
FROM metrics WHERE year
IN ('1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012')";
$sth = mysql_query($sql, $conn) or die(mysql_error());
//start the json data in the format Google Chart js/API expects to receive it change
$JSONdata = "{
\"cols\": [
{\"label\":\"Year\",\"type\":\"string\"},
{\"label\":\"City Council 1\",\"type\":\"number\"},
{\"label\":\"City Council 2\",\"type\":\"number\"},
{\"label\":\"City Council 3\",\"type\":\"number\"},
{\"label\":\"Mayor\",\"type\":\"number\"}
],
\"rows\": [";
//loop through the db query result set and put into the chart cell values (note last ojbect in array has "," behind it but its working)
while($r = mysql_fetch_assoc($sth)) {
$JSONdata .= "{\"c\":[{\"v\": " . $r['year'] . "}, {\"v\": 1, \"f\": \"" . $r['d_council1'] . "\"}, {\"v\": 2, \"f\": \"" . $r['d_council2'] . "\"}, {\"v\": 3, \"f\": \"" . $r['d_council3'] . "\"}, {\"v\": 10, \"f\": \"" . $r['d_mayor'] . "\"},]},";
}
//end the json data/object literal with the correct syntax
$JSONdata .= "]}";
echo $JSONdata;
mysql_close($conn);