protected function getSuggestCollection($query) { $productAdapter = new Mage_Catalog_Model_Convert_Adapter_Product(); $collection = Mage::getModel('catalog/product')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId())->addFieldToFilter('name', array('like' => $query))->addAttributeToSelect(array('sku', 'name', 'small_image', 'is_salable', 'image', 'thumbnail'))->addAttributeToFilter('visibility', array('in' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH))->addAttributeToFilter('type_id', array('in' => $productAdapter->getProductTypes()))->addAttributeToFilter('status', 1)->setPageSize(10); if (empty($collection->getData())) { $collection = Mage::getModel('catalog/product')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId())->addFieldToFilter('sku', array('like' => $query))->addAttributeToSelect(array('name', 'sku', 'small_image', 'image', 'is_salable', 'thumbnail'))->addAttributeToFilter('visibility', array('in' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH))->addAttributeToFilter('status', 1)->addAttributeToFilter('type_id', array('in' => $productAdapter->getProductTypes()))->setPageSize(10); } return $collection; }
/** * Load product collection Id(s) */ public function load() { $attrFilterArray = array(); $attrFilterArray['name'] = 'like'; $attrFilterArray['sku'] = 'startsWith'; $attrFilterArray['type'] = 'eq'; $attrFilterArray['attribute_set'] = 'eq'; $attrFilterArray['visibility'] = 'eq'; $attrFilterArray['status'] = 'eq'; $attrFilterArray['price'] = 'fromTo'; $attrFilterArray['qty'] = 'fromTo'; $attrFilterArray['store_id'] = 'eq'; $attrToDb = array('type' => 'type_id', 'attribute_set' => 'attribute_set_id'); $filters = $this->_parseVars(); if ($qty = $this->getFieldValue($filters, 'qty')) { $qtyFrom = isset($qty['from']) ? (double) $qty['from'] : 0; $qtyTo = isset($qty['to']) ? (double) $qty['to'] : 0; $qtyAttr = array(); $qtyAttr['alias'] = 'qty'; $qtyAttr['attribute'] = 'cataloginventory/stock_item'; $qtyAttr['field'] = 'qty'; $qtyAttr['bind'] = 'product_id=entity_id'; $qtyAttr['cond'] = "{{table}}.qty between '{$qtyFrom}' AND '{$qtyTo}'"; $qtyAttr['joinType'] = 'inner'; $this->setJoinField($qtyAttr); } parent::setFilter($attrFilterArray, $attrToDb); if ($price = $this->getFieldValue($filters, 'price')) { $this->_filter[] = array('attribute' => 'price', 'from' => $price['from'], 'to' => $price['to']); $this->setJoinAttr(array('alias' => 'price', 'attribute' => 'catalog_product/price', 'bind' => 'entity_id', 'joinType' => 'LEFT')); } /**Start Code For Vendor**/ $isVendor = Mage::helper('cartmart')->isVendor(); //current user is vendor or not if ($isVendor) { /**Fetch Current User Id**/ $user = Mage::getSingleton('admin/session'); $userId = $user->getUser()->getUserId(); $this->_filter[] = array('attribute' => 'vendor', 'eq' => $userId); } /**End Code For Vendor**/ return parent::load(); }
/** * Save product (import) * * @param array $importData * @throws Mage_Core_Exception * @return bool */ public function saveRow(array $importData) { parent::saveRow($importData); if (empty($importData['store'])) { if (!is_null($this->getBatchParams('store'))) { $store = $this->getStoreById($this->getBatchParams('store')); } else { $message = Mage::helper('payperrentals')->__('Skipping import row, required field "%s" is not defined.', 'store'); Mage::throwException($message); } } else { $store = $this->getStoreByCode($importData['store']); } $storeId = $store->getId(); $product = $this->getProductModel()->reset(); //$product->setStoreId($storeId); $productId = $product->getIdBySku($importData['sku']); if ($productId) { $product->load($productId); /*Import Reservation prices*/ try { $resPricesData = explode(';', $importData["resprices"]); $stockData = $product->getStockData(); $stockData['qty'] = $importData['payperrentals_quantity']; $stockData['is_in_stock'] = 1; $stockData['manage_stock'] = 0; $stockData['use_config_manage_stock'] = 0; $product->setStockData($stockData); $product->setIsMassupdate(true); $product->setExcludeUrlRewrite(true); $product->save(); Mage::getResourceSingleton('payperrentals/reservationprices')->deleteByEntityId($product->getId()); foreach ($resPricesData as $resPrice) { if (!empty($resPrice)) { $priceData = explode('=', $resPrice); $periodType = ITwebexperts_Payperrentals_Model_Product_Periodtype::MINUTES; switch ($priceData[1]) { case 'Minute': $periodType = ITwebexperts_Payperrentals_Model_Product_Periodtype::MINUTES; break; case 'Hour': $periodType = ITwebexperts_Payperrentals_Model_Product_Periodtype::HOURS; break; case 'Day': $periodType = ITwebexperts_Payperrentals_Model_Product_Periodtype::DAYS; break; case 'Week': $periodType = ITwebexperts_Payperrentals_Model_Product_Periodtype::WEEKS; break; case 'Month': $periodType = ITwebexperts_Payperrentals_Model_Product_Periodtype::MONTHS; break; case 'Year': $periodType = ITwebexperts_Payperrentals_Model_Product_Periodtype::YEARS; break; } $myRes = Mage::getModel('payperrentals/reservationprices')->setEntityId($product->getId())->setStoreId($storeId)->setNumberof($priceData[0])->setPtype($periodType)->setPrice($priceData[2])->setQtyStart($priceData[3])->setQtyEnd($priceData[4])->setDateFrom($priceData[5])->setDateTo($priceData[6])->setCustomersGroup($priceData[7])->save(); } } } catch (Exception $e) { } //import sn numbers try { $resSnData = explode(';', $importData["snppr"]); Mage::getResourceSingleton('payperrentals/serialnumbers')->deleteByEntityId($product->getId()); $p = $product->getPayperrentalsQuantity(); foreach ($resSnData as $resSn) { if (!empty($resSn)) { $snData = explode('=', $resSn); if (!isset($snData[1]) || empty($snData[1])) { $snData[1] = 'A'; } $myRes = Mage::getModel('payperrentals/serialnumbers')->setEntityId($product->getId())->setSn($snData[0])->setStatus($snData[1])->save(); $p--; if ($p <= 0) { break; } } } } catch (Exception $e) { } } /*End Import*/ return true; }