本博文是钥匙博客的重要文章索引页,帮助大家通过我的博客学习magento。本页内容也在不停的更新,完善中。也可以通过本页内容对我博客内容有个大概的了解。
请使用google搜索获取本站的magento文章信息,或者订阅本博客的RSS。
大家好我是钥匙,欢迎大家来到我的博客学习magento的使用与开发。
本博文是钥匙博客的重要文章索引页,帮助大家通过我的博客学习magento。本页内容也在不停的更新,完善中。也可以通过本页内容对我博客内容有个大概的了解。
请使用google搜索获取本站的magento文章信息,或者订阅本博客的RSS。
Filed under - magento, magento其它 66 Comments so far. Add yours now
在Magento中,平时获得collection的时候,我们会根据实际情况设置排序,使用setOrder。如果只是静态的,这个好说,直接写上即可。
现在需要使用ajax的加载product list,实现当前页面动态加载后面页面的内容。这个时候页面排序和排序方式用户可以自己选择的,就需要动态的获取,当前的排序方式。
参考代码如下
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', $visibility)
.............
->setStoreId($storeId)
->addStoreFilter($storeId)
->addCategoryFilter($_featcategory) //feature category to list first
//set order as CurrentOrder
->setOrder(Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentOrder(), Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentDirection())
.......................
代码中如下两行分别获取order和direction,动态的设置collection
Mage::getBlockSingleton(‘catalog/product_list_toolbar’)->getCurrentOrder();
Mage::getBlockSingleton(‘catalog/product_list_toolbar’)->getCurrentDirection();
Filed under - magento, magento wiki No Comments so far. Add yours now
最近使用了magento的商品品牌插件,需要在此插件的数据库表中添加几个字段。
首先需要修改插件的版本号,以便magento发现插件版本升级了,运行升级脚本。
版本号在插件的ect/config.xml文件中,sql脚本示例mysql4-upgrade-0.1.0-0.1.1.php如下
<?php
$installer = $this;
$installer->startSetup();
$installer->getConnection()->addColumn(
$installer->getTable('brand'),
'country',
"varchar(255) NULL"
);
$installer->getConnection()->addColumn(
$installer->getTable('brand'),
'role',
"varchar(255) NULL"
);
$installer->endSetup();
Filed under - magento, magento wiki No Comments so far. Add yours now
Magento的tag是点击后,有一个tag关联商品的list页面。客户需要在商品详情页面product view中点击tag使用ajax直接显示商品。
首先我们需要写个小插件,为ajax提供数据
Controller的参考代码如下:
$tagId = $this->getRequest()->getParam('tagId');
$tag = Mage::getModel('tag/tag')->load($tagId);
if (!$tag->getId() || !$tag->isAvailableInStore()) {
$this->_forward('404');
return;
}
$page_size = 15;
$page = 1;
/* $tagModel = Mage::getModel('tag/tag');
$productCollection = $tagModel->getEntityCollection()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addTagFilter($tagId)
->addStoreFilter(Mage::app()->getStore()->getId())
->addMinimalPrice()
->addUrlRewrite()
->setActiveFilter()
->setPageSize($page_size)
->setCurPage($page);
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($productCollection);
*/
$productIds = $tag->getRelatedProductIds();
$productCollection = Mage::getModel('catalog/product')->getCollection()
->setStoreId($storeId)
->addAttributeToSelect('*')
->addFieldToFilter('entity_id', $productIds)
->setPageSize($page_size)
->setCurPage($page);
$html = '';
foreach ($productCollection as $product) { //to get all product list
$html .= '<div class="item">';
//START
$p_url = $product->getProductUrl();
$p_name = $product->getName();
$p_img_url = Mage::helper('catalog/image')->init($product, 'small_image')->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->resize(200, null);
$p_final_price = Mage::helper('core')->currency($product->getFinalPrice(), true, false);
$html .='<a class="product-image" href="' . $p_url . '"><img src="' . $p_img_url . '" width="200" /></a>';
$html .='<h2 class="product-name" class="product-name"><a href="' . $p_url . '">' . $p_name . '</a></h2>';
$html .='<div class="price-box"><span class="regular-price"><span class="price">' . $p_final_price . '</span></span></div>';
//END
$html.='</div>';
}
//var_dump($productCollection);
echo $html;
模板文件中的ajax获取Controller返回商品信息的参考代码如下
Filed under - magento, magento wiki No Comments so far. Add yours now
Magento页面默认信息设置视频地址 : http://www.tudou.com/programs/view/cnk3FQIUSMk/
Filed under - magento, magento使用教程 No Comments so far. Add yours now
五 06, 2013
No Comments