public function getAllPricesForProduct($sender, $param) { $result = $errors = $outputArray = $finalOutputArray = array(); try { if (!isset($param->CallbackParameter->sku) || ($sku = trim($param->CallbackParameter->sku)) === '') { throw new Exception('No SKU to search on!'); } if (!isset($param->CallbackParameter->companyAliases) || count($companyAliases = json_decode(json_encode($param->CallbackParameter->companyAliases), true)) === 0) { throw new Exception('No companyAliases to search on!'); } if (!isset($param->CallbackParameter->price) || ($myPrice = str_replace(' ', '', $param->CallbackParameter->price)) === '') { $myPrice = 0; } else { if (!is_numeric($myPrice = str_replace('$', '', str_replace(',', '', $myPrice)))) { throw new Exception('No provided my price is NOT a number(=' . $myPrice . '!'); } } $result['item'] = PriceMatcher::getPrices($companyAliases, $sku, $myPrice); } catch (Exception $ex) { $errors[] = $ex->getMessage(); } $param->ResponseData = StringUtilsAbstract::getJson($result, $errors); }
/** * Getting price matching information * * @param unknown $sender * @param unknown $param */ public function priceMatching($sender, $param) { $results = $errors = array(); try { $id = isset($param->CallbackParameter->id) ? $param->CallbackParameter->id : ''; $product = Product::get($id); $prices = ProductPrice::getPrices($product, ProductPriceType::get(ProductPriceType::ID_RRP)); $companies = PriceMatcher::getAllCompaniesForPriceMatching(); $prices = PriceMatcher::getPrices($companies, $product->getSku(), count($prices) === 0 ? 0 : $prices[0]->getPrice()); $myPrice = $prices['myPrice']; $minPrice = $prices['minPrice']; $msyPrice = $prices['companyPrices']['MSY']; $prices['id'] = $id; $results = $prices; } catch (Exception $ex) { $errors[] = $ex->getMessage(); } $param->ResponseData = StringUtilsAbstract::getJson($results, $errors); }