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(); }
/** * put given price match result for all companies into PriceMatchRecord table * * @param unknown $companyPrices * @return PriceMatchConnector */ private function recordResult($priceMatchResults) { foreach ($priceMatchResults as $priceMatchResult) { $company = $priceMatchResult['PriceMatchCompany']; $price = doubleval($priceMatchResult['price']); $url = $priceMatchResult['url']; $name = $priceMatchResult['name']; $min = PriceMatchMin::create($this->sku); // to create PriceMatchRecord must have a PriceMatchMin, the record for PriceMatchMin will be null at this time instance if (abs($price) !== doubleval(0) && $price > doubleval(0) && trim($price) !== '') { PriceMatchRecord::create($company, $min, $price, $url); } } return $this; }