Example #1
0
 /**
  *
  * Retrieve Product data objects
  * LOE: remove if status(=2) is disabled or visibility(=1) false
  *
  * @param int|array $productIds
  * @param int       $storeId
  * @param int       $entityId
  * @param int       $lastEntityId ref
  *
  * @return array
  */
 protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId)
 {
     $storeId = (int) $storeId;
     if (false === $this->_getHelper()->excludeDisabledProducts($storeId) && false === $this->_getHelper()->excludeNotVisibleProducts($storeId) && false === $this->_getHelper()->excludeDisabledCategories($storeId)) {
         return parent::_getProducts($productIds, $storeId, $entityId, $lastEntityId);
     }
     $products = array();
     $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
     /** @var SchumacherFM_FastIndexer_Model_Db_Adapter_Pdo_Mysql $adapter */
     $adapter = $this->_getReadAdapter();
     if ($productIds !== null) {
         if (!is_array($productIds)) {
             $productIds = array($productIds);
         }
     }
     $bind = array('website_id' => (int) $websiteId, 'entity_id' => (int) $entityId);
     /** @var Varien_Db_Select $select */
     $select = $adapter->select()->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))->join(array('w' => $this->getTable('catalog/product_website')), 'e.entity_id = w.product_id AND w.website_id = :website_id', array())->where('e.entity_id > :entity_id')->order('e.entity_id')->limit($this->_productLimit);
     // <fastindexer>
     $this->_addProductStatusToSelect($select, $storeId);
     $this->_addProductVisibilityToSelect($select, $storeId);
     $this->_addProductAttributeToSelect($select, 'name', $storeId);
     $this->_addProductAttributeToSelect($select, 'url_key', $storeId);
     $this->_addProductAttributeToSelect($select, 'url_path', $storeId);
     /*</fastindexer>*/
     if (false === empty($productIds)) {
         $select->where('e.entity_id IN(?)', $productIds);
     }
     Mage::dispatchEvent('fastindexer_get_products_select', array('model' => $this, 'select' => $select, 'store_id' => $storeId));
     $rowSet = $adapter->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         $product = new Varien_Object($row);
         $product->setIdFieldName('entity_id');
         $product->setCategoryIds(array());
         $product->setStoreId($storeId);
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($rowSet);
     if (count($products) > 0 && false === $this->_getHelper()->excludeCategoryPathInProductUrl($storeId)) {
         $select = $adapter->select()->from($this->getTable('catalog/category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products));
         $this->_excludeDisabledCategories($select, $storeId);
         // fastindexer
         $categories = $adapter->fetchAll($select);
         foreach ($categories as $category) {
             $productId = $category['product_id'];
             $categoryIds = $products[$productId]->getCategoryIds();
             $categoryIds[] = $category['category_id'];
             $products[$productId]->setCategoryIds($categoryIds);
         }
     }
     return $products;
 }
Example #2
0
 protected function _getProducts($productIds = null, $storeId, $entityId = 0, &$lastEntityId)
 {
     $products = array();
     $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
     if (!is_null($productIds)) {
         if (!is_array($productIds)) {
             $productIds = array($productIds);
         }
     }
     $select = $this->_getWriteAdapter()->select()->useStraightJoin(true)->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))->join(array('w' => $this->getTable('catalog/product_website')), $this->_getWriteAdapter()->quoteInto('e.entity_id=w.product_id AND w.website_id=?', $websiteId), array())->where('e.entity_id>?', $entityId)->order('e.entity_id')->limit($this->_productLimit);
     if (!is_null($productIds)) {
         $select->where('e.entity_id IN(?)', $productIds);
     }
     $query = $this->_getWriteAdapter()->query($select);
     while ($row = $query->fetch()) {
         $product = new Varien_Object($row);
         $product->setIdFieldName('entity_id');
         $product->setCategoryIds(array());
         $product->setStoreId($storeId);
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($query);
     if ($products) {
         $select = $this->_getReadAdapter()->select()->from($this->getTable('catalog/category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products));
         $categories = $this->_getReadAdapter()->fetchAll($select);
         foreach ($categories as $category) {
             $productId = $category['product_id'];
             $categoryIds = $products[$productId]->getCategoryIds();
             $categoryIds[] = $category['category_id'];
             $products[$productId]->setCategoryIds($categoryIds);
         }
         foreach (array('name', 'url_key', 'url_path', 'visibility', "status") as $attributeCode) {
             $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId);
             foreach ($attributes as $productId => $attributeValue) {
                 $products[$productId]->setData($attributeCode, $attributeValue);
             }
         }
     }
     return $products;
 }
Example #3
0
 protected function _beforeSave(Varien_Object $object)
 {
     if ($object->hasCategoryIds()) {
         $categoryIds = Mage::getResourceSingleton('catalog/category')->verifyIds($object->getCategoryIds());
         $object->setCategoryIds($categoryIds);
     }
     if (!$object->getSku() && Mage::getStoreConfigFlag('udprod/general/auto_sku')) {
         $adapter = $this->_getReadAdapter();
         $pidSuffix = $adapter->fetchOne($adapter->select()->from($this->getEntityTable(), 'max(entity_id)'));
         do {
             $object->setSku($object->getUdropshipVendor() . '-' . ++$pidSuffix);
         } while (Mage::helper('udropship/catalog')->getPidBySku($object->getSku(), $object->getId()));
     }
     $vId = Mage::getSingleton('udropship/session')->getVendorId();
     if (!$vId && Mage::app()->getStore()->isAdmin() && Mage::helper('udropship')->isModuleActive('umicrosite') && ($v = Mage::helper('umicrosite')->getAdminhtmlVendor())) {
         $vId = $v->getId();
     } else {
         $vId = $object->getData('udropship_vendor');
     }
     if (Mage::getStoreConfigFlag('udprod/general/prefix_sku_vid') && $vId && 0 !== strpos($object->getSku(), $vId . '-')) {
         $object->setSku($vId . '-' . $object->getSku());
     }
     if (Mage::getStoreConfigFlag('udprod/general/unique_vendor_sku') && $vId && !Mage::helper('udropship')->isUdmultiActive()) {
         $vSkuAttr = Mage::getStoreConfig('udropship/vendor/vendor_sku_attribute');
         if ($vSkuAttr && $vSkuAttr != 'sku') {
             if (!$object->getData($vSkuAttr)) {
                 Mage::throwException('Vendor SKU attribute is empty');
             } elseif (Mage::helper('udropship/catalog')->getPidByVendorSku($object->getData($vSkuAttr), $vId, $object->getId())) {
                 Mage::throwException(Mage::helper('udropship')->__('Vendor SKU "%s" is already used', $object->getData($vSkuAttr)));
             }
         }
     }
     if (Mage::helper('udropship')->hasMageFeature('resource_1.6')) {
         return Mage_Catalog_Model_Resource_Abstract::_beforeSave($object);
     } else {
         return Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract::_beforeSave($object);
     }
 }
Example #4
0
 /**
  * Process post data before save
  *
  * @param Varien_Object $object
  * @return EM_Blog_Model_Resource_Post
  */
 protected function _beforeSave(Varien_Object $object)
 {
     /**
      * Check if declared category ids in object data.
      */
     if ($object->hasCategoryIds()) {
         $categoryIds = Mage::getResourceSingleton('blog/category')->verifyIds($object->getCategoryIds());
         $object->setCategoryIds($categoryIds);
     }
     if ($object->getId()) {
         $oldImage = $object->getImage();
         // Remove Old Image
         if (is_array($oldImage)) {
             if (isset($oldImage['delete'])) {
                 $path = Mage::getBaseDir('media') . DS . 'emblog' . DS . 'post' . DS;
                 $nameImage = $oldImage['value'];
                 /* Remove primary image */
                 if (is_file($path . $nameImage)) {
                     unlink($path . $nameImage);
                 }
                 /* Remove thumbnail image */
                 $thumbnailWidth = Mage::getStoreConfig('blog/info/thumbnail_width');
                 $thumbnailHeight = Mage::getStoreConfig('blog/info/thumbnail_height');
                 if (is_file($path . 'thumbnail' . DS . "{$thumbnailWidth}x{$thumbnailHeight}" . DS . $nameImage)) {
                     unlink($path . 'thumbnail' . DS . "{$thumbnailWidth}x{$thumbnailHeight}" . DS . $nameImage);
                 }
                 /* Remove thumbnail image at recent post blog */
                 $thumbnailWidth = Mage::getStoreConfig('blog/info/recent_thumbnail_width');
                 $thumbnailHeight = Mage::getStoreConfig('blog/info/recent_thumbnail_height');
                 if (is_file($path . 'thumbnail' . DS . "{$thumbnailWidth}x{$thumbnailHeight}" . DS . $nameImage)) {
                     unlink($path . 'thumbnail' . DS . "{$thumbnailWidth}x{$thumbnailHeight}" . DS . $nameImage);
                 }
             }
         }
     }
     return parent::_beforeSave($object);
 }
Example #5
0
 /**
  * Retrieve Product data objects
  *
  * @param int|array $productIds
  * @param int $storeId
  * @param int $entityId
  * @param int $lastEntityId
  * @return array
  */
 protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId)
 {
     $products = array();
     $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
     $adapter = $this->_getReadAdapter();
     if ($productIds !== null) {
         if (!is_array($productIds)) {
             $productIds = array($productIds);
         }
     }
     $bind = array('website_id' => (int) $websiteId, 'entity_id' => (int) $entityId);
     $select = $adapter->select()->useStraightJoin(true)->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))->join(array('w' => $this->getTable('catalog/product_website')), 'e.entity_id = w.product_id AND w.website_id = :website_id', array())->where('e.entity_id > :entity_id')->order('e.entity_id')->limit($this->_productLimit);
     if ($productIds !== null) {
         $select->where('e.entity_id IN(?)', $productIds);
     }
     $rowSet = $adapter->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         $product = new Varien_Object($row);
         $product->setIdFieldName('entity_id');
         $product->setCategoryIds(array());
         $product->setStoreId($storeId);
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($rowSet);
     if ($products) {
         $select = $adapter->select()->from($this->getTable('catalog/category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products));
         $categories = $adapter->fetchAll($select);
         foreach ($categories as $category) {
             $productId = $category['product_id'];
             $categoryIds = $products[$productId]->getCategoryIds();
             $categoryIds[] = $category['category_id'];
             $products[$productId]->setCategoryIds($categoryIds);
         }
         foreach (array('name', 'url_key', 'url_path') as $attributeCode) {
             $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId);
             foreach ($attributes as $productId => $attributeValue) {
                 $products[$productId]->setData($attributeCode, $attributeValue);
             }
         }
     }
     return $products;
 }
 /**
  * Process product data before save
  *
  * @param Varien_Object $object
  * @return Mage_Catalog_Model_Resource_Product
  */
 protected function _beforeSave(Varien_Object $object)
 {
     /**
      * Try detect product id by sku if id is not declared
      */
     if (!$object->getId() && $object->getSku()) {
         $object->setId($this->getIdBySku($object->getSku()));
     }
     /**
      * Check if declared category ids in object data.
      */
     if ($object->hasCategoryIds()) {
         $categoryIds = Mage::getResourceSingleton('catalog/category')->verifyIds($object->getCategoryIds());
         $object->setCategoryIds($categoryIds);
     }
     return parent::_beforeSave($object);
 }
Example #7
0
 /**
  * Retrieve Product data objects
  * LOE: remove if status(=2) is disabled or visibility(=1) false
  *
  * @param int|array $productIds
  * @param int $storeId
  * @param int $entityId
  * @param int $lastEntityId
  * @return array
  */
 protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId)
 {
     $products = array();
     $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
     $adapter = $this->_getReadAdapter();
     if ($productIds !== null) {
         if (!is_array($productIds)) {
             $productIds = array($productIds);
         }
     }
     $bind = array('website_id' => (int) $websiteId, 'entity_id' => (int) $entityId);
     $select = $adapter->select()->useStraightJoin(true)->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))->join(array('w' => $this->getTable('catalog/product_website')), 'e.entity_id = w.product_id AND w.website_id = :website_id', array())->where('e.entity_id > :entity_id')->order('e.entity_id')->limit($this->_productLimit);
     if ($productIds !== null) {
         $select->where('e.entity_id IN(?)', $productIds);
     }
     //if we are to ignore disabled products... add the necessary joins and conditions
     if ($this->_helper()->HideDisabledProducts($storeId)) {
         $statusCode = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', 'status');
         $bind['status_id'] = (int) $statusCode;
         $bind['disabled'] = Mage_Catalog_Model_Product_Status::STATUS_DISABLED;
         $bind['store_id'] = (int) $storeId;
         $bind['default_store_id'] = 0;
         $select->joinLeft(array('s' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = s.entity_id AND s.attribute_id = :status_id AND s.store_id = :store_id', array());
         $select->joinLeft(array('ds' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = ds.entity_id AND ds.attribute_id = :status_id AND ds.store_id = :default_store_id', array());
         $select->where('s.value <> :disabled OR (s.value IS NULL AND ds.value <> :disabled)');
     }
     //if we are to ignore not visible products... add the necessary joins and conditions
     if ($this->_helper()->HideNotVisibileProducts($storeId)) {
         $visibilityCode = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', 'visibility');
         $bind['not_visible'] = Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE;
         $bind['visibility_id'] = (int) $visibilityCode;
         $bind['store_id'] = (int) $storeId;
         $bind['default_store_id'] = 0;
         $select->joinLeft(array('v' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = v.entity_id AND v.attribute_id = :visibility_id AND v.store_id = :store_id', array());
         $select->joinLeft(array('dv' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = dv.entity_id AND dv.attribute_id = :visibility_id AND dv.store_id = :default_store_id', array());
         $select->where('v.value <> :not_visible OR (v.value IS NULL AND dv.value <> :not_visible)');
     }
     $rowSet = $adapter->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         $product = new Varien_Object($row);
         $product->setIdFieldName('entity_id');
         $product->setCategoryIds(array());
         $product->setStoreId($storeId);
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($rowSet);
     if ($products) {
         $select = $adapter->select()->from($this->getTable('catalog/category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products));
         $categories = $adapter->fetchAll($select);
         foreach ($categories as $category) {
             $productId = $category['product_id'];
             $categoryIds = $products[$productId]->getCategoryIds();
             $categoryIds[] = $category['category_id'];
             $products[$productId]->setCategoryIds($categoryIds);
         }
         foreach (array('name', 'url_key', 'url_path') as $attributeCode) {
             $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId);
             foreach ($attributes as $productId => $attributeValue) {
                 $products[$productId]->setData($attributeCode, $attributeValue);
             }
         }
     }
     return $products;
 }