本文整理汇总了PHP中Varien_Simplexml_Element::addAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Simplexml_Element::addAttribute方法的具体用法?PHP Varien_Simplexml_Element::addAttribute怎么用?PHP Varien_Simplexml_Element::addAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Simplexml_Element
的用法示例。
在下文中一共展示了Varien_Simplexml_Element::addAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateXml
/**
* Generate sitemap xml
*
* @return string
*/
public function generateXml()
{
$storeId = $this->getStoreId();
$date = date('Y-m-d');
$simplexml = new Varien_Simplexml_Element('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>');
$simplexml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
/**
* Generate categories sitemap
*/
$changefreq = (string) Mage::getStoreConfig('sitemap/category/changefreq');
$priority = (string) Mage::getStoreConfig('sitemap/category/priority');
$categories = Mage::getModel('catalog/category')->setStoreId($storeId)->getCollection()->addAttributeToSelect('*')->load();
foreach ($categories as $category) {
$category = Mage::getModel('catalog/category')->load($category->getId());
if (!$category->getIsActive()) {
continue;
}
$url = $simplexml->addChild('url');
$url->addChild('loc', $category->getCategoryUrl());
$url->addChild('lastmod', $date);
$url->addChild('changefreq', $changefreq);
$url->addChild('priority', $priority);
}
/**
* Generate products sitemap
*/
$changefreq = (string) Mage::getStoreConfig('sitemap/product/changefreq');
$priority = (string) Mage::getStoreConfig('sitemap/product/priority');
$products = Mage::getModel('catalog/product')->setStoreId($storeId)->getCollection()->addAttributeToSelect('*');
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
$products->load();
foreach ($products as $product) {
$product = Mage::getModel('catalog/product')->load($product->getId());
$url = $simplexml->addChild('url');
$url->addChild('loc', $product->getProductUrl());
$url->addChild('lastmod', $date);
$url->addChild('changefreq', $changefreq);
$url->addChild('priority', $priority);
}
/**
* Generate CMS pages sitemap
*/
$changefreq = (string) Mage::getStoreConfig('sitemap/page/changefreq');
$priority = (string) Mage::getStoreConfig('sitemap/page/priority');
$pages = Mage::getModel('cms/page')->setStoreId($storeId)->getCollection();
foreach ($pages as $page) {
$page = Mage::getModel('cms/page')->load($page->getId());
$url = $simplexml->addChild('url');
$url->addChild('loc', Mage::getBaseUrl() . $page->getIdentifier());
$url->addChild('lastmod', $date);
$url->addChild('changefreq', $changefreq);
$url->addChild('priority', $priority);
}
// record last generation time
$this->setSitemapTime(now());
$this->save();
return $simplexml->asXml();
}
示例2: _removeRender
/**
* Render remove action
*
* @return Varien_Simplexml_Element
*/
protected function _removeRender()
{
$remove = new Varien_Simplexml_Element('<remove></remove>');
$remove->addAttribute('name', $this->getName());
return $remove;
}