Beispiel #1
0
 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;
 }
Beispiel #2
0
 public static function getConnection()
 {
     if (!self::$_connection) {
         self::$_connection = self::getResource()->getConnection('oemdb_read');
     }
     return self::$_connection;
 }
Beispiel #3
0
 protected function _addProducts($productsData)
 {
     $parts = array();
     foreach ($productsData as $itemData) {
         $partNumber = $itemData[0];
         $qty = max(abs($itemData[1]), 1);
         if (isset($parts[$partNumber])) {
             $parts[$partNumber] += $qty;
         } else {
             $parts[$partNumber] = $qty;
         }
     }
     foreach ($parts as $partNumber => $qty) {
         $productIsOEM = false;
         $productId = Mage::getResourceModel('catalog/product')->getIdBySku($partNumber);
         // if this is not a SKU, but a Part Number
         if (!$productId) {
             $sku = Mage::helper('wholesale/OEM')->getSkuByPartNumber($partNumber);
             $productId = Mage::getResourceModel('catalog/product')->getIdBySku($sku);
         }
         // this is [most probably] OEM product
         if (!$productId) {
             $productId = $this->getDummyProductId();
             $productIsOEM = true;
         }
         $product = Mage::getModel('catalog/product')->load($productId);
         if (!$product->getId()) {
             Mage::log('ERROR: Product not found, ID=' . (int) $productId);
             Mage::throwException($this->__('Cannot load product ID=%d', (int) $productId));
             return;
         }
         if ($productIsOEM) {
             $partInfo = $this->getPartInfo($partNumber);
             $productPrice = Mage::helper('wholesale')->calculateOEMPrice($partInfo['cost']);
             $brandName = Vikont_Wholesale_Helper_OEM::getSupplierName($partInfo['supplier_code']);
             $productName = $this->__('OEM %s | %s', $brandName, $partNumber);
             $customOptionId = $this->getCustomOptionId();
             $addToCartParams = new Varien_Object(array('product' => $productId, 'options' => array($customOptionId => $partNumber), 'qty' => $qty));
             $this->_quote->addProduct($product, $addToCartParams);
             $this->_quote->getItemsCollection()->getLastItem()->setSku($partNumber)->setName($productName)->setOriginalCustomPrice($productPrice);
         } else {
             $addToCartParams = new Varien_Object(array('product' => $productId, 'qty' => $qty));
             try {
                 if (Mage::getStoreConfigFlag('wholesale/order/ignore_stock_status')) {
                     $product->getStockItem()->setManageStock(false)->setUseConfigManageStock(false)->setIsInStock(true)->setNotifyStockQty(false)->setUseConfigNotifyStockQty(false)->setBackorders(true)->setUseConfigBackorders(false)->setStockStatusChangedAutomatically(false);
                 }
                 $this->_quote->addProduct($product, $addToCartParams);
             } catch (Exception $e) {
                 $message = $e->getMessage();
                 if (false !== strpos($message, 'out of stock')) {
                     $message = sprintf('Product %s SKU=%s cannot be ordered because it is currently out of stock.', $product->getName(), $partNumber);
                 }
                 Mage::throwException($message);
             }
         }
     }
 }
Beispiel #4
0
 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);
 }