9 ayrı Magento örneğine ve aynı siteye sahip olduğuna inanıyorum.
Bu nedenle herhangi bir arka uç verisi - config ve hatta CMS blokları için katı prosedürler vardır.
Nasıl bir kurulum komut dosyası üzerinden bir CMS blok eklemek öğrenmek istiyorum.
9 ayrı Magento örneğine ve aynı siteye sahip olduğuna inanıyorum.
Bu nedenle herhangi bir arka uç verisi - config ve hatta CMS blokları için katı prosedürler vardır.
Nasıl bir kurulum komut dosyası üzerinden bir CMS blok eklemek öğrenmek istiyorum.
Yanıtlar:
Bunun dataiçin özel modüllerinizden birinin klasörünü kullanmanızı öneririm .
Diyelim ki modül şu anda sürümde 1.0.4.
Dosyayı data/[module]_setup/data-upgrade-1.0.4-1.0.5.phpaşağıdaki içerikle oluşturun:
Düzenle: dosya adını değiştirdi
$content = 'BLOCK CONTENT HERE';
//if you want one block for each store view, get the store collection
$stores = Mage::getModel('core/store')->getCollection()->addFieldToFilter('store_id', array('gt'=>0))->getAllIds();
//if you want one general block for all the store viwes, uncomment the line below
//$stores = array(0);
foreach ($stores as $store){
$block = Mage::getModel('cms/block');
$block->setTitle('Block title here');
$block->setIdentifier('block_identifier_here');
$block->setStores(array($store));
$block->setIsActive(1);
$block->setContent($content);
$block->save();
}
Bundan sonra sadece versiyonunu değiştirmek config.xmliçin 1.0.5önbelleğini temizleyin ve herhangi bir sayfayı yenileyin.
Mage::app()->getStores()Aynı şeyi yapar mıydı ?
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$staticBlock = array(
'title' => 'Test Block',
'identifier' => 'test-block',
'content' => 'Sample Test Block',
'is_active' => 1,
'stores' => array(0)
);
Mage::getModel('cms/block')->setData($staticBlock)->save();
sqlKlasörü kullanmak yerine, klasöre CMS verilerini değiştiren kurulum komut dosyalarını koymalısınız data. app/code/core/Mage/Cms/data/cms_setupBazı iyi örnekler için bakınız . Bu yükleme komut dosyaları statik bloklar ve CMS sayfaları ekler.
Yapılandırma değerlerini değiştirmek için şu kodu kullanın:
$installer->setConfigData(
Mage_Page_Model_Config::XML_PATH_CMS_LAYOUTS,
'your_value_here'
);
Ayrıca, İşte yararlı bir makale
Yükseltme komut dosyasında aşağıdaki kodu da kullanabilirsiniz:
$installer = $this;
/* @var $installer Mage_Core_Model_Resource_Setup */
$connection = $installer->getConnection();
/* @var $connection Varien_Db_Adapter_Pdo_Mysql */
$installer->startSetup();
$connection->insert($installer->getTable('cms/block'), array(
'title' => 'Footer Links',
'identifier' => 'footer-links',
'content' => '<ul>\r\n<li><a href=\"{{store direct_url=\"about-magento-demo-store\"}}\">About Us</a></li>\r\n<li class=\"last\"><a href=\"{{store direct_url=\"customer-service\"}}\">Customer Service</a></li>\r\n</ul>',
'creation_time' => now(),
'update_time' => now(),
));
$connection->insert($installer->getTable('cms/block_store'), array(
'block_id' => $connection->lastInsertId(),
'store_id' => 0
));
$installer->endSetup();
Aşağıdaki kod, magento komut dosyalarını kullanarak statik blok oluşturur ve günceller
http://www.pearlbells.co.uk/how-to-create-and-update-the-static-blocks-using-magento-script/
function createBlock($blockData) {
$block = Mage::getModel('cms/block')->load($blockData['identifier']);
$block->setTitle($blockData['title']);
$block->setIdentifier($blockData['identifier']);
$block->setStores(array($blockData['storeId']));
$block->setIsActive($blockData['active']);
$block->setContent($blockData['content']);
$block->save();
}