/** * Getting the price match result * * @param array $companyAliases * @param string $sku * @param number $myPrice * * @return multitype:number multitype: unknown Ambigous <number, mixed> */ public static function getPrices($companyAliases, $sku, $myPrice) { $myPrice = StringUtilsAbstract::getValueFromCurrency($myPrice); //initialize values $finalOutputArray = array('sku' => $sku, 'myPrice' => $myPrice, 'minPrice' => 0, 'companyPrices' => array()); foreach ($companyAliases as $key => $value) { $finalOutputArray['companyPrices'][$key] = array('price' => 0, 'priceURL' => '', 'PriceMatchCompanyId' => $value['PriceMatchCompanyId']); } $url = 'http://www.staticice.com.au/cgi-bin/search.cgi'; //getting actual values $productPriceArray = HTMLParser::getPriceListForProduct($url, $sku); foreach ($productPriceArray as $productPriceInfo) { if (($companyDetails = trim($productPriceInfo['companyDetails'])) === '') { continue; } $cdArray = explode('|', $companyDetails); $companyURL = isset($cdArray[count($cdArray) - 2]) ? trim($cdArray[count($cdArray) - 2]) : trim($companyDetails); foreach ($companyAliases as $key => $value) { if (is_array($value) === true && in_array(strtolower($companyURL), array_map(create_function('$a', 'return strtolower($a);'), $value))) { $price = str_replace(' ', '', str_replace('$', '', str_replace(',', '', $productPriceInfo['price']))); if ($finalOutputArray['minPrice'] == 0 || $finalOutputArray['minPrice'] > $price) { $finalOutputArray['minPrice'] = $price; } $finalOutputArray['companyPrices'][$key] = array('price' => $price, 'priceURL' => HTMLParser::getHostUrl($url) . $productPriceInfo['priceLink'], 'PriceMatchCompanyId' => $value['PriceMatchCompanyId']); break; } } } //return the result $finalOutputArray['priceDiff'] = $finalOutputArray['myPrice'] - $finalOutputArray['minPrice']; return $finalOutputArray; }
/** * Getting the price match result * * @return array */ private function getPrices() { $result = array(); $priceMatchResults = HTMLParser::getPriceListForProduct($this->base_url, $this->sku); foreach ($priceMatchResults as $priceMatchResult) { if (($companyDetails = trim($priceMatchResult['companyDetails'])) === '') { continue; } $companyDetailsArray = explode('|', $companyDetails); $companyURL = isset($companyDetailsArray[count($companyDetailsArray) - 2]) ? trim($companyDetailsArray[count($companyDetailsArray) - 2]) : trim($companyDetails); $companyURL = strtolower($companyURL); $companyURL = str_replace('https://', '', $companyURL); $companyURL = str_replace('http://', '', $companyURL); $name = isset($companyDetailsArray[count($companyDetailsArray) - 3]) ? trim($companyDetailsArray[count($companyDetailsArray) - 3]) : trim($companyDetails); $price = str_replace(' ', '', str_replace('$', '', str_replace(',', '', $priceMatchResult['price']))); $url = HTMLParser::getHostUrl($this->base_url) . $priceMatchResult['priceLink']; foreach (PriceMatchCompany::getAll() as $company) { if ($companyURL === strtolower($company->getCompanyAlias())) { $result[] = array('PriceMatchCompany' => $company, 'price' => $price, 'name' => $name, 'url' => $url); if ($this->debug === true) { echo $company->getCompanyName() . '(id=' . $company->getId() . "), \$" . $price . "\n"; } } } } return $result; }