ACC SHELL
<?php
class crProduct
{
private $db;
private $productDBitem;
private $productTitle;
// --------------------------------------------------------------------------------
public function __construct( $db )
{
$this->db = $db;
$this->productTitle = '';
}
// --------------------------------------------------------------------------------
public function load( $product_url )
{
$this->productDBitem = $this->db->getItemWhere( 'product', " WHERE `url`='" . $product_url . "' AND `visibility`=1 " );
if ( isset( $this->productDBitem['ID'] ) )
{
$this->productTitle = $this->productDBitem['title'];
return true;
}
else
{
return false;
}
}
// --------------------------------------------------------------------------------
public function loadByID( $productID )
{
$this->productDBitem = $this->db->getItemWhere( 'product', " WHERE `ID`=" . $productID . " AND `visibility`=1 " );
if ( isset( $this->productDBitem['ID'] ) )
{
$this->productTitle = $this->productDBitem['title'];
return true;
}
else
{
return false;
}
}
// --------------------------------------------------------------------------------
public function getTitle()
{
return $this->productTitle;
}
// --------------------------------------------------------------------------------
public function getType()
{
if ( isset( $this->productDBitem['type'] ) )
{
return $this->productDBitem['type'];
}
else
{
return false;
}
}
// --------------------------------------------------------------------------------
public function isLoaded()
{
if ( isset( $this->productDBitem['ID'] ) )
{
return true;
}
else
{
return false;
}
}
// --------------------------------------------------------------------------------
public function getData()
{
if ( $this->isLoaded() )
{
return $this->productDBitem;
}
else
{
return array();
}
}
// --------------------------------------------------------------------------------
public function getPriceInVat( $sale = true )
{
$priceSale = $this->getPriceSale();
if ( ( $priceSale != 0 ) && $sale )
{
return $priceSale;
}
else
{
if ( isset( $this->productDBitem['ID'] ) )
{
$_productPrice = (float)$this->productDBitem['price'];
$_productVAT = ( (float)$this->productDBitem['VAT'] / 100.0 );
return round( (float)$_productPrice + ( (float)$_productPrice * $_productVAT) ) ;
}
else
{
return false;
}
}
}
public function getPriceExVAT( $sale = true )
{
$priceSaleExVAT = $this->getPriceSaleExVAT();
//if ( $sale )
//{
if ( ( $priceSaleExVAT != 0 ) && $sale )
{
return $priceSaleExVAT;
}
else
{
if ( isset( $this->productDBitem['ID'] ) )
{
return round( $this->productDBitem['price'] );
}
else
{
return false;
}
}
//}
}
public function getPriceType()
{
if ( isset( $this->productDBitem['ID'] ) )
{
return $this->productDBitem['cenaTyp'];
}
else
{
return false;
}
}
public function getPriceSale()
{
if ( ( $this->productDBitem['sleva'] != '' ) && is_numeric($this->productDBitem['sleva']) && ( $this->productDBitem['sleva'] < 100 ) && ( $this->productDBitem['sleva'] > 0 ) )
{
$_productPrice = (float)$this->productDBitem['price'];
$_productPriceSale = $_productPrice - ( ( $_productPrice / 100.0 ) * (float)$this->productDBitem['sleva'] );
$_productVAT = ( (float)$this->productDBitem['VAT'] / 100.0 );
return round( (float)$_productPriceSale + ( (float)$_productPriceSale * $_productVAT) );
}
else
{
return 0;
}
}
public function getPriceSaleExVAT()
{
if ( ( $this->productDBitem['sleva'] != '' ) && is_numeric($this->productDBitem['sleva']) && ( $this->productDBitem['sleva'] < 100 ) && ( $this->productDBitem['sleva'] > 0 ) )
{
$_productPrice = (float)$this->productDBitem['price'];
$_productPriceSale = $_productPrice - ( ( $_productPrice / 100.0 ) * (float)$this->productDBitem['sleva'] );
return round( (float)$_productPriceSale );
}
else
{
return 0;
}
}
// --------------------------------------------------------------------------------
public function getURL( $categoryURL = '' )
{
if ( $this->isLoaded() )
{
if ( $categoryURL == '' )
{
$productCategories = $this->db->getAllItems( 'productCategory', " WHERE `productID`=" . $this->productDBitem['ID'] );
for ( $pci = 0; $pci < count( $productCategories ); $pci++ )
{
$productCategory = $productCategories[ $pci ];
$category = $this->db->getItem( 'category', $productCategory['categoryID'] );
if ( isset($category['ID'] ) )
return '/' . $category['url'] . '/' . $this->productDBitem['url'];
}
}
else
{
return '/' . $categoryURL . '/' . $this->productDBitem['url'];
}
return '/produkty/' . $this->productDBitem['url'];
}
else
{
return array();
}
}
// --------------------------------------------------------------------------------
public function show( $etsHTMLteplate, $imageDir, $imagesDir, $settings='' )
{
if ( $this->isLoaded() && ( $this->productDBitem['visibility'] == 1 ) )
{
$data = new stdClass();
$data->productID = $this->productDBitem['ID'];
$data->title = $this->productDBitem['title'];
$data->subtitle = $this->productDBitem['subtitle'];
$data->text = fuckOffOrphans( $this->productDBitem['text'] );
$data->youtubeVideo = '';
$videoURL1 = getVideoEmbed( $this->productDBitem['videoURL1'], 360, 240 );
if ( $videoURL1 != '' )
$data->youtubeVideo .= '<div class="cleaner10"></div>' . $videoURL1;
$videoURL2 = getVideoEmbed( $this->productDBitem['videoURL2'], 360, 240 );
if ( $videoURL2 != '' )
$data->youtubeVideo .= '<div class="cleaner10"></div>' . $videoURL2;
$videoURL3 = getVideoEmbed( $this->productDBitem['videoURL3'], 360, 240 );
if ( $videoURL3 != '' )
$data->youtubeVideo .= '<div class="cleaner10"></div>' . $videoURL3;
$data->formText = urlencode( $data->title );
$data->price = $this->getPriceInVAT();
$data->freshType = $this->getPriceType();
$dd = array( '0'=>'Skladem', '1'=>'Do týdne', '7'=>'Více jak týden', '10'=>'Do 10 dní', '14'=>'Do 14 dní', '30'=>'Do měsíce', '40'=>'Na objednávku' );
$data->deliveryDate = $dd[ $this->productDBitem['deliveryDate'] ];
$data->priceOld = 0;
$data->priceSale = 0;
$data->priceDiff = 0;
if ( $this->getPriceSale() != 0 )
{
$data->priceOld = (int)$this->getPriceInVAT(false);
$data->priceSale = $this->productDBitem['sleva'];
$data->priceDiff = $data->priceOld - $data->price;
}
$data->priceOld = number_format( $data->priceOld, 0, '.', ' ' );
$data->priceSale = number_format( $data->priceSale, 0, '.', ' ' );
$data->priceDiff = number_format( $data->priceDiff, 0, '.', ' ' );
$data->price = number_format( $data->price, 0, '.', ' ' );
$data->priceExVAT = number_format( $this->getPriceExVAT(), 0, '.', ' ' );
if ( $this->productDBitem['image'] != '' )
{
$data->imgSrc = $imageDir . '/large/' . $this->productDBitem['image'];
$data->imgSrcFull = $imageDir . '/full/' . $this->productDBitem['image'];
}
else
$data->imgSrc = '';
$images = $this->db->getAllItems( 'mediaItem', " WHERE `ownerID`=" . $this->productDBitem['ID'] . " ORDER BY `position` ASC " );
$imagesCount = count( $images );
for ( $i = 0; $i < $imagesCount; $i++ )
{
$image = $images[ $i ];
$data->images[ $i ]->imgSrc = $imagesDir . '/' . $this->productDBitem['ID'] . '/thumbs/' . $image['fileName'];
$data->images[ $i ]->imgSrcFull = $imagesDir . '/' . $this->productDBitem['ID'] . '/' . $image['fileName'];
}
$productVariations = $this->db->getAllItems( 'productVariation', " WHERE `productID`=" . $this->productDBitem['ID'] . " ORDER BY `ID` ASC " );
for ( $i = 0; $i < count( $productVariations ); $i++ )
{
$data->variation[ $i ] = new stdClass();
$productVariation = $productVariations[ $i ];
$data->variation[ $i ]->ID = $productVariation['ID'];
$data->variation[ $i ]->color = $productVariation['color'];
$data->variation[ $i ]->text = shortenText( $productVariation['text'], 55 );
$data->variation[ $i ]->textFull = $productVariation['text'];
$data->variation[ $i ]->value = $productVariation['count'];
$data->variation[ $i ]->availability = $productVariation['availability'];
}
$data->contactPhone = $settings['contactPhone'];
$data->facebookLikeButtonVisible = $settings['facebookLikeButtonVisible'];
$data->addToCart = true;
if ( ( count( $productVariations ) == 0 ) || ( $data->freshType == 'vyprodano' ) )
{
$data->addToCart = false;
}
//
$data->showSproducts = false;
for ( $si = 1; $si <= 3; $si++ )
{
if ( $this->productDBitem['sProduct'.$si.'ID'] != 0 )
{
$data->showSproducts = true;
$_product = new crProduct( $this->db );
$_product->loadByID( $this->productDBitem['sProduct'.$si.'ID'] );
$product = $_product->getData();
$data->sProduct[ $si ]->url = $_product->getURL();
$data->sProduct[ $si ]->title = $_product->getTitle();
$data->sProduct[ $si ]->price = $_product->getPriceInVAT();
$data->sProduct[ $si ]->freshType = $_product->getPriceType();
$data->sProduct[ $si ]->priceOld = 0;
$data->sProduct[ $si ]->priceSale = 0;
$data->sProduct[ $si ]->priceDiff = 0;
if ( $_product->getPriceSale() != 0 )
{
$data->sProduct[ $si ]->priceOld = $_product->getPriceInVAT(false);
$data->sProduct[ $si ]->priceSale = $product['sleva'];
$data->sProduct[ $si ]->priceDiff = $data->sProduct[ $si ]->priceOld - $data->sProduct[ $si ]->price;
}
$data->sProduct[ $si ]->priceOld = number_format( (float)$data->sProduct[ $si ]->priceOld, 0, '.', ' ' );
$data->sProduct[ $si ]->priceSale = number_format( (float)$data->sProduct[ $si ]->priceSale, 0, '.', ' ' );
$data->sProduct[ $si ]->priceDiff = number_format( (float)$data->sProduct[ $si ]->priceDiff, 0, '.', ' ' );
$data->sProduct[ $si ]->price = number_format( (float)$data->sProduct[ $si ]->price, 0, '.', ' ' );
if ( $product['image'] != '' )
{
$data->sProduct[ $si ]->imgSrc = $imageDir . '/small/' . $product['image'];
$data->sProduct[ $si ]->imgSrcLarge = $imageDir . '/large/' . $product['image'];
$data->sProduct[ $si ]->imgSrcFull = $imageDir . '/full/' . $product['image'];
}
else
$data->sProduct[ $si ]->imgSrc = '';
}
}
//
return sprintt( $data, $etsHTMLteplate );
}
else
{
header("HTTP/1.0 301 Moved Permanently");
header("Status: Moved Permanently");
header("Location: http://".$_SERVER['HTTP_HOST']."/");
}
}
}
?>
ACC SHELL 2018