288 lines
8.0 KiB
PHP
288 lines
8.0 KiB
PHP
<?php
|
|
/**
|
|
* Zapisywanie ostatniej ceny produku dla opcji 'full' w konfiguracji produktów.
|
|
*
|
|
* @author Marek Jakubowicz m@sote.pl
|
|
*/
|
|
|
|
/**
|
|
* Opercje związane z st_product_price_history_last - dane z ostatnią ceną produktu.
|
|
*/
|
|
class stPriceHistoryLast
|
|
{
|
|
/**
|
|
* Konstruktor
|
|
* @return true
|
|
*/
|
|
public function __construct($product_id = null)
|
|
{
|
|
if (! empty($product_id))
|
|
{
|
|
$this->product = $this->getLastProduct($product_id);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* Ustaw domyślną walutę ID
|
|
* @param integer $default_currency
|
|
*/
|
|
public function setDefaultCurrency($default_currency)
|
|
{
|
|
$this->default_currency = $default_currency;
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* Sprawdż czy jest zapisana ostatnia cena produktu w st_prodcu_price_history_last
|
|
*
|
|
* @param $product_id integer $id Id produktu
|
|
* @return bool - true jest wpis z ceną, false - nie ma
|
|
*/
|
|
public function isLastProductPrice($product_id)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(ProductPriceHistoryLastPeer::PRODUCT_ID, $product_id);
|
|
$c->addDescendingOrderByColumn(ProductPriceHistoryLastPeer::CREATED_AT);
|
|
$last = ProductPriceHistoryLastPeer::doSelectOne($c);
|
|
|
|
if (! empty($last))
|
|
{
|
|
return true;
|
|
} else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sprawdza czy jest odcvzytany produkt $this->product
|
|
*/
|
|
public function getProduct()
|
|
{
|
|
if ($this->product) return true;
|
|
else return false;
|
|
}
|
|
|
|
/**
|
|
* Odczytaj ostatnią cenę produktu z st_prodcu_price_history_last
|
|
*
|
|
* @param integer $id Id produktu
|
|
* @return float ostatnia cena brutto
|
|
*/
|
|
public function getLastProductPriceBrutto($product_id)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(ProductPriceHistoryLastPeer::PRODUCT_ID, $product_id);
|
|
$c->addDescendingOrderByColumn(ProductPriceHistoryLastPeer::CREATED_AT);
|
|
$last = ProductPriceHistoryLastPeer::doSelectOne($c);
|
|
$this->product = $last;
|
|
if (! empty($last))
|
|
{
|
|
$price_brutto = $last->getPriceBrutto();
|
|
return $price_brutto;
|
|
} else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Odczytaj ostatnie dane z last dla produktu
|
|
*
|
|
* @param integer $id Id produktu
|
|
* @return object ProductPriceHistoryLast
|
|
*/
|
|
public function getLastProduct($product_id)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(ProductPriceHistoryLastPeer::PRODUCT_ID, $product_id);
|
|
$c->addDescendingOrderByColumn(ProductPriceHistoryLastPeer::CREATED_AT);
|
|
$last = ProductPriceHistoryLastPeer::doSelectOne($c);
|
|
if (! empty($last))
|
|
{
|
|
$this->product = $last;
|
|
return $last;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Zwróć id waluty.
|
|
* @return int Currency ID
|
|
*/
|
|
public function getCurrencyId()
|
|
{
|
|
if (! empty($this->product)) return $this->product->getCurrencyId();
|
|
else return null;
|
|
}
|
|
|
|
/**
|
|
* Zwróć wartość UpdatedAt.
|
|
* @return int Currency ID
|
|
*/
|
|
public function getUpdatedAt()
|
|
{
|
|
if (! empty($this->product)) return $this->product->getUpdatedAt();
|
|
else return null;
|
|
}
|
|
|
|
/**
|
|
* Zwróć wartość CreatedAt.
|
|
* @return int Currency ID
|
|
*/
|
|
public function getCreatedAt()
|
|
{
|
|
if (! empty($this->product)) return $this->product->getCreatedAt();
|
|
else return null;
|
|
}
|
|
|
|
/**
|
|
* Zwróć Price
|
|
* @return float
|
|
*/
|
|
public function getPrice()
|
|
{
|
|
if (! empty($this->product)) return $this->product->getPrice();
|
|
else return null;
|
|
}
|
|
|
|
/**
|
|
* Zwróć PriceNetto
|
|
* @return float
|
|
*/
|
|
public function getPriceNetto()
|
|
{
|
|
if (! empty($this->product)) return $this->product->getPriceNetto();
|
|
else return null;
|
|
}
|
|
|
|
/**
|
|
* Zwróć PriceBrutto
|
|
* @return float
|
|
*/
|
|
public function getPriceBrutto()
|
|
{
|
|
if (! empty($this->product)) return $this->product->getPriceBrutto();
|
|
else return null;
|
|
}
|
|
|
|
/**
|
|
* Zwróć MainPrice
|
|
* @return float
|
|
*/
|
|
public function getMainPrice()
|
|
{
|
|
if (! empty($this->product)) return $this->product->getMainPrice();
|
|
else return null;
|
|
}
|
|
|
|
/**
|
|
* Zwróć MainPriceNetto
|
|
* @return float
|
|
*/
|
|
public function getMainPriceNetto()
|
|
{
|
|
if (! empty($this->product)) return $this->product->getMainPriceNetto();
|
|
else return null;
|
|
}
|
|
|
|
/**
|
|
* Zwróć MainPriceBrutto
|
|
* @return float
|
|
*/
|
|
public function getMainPriceBrutto()
|
|
{
|
|
if (! empty($this->product)) return $this->product->getMainPriceBrutto();
|
|
else return null;
|
|
}
|
|
|
|
/**
|
|
* Zapisz cenę produktu w st_prodcu_price_history_last. Dodanie wpisu.
|
|
*
|
|
* @param $product object stProduct - odwołanie bezpośrednie referencja
|
|
* @return NULL
|
|
*/
|
|
public function addLastProductPrice($product)
|
|
{
|
|
$id = $product->getId();
|
|
$price = $product->getFrontendCurrencyPrice();
|
|
$price_netto = $product->getFrontendPriceNetto();
|
|
$price_brutto = $product->getFrontendPriceBrutto();
|
|
|
|
$main_price = $product->getMainCurrencyPrice(true);
|
|
$main_price_netto = $product->getMainPriceNetto();
|
|
$main_price_brutto = $product->getMainPriceBrutto();
|
|
|
|
$price_currency = $product->getCurrencyPrice();
|
|
if (empty($price_currency))
|
|
{
|
|
$price_currency = $product->getFrontendPriceBrutto(true);
|
|
}
|
|
|
|
$currency_id = $product->getCurrencyId();
|
|
if (empty($currency_id)) $currency_id = $this->default_currency;
|
|
|
|
$product_last = new ProductPriceHistoryLast();
|
|
$product_last->setProductId($id);
|
|
$product_last->setPrice($price_currency);
|
|
$product_last->setPriceNetto($price_netto);
|
|
$product_last->setPriceBrutto($price_brutto);
|
|
$product_last->setMainPrice($main_price);
|
|
$product_last->setMainPriceNetto($main_price_netto);
|
|
$product_last->setMainPriceBrutto($main_price_brutto);
|
|
$product_last->setCurrencyId($currency_id);
|
|
$product_last->save();
|
|
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* Zapisz cenę produktu w st_prodcu_price_history_last. Aktuaizacja.
|
|
*
|
|
* @param $product object stProduct - odwołanie bezpośrednie referencja
|
|
* @return NULL
|
|
*/
|
|
public function updateLastProductPrice($product)
|
|
{
|
|
$id = $product->getId();
|
|
$price = $product->getFrontendCurrencyPrice();
|
|
$price_netto = $product->getFrontendPriceNetto();
|
|
$price_brutto = $product->getFrontendPriceBrutto();
|
|
|
|
$main_price = $product->getMainCurrencyPrice(true);
|
|
$main_price_netto = $product->getMainPriceNetto();
|
|
$main_price_brutto = $product->getMainPriceBrutto();
|
|
|
|
$price_currency = $product->getCurrencyPrice();
|
|
if (empty($price_currency))
|
|
{
|
|
$price_currency = $product->getFrontendPriceBrutto(true);
|
|
}
|
|
|
|
$currency_id = $product->getCurrencyId();
|
|
if (empty($currency_id)) $currency_id = $this->default_currency;
|
|
|
|
$c = new Criteria();
|
|
$c->add(ProductPriceHistoryLastPeer::PRODUCT_ID, $id);
|
|
$c->addDescendingOrderByColumn(ProductPriceHistoryLastPeer::CREATED_AT);
|
|
$product_last = ProductPriceHistoryLastPeer::doSelectOne($c);
|
|
|
|
$product_last->setProductId($id);
|
|
$product_last->setPrice($price_currency);
|
|
$product_last->setPriceNetto($price_netto);
|
|
$product_last->setPriceBrutto($price_brutto);
|
|
$product_last->setMainPrice($main_price);
|
|
$product_last->setMainPriceNetto($main_price_netto);
|
|
$product_last->setMainPriceBrutto($main_price_brutto);
|
|
$product_last->setCurrencyId($currency_id);
|
|
$product_last->save();
|
|
|
|
|
|
return NULL;
|
|
}
|
|
|
|
} |