Beispiel #1
0
 /**
  * Save the collection array as object property
  * Added name and url_key as part of the array.
  */
 private function _initProductCollectionArray()
 {
     if (!$this->_collectionArray && !$this->_doNothing) {
         $productCollection = $this->_category->getProductCollection();
         $productCollection->addAttributeToSelect(array('entity_id', 'name', 'url_key'))->addAttributeToFilter('status', 1)->addAttributeToFilter('visibility', 4)->addCategoryFilter($this->_category)->setOrder('entity_id', 'ASC');
         $this->_collectionArray = $productCollection->exportToArray();
     }
 }
Beispiel #2
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;
 }
Beispiel #3
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;
 }
 /**
  * Get category products collection
  *
  * The method is redefined to load all descending products when it's allowed
  * and category is not anchor (anchor categories load descending products
  * by default)
  *
  * @return Varien_Data_Collection_Db
  */
 public function getProductCollection()
 {
     $default = $this->getIsAnchor() || !Mage::getStoreConfig(MVentory_Productivity_Model_Config::_DISPLAY_PRODUCTS);
     if ($default) {
         return parent::getProductCollection();
     }
     return Mage::getResourceModel('catalog/product_collection')->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')->addAttributeToFilter('category_id', array('in' => $this->getAllChildren(true)))->setStoreId($this->getStoreId());
 }
 /** @return Mage_Core_Model_Mysql4_Collection_Abstract */
 function getProductCollection()
 {
     $collection = parent::getProductCollection();
     if ($this->shouldFilter()) {
         $collection->addIdFilter($this->getProductIdsInFilter());
         $this->filtered = true;
         // test only
     } else {
         $this->filtered = false;
         // test only
     }
     return $collection;
 }
 /**
  */
 private function _moveProducts()
 {
     $productSourceIds = $this->_source->getProductCollection()->setOrder('position', 'asc')->getAllIds();
     $productSourceItems = array_fill_keys($productSourceIds, 1);
     $productInsert = array_diff_key($productSourceItems, $this->_target->getProductsPosition());
     if (!empty($productInsert)) {
         $data = array();
         foreach ($productInsert as $productId => $position) {
             $data[] = array('category_id' => (int) $this->_target->getId(), 'product_id' => (int) $productId, 'position' => (int) $position);
         }
         $this->_getWriteAdapter()->insertMultiple($this->_getTable(), $data);
     }
 }
 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;
 }
 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;
 }
 public function getObject(Mage_Catalog_Model_Category $category)
 {
     /** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
     $productCollection = $category->getProductCollection();
     $productCollection = $productCollection->addMinimalPrice();
     $category->setProductCount($productCollection->getSize());
     $transport = new Varien_Object();
     Mage::dispatchEvent('algolia_category_index_before', array('category' => $category, 'custom_data' => $transport));
     $customData = $transport->getData();
     $storeId = $category->getStoreId();
     $category->getUrlInstance()->setStore($storeId);
     $path = '';
     foreach ($category->getPathIds() as $categoryId) {
         if ($path != '') {
             $path .= ' / ';
         }
         $path .= $this->getCategoryName($categoryId, $storeId);
     }
     $image_url = NULL;
     try {
         $image_url = $category->getImageUrl();
     } catch (Exception $e) {
         /* no image, no default: not fatal */
     }
     $data = array('objectID' => $category->getId(), 'name' => $category->getName(), 'path' => $path, 'level' => $category->getLevel(), 'url' => Mage::getBaseUrl() . $category->getRequestPath(), '_tags' => array('category'), 'popularity' => 1, 'product_count' => $category->getProductCount());
     if (!empty($image_url)) {
         $data['image_url'] = $image_url;
     }
     foreach ($this->config->getCategoryAdditionalAttributes($storeId) as $attribute) {
         $value = $category->getData($attribute['attribute']);
         $attribute_ressource = $category->getResource()->getAttribute($attribute['attribute']);
         if ($attribute_ressource) {
             $value = $attribute_ressource->getFrontend()->getValue($category);
         }
         if (isset($data[$attribute['attribute']])) {
             $value = $data[$attribute['attribute']];
         }
         if ($value) {
             $data[$attribute['attribute']] = $value;
         }
     }
     $data = array_merge($data, $customData);
     foreach ($data as &$data0) {
         $data0 = $this->try_cast($data0);
     }
     return $data;
 }
 /**
  * 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;
 }
Beispiel #11
0
 public function testGetProductCollection()
 {
     $collection = $this->_model->getProductCollection();
     $this->assertInstanceOf('Mage_Catalog_Model_Resource_Product_Collection', $collection);
     $this->assertEquals($this->_model->getStoreId(), $collection->getStoreId());
 }
 /**
  * Initialise product collection from the category
  *
  * Code is taken from Mage_Catalog_Model_Layer::prepareProductCollection()
  * method
  *
  * @param Mage_Catalog_Model_Category $category
  *
  * @return Mage_Catalog_Model_Resource_Product_Collection
  */
 protected function _getProductCollection($category)
 {
     $productAttributes = Mage::getSingleton('catalog/config')->getProductAttributes();
     $collection = $category->getProductCollection()->addAttributeToSelect($productAttributes)->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addUrlRewrite($category->getId());
     Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
     Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
     //Dispatch the event to emul;ate loading collection of products in catalog
     Mage::dispatchEvent('catalog_block_product_list_collection', array('collection' => $collection));
     return $collection;
 }
Beispiel #13
0
 /**
  * Render Featured products inside navigation menu
  *
  * @param Mage_Catalog_Model_Category $category
  * @return string
  */
 public function getFeaturedProductsBox($category)
 {
     $cid = $category->getId();
     $html = array();
     $html[] = '<!-- NOCACHE key="featured-' . $cid . '" -->';
     $html[] = '<div class="featured-products"><span class="category-title">Featured product(s)</span>';
     $featured_products = $category->getProductCollection()->addAttributeToSelect('*')->addFieldToFilter(array(array('attribute' => 'max_featured', 'eq' => '1')))->load();
     $ids = $featured_products->getAllIds();
     if (!$ids || $ids == '' || $ids == 0) {
         return '';
     } else {
         $keys = array_rand($ids, 3);
         $random_ids = array();
         foreach ($keys as $key) {
             $random_ids[] = $ids[$key];
         }
         foreach ($random_ids as $id) {
             $featured = $featured_products->getItemById($id);
             $html[] = '<div class="product">';
             $html[] = '<a href="' . $featured->getProductUrl($category) . '">';
             $html[] = '<img src="' . Mage::helper('catalog/image')->init($featured, 'small_image')->resize(190, 150) . '" alt="' . $featured->getName() . '" />';
             $html[] = '<span class="product-name">' . $featured->getName() . '</span></a>';
             $html[] = '</div>';
         }
         $html[] = '<a class="view-more" href="' . $this->getCategoryUrl($category) . '">+ View more products</a>';
         $html[] = '</div>';
         $html[] = '<!-- ENDNOCACHE -->';
         return implode("\n", $html);
     }
 }
Beispiel #14
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();
 }
$currentCategory = Mage::registry('current_category');
foreach ($_categories as $_category) {
    $catid = $_category->getId();
    $caturl = $_helper->getCategoryUrl($_category);
    $cat_elt = $doc->createElement('category_id');
    $doc->appendChild($cat_elt);
    $catid_elt = $doc->createElement('catid', $catid);
    $doc->appendChild($catid_elt);
    $note_elt->appendChild($cat_elt);
    $cat_elt->appendChild($catid_elt);
    $result = array();
    $brandid = array();
    $bname = array();
    $category = new Mage_Catalog_Model_Category();
    $category->load($catid);
    $collection = $category->getProductCollection()->addAttributeToFilter('attribute', 'brand');
    foreach ($collection as $_product) {
        $result[] = $_product->getId();
    }
    $newa = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('attribute_code', 'brand')->addAttributeToFilter('entity_id', array('in' => $result))->addAttributeToSelect(array('brand'), 'inner');
    foreach ($newa as $product) {
        $brandid[] = $product->getBrand();
        $bname[] = $product->getAttributeText('brand');
    }
    $a = array_unique($brandid);
    $b = array_unique($bname);
    $brand = array_combine($a, $b);
    foreach ($brand as $key => $value) {
        $brandid = $key;
        $brandname = $value;
        $brandurl = $caturl . '?action=view_all&amp;fq[brand]=' . str_replace(" ", "+", $value);
 /**
  * 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;
 }
Beispiel #17
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();
 }
Beispiel #18
0
} 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
            $j++;
        }
        $i++;
 /**
  * Adding product count when load collection is incorrect.
  * The method applies the same limitation as on frontend to get correct product count for the category in the specified store.
  * Product collection will not be loaded so this solution is fast.
  *
  * @param Mage_Catalog_Model_Category $category
  * @return Algolia_Algoliasearch_Helper_Data
  */
 public function addCategoryProductCount(Mage_Catalog_Model_Category $category)
 {
     $productCollection = $category->getProductCollection();
     /** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
     $category->setProductCount($productCollection->addMinimalPrice()->count());
     return $this;
 }
Beispiel #20
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();
 }
Beispiel #21
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 = "";
         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;
 }