Пример #1
0
 public function testGetProductCollection()
 {
     /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
     $collection = $this->_model->getProductCollection();
     $this->assertInstanceOf('Mage_Catalog_Model_Resource_Product_Collection', $collection);
     $ids = $collection->getAllIds();
     $this->assertContains(1, $ids);
     $this->assertContains(2, $ids);
     $this->assertSame($collection, $this->_model->getProductCollection());
 }
Пример #2
0
 /**
  * Retrieve current layer product collection
  *
  * @return Celebros_Conversionpro_Model_Resource_Collection
  */
 public function getProductCollection()
 {
     if (Mage::helper('conversionpro')->getIsEngineAvailableForNavigation()) {
         if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
             $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
         } else {
             $answerId = Mage::helper('conversionpro')->getAnswerIdByCategoryId($this->getCurrentCategory()->getId());
             //@todo switch to our helper.
             $collection = Mage::helper('catalogsearch')->getEngine()->getResultCollection();
             $collection->setStoreId($this->getCurrentCategory()->getStoreId());
             //We have two options here that correspond to the two methods of using nav2search - query strings and answer ids.
             if (Mage::helper('conversionpro')->getCelebrosConfigData('nav_to_search_settings/nav_to_search_search_by') == 'answer_id') {
                 //This option adds a filter with the category\'s answer id.
                 $collection->addFqFilter(array('category' => $answerId));
                 //If we're adding an answer id, and not changing the query string, we'll need to add the default query string
                 // to the collection's base parameters for the call to Quiser's API.
                 $collection->setGeneralDefaultQuery();
             } else {
                 //This option adds a search query string with the name of the category.
                 $query = Mage::helper('conversionpro')->getCategoryRewriteQuery($this->getCurrentCategory());
                 $collection->addSearchParam(null, $query);
             }
             $this->prepareProductCollection($collection);
             $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
         }
         return $collection;
     } else {
         return parent::getProductCollection();
     }
 }
Пример #3
0
 /**
  * @dataProvider pricesSegmentationDataProvider
  */
 public function testPricesSegmentation($categoryId, $intervalsNumber, $intervalItems)
 {
     $this->_layer->setCurrentCategory($categoryId);
     $collection = $this->_layer->getProductCollection();
     $memoryUsedBefore = memory_get_usage();
     $this->_model->setPricesModel($this->_filter)->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getSize());
     if (!is_null($intervalsNumber)) {
         $this->assertEquals($intervalsNumber, $this->_model->getIntervalsNumber());
     }
     $items = $this->_model->calculateSeparators();
     $this->assertEquals(array_keys($intervalItems), array_keys($items));
     for ($i = 0; $i < count($intervalItems); ++$i) {
         $this->assertInternalType('array', $items[$i]);
         $this->assertEquals($intervalItems[$i]['from'], $items[$i]['from']);
         $this->assertEquals($intervalItems[$i]['to'], $items[$i]['to']);
         $this->assertEquals($intervalItems[$i]['count'], $items[$i]['count']);
     }
     // Algorythm should use less than 10M
     $this->assertLessThan(10 * 1024 * 1024, memory_get_usage() - $memoryUsedBefore);
 }