Exemple #1
0
 protected function setUp()
 {
     $this->_category = Mage::getModel('Mage_Catalog_Model_Category');
     $this->_category->load(5);
     $this->_model = Mage::getModel('Mage_Catalog_Model_Layer_Filter_Category');
     $this->_model->setData(array('layer' => Mage::getModel('Mage_Catalog_Model_Layer', array('data' => array('current_category' => $this->_category)))));
 }
Exemple #2
0
 protected function setUp()
 {
     $this->_category = new Mage_Catalog_Model_Category();
     $this->_category->load(5);
     $this->_model = new Mage_Catalog_Model_Layer_Filter_Category();
     $this->_model->setData(array('layer' => new Mage_Catalog_Model_Layer(array('current_category' => $this->_category))));
 }
 /**
  * Get category ids path by id
  *
  * @param int $categoryId
  * @return string
  *
  * @return void
  */
 protected function _getCategoryPath($categoryId)
 {
     if (!isset($this->_paths[$categoryId])) {
         $this->_paths[$categoryId] = $this->_categoryModel->load($categoryId)->getPath();
     }
     return $this->_paths[$categoryId];
 }
Exemple #4
0
 /**
  * Retrieve loaded category collection.
  * Variables collected from CMS markup: category_id, product_count, is_random
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $categoryID = $this->getCategoryId();
         if ($categoryID) {
             $category = new Mage_Catalog_Model_Category();
             $category->load($categoryID);
             $collection = $category->getProductCollection();
             //Sort order parameters
             $sortBy = $this->getSortBy();
             //param: sort_by
             if ($sortBy === NULL) {
                 $sortBy = 'position';
             }
             $sortDirection = $this->getSortDirection();
             //param: sort_direction
             if ($sortDirection === NULL) {
                 $sortDirection = 'ASC';
             }
             $collection->addAttributeToSort($sortBy, $sortDirection);
         } else {
             $collection = Mage::getResourceModel('catalog/product_collection');
         }
         Mage::getModel('catalog/layer')->prepareProductCollection($collection);
         if ($this->getIsRandom()) {
             $collection->getSelect()->order('rand()');
         }
         $collection->addStoreFilter();
         $productCount = $this->getProductCount() ? $this->getProductCount() : 8;
         $collection->setPage(1, $productCount)->load();
         $this->_productCollection = $collection;
     }
     return $this->_productCollection;
 }
 /**
  * @magentoDataFixture Mage/Core/_files/store.php
  * @magentoDbIsolation enabled
  * @dataProvider saveActionDataProvider
  * @param array $inputData
  * @param array $defaultAttributes
  * @param array $attributesSaved
  */
 public function testSaveAction($inputData, $defaultAttributes, $attributesSaved = array())
 {
     $store = new Mage_Core_Model_Store();
     $store->load('fixturestore', 'code');
     $storeId = $store->getId();
     $this->getRequest()->setPost($inputData);
     $this->getRequest()->setParam('store', $storeId);
     $this->getRequest()->setParam('id', 2);
     $this->dispatch('backend/admin/catalog_category/save');
     $messages = Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS);
     $this->assertNotEmpty($messages, "Could not save category");
     $this->assertEquals('The category has been saved.', current($messages)->getCode());
     $category = new Mage_Catalog_Model_Category();
     $category->setStoreId($storeId);
     $category->load(2);
     $errors = array();
     foreach ($attributesSaved as $attribute => $value) {
         $actualValue = $category->getData($attribute);
         if ($value !== $actualValue) {
             $errors[] = "value for '{$attribute}' attribute must be '{$value}', but '{$actualValue}' is found instead";
         }
     }
     foreach ($defaultAttributes as $attribute => $exists) {
         if ($exists !== $category->getExistsStoreValueFlag($attribute)) {
             if ($exists) {
                 $errors[] = "custom value for '{$attribute}' attribute is not found";
             } else {
                 $errors[] = "custom value for '{$attribute}' attribute is found, but default one must be used";
             }
         }
     }
     $this->assertEmpty($errors, "\n" . join("\n", $errors));
 }
 public function testIsInRootCategoryList()
 {
     $this->assertFalse($this->_model->isInRootCategoryList());
     $this->_model->unsetData();
     $this->_model->load(3);
     $this->assertTrue($this->_model->isInRootCategoryList());
 }
Exemple #7
0
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $categoryID = $this->getCategoryId();
         if ($categoryID) {
             $category = new Mage_Catalog_Model_Category();
             $category->load($categoryID);
             // this is category id
             $collection = $category->getProductCollection();
         } else {
             $collection = Mage::getResourceModel('catalog/product_collection');
         }
         $todayDate = date('m/d/y');
         $tomorrow = mktime(0, 0, 0, date('m'), date('d') + 1, date('y'));
         $tomorrowDate = date('m/d/y', $tomorrow);
         Mage::getModel('catalog/layer')->prepareProductCollection($collection);
         //$collection->getSelect()->order('rand()');
         $collection->addAttributeToSort('created_at', 'desc');
         $collection->addStoreFilter();
         $collection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))->addAttributeToFilter('special_to_date', array('or' => array(0 => array('date' => true, 'from' => $tomorrowDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left');
         $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;
         $collection->setPage(1, $numProducts)->load();
         $this->_productCollection = $collection;
     }
     return $this->_productCollection;
 }
Exemple #8
0
 public function testGetProductCount()
 {
     $this->_model->load(6);
     $this->assertEquals(0, $this->_model->getProductCount());
     $this->_model->setData(array());
     $this->_model->load(3);
     $this->assertEquals(1, $this->_model->getProductCount());
 }
Exemple #9
0
 protected function setUp()
 {
     $category = new Mage_Catalog_Model_Category();
     $category->load(4);
     $attribute = new Mage_Catalog_Model_Entity_Attribute();
     $attribute->loadByCode('catalog_product', 'weight');
     $this->_model = new Mage_Catalog_Model_Layer_Filter_Decimal();
     $this->_model->setData(array('layer' => new Mage_Catalog_Model_Layer(array('current_category' => $category)), 'attribute_model' => $attribute));
 }
 public function getProductIds()
 {
     $categories = array(20, 49, 62, 72, 88, 101, 105, 114, 115);
     foreach ($categories as $cat) {
         $category = new Mage_Catalog_Model_Category();
         $category->load($cat);
         $collection = $category->getProductCollection()->addAttributeToFilter(array(array('attribute' => 'image', 'nlike' => 'no_selection'), array('attribute' => 'image', 'null' => false)))->setPageSize(4)->addAttributeToSort('created_at', 'desc');
         foreach ($collection as $product) {
             $result[] = $product->getId();
         }
     }
     return $result;
 }
 /**
  * Get Category from request
  *
  * @return Mage_Catalog_Model_Category
  */
 private function _getCategory()
 {
     if (!$this->_category) {
         $this->_category = Mage::getModel('Mage_Catalog_Model_Category');
         $categoryId = (int) $this->getRequest()->getParam('category', 0);
         if (!$categoryId && $this->_getUrlRewrite()->getId()) {
             $categoryId = $this->_getUrlRewrite()->getCategoryId();
         }
         if ($categoryId) {
             $this->_category->load($categoryId);
         }
     }
     return $this->_category;
 }
 public function getProductsInCategory(int $catId)
 {
     $_category = Mage::getModel('catalog/category')->load($catId);
     $subs = $_category->getAllChildren(true);
     $result = array();
     foreach ($subs as $cat_id) {
         $category = new Mage_Catalog_Model_Category();
         $category->load($cat_id);
         $collection = $category->getProductCollection();
         foreach ($collection as $product) {
             $result[] = $product->getId();
         }
     }
     return $result;
 }
Exemple #13
0
 /**
  * @magentoDataFixture Mage/Catalog/_files/categories.php
  */
 public function testGetBreadcrumbPath()
 {
     $category = new Mage_Catalog_Model_Category();
     $category->load(5);
     Mage::register('current_category', $category);
     try {
         $path = $this->_helper->getBreadcrumbPath();
         $this->assertInternalType('array', $path);
         $this->assertEquals(array('category3', 'category4', 'category5'), array_keys($path));
         $this->assertArrayHasKey('label', $path['category3']);
         $this->assertArrayHasKey('link', $path['category3']);
         Mage::unregister('current_category');
     } catch (Exception $e) {
         Mage::unregister('current_category');
         throw $e;
     }
 }
 /**
  * Retrieve loaded category collection.
  * Variables collected from CMS markup: category_id, product_count, is_random
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $categoryID = $this->getCategoryId();
         if ($categoryID) {
             $category = new Mage_Catalog_Model_Category();
             $category->load($categoryID);
             $collection = $category->getProductCollection();
         } else {
             $collection = Mage::getResourceModel('catalog/product_collection');
         }
         Mage::getModel('catalog/layer')->prepareProductCollection($collection);
         if ($this->getIsRandom()) {
             $collection->getSelect()->order('rand()');
         }
         $collection->addStoreFilter();
         $productCount = $this->getProductCount() ? $this->getProductCount() : 8;
         $collection->setPage(1, $productCount)->load();
         $this->_productCollection = $collection;
     }
     return $this->_productCollection;
 }
Exemple #15
0
 public function testGetSetCurrentCategory()
 {
     $existingCategory = new Mage_Catalog_Model_Category();
     $existingCategory->load(5);
     /* Category object */
     $model = new Mage_Catalog_Model_Layer();
     $model->setCurrentCategory($existingCategory);
     $this->assertSame($existingCategory, $model->getCurrentCategory());
     /* Category id */
     $model = new Mage_Catalog_Model_Layer();
     $model->setCurrentCategory(3);
     $actualCategory = $model->getCurrentCategory();
     $this->assertInstanceOf('Mage_Catalog_Model_Category', $actualCategory);
     $this->assertEquals(3, $actualCategory->getId());
     $this->assertSame($actualCategory, $model->getCurrentCategory());
     /* Category in registry */
     Mage::register('current_category', $existingCategory);
     try {
         $model = new Mage_Catalog_Model_Layer();
         $this->assertSame($existingCategory, $model->getCurrentCategory());
         Mage::unregister('current_category');
         $this->assertSame($existingCategory, $model->getCurrentCategory());
     } catch (Exception $e) {
         Mage::unregister('current_category');
         throw $e;
     }
     try {
         $model = new Mage_Catalog_Model_Layer();
         $model->setCurrentCategory(new Varien_Object());
         $this->fail('Assign category of invalid class.');
     } catch (Mage_Core_Exception $e) {
     }
     try {
         $model = new Mage_Catalog_Model_Layer();
         $model->setCurrentCategory(new Mage_Catalog_Model_Category());
         $this->fail('Assign category with invalid id.');
     } catch (Mage_Core_Exception $e) {
     }
 }
 /**
  * Execute refresh operation.
  *  - clean redirect url rewrites
  *  - refresh redirect url rewrites
  *  - refresh redirect to url rewrite relations
  *
  * @return Enterprise_Mview_Model_Action_Interface
  * @throws Enterprise_Index_Model_Action_Exception
  */
 public function execute()
 {
     try {
         $this->_metadata->setInProgressStatus()->save();
         $this->_connection->beginTransaction();
         $this->_cleanDeletedCategories();
         /** @var Mage_Core_Model_Store $store */
         foreach ($this->_stores as $store) {
             $rootCategoryId = $store->getGroup()->getRootCategoryId();
             $this->_category->load($rootCategoryId);
             $this->_category->setParentUrl('');
             $this->_indexCategoriesRecursively($this->_category, $store);
         }
         $this->_setChangelogValid();
         $this->_connection->commit();
         // we should clean cache after commit
         $this->_flushCache();
     } catch (Exception $e) {
         $this->_connection->rollBack();
         $this->_metadata->setInvalidStatus()->save();
         throw new Enterprise_Index_Model_Action_Exception($e->getMessage(), $e->getCode());
     }
     return $this;
 }
Exemple #17
0
 /**
  * @magentoAppIsolation enabled
  * @magentoDataFixture Mage/Catalog/_files/categories.php
  * @magentoDataFixture Mage/Catalog/_files/filterable_attributes.php
  */
 public function testGetFilters()
 {
     $currentCategory = new Mage_Catalog_Model_Category();
     $currentCategory->load(3);
     /** @var $layer Mage_Catalog_Model_Layer */
     $layer = Mage::getSingleton('Mage_Catalog_Model_Layer');
     $layer->setCurrentCategory($currentCategory);
     $layout = new Mage_Core_Model_Layout();
     $block = $layout->createBlock('Mage_Catalog_Block_Layer_View', 'block');
     $filters = $block->getFilters();
     $this->assertInternalType('array', $filters);
     $this->assertGreaterThan(3, count($filters));
     // At minimum - category filter + 2 fixture attribute filters
     $found = false;
     foreach ($filters as $filter) {
         if ($filter instanceof Mage_Catalog_Block_Layer_Filter_Category) {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found, 'Category filter must be present');
     $attributeCodes = array('filterable_attribute_a', 'filterable_attribute_b');
     foreach ($attributeCodes as $attributeCode) {
         $found = false;
         foreach ($filters as $filter) {
             if (!$filter instanceof Mage_Catalog_Block_Layer_Filter_Attribute) {
                 continue;
             }
             if ($attributeCode == $filter->getAttributeModel()->getAttributeCode()) {
                 $found = true;
                 break;
             }
         }
         $this->assertTrue($found, "Filter for attribute {$attributeCode} must be present");
     }
 }
 /**
  * Retrieve loaded category collection.
  * Variables collected from CMS markup: category_id, product_count, is_random
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $categoryID = $this->getCategoryId();
         if ($categoryID) {
             $category = new Mage_Catalog_Model_Category();
             $category->load($categoryID);
             $collection = $category->getProductCollection();
         } else {
             $collection = Mage::getResourceModel('catalog/product_collection');
         }
         $userids = array();
         $state = "";
         Mage::getModel('core/cookie')->set('testcookie', 'testvalue');
         if (Mage::getModel('core/cookie')->get('testcookie') != "") {
             $country = Mage::getModel('core/cookie')->get('Country');
         } else {
             $country = Mage::getSingleton('core/session', array('name' => 'frontend'))->getCountry();
         }
         if (Mage::getModel('core/cookie')->get('testcookie') != "") {
             $my_states = Mage::getModel('directory/region')->getCollection()->addFieldToSelect('region_id')->addFieldToFilter('name', array('in' => array(Mage::getModel('core/cookie')->get('Region'))))->load();
             foreach ($my_states as $st) {
                 $state = $st->getData('region_id');
             }
         } else {
             $my_states = Mage::getModel('directory/region')->getCollection()->addFieldToSelect('region_id')->addFieldToFilter('name', array('in' => array(Mage::getSingleton('core/session', array('name' => 'frontend'))->getRegion())))->load();
             foreach ($my_states as $st) {
                 $state = $st->getData('region_id');
             }
         }
         if (Mage::getModel('core/cookie')->get('testcookie') != "") {
             $city = Mage::getModel('core/cookie')->get('City');
         } else {
             $city = Mage::getSingleton('core/session', array('name' => 'frontend'))->getCity();
         }
         if ($state == "") {
             if (Mage::getModel('core/cookie')->get('testcookie') != "") {
                 $state = Mage::getModel('core/cookie')->get('Region');
             } else {
                 $state = Mage::getSingleton('core/session', array('name' => 'frontend'))->getRegion();
             }
         }
         $my_suppliers = Mage::getModel('multisuppliers/multisuppliers')->getCollection()->load();
         foreach ($my_suppliers as $supplier) {
             $shipppingaddress = json_decode($supplier->getData('shippingaddress'));
             foreach ($shipppingaddress as $sph) {
                 if (strtolower($sph->country) == strtolower($country)) {
                     if (strtolower($sph->state) == strtolower($state) || $sph->state == 'All') {
                         if (strtolower($sph->city) == strtolower($city) || $sph->city == 'All') {
                             $userids[] = $supplier->getData('userid');
                         }
                     }
                 }
             }
         }
         $my_users = Mage::getModel('admin/user')->getCollection()->addFieldToSelect('user_id')->addFieldToFilter('user_id', array('in' => $userids))->addFieldToFilter('is_active', 1)->load();
         foreach ($my_users as $user) {
             $my_users_array[] = $user->getUserId();
         }
         $my_products = Mage::getModel('multisuppliers/productscollect')->getCollection()->addFieldToSelect('product_id')->addFieldToFilter('user_id', array('in' => $my_users_array))->load();
         foreach ($my_products as $product) {
             $my_product_array[] = $product->getProductId();
         }
         $_testproductCollection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*')->addAttributeToFilter('type_id', 'configurable');
         $_testproductCollection->addAttributeToFilter('entity_id', array('in' => $my_product_array))->load();
         $nskuarray = array();
         foreach ($_testproductCollection as $_testproduct) {
             if ($_testproduct->getData('nsku') != "") {
                 $nskuarray[$_testproduct->getData('nsku')][$_testproduct->getData('entity_id')] = $_testproduct->getData('price');
             }
         }
         //echo("<pre>");print_r($nskuarray);exit;
         $minprice = array();
         foreach ($nskuarray as $index => $arr) {
             $minprice[] = array_search(min($nskuarray[$index]), $nskuarray[$index]);
         }
         $collection->addAttributeToFilter('entity_id', array('in' => $minprice));
         Mage::getModel('catalog/layer')->prepareProductCollection($collection);
         if ($this->getIsRandom()) {
             $collection->getSelect()->order('rand()');
         }
         $collection->addStoreFilter();
         $productCount = $this->getProductCount() ? $this->getProductCount() : 8;
         $collection->setPage(1, $productCount)->load();
         $this->_productCollection = $collection;
     }
     return $this->_productCollection;
 }
Exemple #19
0
 public function setRelatedProducts()
 {
     $this->_beforeQuery();
     echo date("\nY-d-m H:i:s") . " - Adding related products\n";
     $sku_arr = array();
     foreach ($this->values as $lenses) {
         $sku_arr[] = $lenses['sku'];
     }
     $reltedIds = null;
     foreach ($sku_arr as $sku) {
         $relatedIds[] = Mage::getModel('catalog/product')->getCollection()->getItemByColumnValue('sku', $sku)->getId();
     }
     $_category = Mage::getModel('catalog/category')->getCollection()->setStoreId('0')->addAttributeToSelect('name')->addAttributeToFilter('name', 'Prescription Sunglasses')->getFirstItem();
     $subs = $_category->getAllChildren(true);
     $idsFromCat = array();
     foreach ($subs as $cat_id) {
         $category = new Mage_Catalog_Model_Category();
         $category->load($cat_id);
         $collection = $category->getProductCollection();
         foreach ($collection as $product) {
             $idsFromCat[] = $product->getId();
         }
     }
     // +++++ select Oakley Ids  +++++ //
     $productsOakley = Mage::getModel('catalog/category')->load($this->oakleyCategoryId)->getProductCollection();
     $oakleyIds = array();
     foreach ($productsOakley as $product) {
         $oakleyIds[] = $product->getEntityId();
     }
     // +++++ select Special Sunglasses +++++ //
     $selectSpecial = Mage::getModel('catalog/product')->getCollection()->getSelect()->reset(Zend_Db_Select::COLUMNS)->joinInner(array('ps' => 'prescription_sunglasses'), 'e.sku = ps.sku', 'e.entity_id');
     $productsSpecial = $selectSpecial->query()->fetchAll();
     $specialIds = array();
     foreach ($productsSpecial as $product) {
         $specialIds[] = $product['entity_id'];
     }
     $productIds = array_diff($idsFromCat, $oakleyIds, $specialIds);
     echo "count Sunglasses Standard = " . count($productIds) . " samples: " . current($productIds) . ", " . next($productIds) . ", " . next($productIds) . "\n";
     foreach ($productIds as $prodId) {
         $this->setRelatedProduct($prodId, $relatedIds);
     }
     echo date("\nY-d-m H:i:s") . " - Related products added\n";
     $this->_afterQuery();
 }
Exemple #20
0
 public function standard()
 {
     //$this->_beforeQuery();
     echo date("\nY-d-m H:i:s") . " - Adding related products " . __METHOD__ . "\n";
     $relatedId = null;
     $relatedId = Mage::getModel('catalog/product')->getCollection()->getItemByColumnValue('sku', self::STANDARD)->getId();
     $_category = Mage::getModel('catalog/category')->getCollection()->setStoreId('0')->addAttributeToSelect('name')->addAttributeToFilter('name', 'Prescription Sunglasses')->getFirstItem();
     //#$_category = Mage::getModel('catalog/category')->loadByAttribute('name', 'Clearance');
     //#$prescription_sunglasses_id = Mage::getModel('eav/entity_attribute_set')->getCollection()->setEntityTypeFilter($this->typeId)->addFilter('attribute_set_name', 'Prescription Sunglasses')->getFirstItem()->getId();
     $subs = $_category->getAllChildren(true);
     $idsFromCat = array();
     foreach ($subs as $cat_id) {
         $category = new Mage_Catalog_Model_Category();
         $category->load($cat_id);
         $collection = $category->getProductCollection();
         foreach ($collection as $product) {
             //#if( $product->getAttributeSetId() === $prescription_sunglasses_id ){ var_dump($prescription_sunglasses_id); }
             $idsFromCat[] = $product->getId();
         }
     }
     // +++++ select Oakley Ids  +++++ //
     $productsOakley = Mage::getModel('catalog/category')->load($this->oakleyCategoryId)->getProductCollection();
     $oakleyIds = array();
     foreach ($productsOakley as $product) {
         $oakleyIds[] = $product->getEntityId();
     }
     // +++++ select Special Sunglasses +++++ //
     $selectSpecial = Mage::getModel('catalog/product')->getCollection()->getSelect()->reset(Zend_Db_Select::COLUMNS)->joinInner(array('ps' => 'prescription_sunglasses'), 'e.sku = ps.sku', 'e.entity_id');
     $productsSpecial = $selectSpecial->query()->fetchAll();
     $specialIds = array();
     foreach ($productsSpecial as $product) {
         $specialIds[] = $product['entity_id'];
     }
     $productIds = array_diff($idsFromCat, $oakleyIds, $specialIds);
     echo "count Sunglasses Standard = " . count($productIds) . " samples: " . current($productIds) . ", " . next($productIds) . ", " . next($productIds) . "\n";
     $i = 0;
     $count = count($productIds);
     foreach ($productIds as $prodId) {
         $sku = $this->setRelatedProduct($prodId, $relatedId);
         if ($sku) {
             echo $sku . "\n";
         }
         ++$i;
         echo ' ' . floor($i * 100 / $count) . '%';
     }
     echo date("\nY-d-m H:i:s") . " - Related products added" . __METHOD__ . "\n";
     //$this->_afterQuery();
 }
 /**
  * Retrieve loaded category collection.
  * Variables collected from CMS markup: category_id, product_count, is_random
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $categoryID = $this->getCategoryId();
         if ($categoryID) {
             $category = new Mage_Catalog_Model_Category();
             $category->load($categoryID);
             $collection = $category->getProductCollection();
         } else {
             $collection = Mage::getResourceModel('catalog/product_collection');
         }
         $userids = array();
         $state = "";
         $country = Mage::getSingleton('core/session', array('name' => 'frontend'))->getCountry();
         $my_states = Mage::getModel('directory/region')->getCollection()->addFieldToSelect('region_id')->addFieldToFilter('name', array('in' => array(Mage::getSingleton('core/session', array('name' => 'frontend'))->getRegion())))->load();
         foreach ($my_states as $st) {
             $state = $st->getData('region_id');
         }
         $city = Mage::getSingleton('core/session', array('name' => 'frontend'))->getCity();
         if ($state == "") {
             $state = Mage::getSingleton('core/session', array('name' => 'frontend'))->getRegion();
         }
         $my_suppliers = Mage::getModel('multisuppliers/multisuppliers')->getCollection()->load();
         foreach ($my_suppliers as $supplier) {
             $shipppingaddress = json_decode($supplier->getData('shippingaddress'));
             foreach ($shipppingaddress as $sph) {
                 if (strtolower($sph->country) == strtolower($country)) {
                     if (strtolower($sph->state) == strtolower($state) || $sph->state == 'All') {
                         if (strtolower($sph->city) == strtolower($city) || $sph->city == 'All') {
                             $userids[] = $supplier->getData('userid');
                         }
                     }
                 }
             }
         }
         $my_users = Mage::getModel('admin/user')->getCollection()->addFieldToSelect('user_id')->addFieldToFilter('user_id', array('in' => $userids))->addFieldToFilter('is_active', 1)->load();
         foreach ($my_users as $user) {
             $my_users_array[] = $user->getUserId();
         }
         $my_products = Mage::getModel('multisuppliers/productscollect')->getCollection()->addFieldToSelect('product_id')->addFieldToFilter('user_id', array('in' => $my_users_array))->load();
         foreach ($my_products as $product) {
             $my_product_array[] = $product->getProductId();
         }
         // $mycollection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => $my_product_array));
         //        //echo('<pre>');print_r($my_product_array);exit;
         //        $uniqueskuid=array();
         //        foreach($mycollection as $k)
         //        {
         //            $p = Mage::getModel('catalog/product')->load($k->getId());
         //            $productID = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('nsku', $p->getNsku())->setOrder('price', 'ASC')->getFirstItem()->getData('entity_id');
         //            if($productID != "")
         //            {
         //             $uniqueskuid[]=$productID;
         //            }else{
         //                $uniqueskuid[]=$k->getId();
         //            }
         //
         //
         //        }
         $collection->addAttributeToFilter('entity_id', array('in' => $my_product_array));
         Mage::getModel('catalog/layer')->prepareProductCollection($collection);
         if ($this->getIsRandom()) {
             $collection->getSelect()->order('rand()');
         }
         $collection->addStoreFilter();
         $productCount = $this->getProductCount() ? $this->getProductCount() : 8;
         $collection->setPage(1, $productCount)->load();
         $this->_productCollection = $collection;
     }
     return $this->_productCollection;
 }
Exemple #22
0
require '../app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);


    //$collection = Mage::getModel('catalog/category')->load(75)->getProductCollection();
    //$result = 0;
    //foreach ($collection as $product) {
        //$result[] = $product;
        //mage::D($product->getEntityId());
    //}

$_category = Mage::getModel('catalog/category')->getCollection()->setStoreId('0')->addAttributeToSelect('name')->addAttributeToFilter('name', 'Designer Frames')->getFirstItem();
$subs = $_category->getAllChildren(true);
$result = array();
foreach($subs as $cat_id) {
    $category = new Mage_Catalog_Model_Category();
    $category->load($cat_id);
    $collection = $category->getProductCollection();
    foreach ($collection as $product) {
        $result[] = $product->getId();
    }

}

var_dump($subs);
$collection = Mage::getModel('catalog/category')->getCollection()->setStoreId('0')->addAttributeToSelect('name')->addAttributeToFilter('name', 'Designer Frames');

var_dump($collection->getSelect()->__toString());
//mage::ms($collection);
//mage::d(count($collection));
Exemple #23
0
 public function setRelatedProducts()
 {
     //$this->_beforeQuery();
     echo date("\nY-d-m H:i:s") . " - Adding related products\n";
     $sku_arr = array();
     foreach ($this->values as $lenses) {
         $sku_arr[] = $lenses['sku'];
     }
     $reltedIds = null;
     foreach ($sku_arr as $sku) {
         $relatedIds[] = Mage::getModel('catalog/product')->getCollection()->getItemByColumnValue('sku', $sku)->getId();
     }
     $optId1 = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'frame_type')->getSource()->getOptionId('Metal');
     $optId2 = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'frame_type')->getSource()->getOptionId('Plastic');
     $idsFrameTypeItems = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('frame_type', array($optId1, $optId2))->load()->getItems();
     $idsFrameType = null;
     foreach ($idsFrameTypeItems as $item) {
         $idsFrameType[] = $item->getId();
         //mage::d($product->getId());  if ( $product->getId() > 10 ) break;
     }
     $_category = Mage::getModel('catalog/category')->getCollection()->setStoreId('0')->addAttributeToSelect('name')->addAttributeToFilter('name', 'Designer Frames')->getFirstItem();
     //$_category = Mage::getModel('catalog/category')->loadByAttribute('name', 'Clearance');
     $subs = $_category->getAllChildren(true);
     $idsFromCat = array();
     foreach ($subs as $cat_id) {
         $category = new Mage_Catalog_Model_Category();
         $category->load($cat_id);
         $collection = $category->getProductCollection();
         foreach ($collection as $product) {
             $idsFromCat[] = $product->getId();
         }
     }
     $productIds = array_diff($idsFromCat, array_diff($idsFromCat, $idsFrameType));
     $i = 0;
     $count = count($productIds);
     foreach ($productIds as $id) {
         $sku = $this->setRelatedProduct($id, $relatedIds);
         if ($sku) {
             echo $sku . "\n";
         }
         //mage::d($product->getId());  if ( $product->getId() > 10 ) break;
         ++$i;
         echo ' ' . floor($i * 100 / $count) . '%';
     }
     echo date("\nY-d-m H:i:s") . " - Related products added\n";
     //$this->_afterQuery();
 }
Exemple #24
0
$xmlPath = Mage::getBaseDir() . "/metakeywords.xml";
if (!($xml = simplexml_load_file($xmlPath))) {
    echo "Unable to load XML file";
} else {
    $i = 0;
    $metaArray = array();
    /*** loop over the elements ***/
    $metaArray[0][] = 'sku';
    $metaArray[0][] = 'meta_title';
    $metaArray[0][] = 'meta_description';
    $metaArray[0][] = 'meta_keyword';
    $j = 1;
    foreach ($xml as $node) {
        $catid = $xml->category[$i]->category_id;
        $category = new Mage_Catalog_Model_Category();
        $category->load($catid);
        //My cat id is 10
        $categoryName = $category->getName();
        $prodCollection = $category->getProductCollection();
        foreach ($prodCollection as $product) {
            //echo $product->getId()."<br />";
            $_product = Mage::getModel('catalog/product')->load($product->getId());
            $productSku = $_product->getSku();
            $productName = $_product->getName();
            $productMetaTitle = str_replace('##productname##', $productName, $xml->category[$i]->meta_title);
            $productMetaDesc = str_replace('##productname##', $productName, $xml->category[$i]->meta_description);
            $metaArray[$j][] = $productSku;
            $metaArray[$j][] = $productMetaTitle;
            $metaArray[$j][] = $productMetaDesc;
            $metaArray[$j][] = $xml->category[$i]->meta_keywords;
            //$prdIds[] = $product->getId(); ///Store all th eproduct id in $prdIds array
Exemple #25
0
 public function setRelatedProducts()
 {
     $this->_beforeQuery();
     echo date("\nY-d-m H:i:s") . " - Adding related products\n";
     $sku_arr = array();
     foreach ($this->values as $lenses) {
         $sku_arr[] = $lenses['sku'];
     }
     $reltedIds = null;
     foreach ($sku_arr as $sku) {
         $relatedIds[] = Mage::getModel('catalog/product')->getCollection()->getItemByColumnValue('sku', $sku)->getId();
     }
     $optId1 = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'frame_type')->getSource()->getOptionId('Half Rim (Supra)');
     $optId2 = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'frame_type')->getSource()->getOptionId('Rimless');
     $itemsFrameType = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('frame_type', array($optId1, $optId2))->load()->getItems();
     $idsFrameType = null;
     foreach ($itemsFrameType as $item) {
         $idsFrameType[] = $item->getId();
         //mage::d($product->getId());  if ( $product->getId() > 10 ) break;
     }
     $_category = Mage::getModel('catalog/category')->getCollection()->setStoreId('0')->addAttributeToSelect('name')->addAttributeToFilter('name', 'Designer Frames')->getFirstItem();
     $subs = $_category->getAllChildren(true);
     $idsFromCat = array();
     foreach ($subs as $cat_id) {
         $category = new Mage_Catalog_Model_Category();
         $category->load($cat_id);
         $collection = $category->getProductCollection();
         foreach ($collection as $product) {
             $idsFromCat[] = $product->getId();
         }
     }
     $productIds = array_diff($idsFromCat, array_diff($idsFromCat, $idsFrameType));
     echo "count Rimless and Supra = " . count($productIds) . " samples: " . current($productIds) . ", " . next($productIds) . ", " . next($productIds) . "\n";
     foreach ($productIds as $prodId) {
         $this->setRelatedProduct($prodId, $relatedIds);
     }
     echo date("\nY-d-m H:i:s") . " - Related products added\n";
     $this->_afterQuery();
 }
Exemple #26
0
 public function createCategory($object)
 {
     $collection = Mage::getModel('catalog/category')->getCollection()->clear();
     $category = new Mage_Catalog_Model_Category();
     $category->setEntityTypeId($this->entityTypeId);
     $category->setAttributeSetId($this->attributeSetId);
     if (!empty($object['custom_apply_to_products'])) {
         $category->setCustomApplyToProducts($object['custom_apply_to_products']);
     }
     if (!empty($object['custom_design'])) {
         $category->setCustomDesign($object['custom_design']);
     }
     if (!empty($object['custom_design_from'])) {
         $category->setCustomDesignFrom($object['custom_design_from']);
     }
     if (!empty($object['custom_design_to'])) {
         $category->setCustomDesignTo($object['custom_design_to']);
     }
     if (!empty($object['custom_layout_update'])) {
         $category->setCustomLayoutUpdate($object['custom_layout_update']);
     }
     if (!empty($object['custom_use_parent_settings'])) {
         $category->setCustomUseParentSettings($object['custom_use_parent_settings']);
     }
     $category->setAvailablesortBy($object['available_sort_by']);
     $category->setParentId(0);
     $category->setCreatedAt($object['created_at']);
     $category->setUpdatedAt($object['updated_at']);
     $category->setPosition((int) $object['position']);
     $category->setChildrenCount($object['children_count']);
     $category->setDescription($object['description']);
     $category->setDisplayMode($object['display_mode']);
     $category->setDefaultSortBy($object['default_sort_by']);
     $category->setFilterPriceRange($object['filter_price_range']);
     $category->setImage($object['image']);
     $category->setIncludeInMenu($object['include_in_menu']);
     $category->setIsActive($object['is_active']);
     $category->setIsAnchor($object['is_anchor']);
     $category->setLandingPage($object['landing_page']);
     $category->setLevel($object['level']);
     $category->setMetaTitle($object['meta_title']);
     $category->setMetaKeywords($object['meta_keywords']);
     $category->setMetaDescription($object['meta_description']);
     $category->setName($object['name']);
     $category->setPageLayout($object['page_layout']);
     if (!empty($object['path'])) {
         $category->setPath($object['path']);
     }
     if (!empty($object['path_in_store'])) {
         $category->setPathInStore($object['path_in_store']);
     }
     $category->setPosition((int) $object['position']);
     $category->setThumbnail((int) $object['thumbnail']);
     $category->setUrlKey($object['url_key']);
     $category->setUrlPath($object['url_path']);
     try {
         $category->save();
         $category->load();
         // must do it, because of position set wrong for first saving. magento bug?
         $category->setPosition((int) $object['position']);
         $category->save();
     } catch (Exception $e) {
         zend_debug::dump($e);
         return;
     }
     return $category->getId();
 }
Exemple #27
0
 public function getCategoryUrl(Mage_Catalog_Model_Category $category)
 {
     // TODO: this just returns an empty string, not really hiding anchor..
     return $category->load()->getNavilinkUnactive() ? 'javascript:void(0);' : parent::getCategoryUrl($category);
 }