I wish I knew where to find the position that makes the backend OpenCart Remove Option Value-for product / option - table
If you mean which file options get deleted and re-generated when you edit a product, the file is admin/model/catalog/product.php and the method is the editProduct() method. You'll notice that there's these two lines in there
$this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");
$this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'");
You might try setting max_input_vars value in php.ini to 2000 and restart apache. This seem to fixed my issue where option values were deleted even when only product name was updated from product update page.
Related
I want to implement a task similar to the one here Getting stock information in opencart 2.3.0.2, but my problem is that when deleting a product, the information about the warehouse will disappear. I want to enter the data into the table order_product, but I still don’t understand how. Help me please.
I can't figure out how to write information about the rest of the goods to the database. I don't understand how to implement it.
Hmm... You want to save product`s stock information in order_product table?
So first you must to add custom field in oc_order_product
ALTER TABLE `oc_order_product` ADD `stock_status` INT(11) NOT NULL AFTER `reward`;
Then in catalog/controller/checkout/confirm.php in $order_data['products'][] = array( You must add key - stock_status
'stock' => $this->model_catalog_product->getProduct($product['product_id'])['stock_status'],
So we modified our controller in customer side, and now our data receive the stock_status.
After receive products data from customer side, we must save in oc_order_table
Open path - catalog/model/checkout/order.php and edit addOrder function... After reward = '" . (int)$product['reward'] . "' in products loop add after comma:
stock_status = '" . $this->db->escape(product['stock_status']) . "'
I write an example, how to save data from customer side about product stock data.
I'm working with Opencart 3.0 to set up a product cross-sell to display similar items to the user when they add something to the cart. I thought I had seen a pattern with the array of products in the cart that put the last item of cart at the end. So my php looked something like this:
$this->load->model('catalog/product');
$related_product_id = $products;
$related_product_id = end($related_product_id);
$related_product_id = $related_product_id['product_id'];
$related = $this->model_catalog_product->getProductRelated($related_product_id);
foreach ($related as $related) {
//..do something
}
Using the end() method in the above code would take the very last Key=>Value (Product_id) in the array so I could use it to display the product on the page.
This worked for a while until I noticed that it was not always accurate. If someone added something already in the cart, it wouldn't place it at the end of the array, and also other certain products for some reason didn't show up at the end of the array.
Is there another way to get the Product_Id of the last item a user added to the cart than the way I'm going about it? My way doesn't seem very consistent. Thanks!
I was able to figured it out adding my own function to /system/libray/cart/cart.php
I added this function
public function getProductsInCart() {
$product_data = array();
$cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' ORDER BY date_added ASC");
foreach ($cart_query->rows as $cart) {
$product_data[] = array(
'cart_id' => $cart['cart_id'],
'product_id' => $cart['product_id'],
'date_added' => $cart['date_added'],
);
}
return $product_data;
}
And instead of using the $this->cart->getProducts() line to get products from the cart, I'm using my new function $this->cart->getProductsInCart().
This works way more consistent. The only thing it doesn't take into consideration is when someone goes back to a product already added. It doesn't count it as a new product added, but instead just updates it quantity.
Let me know if someone finds a better solution.
I'm trying to figure out whether an AWS Athena query is successfully folding on the Native Query in PowerBI, for the purpose of setting up an incremental refresh. I created the parameters, filtered my datetime column on those parameters and tried the Diagnose tool (see https://www.youtube.com/watch?v=QEFze-LdLqo from 4:50 on), but it keeps running and doesn't show any results. So, I'm trying the approach of querying in the Advanced Editor (https://www.youtube.com/watch?v=KEh2Udm6ibA&feature=youtu.be 20:00 onwards). But since this example is in SQL and I'm working with AWS Athena, I keep getting errors. Here are the Advanced Editor queries I have tried so far:
Example 1:
> let
> Source = Odbc.Query("dsn=Simba Athena", "SELECT * FROM ""databasename"".""tablename"" where StartTimeCET>= ' " &
> DateTime.From(RangeStart) & "' and StartTimeCET< '" &
> DateTime.From(RangeEnd) & "' ") in Source
Error: We cannot apply operator & to types Text and DateTime.
Example 2:
> let
> Source= Odbc.Query("dsn=Simba Athena", "SELECT * FROM ""database"".""tablename""
> where StartTimeCET>= ' " DateTime.From(RangeStart) "' and
> StartTimeCET< '" DateTime.From(RangeEnd) "' ")
Error: Token Comma expected.
Example 3:
let
Source = Odbc.Query("dsn=Simba Athena", "SELECT * FROM ""database"".""tablename"" where StartTimeCET>= ' "" &
Text.From(RangeStart) & ""' and StartTimeCET < '"" & Text.From(RangeEnd) & "" ' ") in Source
Error: Exception parsing query SELECT * FROM ""database"".""tablename"" where StartTimeCET>= ' " & Text.From(RangeStart) & "' and StartTimeCET < '" & Text.From(RangeEnd) & " ' with parser version athena_v1 and context QueryExecutionContext(queryId=null, database=default, catalog=null) [Execution ID: ]
Any ideas on how to write such an Advanced Editor query for AWS Athena? To simplify, I want to filter the Advanced Editor query in PowerBI based on the RangeStart and RangeEnd paramaters. Both parameters and StartTimeCET column are type date/time.
I think I solved the error but still failed to "View Native Query".
You can pass the manual Athena direct query step by writing with Presto syntax and using DateTime.ToText() function with appropriate date format i.e.
Odbc.Query("dsn=Simba Athena",
"SELECT * FROM tablename
WHERE StartTimeCET >= TIMESTAMP '" & DateTime.ToText(RangeStart, "yyyy-MM-dd") & "'
AND StartTimeCET < TIMESTAMP '" & DateTime.ToText(RangeEnd, "yyyy-MM-dd") & "'
")
EDIT:
I think I have managed to achieve the "Incremental Load" in Power BI using Athena. This (still) does not allow you to view Native query but you can still make Power BI manipulate the direct query to implement it.
To avoid full scan of S3 data in Athena - you have to enable Partitions in your dataset.
Without going off topic, once you partition the S3 data via Athena you can then pin point the datasets with days/months/years without scanning your whole dataset.
Once you do that, you can achieve the Incremental Load by running Direct Queries as mentioned in the last video link you shared and achieve resource-efficient query execution.
The final query will look something like -
Odbc.Query("dsn=Simba Athena",
"SELECT * FROM tablename
WHERE year >= " & DateTime.ToText(RangeStart, "yyyy") & "
AND month >= " & DateTime.ToText(RangeStart, "MM") & "
AND day >= " & DateTime.ToText(RangeStart, "dd") & "
AND year <= " & DateTime.ToText(RangeEnd, "yyyy") & "
AND month <= " & DateTime.ToText(RangeEnd, "MM") & "
AND day <= " & DateTime.ToText(RangeEnd, "dd") & "
")
EDIT #2: OR simply
Odbc.Query("dsn=Simba Athena",
"SELECT * FROM tablename
WHERE dt >= '" & DateTime.ToText(RangeStart, "yyyy/MM/dd") & "'
AND dt <= '" & DateTime.ToText(RangeEnd, "yyyy/MM/dd") & "'
")
I am a .NET programmer and rarely work with PHP. How can I tell if this query fails or if this query updates 0 rows? I am using OpenCart:
public function updateInventory($product_id, $quantity)
{
$query = $this->db->query("Update " . DB_PREFIX . "product SET quantity ='" . $this->db->escape($quantity) . "' WHERE sku='" . $this->db->escape($product_id) . "'");
return "OK";
}
replacing
return "OK";
with (depends on libraries you use to connect with database. mysql , mysqli or pdo)
return mysql_affected_rows();
will get you the affected rows. That is from PHP code side. Opencart has a default function that you can use: $this->db->countAffected()
but i am not sure if they have kept it the same through different versions.
source : http://us3.php.net//manual/en/function.mysql-affected-rows.php
Hope everything is clear enough.
You probably have no updated quantity for the product because you are comparing SKU and product_id in your query.
If you want to update product quantity by product_id, you need to change your expression to this one:
'UPDATE `' . DB_PREFIX . 'product` SET `quantity` =' . (int)$quantity . ' WHERE `product_id`= " . (int)$product_id
"WHERE product_id = some_product_id" instead of "WHERE sku = some_product_id"
Comparing SKU with product_id in WHERE statement is the reason why your query updates 0 rows.
I "inherited" an existing and working install of OpenCart 1.5.2.1.
For test purpuses I wanted to set up a dev site on my local server. So I installed it locally and copied the DB over.
I can log into the backend without any issues - stores are set up, all the products and categories are there as well.
On the frontend, I can visit the home page of the store, and the list of categories gets displayed correctly, including the product count per category.
However, when I try to view the category listings, or an individual product for that matter, I get a blank page.
I am not getting a PHP error - I appended
display_errors = 1;
error_reporting = E_ALL;
log_errors = 1;
to the php.ini in the cart root folder.
From within the OpenCart Error Log, I am getting the following error message:
2013-03-13 18:51:15 - PHP Notice: Error: Column 'product_id' cannot be null<br />Error No: 1048<br />SELECT DISTINCT *, p [...] AND p2s.store_id = '5' in /path/to/root/system/database/mysql.php on line 49
Any idea how to resolve this issue?
** UPDATE: **
The full query is:
SELECT DISTINCT *, pd.name, pd.creator, pd.keyword, pd.circa, pd.year, pd.century, pd.decade, pd.scenelocation, pd.fm_quicksearch AS fm_quicksearch, p.image, m.name AS manufacturer, (SELECT price FROM product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '8' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '8' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '8') AS reward, (SELECT ss.name FROM stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '1') AS stock_status, (SELECT wcd.unit FROM weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '1') AS weight_class, (SELECT lcd.unit FROM length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '1') AS length_class, (select (r.sum + p.rat)/(r.tot + p.tot) from (select COALESCE(j.sum,0) as sum , COALESCE(j.tot,0) as tot from (select SUM(rating) as sum , COUNT(rating) as tot, product_id from rating where product_id = '9206' group by product_id) j right join product on product.product_id = j.product_id where product.product_id = '9206') r, (select product_id, COALESCE(rating,0) as rat, count(rating) as tot from product where product_id = '9206' and rating > 0) p ) AS rating, p.sort_order FROM product p LEFT JOIN product_description pd ON (p.product_id = pd.product_id) LEFT JOIN product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '9206' AND pd.language_id = '1' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '5'
UPDATE
I suspect it has something to do with the MySQL or PHP configuration. Because when I run the same query on the live site, it works without fail.
UPDATE
The issue is related to my local MySQL install. When using the online DB all is fine. Someone in the OpenCart Forum - Link to Post indicated the following:
This error originates from an insert query on a specific contribution which the author has >untestedly tried to add a null statement which an auto-incremented field will reject >especially starting on mySQL 5.1+ . This methodology from mySQL developers has been blocked >ages ago.
Contact the author to address this issue by stating that the auto-incremented field does NOT >require to be addressed in the query as it is already creating an incremented value >automatically along with the executed query.
It might be along these lines. The query itself is not an insert, but it has most likely to do with that. I'll look further into the matter.
Set “Output Compression Level” to 0 in the System > Settings > Server tab.
Then in php.ini file display_errors = 1; error_reporting = E_ALL; log_errors = 1;
So the problem is with the 'product_id' . In the page controller page check the product id (just echo it). then check the model query. the problem is product id only.
Yes, the answer indeed had to do with my local MySQL install. I moved it to a different server, and it worked just fine. Thank you for the input! Sorry to not have a more specific answer than that. I just wanted to tie up a loose end with this post.