Magento语言包修改和多语言实现

此教程讲解如何修改magento的语言包,对如何实现多语言也做了一定的说明和讲解。在看此视频前,需要大家熟悉如何使用magento connect安装语言包,如何设置magento多语言,不会的看我的2013年Magento视频教程

视频地址:http://www.tudou.com/programs/view/e81dLlGkKjg/

继续阅读“Magento语言包修改和多语言实现”

谈Magento多语言与特价Special Price翻译

Magento商品属性翻译修改
Magento商品属性翻译修改

安装Magento语言包后,Magento的翻译文件依据语言不同,分成不同文件夹存放在 app/locale文件夹下,如下图

Magento语言包文件夹
Magento语言包文件夹

每个文件夹是一个语言包,打开可以看到很多CSV文件,打开以后可以看到类似如下格式的内容

"Currently Shopping by:","Actualmente Comprando en:"
"Custom Design","Diseño Personalizado"
"Custom Options","Opciones Personalizadas"
"Custom options","Opciones de personalización"
"Customer Group","Grupo de Clientes

左边是magento英文原文,右边是翻译后的,使用UTF8编码来编辑这些语言文件,以此来修改翻译不当的内容。
保存后,记得刷新magento缓存,来查看修改结果。
要想找到自己需要找的翻译内容,可能不太好找,需要查找多个CSV文件才能找到。如果所有的文件都没有你需要找的内容,你可以在某个CSV文件中自己添加一条。
如上就是一般的修改magento翻译的方法。
有的时候,可能我们通过修改编辑文件解决不了你的问题。(也可以试试magento在线翻译。什么是在线翻译?见我的视频:http://www.hellokeykey.com/magento-transfer-online/)这可能和你的模板代码有一定的关系。

继续阅读“谈Magento多语言与特价Special Price翻译”

Magento去掉价格的小数点

Magento去掉价格小数点
Magento去掉价格小数点

Magento的默认情况,价格后面是有小数点的,我们来看下如何正确的来去掉小数点。

1.复制如下路径的文件 app/code/core/Mage/Directory/Model/Currency.php 到 app\code\local\Mage\Directory\Model\ 文件夹下面,这个文件夹没有自己手动创建下。

2.打开新复制的这个文件 Currency.php

继续阅读“Magento去掉价格的小数点”

Magento控制器中添加Block

如果不想在模板的xml中设置block或者block是动态的,那么在Magento在控制器中添加block的时候可以做下动态的调整,进而动态的修改页面。

代码如下:

$this->loadLayout();

//set view page top content
$block = $this->getLayout()->createBlock(
                    'activitie/activitie_view', 'activitie_view', array('template' => 'hellokeykey_activitie/activitie/view.phtml')
            );
$this->getLayout()->getBlock('content')->insert($block);
//$this->getLayout()->getBlock('content')->append($block);

$this->renderLayout();

 

getBlock('content')是只更新content部分

append是指添加到后面,insert是添加到前面

参考文章:http://inchoo.net/ecommerce/magento/programatically-create-magento-blocks-and-inject-them-into-layout/

转载表明出处:www.hellokeykey.com

Magento清空数据库log和var缓存文件脚本

magento清空log与var脚本
magento清空log与var脚本

Magento的数据库,用久了,很多log表会变的非常巨大,数据库体积也越来越大,这会严重影响到数据库的运行。

此脚本可以自动清空数据库log表。如果你的log表有用,可以按照实际情况修改此脚本。

将文件上传至你的magento文件根目录,然后用如下地址执行清空命令:

清空数据库log表:http://你网站的网址/clear-magento.php?clean=log

清空magento缓存文件:http://你网站的网址/clear-magento.php?clean=var

如果你的数据库log表比较大,那么使用如上命令清log可能会失败,或者用去很长时间,你可以手动清空,在脚本代码中的log表有:

‘dataflow_batch_export’,
‘dataflow_batch_import’,
‘log_customer’,
‘log_quote’,
‘log_summary’,
‘log_summary_type’,
‘log_url’,
‘log_url_info’,
‘log_visitor’,
‘log_visitor_info’,
‘log_visitor_online’,
‘index_event’,
‘report_event’,
‘report_compared_product_index’,
‘report_viewed_product_index’,
‘catalog_compare_item’,
‘catalogindex_aggregation’,
‘catalogindex_aggregation_tag’,
‘catalogindex_aggregation_to_tag’,
‘catalogsearch_query’,
‘catalogsearch_fulltext’,
‘catalogsearch_result’

清空var缓存文件一般不会花费太多时间,缓存文件在脚本中路径分别为:

继续阅读“Magento清空数据库log和var缓存文件脚本”

magento set image fit or fill the parent container

magento图片自适应容器大小
magento图片自适应容器大小

magento原始模板原先自带的图片处理会有白边,就是图片比例不符合代码中的尺寸时,magento会自动resize图片尺寸,并且自动加上白边。

其实去掉白边好搞,增加去白边的代码即可,如下

$this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(210);

keepFrame(FALSE)这个是控制白边的,参数false就是不带白边。resize控制图片的比例,单独一个数字,如上面 200,是将图片搞成200*200的尺寸,这个只有在有白边的时候才有效,没有白边了这个resize就不太管用了,会按照实际比例缩放图片,你可以试试。

对于很多人来说也许去掉白边就够用了,但是有的时候有变态的情况,比如图片比例是1:5甚至1:10,尼玛 – – ! 怎么会有这么变态的图片比例,这会将你的布局搞的乱七八糟。如果你有这个情况,又想控制图片的最大宽高的话,看这篇博文会有所帮助。

首先我们将magento的图片的白边去掉了,下一步就是使图片自适应到你设置的大小,即使比例差别很大,也自适应下,图片不超出你指定的长宽。相当于,你设置了图片的最大宽度,最大高度。这样对于你布局来说,会好狠多。

jquery有很多图片缩放,自适应的插件,我找到的这个是我自己认为比较合适的 http://imgscale.kjmeath.com/,当然大家也可以找自己喜欢的,或者更满足大家自己需求的js插件。

看插件的说明,他要求在图片的外层有个div或者什么的是block类型的html标签,并且css中写上宽高。

继续阅读“magento set image fit or fill the parent container”

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在product view页面ajax显示tag的商品

magento ajax获取tag商品
magento ajax获取tag商品

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返回商品信息的参考代码如下

继续阅读“Magento在product view页面ajax显示tag的商品”

获取magento全部商品评价reviews

magento-all-reviews
magento-all-reviews

最新写个magento获取评价的插件,获取全部评价的代码分享下。

如下代码片段如下,仅供参考:

Block中的代码如下

class Hellokeykey_Allreviews_Block_Allreviews extends Mage_Core_Block_Template
{
	protected $_collection;

	protected function _construct()
    {
		$this->_collection = Mage::getModel('review/review')->getProductCollection();
        $this->_collection
            ->addStoreFilter(Mage::app()->getStore()->getId())
            //->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId())
			->addStatusFilter(1)  //const STATUS_APPROVED       = 1;
            ->setDateOrder();
    }

	// add by lee

	public function getReviewsSummaryHtml(Mage_Catalog_Model_Product $product, $templateType = false, $displayIfNoReviews = false)
    {
        return
            $this->getLayout()->createBlock('rating/entity_detailed')
                ->setEntityId($this->getProduct()->getId())
                ->toHtml()
            .
            $this->getLayout()->getBlock('product_review_list.count')
                ->assign('count', $this->getReviewsCollection()->getSize())
                ->toHtml()
            ;
    }

	/**
     * Gets collection items count
     *
     * @return int
     */
    public function count()
    {
        return $this->_collection->getSize();
    }

    /**
     * Get html code for toolbar
     *
     * @return string
     */
    public function getToolbarHtml()
    {
        return $this->getChildHtml('toolbar');
    }

    /**
     * Initializes toolbar
     *
     * @return Mage_Core_Block_Abstract
     */
    protected function _prepareLayout()
    {
        $toolbar = $this->getLayout()->createBlock('page/html_pager', 'customer_review_list.toolbar')
            ->setCollection($this->getCollection());

        $this->setChild('toolbar', $toolbar);
        return parent::_prepareLayout();
    }

	/**
     * Get collection
     *
     * @return Mage_Review_Model_Resource_Review_Product_Collection
     */
    protected function _getCollection()
    {
        return $this->_collection;
    }

    /**
     * Get collection
     *
     * @return Mage_Review_Model_Resource_Review_Product_Collection
     */
    public function getCollection()
    {
        return $this->_getCollection();
    }

    /**
     * Get product link
     *
     * @return string
     */
    public function getProductReviewLink()
    {
        return Mage::getUrl('review/product/list/id/');
    }

    /**
     * Format date in short format
     *
     * @param $date
     * @return string
     */
    public function dateFormat($date)
    {
        return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
    }

	protected function _beforeToHtml()
    {
        $this->_getCollection()
            ->load()
            ->addReviewSummary();
        return parent::_beforeToHtml();
    }
}

上面代码来自核心代码的修改,注意的地方就是去掉用户筛选出状态是通过的评价

maegnto模板文件中输出,模板文件中的代码如下

<?php if( $this->getCollection() && $this->count()): ?>
    <?php echo $this->getToolbarHtml() ?>
		<table class="data-table" id="my-reviews-table">
            <col width="1" />
            <col width="210" />
            <col width="1" />
            <col />
            <tbody>
                <?php foreach ($this->getCollection() as $_review): ?>
                <?php
					$_product = Mage::getModel('catalog/product')->load($_review->getEntityPkValue());
					$storeId = Mage::app()->getStore()->getId();
					//$reviewsCount = Mage::getModel('review/review')->getTotalReviews($_review->getEntityPkValue(), true , $storeId);
				?>
				<tr>
                    <td>
						<P><strong><?php echo $_review->getNickname(); ?></strong></P>
						<span class="nobr"><?php echo $this->dateFormat($_review->getReviewCreatedAt()); ?></span>
					</td>
                    <td>
						<a href="<?php echo $_product->getProductUrl(); ?>" target="_blank"><?php echo $this->htmlEscape($_review->getName()) ?></a>
						<img src="<?php echo $_product->getImageUrl() ?>" />
					</td>
                    <td>
                    <?php if($_review->getSum()): ?>
                        <div class="rating-box">
                            <div class="rating" style="width:<?php echo ( $_review->getSum() / $_review->getCount() ) ?>%;"></div>
                        </div>
						<a href="<?php echo $this->getProductReviewLink() ?>id/<?php echo $_review->getEntityPkValue() ?>" target="_blank"><?php echo $_review->getCount() ?> <?php echo $this->__('reviews') ?></a>
                    <?php endif; ?>
                    </td>
                    <td><?php echo $this->helper('review')->getDetailHtml($_review->getDetail()) ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
	    <script type="text/javascript">decorateTable('my-reviews-table')</script>
    <?php echo $this->getToolbarHtml() ?>
<?php else: ?>
    <p><?php echo $this->__('You have submitted no reviews.') ?></p>
<?php endif; ?>

此为magento 1.7.2.0测试代码,不建议用于生产环境。大家根据自己magento版本和经验适当修改。

继续阅读“获取magento全部商品评价reviews”

magento异地备份,灾难恢复

magento异地备份,灾难恢复
magento异地备份,灾难恢复

网站异地备份,避免服务器硬盘挂掉资料丢失。也许你会说我装的raid1+0不慌,那么如果是地震和海啸把机房毁了呢?也许你会说你已经将备份下载到本地了,如果你的文件有好几个G,我想你上传文件就是个大问题。如果你的资金允许,不妨给你的网站建立灾难恢复方案,比如将网站的文件存在别的机房的备份服务器上。这样即备份了文件,又在需要文件恢复的时候可以快速的将文件传递过去,机房和机房之间传文件速度比你在家里快很多。 – – ! 别说从中国机房的事情,中国机房还处于YY阶段。

如果你是小白级人物又懂点英语,今天推荐一个提供文件、数据库异地备份、恢复的网站:http://myrepono.com/  (此链接是赞助我的链接)

特点:

1.文件备份和恢复

2.数据库备份和恢复

3.定时备份

4.备份文件一键恢复

 

注意事项:

1.选择在你网站没有人访问的时候,或者很少人访问的时候进行备份。如果有必要可以暂停网站服务,再进行备份。

2.数据库的备份,似乎这类的备份服务提供商们都没有特别好的解决方案。你可以在自己服务器上写脚本,定时使用mysql的备份命令来备份文件,然后将此文件加到备份文件中,以sql文件的形式来备份数据库文件,这样可能更安全。我的意思是说,他的数据库备份不一定好用,但是文件备份是没有问题的。

3.我们magento的网站最大的文件就是根目录的那个media文件夹(如果你商品够多,你这个文件夹有好几个G大),这个文件夹存的是商品的图片,所以很大,你可以不存此文件里面的cache文件夹,如果你使用批量导入功能,你可以不存储里面的import文件夹,以减少备份的体积。

4.即使有异地备份,也将文件定期存在你的本地硬盘上,万一爆发核战争,大多数机房都毁了,而你又想在核战争结束后继续卖阿迪达斯,这是很有必要的。

 

这类提供网站备份的网站还有很多,如果你不喜欢这家可以用其它家的,同 等价位的,一般都差不多。

 

转载标明出处:www.hellokeykey.com