Magento获取当前Collection的排序方式

 

汤面和namu
汤面和namu

在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();

继续阅读“Magento获取当前Collection的排序方式”

Magento sql升级脚本加入新的字段add column

magento add column
magento add column

最近使用了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();

继续阅读“Magento sql升级脚本加入新的字段add column”

Magento升级paypal报错Call to a member function setFieldNamePrefix

Call to a member function setFieldNamePrefix
Call to a member function setFieldNamePrefix

Magento网站升级1.7后,paypal支付出现报错信息如下:

Fatal error: Call to a member function setFieldNamePrefix() on a non-object in /home/********/public_html/app/design/frontend/base/default/template/paypal/express/review.phtml on line 28″

google了一下,发现官方论坛有此报错的解决办法,网址:http://www.magentocommerce.com/boards/viewth./viewthread/282519/#t393628

这是由于模板文件不兼容引起的,最快捷的办法就是删除当前模板中的paypal.xml文件。删除后,magento会使用base/default/layout中的paypal.xml 。注意此删除是否会影响你的网站,删除前备份此文件。

继续阅读“Magento升级paypal报错Call to a member function setFieldNamePrefix”

使用命令行刷新Magento索引管理

magento索引管理
magento索引管理

当我们网站商品很多的时候,比如有几千件,我们刷新Magento的索引管理(Index Management)经常会失败。那么后台刷新不了,我们还可以通过命令行来刷新。使用命令行来刷新索引管理会极大降低系统消耗,容易成功。
我们来看下步骤,如果你在使用linux服务器,登入你的ssh客户端,切换目录到你magento根文件夹中名字是shell的文件中。
在此文件夹中输入如下命令

php -f indexer.php -- -reindex catalog_url

它的意思是刷新Catalog Url Rewrites即网址重写。成功后会有成功提示,如:Catalog URL Rewrites index was rebuilt successfully

magento使用Shell刷新索引管理
magento使用Shell刷新索引管理

我们来看下有哪些索引管理,可以使用Shell的命令行来刷新,如下

catalog_product_attribute     Product Attributes
catalog_product_price         Product Prices
catalog_url                   Catalog Url Rewrites
catalog_product_flat          Product Flat Data
catalog_category_flat         Category Flat Data
catalog_category_product      Category Products
catalogsearch_fulltext        Catalog Search Index
cataloginventory_stock        Stock status

如上分别对应后每项台的索引管理。

命令执行后需要耐心等待一段时间,因你商品数量和你服务器性能决定等待多久。注意命令中reinde前一共是三个英文横线。如有代码错误提示,直接黏贴本文的命令或者
如下参考文章的命令,直接修改执行参数即可。

参考文章:http://inchoo.net/ecommerce/magento/executing-magento-indexer-from-shell/
继续阅读“使用命令行刷新Magento索引管理”

Magento组商品显示商品属性

magento组商品显示商品属性表格
magento组商品显示商品属性表格

Magento组商品(Magento grouped product),是用来对属于一个系列或者一个组合的商品进行销售。如上图,为默认情况下的Magento组商品,此例子是对于一个沙发组合进行销售。组商品的特点就是你可以根据自己需要,每件可以购买不同的数量。

在某些时候,我们可能需要更加详细的内容显示,如下图,为销售一些五金商品,那么购买者可能需要更多的参数信息。

magento组商品显示每件商品属性
magento组商品显示每件商品属性

我们可以看到,这就是对组商品进行扩展,让其显示更多的属性值。

这个是怎样做到的呢?

继续阅读“Magento组商品显示商品属性”

Magento开发协议注意事项

magento开发协议注意事项
magento开发协议注意事项

最近做Magento开发的人越来越多了。

不管是做模板还是做插件;不管是个人还是公司,我们都有要注意的地方,一定要在合同中声明,没写合同也发邮件确认下工作内容。

对于开发者,其实很简单,要收取定金,以防雇主反悔。即使雇主反悔,也不会损失很大,开发成果也可以卖给别人。根据我个人经验,一般没有事前和雇主明确工作内容,会导致工作内容增加很多,所以一定要明确工作内容和增加工作内容后的收费细则。

对于雇主,可能需要注意的事情就比较多了,以下四点可能是需要明确的:

1.开发周期。明确没有按期完成开发内容各方所承担的后果。一般都不着急,此处可以宽松些,不必太计较。赶期完成的东西表面看,可能很好,但以后问题可能会更多。

2.分期付款,不要一次付清,以防毁约。更不要在最后不付全款,程序有后门你可伤不起。

3.明确开发后的模板插件版权,以及保密协议。版权是最重要的,保密协议只是个君子协议。

4.要求开发结果不会修改magento核心文件,不影响magento升级或者安装其余插件。

继续阅读“Magento开发协议注意事项”