Esempio n. 1
0
 /**
  * Getting all the price match companies
  * @return Ambigous <multitype:multitype: , string>
  */
 public static function getAllCompaniesForPriceMatching()
 {
     $outputArray = array();
     foreach (PriceMatchCompany::findAll() as $pmc) {
         $companyName = trim($pmc->getCompanyName());
         if (!isset($outputArray[$companyName])) {
             $outputArray[$companyName] = array();
         }
         $outputArray[$companyName][] = trim($pmc->getCompanyAlias());
         $outputArray[$companyName]['PriceMatchCompanyId'] = $pmc->getId();
         // added b/c improvment of pricematch (Jun2015). it keeps PriceMatchCompany for further reference
     }
     return $outputArray;
 }
 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);
 }
Esempio n. 3
0
 public function getMin()
 {
     $sku = trim($this->getSku());
     $product = Product::getBySku($sku);
     if ($product instanceof Product) {
         $where = array(1);
         $params = array();
         $where[] = "minId = ? ";
         $params[] = $this->getId();
         $companies = PriceMatchCompany::getAll();
         $companyIds = array_map(create_function('$a', 'return $a->getId();'), $companies);
         $where[] = 'companyId IN (' . implode(", ", array_fill(0, count($companyIds), "?")) . ')';
         $params = array_merge($params, $companyIds);
         //calculate real price range
         $records = PriceMatchRecord::getAllByCriteria(implode(' AND ', $where), $params, true, 1, 1, array('price' => 'asc'));
         if (count($records) > 0) {
             $this->setRecord($records[0])->setActive(true)->save();
         }
     }
     return $this->getRecord();
 }
Esempio n. 4
0
 public static function getMatchPrices($sku)
 {
     //file_put_contents('/tmp/datafeed/web.log', __FILE__ .':' . __FUNCTION__ . ':' . __LINE__ . ':' . '----start getMatchPrices' . PHP_EOL, FILE_APPEND | LOCK_EX);
     $result = array();
     $priceMatchResults = self::getPricesBySku($sku);
     $priceMatchResults = $priceMatchResults['items'];
     $companies = PriceMatchCompany::getAll();
     foreach ($priceMatchResults as $priceMatchResult) {
         if (($name = trim($priceMatchResult['name'])) === '') {
             continue;
         }
         $price = str_replace(' ', '', str_replace('$', '', str_replace(',', '', $priceMatchResult['price'])));
         $url = $priceMatchResult['url'];
         foreach ($companies as $company) {
             $companyAlias = $company->getCompanyAlias();
             if (strtolower($name) === strtolower($companyAlias)) {
                 $result[] = array('PriceMatchCompany' => $company, 'price' => $price, 'name' => $name, 'url' => $url);
             }
         }
     }
     //file_put_contents('/tmp/datafeed/web.log', __FILE__ .':' . __FUNCTION__ . ':' . __LINE__ . ':' . '----end getMatchPrices' . PHP_EOL, FILE_APPEND | LOCK_EX);
     return $result;
 }
Esempio n. 5
0
 /**
  * create for PriceMatchRecord
  * 
  * @param PriceMatchCompany $company
  * @param PriceMatchMin $min
  * @param string $price
  * @param string $url
  * @param string $name
  * @throws Exception
  */
 public static function create(PriceMatchCompany $company, PriceMatchMin $min, $price, $url = '', $name = '')
 {
     if (abs(doubleval($price)) === 0.0 || doubleval($price) < 0.0 || trim($price) === '') {
         throw new Exception('price must be positive, "' . $price . '" given');
     }
     $price = doubleval($price);
     $from_date = UDate::now('Australia/Melbourne')->setTime(0, 0, 0)->setTimeZone('UTC');
     $to_date = UDate::now('Australia/Melbourne')->setTime(23, 59, 59)->setTimeZone('UTC');
     if (count($i = self::getAllByCriteria('companyId = ? and minId = ? and created >= ? and created <= ?', array($company->getId(), $min->getId(), $from_date, $to_date), true, 1, 1, array('id' => 'desc'))) > 0) {
         $entity = $i[0];
     } else {
         $entity = new self();
     }
     $entity->setCompany($company)->setMin($min)->setPrice($price)->setUrl(trim($url))->setName(trim($name))->save();
     return $entity;
 }
Esempio n. 6
0
 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);
 }