本文整理汇总了PHP中Mage_Catalog_Model_Category::setStoreId方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Category::setStoreId方法的具体用法?PHP Mage_Catalog_Model_Category::setStoreId怎么用?PHP Mage_Catalog_Model_Category::setStoreId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Category
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Category::setStoreId方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: getCategory
/**
* Search category by the name from root category or specified one.
* Create category when it doesn't exist if $createIfNotExists
* parameter is set.
* Search category by store-specific name if $store parameter is set.
*
* @param string $name
* @param bool $createIfNotExists
* @param Mage_Catalog_Model_Category $parent
* @param null|Mage_Core_Model_Store $store
*
* @return Mage_Catalog_Model_Category|null
*/
public function getCategory($name, $createIfNotExists = false, $parent = null, $store = null)
{
$store = $store instanceof Mage_Core_Model_Store ? $store : Mage::app()->getStore();
$collection = $parent && ($parentId = $parent->getId()) ? $parent->setStoreId($store->getId())->getCollection()->addFieldToFilter('parent_id', $parentId) : Mage::getModel('catalog/category')->setStoreId($store->getId())->load($store->getRootCategoryId())->getCollection();
$collection->addAttributeToFilter('name', $name);
if ($collection->count()) {
return $collection->getFirstItem();
}
if (!$createIfNotExists) {
return;
}
if ($parent && $parent->getId()) {
$rootCategory = $parent;
} else {
$collection = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('parent_id', 1);
if (count($collection) != 1) {
return null;
}
$rootCategory = $collection->getFirstItem();
if (!$rootCategory->getId()) {
return null;
}
}
$model = Mage::getModel('catalog/category');
$model->setStoreId($rootCategory->getStoreId())->setData(array('name' => $name, 'is_active' => 1, 'include_in_menu' => 1))->setPath($rootCategory->getPath())->setAttributeSetId($model->getDefaultAttributeSetId());
try {
$model->save();
} catch (Exception $e) {
return null;
}
return $model;
}
示例3: getRootCategory
public function getRootCategory()
{
if (!$this->_rootCategory) {
$this->_rootCategory = Mage::getModel('catalog/category');
$this->_rootCategory->setStoreId(Mage::app()->getStore()->getId())->load(Mage::app()->getStore()->getRootCategoryId());
}
return $this->_rootCategory;
}
示例4: _setUrlKeyForDefaultStore
/**
* Write category url_key for category into default store
*
* @param Mage_Catalog_Model_Category $category
* @param Mage_Core_Model_Store $store
* @return Mage_Catalog_Model_Category
*/
protected function _setUrlKeyForDefaultStore(Mage_Catalog_Model_Category $category, Mage_Core_Model_Store $store)
{
//we should save url key for default store
$category->setStoreId(0);
$this->_urlModel->getResource()->saveCategoryAttribute($category, 'url_key');
//return current store to category
$category->setStoreId($store->getId());
return $category;
}
示例5: testSetGetStoreId
public function testSetGetStoreId()
{
$this->assertEquals(Mage::app()->getStore()->getId(), $this->_model->getStoreId());
$this->_model->setStoreId(1000);
$this->assertEquals(1000, $this->_model->getStoreId());
}
示例6: processCategory
/**
* Update category url key
*
* @param Mage_Catalog_Model_Category $category
* @param string $newUrlKey
* @param int $storeId
*/
function processCategory($category, $newUrlKey, $storeId)
{
$store = Mage::app()->getStore();
Mage::app()->setCurrentStore(Mage::app()->getStore(0));
if (!$this->isEntityProcessed(self::ENTITY_TYPE_CATEGORY, $category->getId() . '-' . $storeId) && !preg_match('~-[a-f0-9]{32}$~i', $newUrlKey)) {
$category->setStoreId($storeId);
$category->setUrlKey($newUrlKey . '-' . md5($category->getStoreId() . $category->getId()));
$category->save();
$this->_reindexCategory($category->getId());
$category->unsetData('request_path');
$category->unsetData('url');
$this->markEntityProcessed(self::ENTITY_TYPE_CATEGORY, $category->getId() . '-' . $category->getStoreId());
}
Mage::app()->setCurrentStore($store);
}