Example #1
0
 public function validate(Varien_Object $object)
 {
     if ($this->getAttribute() == 'sku') {
         $sku = explode(',', $this->getValue());
         foreach ($sku as $skuA) {
             foreach ($object->getSku() as $skuB) {
                 if ($skuA == $skuB) {
                     return true;
                 }
             }
         }
         return false;
     }
     if ($this->getAttribute() == 'category') {
         if (is_array($object->getCategories())) {
             foreach ($object->getCategories() as $key => $value) {
                 $result = $this->validateAttribute($value);
                 if ($result) {
                     return $result;
                 }
             }
         } else {
             return $this->validateAttribute($object->getCategories());
         }
     }
     return parent::validate($object);
 }
Example #2
0
 /**
  * Initialize categories text-path to ID hash.
  *
  * @return Mage_ImportExport_Model_Import_Entity_Product
  */
 protected function _initCategories()
 {
     $transportObject = new Varien_Object();
     Mage::dispatchEvent('avs_fastsimpleimport_entity_product_init_categories', array('transport' => $transportObject));
     if ($transportObject->getCategories()) {
         $this->_categories = $transportObject->getCategories();
     } else {
         $collection = Mage::getResourceModel('catalog/category_collection')->addNameToResult();
         /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
         foreach ($collection as $category) {
             $structure = explode('/', $category->getPath());
             $pathSize = count($structure);
             if ($pathSize > 2) {
                 $path = array();
                 $this->_categories[implode('/', $path)] = $category->getId();
                 for ($i = 1; $i < $pathSize; $i++) {
                     $path[] = $collection->getItemById($structure[$i])->getName();
                 }
                 // additional options for category referencing: name starting from base category, or category id
                 $this->_categories[implode('/', $path)] = $category->getId();
                 array_shift($path);
                 $this->_categories[implode('/', $path)] = $category->getId();
                 $this->_categories[$category->getId()] = $category->getId();
             }
         }
     }
     return $this;
 }