Location: PHPKode > projects > Katyshop > katyshop_ro_0.3.2.1/classes/logic/OrderProduct.php
<?php

/**
 * Product: Katyshop
 * @version 0.3.2.1
 * @author Catalin Hulea - hide@address.com
 * @copyright Copyright (C) 2007 Catalin Hulea
 * @license GNU General Public License version 3
 * 			You can find a copy of GNU GPL v3 at this path: /docs/LICENSE
 * @link https://sourceforge.net/projects/katyshop
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

class OrderProduct extends LogicObject
{
	var $id_order = 0;
	var $line_number = 0;

	// from Product object
	var $id_product = 0;
	var $product_name = "";
	var $product_description = "";
	var $price = 0;
	var $measuring_unit = "";

	var $quantity = 0;
	var $value_without_vat = 0;
	var $value_vat = 0;
	var $value_total = 0;

	function OrderProduct()
	{
		parent::LogicObject();
	}

	function getInstanceProps($myClass = "")
	{
		if(empty($myClass))
			$myClass = __CLASS__;
		return parent::getInstanceProps($myClass);
	}

	function validate()
	{
		$errors = array();
		if(!Tools::validateInt($this->id_order, true))
			$errors[] = "Proprietatea id_order a obiectului de tip OrderProduct trebuie sa fie pozitiv intreg";
		if(!Tools::validateInt($this->line_number) || intval($this->line_number) < 1 || intval($this->line_number) > 50)
			$errors[] = "O comanda poate sa contina intre 1 si 50 de produse";
		if(!Tools::validateInt($this->id_product, true, true))
			$errors[] = "Proprietatea id_product trebuie sa fie numar intreg pozitiv";
		if(strlen($this->product_name) < 3 || strlen($this->product_name) > 255)
			$errors[] = "Produsele trebuie sa aiba intre 3 si 255 caractere";
		if(!Tools::validateFloat($this->price, true, true))
			$errors[] = "Pretul trebuie sa fie numar pozitiv intreg";
		if(!Product::validateQuantity($this->quantity, $this->measuring_unit))
			$errors[] = "Cantitatea nu este corecta";

		if(!Tools::validateFloat($this->value_without_vat) || $this->value_without_vat < 0)
			$errors[] = "Valoarea comenzii trebuie sa fie numar pozitiv";
		if(!Tools::validateFloat($this->value_vat) || $this->value_vat < 0)
			$errors[] = "Valoarea TVA trebuie sa fie mai mare ca zero";
		if(!Tools::validateFloat($this->value_total) || $this->value_total < 0)
			$errors[] = "Valoarea totala a comenzii trebuie sa fie numar pozitiv";

		if(count($errors) == 0)
		{
			$db = Application::getDb();
			if(!$db->tbProduct->productExists($this->id_product))
				$errors[] = "Produsul numit {$this->product_name} de pe linia {$this->line_number} nu exista in baza noastra de date";
			$p = $db->tbProduct->getRecordById($this->id_product);
			if(intval($p->active) != 1)
				$errors[] = "Produsul numit {$this->product_name} de pe linia {$this->line_number} din comanda nu poate fi comandat deoarece nu mai este activ pe site";
		}

		Application::appendErrors($errors);
		return (count($errors) == 0);
	}

	/**
	 * @param Product $p
	 */
	function initFromProduct($p)
	{
		$this->id_product = $p->id;
		$this->product_name = $p->title;
		$this->product_description = $p->description;
		$this->price = $p->price;
		$this->measuring_unit = $p->measuring_unit;
	}

	function computeValue()
	{
		$vat = Application::getConfigValue("default_vat");
		$this->value_without_vat = $this->quantity * $this->price;
		$this->value_vat = $this->value_without_vat * $vat / 100;
		$this->value_total = $this->value_without_vat + $this->value_vat;
	}

}

?>
Return current item: Katyshop