first commit
This commit is contained in:
159
class/class.Products.php
Normal file
159
class/class.Products.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
class Products
|
||||
{
|
||||
public $ID = 0;
|
||||
public $path = ['to_root' => ''];
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public function __construct($prod, $toRoot)
|
||||
{
|
||||
$this->ID = $prod;
|
||||
$this->path['to_root'] = $toRoot;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public function subtractPiecesInStore($count = 1, $sign = '-')
|
||||
{
|
||||
$no = (int) returnSQLResult('SELECT in_store
|
||||
FROM '.getTableName('products').'
|
||||
WHERE id=\''.$this->ID.'\' ');
|
||||
if ($no != '-1') {
|
||||
if ($sign == '-') {
|
||||
$no -= $count;
|
||||
} elseif ($sign == '+') {
|
||||
$no += $count;
|
||||
}
|
||||
|
||||
if ($no < 0) {
|
||||
$no = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
if($no==0)
|
||||
{
|
||||
$SQL = sqlQuery("UPDATE " . getTableName("products") . "
|
||||
SET in_store='".$no."', delivery_time='-1'
|
||||
WHERE id='" . $this->ID . "' ", '@');
|
||||
}
|
||||
else
|
||||
{
|
||||
$SQL = sqlQuery("UPDATE " . getTableName("products") . "
|
||||
SET in_store='".$no."'
|
||||
WHERE id='" . $this->ID . "' ", '@');
|
||||
}
|
||||
*/
|
||||
$SQL = sqlQuery('UPDATE '.getTableName('products')."
|
||||
SET in_store='".$no."'
|
||||
WHERE id='".$this->ID."' ", '@');
|
||||
|
||||
if (!$SQL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $no;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public function soldPieces($pieces = 1, $sign = '+')
|
||||
{
|
||||
if ($sign == '+') {
|
||||
$SQL = sqlQuery('UPDATE '.getTableName('products').'
|
||||
SET pieces_sold=pieces_sold+'.$pieces."
|
||||
WHERE id='".$this->ID."' ", '@');
|
||||
} elseif ($sign == '-') {
|
||||
$SQL = sqlQuery('UPDATE '.getTableName('products').'
|
||||
SET pieces_sold=pieces_sold-'.$pieces."
|
||||
WHERE id='".$this->ID."' ", '@');
|
||||
}
|
||||
if (!$SQL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$img = new Photos('product', $this->path['to_root']);
|
||||
|
||||
$SQL = sqlQuery('SELECT ph.id, ph.descr, ph.source, php.show_in_lead
|
||||
FROM '.getTableName('photos').' AS ph, '.getTableName('photos-products')." AS php
|
||||
WHERE ph.id=php.id_photo AND php.id_product='".$this->ID."' ");
|
||||
$found = sqlNumRows($SQL);
|
||||
|
||||
// for($i = 0; $i < $found; $i++)
|
||||
foreach ($SQL as $row) {
|
||||
$img->erasePhoto($row['id']);
|
||||
}
|
||||
|
||||
// ##############################################
|
||||
unset($img);
|
||||
// ##############################################
|
||||
|
||||
// smazat komentare ke zbozi
|
||||
sqlQuery('DELETE FROM '.getTableName('comments')." WHERE id_item='".$this->ID."' AND type='product' ", '@');
|
||||
// smazat sekce
|
||||
sqlQuery('DELETE FROM '.getTableName('products-sections')." WHERE id_product='".$this->ID."' ", '@');
|
||||
// smazat odkazy
|
||||
sqlQuery('DELETE FROM '.getTableName('links')." WHERE id_product='".$this->ID."' ", '@');
|
||||
// smazat prilohy
|
||||
sqlQuery('DELETE FROM '.getTableName('attachments')." WHERE id_product='".$this->ID."' ", '@');
|
||||
// smazat souvisejici zbozi
|
||||
sqlQuery('DELETE FROM '.getTableName('products-related')." WHERE id_top_product='".$this->ID."' ", '@');
|
||||
// smazat zbozi
|
||||
sqlQuery('DELETE FROM '.getTableName('products')." WHERE id='".$this->ID."' ", '@');
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// fce spocita pocet ks kazde varianty zbozi a prepise to do celkoveho poctu kusu na sklade
|
||||
|
||||
public function recountInStoreAccordingToVariations()
|
||||
{
|
||||
// zjistit jestli ma zbozi varianty
|
||||
|
||||
$SQL = sqlQuery('SELECT id, in_store
|
||||
FROM '.getTableName('products_variations').' AS pv
|
||||
WHERE id_product='.intval($this->ID).' ');
|
||||
$found = sqlNumRows($SQL);
|
||||
|
||||
// kdyz nema varianty -> skoncit
|
||||
if ($found == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$total_in_store = 0;
|
||||
|
||||
foreach ($SQL as $row) {
|
||||
$total_in_store += $row['in_store'];
|
||||
}
|
||||
|
||||
// preulozit celkove mnozstvi kusu na sklade do produktu
|
||||
sqlQuery('UPDATE '.getTableName('products').'
|
||||
SET in_store='.intval($total_in_store).'
|
||||
WHERE id='.intval($this->ID).' ');
|
||||
|
||||
// echo "Pocet ks: ".$total_in_store;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user