本文整理汇总了PHP中Mage_Catalog_Model_Category::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Category::load方法的具体用法?PHP Mage_Catalog_Model_Category::load怎么用?PHP Mage_Catalog_Model_Category::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Category
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Category::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
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)))));
}
示例2: setUp
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))));
}
示例3: _getCategoryPath
/**
* 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];
}
示例4: _getProductCollection
/**
* 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;
}
示例5: testSaveAction
/**
* @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));
}
示例6: testIsInRootCategoryList
public function testIsInRootCategoryList()
{
$this->assertFalse($this->_model->isInRootCategoryList());
$this->_model->unsetData();
$this->_model->load(3);
$this->assertTrue($this->_model->isInRootCategoryList());
}
示例7: _getProductCollection
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;
}
示例8: testGetProductCount
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());
}
示例9: setUp
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));
}
示例10: getProductIds
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;
}
示例11: _getCategory
/**
* 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;
}
示例12: getProductsInCategory
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;
}
示例13: testGetBreadcrumbPath
/**
* @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;
}
}
示例14: _getProductCollection
/**
* 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;
}
示例15: testGetSetCurrentCategory
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) {
}
}