/** * updateproduct price * * @param unknown $sender * @param unknown $param */ public function updatePrice($sender, $param) { $results = $errors = array(); try { Dao::beginTransaction(); $id = isset($param->CallbackParameter->productId) ? $param->CallbackParameter->productId : ''; if (!($product = Product::get($id)) instanceof Product) { throw new Exception('Invalid product!'); } if (!isset($param->CallbackParameter->newPrice)) { throw new Exception('No New Price Provided!'); } $isSpecial = 0; if (isset($param->CallbackParameter->isSpecial)) { $isSpecial = intval($param->CallbackParameter->isSpecial); } $newPrice = StringUtilsAbstract::getValueFromCurrency(trim($param->CallbackParameter->newPrice)); if ($isSpecial === 0) { $priceType = ProductPriceType::ID_RRP; } else { $priceType = ProductPriceType::ID_CASUAL_SPECIAL; } $prices = ProductPrice::getAllByCriteria('productId = ? and typeId = ?', array($product->getId(), $priceType), true, 1, 1); if (count($prices) > 0) { $msg = 'Update price for product(SKU=' . $product->getSku() . ') to ' . StringUtilsAbstract::getCurrency($newPrice); $price = $prices[0]; } else { $msg = 'New Price Created for product(SKU=' . $product->getSku() . '): ' . StringUtilsAbstract::getCurrency($newPrice); $price = new ProductPrice(); $price->setProduct($product)->setType(ProductPriceType::get($priceType)); } $price->setPrice($newPrice)->save()->addComment($msg, Comments::TYPE_NORMAL)->addLog($msg, Log::TYPE_SYSTEM); $product->addComment($msg, Log::TYPE_SYSTEM)->addLog($msg, Log::TYPE_SYSTEM); $results['item'] = $product->getJson(); Dao::commitTransaction(); } catch (Exception $ex) { Dao::rollbackTransaction(); $errors[] = $ex->getMessage() . $ex->getTraceAsString(); } $param->ResponseData = StringUtilsAbstract::getJson($results, $errors); }