public function deleteAliasForPriceMatchCompany($sender, $param) { $result = $error = array(); try { if (!isset($param->CallbackParameter->data)) { throw new Exception('System Error: Noting to Delete!!!'); } $data = $param->CallbackParameter->data; if (!isset($data->id) || !isset($data->companyAlias) || ($id = trim($data->id)) == '' || ($alias = trim($data->companyAlias)) == '') { throw new Exception('Data to be deleted is NOT proper format'); } if (!($pmc = PriceMatchCompany::get($id)) instanceof PriceMatchCompany) { throw new Exception('Invalid Id [' . $id . '] provided for PriceMatchCompany!!!'); } $result['items'] = $pmc->setActive(false)->save()->getJson(); } catch (Exception $ex) { $error[] = $ex->getMessage(); } $param->ResponseData = StringUtilsAbstract::getJson($result, $error); }
public function newRule($sender, $param) { $results = $errors = array(); try { Dao::beginTransaction(); $results = $param->CallbackParameter; if (!isset($param->CallbackParameter->productId) || !($product = Product::get(trim($param->CallbackParameter->productId))) instanceof Product) { throw new Exception('Invalid Product Id passed in, "' . $param->CallbackParameter->productId . '" given'); } if (!isset($param->CallbackParameter->rule)) { throw new Exception('Invalid PriceMatchRule passed in, "' . $param->CallbackParameter->rule . '" given'); } if (!isset($param->CallbackParameter->rule->active)) { throw new Exception('Must pass in active (bool) for PriceMatchRule, "' . $param->CallbackParameter->rule->active . '" given'); } else { $active = $param->CallbackParameter->rule->active; } if ($active === true && (!isset($param->CallbackParameter->rule->company_id) || !($company = PriceMatchCompany::get(trim($param->CallbackParameter->rule->company_id))) instanceof PriceMatchCompany)) { throw new Exception('Invalid PriceMatchCompany Id passed in, "' . $param->CallbackParameter->rule->company_id . '" given'); } if ($active === false && ($rule = ProductPriceMatchRule::getByProduct($product)) instanceof ProductPriceMatchRule) { $rule->setActive($active)->save(); $results = $rule->getJson(); } elseif ($active === true) { $rule = ProductPriceMatchRule::create($product, $company, trim($param->CallbackParameter->rule->price_from), trim($param->CallbackParameter->rule->price_to), trim($param->CallbackParameter->rule->offset)); //file_put_contents('/tmp/datafeed/web.log', __FILE__ .':' . __FUNCTION__ . ':' . __LINE__ . ': run' . date('Y-m-d\TH:i:sP') . PHP_EOL, FILE_APPEND | LOCK_EX); PriceMatchConnector::run($product->getSku(), true); //file_put_contents('/tmp/datafeed/web.log', __FILE__ .':' . __FUNCTION__ . ':' . __LINE__ . ': getMinRecord' . date('Y-m-d\TH:i:sP'). PHP_EOL, FILE_APPEND | LOCK_EX); PriceMatchConnector::getMinRecord($product->getSku(), true); //file_put_contents('/tmp/datafeed/web.log', __FILE__ .':' . __FUNCTION__ . ':' . __LINE__ . ': getNewPrice' . date('Y-m-d\TH:i:sP') . PHP_EOL, FILE_APPEND | LOCK_EX); PriceMatchConnector::getNewPrice($product->getSku(), true, true); //file_put_contents('/tmp/datafeed/web.log', __FILE__ .':' . __FUNCTION__ . ':' . __LINE__ . ': end' . date('Y-m-d\TH:i:sP'). PHP_EOL, FILE_APPEND | LOCK_EX); $results = $rule->getJson(); } Dao::commitTransaction(); } catch (Exception $ex) { Dao::rollbackTransaction(); $errors[] = $ex->getMessage(); } $param->ResponseData = StringUtilsAbstract::getJson($results, $errors); }