Opencart list categories inside manufacturers - opencart

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 )

Related

How open modal pages conditionally?

I am using Oracle APEX 21.1. I have a table visits with a column visit_type. visit_type has only values 1 or 2. There are 2 dialog pages(1 and 2). I need to create a query that returns a link that opens page 1 when visit_type = 1 and opens page 2 when visit_type = 2. Should I select a string with <a href=""</a> tag or use APEX_PAGE.GET_URL API. Either way, kindly, give me an example.
Here is a typical format
apex_string.format(
'<a class="t-Button t-Button--hot t-Button--simple t-Button--stretch" href="%s">%s</a>'
, apex_page.get_url
(p_application => 'YOUR_APP'
,p_page => t.visit_type
,p_items => 'p'||t.visit_type||'_id'
,p_values => t.visit_id
)
, 'Link text'
) as link_target
Don't forget to not escape special characters in your column definition.

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.

Fixed Option Price in Opencart

Here is the issue.
I had a product say "Love Bird" which price is 10$. Now is option I have Cage having price 5$.
If a customer order 3 lover birds Price = 30$ but when he select cage as well. It should add 30+5 =35 but it works different in opencart. (10 + 5)*3=45 basically (10*3)+(5*3).
I don't know how to overcome this basis issue in opencart system.
This isn't going to be an easy one to do, as I think multiple files will need to be edited for this to happen.
As a start though - and the main bit of code to change, in the file system\library\cart.php you can replace this:
'price' => ($price + $option_price),
'total' => ($price + $option_price) * $quantity,
With this:
'price' => ($price + $option_price),
'total' => (($price * $quantity) + $option_price),
This WILL completely replace the existing option method though, and will give you fixed priced options throughout (once all other files edited as required).

Doctrine2 How to compare two result sets

I have two entities: Category and Icon they have a many to many relationship so i end up with three tables: category icon and icon_category
My goal is to find Icons that are in multiple categories.
For example I have the following
categories: a b c and icons 1 2 3
Here are the categories for the icons:
1 - a b
2 - a
3 - c
I would like to search for an icon that is in category a and b and get 1 as the result.
My first approach was to load in each category (a and b) into separate results and then compare using array_intersect():
$cats = array();
foreach($terms as $term){
$cat = $em->getRepository('SixStringPearBundle:Category')->findOneBy(array("name" => $term));
if($cat){
$cats[$term] = $cat->getIcons();
}
}
This returned $cats[a] = array(icon(1), icon(2) and $cats[b] = array(icon(1))
I then tried the following:
$res = array_shift($cats);
foreach($cats as $cat){
$res = array_intersect($res, $cat);
}
but got the following error: Argument #1 is not an array
I checked the type of $cat[a] and $cat[b] and they are a Doctrine Persistence Collection
I also tried calling $res = $res->toArray() and $cat = $cat->toArray() before calling array_intersect This resolved the error but did not return the expected results: Icon(1)
Does anyone have any thoughts or maybe even a better approach to all of this?
I ended up using the doctrine query builder. It was agonizing but I finally figure it out. Here is the end result:
$qb->select('i')
->from('SixStringPearBundle:Icon', 'i')
->leftJoin('i.categories', 'c')
->where('c.name IN (?1)')
->groupBy('i.id')
->having('count(i.id) = ?2')
->setParameters(array(1 => $terms, 2 => count($terms)));

How to get Place ID of city from Latitude/Longitude using Facebook API

I need to find the Facebook place for the city for many lat/long points. The actual points refer to personal addresses, so there are no exact place ID's to look for as in the case of a business.
For testing, I was looking for the town of Red Feather Lakes, CO.
The graph search function will return a lot of places, but does not return cities Example
Raw FQL does not let you search by lat/long, and has no concept of "nearby" anyway. Example
An FQL query by ID reveals that there is an least a "Display Subtext" field which indicates that object is a city. Example
Thanks for any help. I have over 80 years of dated and geotagged photos of my dad that he would love to see on his timeline!
EDIT
Cities are not in the place table, they are only in the page table.
There is an undocumented distance() FQL function, but it only works in the place table. (Via this SO answer.)
This works:
SELECT name,description,geometry,latitude,longitude, display_subtext
FROM place
WHERE distance(latitude, longitude, "40.801985", "-105.593719") < 50000
But this gives an error "distance is not valid in table page":
SELECT page_id,name,description,type,location
FROM page
WHERE distance(
location.latitude,location.longitude,
"40.801985", "-105.593719") < 50000
It's a glorious hack, but this code works. The trick is to make two queries. First we look for places near our point. This returns a lot of business places. We then take the city of one of these places, and use this to look in the page table for that city's page. There seems to be a standard naming conventions for cities, but different for US and non-US cities.
Some small cities have various spellings in the place table, so the code loops through the returned places until it finds a match in the page table.
$fb_token = 'YOUR_TOKEN';
// Red Feather Lakes, Colorado
$lat = '40.8078';
$long = '-105.579';
// Karlsruhe, Germany
$lat = '49.037868';
$long = '8.350124';
$states_arr = array('AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona",'AR'=>"Arkansas",'CA'=>"California",'CO'=>"Colorado",'CT'=>"Connecticut",'DE'=>"Delaware",'FL'=>"Florida",'GA'=>"Georgia",'HI'=>"Hawaii",'ID'=>"Idaho",'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas",'KY'=>"Kentucky",'LA'=>"Louisiana",'ME'=>"Maine",'MD'=>"Maryland", 'MA'=>"Massachusetts",'MI'=>"Michigan",'MN'=>"Minnesota",'MS'=>"Mississippi",'MO'=>"Missouri",'MT'=>"Montana",'NE'=>"Nebraska",'NV'=>"Nevada",'NH'=>"New Hampshire",'NJ'=>"New Jersey",'NM'=>"New Mexico",'NY'=>"New York",'NC'=>"North Carolina",'ND'=>"North Dakota",'OH'=>"Ohio",'OK'=>"Oklahoma", 'OR'=>"Oregon",'PA'=>"Pennsylvania",'RI'=>"Rhode Island",'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas",'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'DC'=>"Washington D.C.",'WV'=>"West Virginia",'WI'=>"Wisconsin",'WY'=>"Wyoming");
$place_search = json_decode(file_get_contents('https://graph.facebook.com/search?type=place&center=' . $lat . ',' . $long . '&distance=10000&access_token=' . $fb_token));
foreach($place_search->data as $result) {
if ($result->location->city) {
$city = $result->location->city;
$state = $result->location->state;
$country = $result->location->country;
if ($country=='United States') {
$city_name = $city . ', ' . $states_arr[$state]; // e.g. 'Chicago, Illinois'
}
else {
$city_name = $city . ', ' . $country; // e.g. 'Rome, Italy'
}
$fql = 'SELECT name,page_id,name,description,type,location FROM page WHERE type="CITY" and name="' .$city_name. '"';
$result = json_decode(file_get_contents('https://graph.facebook.com/fql?q=' . rawurlencode($fql) . '&access_token=' . $fb_token));
if (count($result->data)>0) {
// We found it!
print_r($result);
break;
}
else {
// No luck, try the next place
print ("Couldn't find " . $city_name . "\n");
}
}
}
I found this solution worked for me when looking for a page for the closest city to the specified latitude/longitude. For some reason LIMIT 1 didn't return the closest city so I bumped up the limit and then took the first result.
SELECT page_id
FROM place
WHERE is_city and distance(latitude, longitude, "<latitude>", "<longitude>") < 100000
ORDER BY distance(latitude, longitude, "<latitude>", "<longitude>")
LIMIT 20