public function getOutputData() { $result = false; $partNumber = $this->getPartNumber(); $oemPart = Mage::helper('wholesale/OEM')->findPart($partNumber); if ($oemPart) { $result = array('type' => 'oem', 'sku' => $partNumber, 'brand' => Vikont_Wholesale_Helper_OEM::getBrandNameByCode(Vikont_Wholesale_Helper_OEM::getARI2TMSCode(trim($oemPart['supplier_code']))), 'name' => $oemPart['part_name'], 'msrp' => Vikont_Format::formatPrice($oemPart['msrp']), 'price' => Vikont_Format::formatPrice(Mage::helper('wholesale')->calculateOEMPrice($oemPart['cost']))); } else { $productId = Mage::helper('wholesale/product')->findProductIdByAttributeValue('ari_part_number', $partNumber); if ($productId) { $product = Mage::getModel('catalog/product')->load($productId); $result = array('type' => 'regular', 'sku' => $product->getSku(), 'brand' => $product->getData('ari_manufacturer'), 'name' => $product->getName(), 'msrp' => Vikont_Format::formatPrice($product->getMsrp()), 'price' => Vikont_Format::formatPrice(Mage::helper('wholesale')->calculateWholesalePrice($product->getPrice()))); } else { $sku = Mage::helper('wholesale/OEM')->getSkuByPartNumber($partNumber); if ($sku) { $productId = Mage::getResourceModel('catalog/product')->getIdBySku($sku); if ($productId) { $product = Mage::getModel('catalog/product')->load($productId); $result = array('type' => 'sku', 'sku' => $sku, 'brand' => $product->getData('ari_manufacturer'), 'name' => $product->getName(), 'msrp' => Vikont_Format::formatPrice($product->getMsrp()), 'price' => Vikont_Format::formatPrice(Mage::helper('wholesale')->calculateWholesalePrice($product->getPrice()))); } } } } return $result; }
protected function _processSearchPart($brandCode, $partNumber, $modelName = null, $paging = array(), $requestType = 'parts') { $result = array('res' => array()); switch ($requestType) { case 'parts': $data = $this->request($this->_config['ari']['calls']['search']['parts'], array('brandCode' => $brandCode, 'search' => $partNumber), $paging); break; case 'parts_within_models': $data = $this->request($this->_config['ari']['calls']['search']['parts_within_models'], array('brandCode' => $brandCode, 'modelSearch' => $modelName, 'partSearch' => $partNumber), $paging); break; } if (@self::$_params['debug']) { vd($data); } if (!isset($data['Data'])) { throw new Exception('No Data key in result'); } require_once 'Format.php'; if (isset($data['Data']['Results']) && count($data['Data']['Results'])) { $skus = array(); foreach ($data['Data']['Results'] as $part) { $skus[] = $part['Sku']; } $oemData = $this->getOEMData($brandCode, $skus); $this->initSession(); $result['customerId'] = (int) @$_SESSION['customer_base']['id']; $isWholesale = @$_SESSION['customer_base']['is_wholesale']; $customerCostPercent = @$_SESSION['customer_base']['cost_percent']; foreach ($data['Data']['Results'] as $part) { $sku = $part['Sku']; if (isset($oemData[$sku]) && $oemData[$sku]['available']) { // if there is such record in OEM table $retailPrice = $oemData[$sku]['price'] ? (double) $oemData[$sku]['price'] : (double) $part['MSRP']; $price = $isWholesale && $customerCostPercent > 0 ? round($oemData[$sku]['cost'] * (100 + $customerCostPercent) / 100, 2) : $retailPrice; $result['res'][] = array('available' => 1, 'id' => $part['PartId'], 'sku' => trim($sku), 'name' => trim($oemData[$sku]['part_name'] ? $oemData[$sku]['part_name'] : $part['Description']), 'uom' => $oemData[$sku]['uom'], 'msrp' => Vikont_Format::formatPrice($oemData[$sku]['msrp']), 'price' => Vikont_Format::formatPrice($price), 'hidePrice' => (int) $oemData[$sku]['hide_price'], 'isSuperseded' => (bool) $part['IsSuperseded'], 'nla' => (bool) $part['NLA'], 'hasModels' => (int) $part['HasModels'], 'invW' => (int) $oemData[$sku]['inv_wh'], 'stockStatus' => (int) ($oemData[$sku]['inv_wh'] > 0)); } else { $result['res'][] = array('available' => 0, 'id' => $part['PartId'], 'sku' => trim($sku), 'name' => $part['Description']); } } } $result = array_merge_recursive($result, $this->_checkPaging($data)); if (@self::$_params['debug']) { vd($result); } return $result; }
public function getOutputData() { $result = array(); $partNumbers = array(); if (!is_array($this->getPartNumbers())) { // just for a case return $result; } foreach ($this->getPartNumbers() as $line) { $partNumber = @$line[0]; if (!$partNumber) { continue; } if (count($line) > 0) { if (count($line) > 1) { $qty = (int) $line[1]; $qty = $qty ? $qty : 1; } else { $qty = 1; } if (isset($result[$partNumber])) { $result[$partNumber]['qty'] += $qty; } else { $partNumbers[$partNumber] = true; $result[$partNumber] = array('partNumber' => $partNumber, 'qty' => $qty, 'type' => 'na', 'name' => 'Part not found'); } } } $oemData = Mage::helper('wholesale/OEM')->findParts(array_keys($partNumbers)); if ($oemData) { foreach ($oemData as $item) { $partNumber = $item['part_number']; unset($partNumbers[$partNumber]); $result[$partNumber]['type'] = 'oem'; $result[$partNumber]['brand'] = Vikont_Wholesale_Helper_OEM::getBrandNameByCode(Vikont_Wholesale_Helper_OEM::getARI2TMSCode($item['supplier_code'])); $result[$partNumber]['name'] = $item['part_name']; $result[$partNumber]['msrp'] = Vikont_Format::formatPrice($item['msrp']); $result[$partNumber]['price'] = Vikont_Format::formatPrice(Mage::helper('wholesale')->calculateOEMPrice($item['cost'], $item['price'], $item['msrp'])); } } // now checking for regular products if (count($partNumbers)) { $productIds = Mage::helper('wholesale/product')->findRegularProducts(array_keys($partNumbers)); if ($productIds) { foreach ($productIds as $productId => $partNumber) { unset($partNumbers[$partNumber]); $product = Mage::getModel('catalog/product')->load($productId); $result[$partNumber]['type'] = 'regular'; $result[$partNumber]['brand'] = $product->getData('ari_manufacturer'); $result[$partNumber]['name'] = $product->getName(); $result[$partNumber]['msrp'] = Vikont_Format::formatPrice($product->getMsrp()); $result[$partNumber]['price'] = Vikont_Format::formatPrice(calculateWholesalePrice($product->getPrice())); } } } // now checking for regular products found by part number if (count($partNumbers)) { foreach ($partNumbers as $partNumber => $value) { // yes, we don't need $value here $sku = Mage::helper('wholesale/OEM')->getSkuByPartNumber($partNumber); if ($sku) { $productId = Mage::getResourceModel('catalog/product')->getIdBySku($sku); if ($productId) { $product = Mage::getModel('catalog/product')->load($productId); $result[$partNumber]['type'] = 'sku'; $result[$partNumber]['brand'] = $product->getData('ari_manufacturer'); $result[$partNumber]['name'] = $product->getName(); $result[$partNumber]['msrp'] = Vikont_Format::formatPrice($product->getMsrp()); $result[$partNumber]['price'] = Vikont_Format::formatPrice(calculateWholesalePrice($product->getPrice())); } } } } return array_values($result); }
public function getPrice($formatted = false) { $this->getPartInfo(); return $formatted ? Vikont_Format::formatPrice($this->_partInfo['price']) : $this->_partInfo['price']; }