Example #1
0
 public function getProduct()
 {
     if (is_null($this->_afpVO)) {
         $this->_afpVO = new Varien_Object();
     }
     if (!$this->_afpVO->getCategoryIds()) {
         $_data = Mage::helper('awautorelated/forms')->getFormData($this->getRequest()->getParam('id'));
         if (!is_object($_data)) {
             $_data = new Varien_Object($_data);
         }
         if ($_data->getCategoryIds()) {
             $this->_afpVO->setCategoryIds(is_array($_data->getCategoryIds()) ? $_data->getCategoryIds() : @explode(',', $_data->getCategoryIds()));
         } else {
             $_currentlyViewed = $_data->getData('currently_viewed');
             $cats = array();
             if ($_currentlyViewed && (is_array($_currentlyViewed) || is_object($_currentlyViewed))) {
                 if (is_array($_currentlyViewed) && isset($_currentlyViewed['category_ids'])) {
                     $cats = is_array($_currentlyViewed['category_ids']) ? $_currentlyViewed['category_ids'] : explode(',', $_currentlyViewed['category_ids']);
                 } else {
                     if (is_object($_currentlyViewed) && $_currentlyViewed->getData('category_ids')) {
                         $cats = is_array($_currentlyViewed->getData('category_ids')) ? $_currentlyViewed->getData('category_ids') : explode(',', $_currentlyViewed->getData('category_ids'));
                     }
                 }
             }
             $this->_afpVO->setCategoryIds($cats);
         }
     }
     return $this->_afpVO;
 }
Example #2
0
 /**
  * Process fblock data before save
  *
  * @param Varien_Object $object
  * @return MF_Flexibleblock_Model_Resource_Fblock
  */
 protected function _beforeSave(Varien_Object $object)
 {
     /**
      * Check if declared category ids in object data.
      */
     if ($object->hasCategoryIds() && is_array($object->getCategoryIds()) && count($object->getCategoryIds())) {
         $categoryIds = Mage::getResourceSingleton('catalog/category')->verifyIds($object->getCategoryIds());
         $object->setData('category_ids', implode(',', $categoryIds));
     }
     //echo '<pre>';print_r($object->getData());exit;
     return parent::_beforeSave($object);
 }
Example #3
0
 /**
  * Save product category relations
  *
  * @param Varien_Object $object
  * @return Mage_Catalog_Model_Resource_Product
  */
 protected function _saveCategories(Varien_Object $object)
 {
     //pr($object->getData('category_subjects'));die();
     $l_aCategorySubjects = $object->getData('category_subjects');
     if (!is_array($l_aCategorySubjects)) {
         $l_aCategorySubjects = array();
     }
     /**
      * If category ids data is not declared we haven't do manipulations
      */
     if (!$object->hasCategoryIds()) {
         return $this;
     }
     $categoryIds = $object->getCategoryIds();
     $oldCategoryIds = $this->getCategoryIds($object);
     $object->setIsChangedCategories(false);
     $insert = array_diff($categoryIds, $oldCategoryIds);
     $delete = array_diff($oldCategoryIds, $categoryIds);
     $need_to_be_updated = array_diff($oldCategoryIds, $delete);
     $write = $this->_getWriteAdapter();
     if (!empty($need_to_be_updated)) {
         foreach ($need_to_be_updated as $categoryId) {
             if (empty($categoryId)) {
                 continue;
             }
             if (isset($l_aCategorySubjects[$categoryId])) {
                 $data = array('subject' => isset($l_aCategorySubjects[$categoryId]) ? $l_aCategorySubjects[$categoryId]['subject'] : null, 'subsubject' => isset($l_aCategorySubjects[$categoryId]) ? $l_aCategorySubjects[$categoryId]['subsubject'] : null);
                 $write->update($this->_productCategoryTable, $data, 'category_id = ' . (int) $categoryId . ' AND product_id = ' . (int) $object->getId());
             }
         }
     }
     if (!empty($insert)) {
         $data = array();
         foreach ($insert as $categoryId) {
             if (empty($categoryId)) {
                 continue;
             }
             $data[] = array('category_id' => (int) $categoryId, 'product_id' => (int) $object->getId(), 'position' => 1, 'subject' => isset($l_aCategorySubjects[$categoryId]) ? $l_aCategorySubjects[$categoryId]['subject'] : null, 'subsubject' => isset($l_aCategorySubjects[$categoryId]) ? $l_aCategorySubjects[$categoryId]['subsubject'] : null);
         }
         if ($data) {
             $write->insertMultiple($this->_productCategoryTable, $data);
         }
     }
     if (!empty($delete)) {
         foreach ($delete as $categoryId) {
             $where = array('product_id = ?' => (int) $object->getId(), 'category_id = ?' => (int) $categoryId);
             $write->delete($this->_productCategoryTable, $where);
         }
     }
     if (!empty($insert) || !empty($delete)) {
         $object->setAffectedCategoryIds(array_merge($insert, $delete));
         $object->setIsChangedCategories(true);
     }
     return $this;
 }
 public function render(Varien_Object $row)
 {
     $text = array();
     $categoryIds = $row->getCategoryIds();
     $allCats = Mage::helper('customoptions')->getCategories();
     if ($categoryIds && is_array($categoryIds)) {
         foreach ($categoryIds as $id) {
             if (isset($allCats[$id])) {
                 $text[] = str_replace('&nbsp;', '', $allCats[$id]);
             }
         }
     }
     return implode(', ', $text);
 }
Example #5
0
 public function getProduct()
 {
     if (is_null($this->_afpVO)) {
         $this->_afpVO = new Varien_Object();
     }
     if (!$this->_afpVO->getCategoryIds()) {
         $_data = Mage::getSingleton('adminhtml/session')->getData(AW_Featured_Helper_Data::FORM_DATA_KEY);
         if (!is_object($_data)) {
             $_data = new Varien_Object($_data);
         }
         if ($_data->getCategoryIds()) {
             $this->_afpVO->setCategoryIds(@explode(',', $_data->getCategoryIds()));
         } else {
             $_automationData = $_data->getAutomationData();
             if ($_automationData && isset($_automationData['categories'])) {
                 $this->_afpVO->setCategoryIds(@explode(',', $_automationData['categories']));
             } else {
                 $this->_afpVO->setCategoryIds(array());
             }
         }
     }
     return $this->_afpVO;
 }
Example #6
0
 /**
  * Validate product attribute value for condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $attrCode = $this->getAttribute();
     if ('category_ids' == $attrCode) {
         return $this->validateAttribute($object->getCategoryIds());
     }
     if ('attribute_set_id' == $attrCode) {
         return $this->validateAttribute($object->getData($attrCode));
     }
     $oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null;
     $object->setData($attrCode, $this->_getAttributeValue($object));
     $result = $this->_validateProduct($object);
     $this->_restoreOldAttrValue($object, $oldAttrValue);
     return (bool) $result;
 }
Example #7
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);
     }
 }
 /**
  * Save product category relations
  *
  * @param   Mage_Catalog_Model_Product $product
  * @return  Mage_Catalog_Model_Resource_Eav_Mysql4_Product
  */
 protected function _saveCategories(Varien_Object $object)
 {
     $categoryIds = $object->getCategoryIds();
     $oldCategoryIds = $object->getOrigData('category_ids');
     $oldCategoryIds = !empty($oldCategoryIds) ? explode(',', $oldCategoryIds) : array();
     $object->setIsChangedCategories(false);
     $insert = array_diff($categoryIds, $oldCategoryIds);
     $delete = array_diff($oldCategoryIds, $categoryIds);
     $write = $this->_getWriteAdapter();
     if (!empty($insert)) {
         $insertSql = array();
         foreach ($insert as $v) {
             if (!empty($v)) {
                 $insertSql[] = '(' . (int) $v . ',' . $object->getId() . ',0)';
             }
         }
         if ($insertSql) {
             $write->query("insert into {$this->_productCategoryTable}\n                    (category_id, product_id, position) values " . join(',', $insertSql));
         }
     }
     if (!empty($delete)) {
         $write->delete($this->_productCategoryTable, $write->quoteInto('product_id=?', $object->getId()) . ' and ' . $write->quoteInto('category_id in (?)', $delete));
     }
     if (!empty($insert) || !empty($delete)) {
         $object->setIsChangedCategories(true);
     }
     return $this;
 }
 /**
  * Return the category ids from a category mass action event
  *
  * @param Varien_Object $entity
  * @return array|null
  * @see Netzarbeiter_GroupsCatalog2_Model_Indexer_Abstract::_registerEvent()
  */
 protected function _getEntityIdsFromEntity(Varien_Object $entity)
 {
     return $entity->getCategoryIds();
 }
 /**
  * Save product category relations
  *
  * @param Varien_Object $object
  * @return Mage_Catalog_Model_Resource_Product
  */
 protected function _saveCategories(Varien_Object $object)
 {
     /**
      * If category ids data is not declared we haven't do manipulations
      */
     if (!$object->hasCategoryIds()) {
         return $this;
     }
     $categoryIds = $object->getCategoryIds();
     $oldCategoryIds = $this->getCategoryIds($object);
     $object->setIsChangedCategories(false);
     $insert = array_diff($categoryIds, $oldCategoryIds);
     $delete = array_diff($oldCategoryIds, $categoryIds);
     $write = $this->_getWriteAdapter();
     if (!empty($insert)) {
         $data = array();
         foreach ($insert as $categoryId) {
             if (empty($categoryId)) {
                 continue;
             }
             $data[] = array('category_id' => (int) $categoryId, 'product_id' => (int) $object->getId(), 'position' => 1);
         }
         if ($data) {
             $write->insertMultiple($this->_productCategoryTable, $data);
         }
     }
     if (!empty($delete)) {
         foreach ($delete as $categoryId) {
             $where = array('product_id = ?' => (int) $object->getId(), 'category_id = ?' => (int) $categoryId);
             $write->delete($this->_productCategoryTable, $where);
         }
     }
     if (!empty($insert) || !empty($delete)) {
         $object->setAffectedCategoryIds(array_merge($insert, $delete));
         $object->setIsChangedCategories(true);
     }
     return $this;
 }
 public function rebuildCategoryIndex(Varien_Object $event)
 {
     $storeId = $event->getStoreId();
     $categoryIds = $event->getCategoryIds();
     $page = $event->getPage();
     $pageSize = $event->getPageSize();
     if (is_null($storeId) && !empty($categoryIds)) {
         foreach (Mage::app()->getStores() as $storeId => $store) {
             if (!$store->getIsActive()) {
                 continue;
             }
             $this->helper->rebuildStoreCategoryIndex($storeId, $categoryIds);
         }
     } else {
         if (!empty($page) && !empty($pageSize)) {
             $this->helper->rebuildStoreCategoryIndexPage($storeId, $this->category_helper->getCategoryCollectionQuery($storeId, $categoryIds), $page, $pageSize);
         } else {
             $this->helper->rebuildStoreCategoryIndex($storeId, $categoryIds);
         }
     }
     return $this;
 }
Example #12
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()->from(array('e' => $this->getTable('catalog/product')), array('entity_id', 'category_ids'))->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((string) $select);
     while ($row = $query->fetch()) {
         $product = new Varien_Object($row);
         $product->setIdFieldName('entity_id');
         $product->setCategoryIds(split(',', $product->getCategoryIds()));
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($query);
     if ($products) {
         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;
 }
 /**
  * Rebuild index for the specified categories
  *
  * @param Varien_Object $event
  * @return Algolia_Algoliasearch_Model_Observer
  */
 public function rebuildCategoryIndex(Varien_Object $event)
 {
     $storeId = $event->getStoreId();
     $categoryIds = $event->getCategoryIds();
     if (is_null($storeId) && !empty($categoryIds)) {
         foreach (Mage::app()->getStores() as $storeId => $store) {
             if (!$store->getIsActive()) {
                 continue;
             }
             $this->rebuildStoreCategoryIndex($storeId, $categoryIds);
         }
     } else {
         $this->rebuildStoreCategoryIndex($storeId, $categoryIds);
     }
     return $this;
 }