public function __construct(Product $product, $quantity) { $this->id = $product->getId(); $this->name = $product->getName(); $this->description = $product->getDescription(); $this->price = $product->getPrice(); $this->images = $product->getImages(); $this->setQuantity($quantity); }
public static function update(Product $oProduct) { $sName = addslashes($oProduct->getName()); $sDescription = addslashes($oProduct->getDescription()); $sImage = addslashes($oProduct->getImage()); $fPrice = floatval($oProduct->getPrice()); // get product id $iProductId = $oProduct->getId(); $sQuery = "update product "; $sQuery .= "set name='{$sName}',description='{$sDescription}',image='{$sImage}',price={$fPrice}"; $sQuery .= " where id = {$iProductId}"; $bSuccess = DBOperation::exec($sQuery); if (!$bSuccess) { return false; } $sQuery = "delete from product_category where product_id = {$iProductId}"; $bSuccess = DBOperation::exec($sQuery); // insert categories $aCategories = $oProduct->getCategories(); if (count($aCategories) > 0) { foreach ($aCategories as $oCategory) { $sQuery = 'insert into product_category(product_id,category_id) values('; $sQuery .= "'{$iProductId}','{$oCategory->getId()}'"; $sQuery .= ')'; DBOperation::exec($sQuery); } } return true; }