Reputation: 935
i am writing an external application in codeigniter, which will read barcode of products and update quantity in the Prestashop database. now i am not sure which table/tables i should update. there are _DB_PREFIX_product, _DB_PREFIX_product_attribute, _DB_PREFIX_stock_available tables in the db where, product id and quantity column is available.
and barcode column (ean13) is available in first 2 tables. please let me know which table or tables i should update to change the product qty properly
(prestashop version is 1.6)
Upvotes: 2
Views: 4624
Reputation: 351
Select id_product
from _DB_PREFIX_product
then update quantity in _DB_PREFIX_stock_available
.
You can use prestashop classes, I have never worked with barcodes so dont know what is ean13 but the code must be.
<?php
include('config/config.inc.php');
include('init.php');
$ean13 = "ean13";
$sql = "SELECT id_product FROM _DB_PREFIX_product WHERE ean13='$ean13'";
//replace _DB_PREFIX_ with your prefix or define _DB_PREFIX_ on top.
$product_id = Db::getInstance()->getValue($sql);
if (!empty($product_id)) {
$quantity = 100;
StockAvailable::setQuantity((int)$product_id, 0, $quantity);
}
?>
StockAvailable::setQuantity((int)$product_id, 0, $quantity);
Here second parameter is of id_product_attribute
why I pass 0
as id_product_attribute
is in pestashop user can add stock for every attribute combination e.g 300 quantity for blue color and Mediam size
. So if you want to update the quantity of specific combination then you will have to pass the id of that combination as id_product_attribute
. Passing 0
as id_product_attribute
will update the overall quantity and stock of the product.
If you dont want to use prestashop classes and want to update db from external classes then the query will be UPDATE _Db_PREFIX_stock_availble SET quantity='$quantity' WHERE id_product='$productID' AND id_product_attribute=0
Upvotes: 2