Magento – Left/Right Callout open external link in new window

http://rricketts.com/magento-leftright-callout-open-external-link-in-new-window/

There are “magic” functions in Magento that allow you to literally create functions on the fly that handle the getting / setting of data. I have two callouts in the left column, one which points internally and one that points externally and I wanted only the external link to open in a new window. So, in page.xml layout, I added the following:

<block type="core/template" name="left.permanent.callout.survey" template="callouts/left_col.phtml">
<action method="setImgSrc"><src>images/survey-promo-graphic.jpg</src></action>
<action method="setImgAlt" translate="alt"><alt>$5 off your next order</alt></action>
<action method="setLinkUrl"><url>http://surveyurl.com</url></action>
<action method="setLinkTarget"><target>_blank</target></action>
</block>

I added an action element with the method attribute of “setLinkTarget”, and a child element of “target” with the value of “_blank” (for my target attribute of the A tag). In left_col.phtml, I added the “target” element to the “a” element:

<a href="<?php echo $this->getLinkUrl() ?>" <?php if ($this->getLinkTarget()) { echo('target="'.$this->getLinkTarget().'"'); } ?>>

Because of the “magic” functions in Magento, I was able to retrieve the value of “_blank” and insert it into my a element to open the survey in a new window. Hope this helps others!

Another helpful link: Dynamic Left / Right Callout Block by Category AND file_exist

Magento Onepage Checkout – Add New Step

原帖地址见

http://www.excellencemagentoblog.com/magento-onestep-checkout-add-step?facebook=1

Adding New Step at First Position


So here we are going to add a new step just after login step or if user is already logged ours will be the first step. The title of step added is “Excellence Blog Review” and id of step would be “excellence”, the step will have a single drop down field. The code for saving this field to database is not explained in this blog, as it was already covered in the previous blog.

Now lets see the steps to make this happen Here the module name i am using is Excellence_Custom


Step1: Creating the HTML


The simplest step as always, first we will create our phtml file excellence.phtml at location custom\checkout\onepage\excellence.phtml. This file contains the html code for our new tab and field in the tab.

<form id="co-excellence-form" action="">
<fieldset>
    <ul class="form-list">
    <li id="excellence-form">
        <fieldset>
            <ul>
                <li class="wide">
                    <label for="excellence:like" class="required"><em>*</em><?php echo $this->__('Do you like Excellence Magento Blog?') ?></label>
                    <div class="input-box">
                        <select class="required-entry" name="excellence[like]" id="excellence:like">
                            <option value=''><?php echo $this->__('Please Choose..');?></option>
                            <option value='1' <?php if($this->getQuote()->getExcellenceLike() == 1){echo 'selected="selected"';} ?>><?php echo $this->__('Yes');?></option>
                            <option value='2' <?php if($this->getQuote()->getExcellenceLike() == 2){echo 'selected="selected"';} ?>><?php echo $this->__('No');?></option>
                        </select>
                    </div>
                </li>
            </ul>
        </fieldset>
     </li>
    </ul>
    <div class="buttons-set" id="excellence-buttons-container">
        <p class="required"><?php echo $this->__('* Required Fields') ?></p>
        <button type="button" title="<?php echo $this->__('Continue') ?>" class="button" onclick="excellence.save()"><span><span><?php echo $this->__('Continue') ?></span></span></button>
        <span class="please-wait" id="excellence-please-wait" style="display:none;">
            <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Loading next step...') ?>" title="<?php echo $this->__('Loading next step...') ?>" class="v-middle" /> <?php echo $this->__('Loading next step...') ?>
        </span>
    </div>
</fieldset>
</form>
<script type="text/javascript">
//<![CDATA[
    var excellence = new ExcellenceMethod('co-excellence-form','<?php echo $this->getUrl('custom/onepage/saveExcellence') ?>');
    var excellenceForm = new VarienForm('co-excellence-form');
//]]>
</script>

So if you look at code and compare it with default onepage.phtml file, i have included a new javascript file called excellencecheckout.js and instead of “new Checkout” i have used “new Excellence”. Next we need to change the html of the progress.phtml file (The progress blocks which show on the right side). For this i have created my own progress.phtml file at location custom/checkout/onepage/progress.phtml. Since i am adding the step at first position, i will add the below code before the billing step

<dl>
        <?php if ($this->getCheckout()->getStepData('excellence', 'is_show')): ?>
        <?php if($this->getCheckout()->getStepData('excellence', 'complete')): ?>
            <dt class="complete">
                <?php echo $this->__('Excellence Review') ?> <span class="separator">|</span> <a href="#excellence" onclick="checkout.accordion.openSection('opc-excellence'); return false;"><?php echo $this->__('Change') ?></a>
            </dt>
            <dd class="complete">
                <div>
                    <?php echo $this->__('Excellence Review Is: ');?>
                    <?php 
                        $like = $this->getQuote()->getExcellenceLike();
                        if($like == 1){
                            echo $this->__('Yes');
                        } else{
                            echo $this->__('No');
                        }
                    ?>
                </div>
            </dd>
        <?php else: ?>
            <dt>
                <?php echo $this->__('Excellence Review') ?>
            </dt>
        <?php endif; ?>
        <?php endif; ?>

Next we need to include these files in our layout xml file, so in my module layout file custom.xml file i have added code

<?xml version="1.0"?>
<layout version="0.1.0">
    <sales_order_view> <!-- Code From Previous Module -->
        <reference name="my.account.wrapper">
            <block type="custom/custom_order" name="custom.order" template="custom/order.phtml" after='sales.order.info' />
        </reference>
    </sales_order_view>
    <checkout_onepage_index> <!-- Adding our new step to onepage block  -->
        <reference name='checkout.onepage'>
             <action method='setTemplate'><template>custom/checkout/onepage.phtml</template></action>
             <block type="custom/checkout_onepage_excellence" name="checkout.onepage.excellence" as="excellence" template="custom/checkout/onepage/excellence.phtml"/> <!-- Here we change the template of onepage block to our custom template -->
        </reference>
        <reference name='checkout.progress'> <!-- Change the template of progress block -->
              <action method='setTemplate'><template>custom/checkout/onepage/progress.phtml</template></action>
        </reference> <!-- Here we change the template of the progress block to our custom template created -->
    </checkout_onepage_index>
    <checkout_onepage_progress>  <!-- Change the template of progress block -->
        <reference name='root'>
            <action method='setTemplate'><template>custom/checkout/onepage/progress.phtml</template></action>
        </reference>
    </checkout_onepage_progress>
</layout> 

Now we have created all the required html files and made the changes in layout files to include them in the checkout page.

Step2: Javascript Classes


In the previous code we have included one new javascipt file excellencecheckout.js and created two new javascript classes Excellence and ExcellenceMethod. So first i will create the javascript file excellencecheckout.js in my skin folder at location skin\frontend\default\default\js\excellencecheckout.js and put the code shown below.
First lets look at the class Excellence, which we used in the new onepage.phtml file. The class Excellence actually replaces the default magento Checkout class. If you look at onepage.phtml this is the code i had written is

Change Magento search result

Magento默认的搜索结果

like word1 or word2 or word3

这样只要包含了word1-3任何一个结果的页面都会出现,导致很多乱七八糟的结果。

需要的搜索结果应该是与关系,而不是或关系。

修改如下。

Make a copy of

app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php
to
app/code/local/Mage/CatalogSearch/Model/Resource/Fulltext.php

change the line 331

$likeCond = ‘(‘ . join(‘ OR ‘, $like) . ‘)’;
to
$likeCond = ‘(‘ . join(‘ AND ‘, $like) . ‘)’;

然后到

System ? Catalog ? Catalog Search ? Search Type

把Seach Type更改为Fulltext

然后修改搜索结果的排序

找出当前theme下的form.mini.phtml

<form id="search_mini_form" action="<?php echo $this->helper('catalogsearch')->getResultUrl() ?>" method="get">

这句下边添加

<input type="hidden" name="order" value="relevance"> 
<input type="hidden" name="dir" value="desc">

然后

System» Index Management and clicking on “Reindex Data” against “Catalog Search Index”.

参考

http://www.infotales.com/magento-performance-search-type-selection/

http://www.woolleydesign.net/2012/04/improving-magentos-catalog-search/

http://karlagius.com/2012/01/17/magento-search-better-results-product-searches/

How to sort Magento products by date added as default

http://www.blastar.biz/2011/07/29/how-to-sort-magento-products-by-date-added-as-default/

Today I had to change Magento default products list sorting to sort by product’s date. In fact we don’t need to sort by date, just by entity_id which is product ID in Magento world. To accomplish this, we need to edit /app/code/core/Mage/Catalog/Block/Product/List.php

You have to find _beforeToHtml() function and change some things inside. First we need to define all available sorting options:

 

 

then remove all getters of default sorting and order, and put those:

 

 

so finally your _beforeToHtml() should looks like this one:

 

Pure-ftpd在Debian和Ubuntu中简单的安装配置

本文介绍在DebianUbuntu下使用手工生成数据库的方式存储虚拟用户的方法搭建一个简单的ftp服务器,适合虚拟用户比较少环境。





1.安装:

 

  1. # apt-get install pure-ftpd

复制代码







2.创建ftp的用户与组:

  1. # groupadd -g 2000 ftpgroup
  2. # useradd -u 2000 -g 2000 -d /dev/null -s /bin/false ftpuser
  3. 因为要创建虚拟用户,所以不给ftpuser在系统中留home目录,同时也不能让它登陆shell

复制代码







3.创建虚拟用户:

  1. # mkdir /home/ftp #创建ftp目录
  2. # chown -R 2000.2000 /home/ftp
  3. # pure-pw useradd yourftpusername -u 2000 -g 2000 -d /home/ftp
  4. 接下来输入用户密码

复制代码







生成数据库文件:

  1. # pure-pw mkdb

复制代码

  1. # ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb

复制代码




这一步很关键,告诉系统如何验证用户。





4.重启ftp服务器


注:pure-ftpd在Debian下默认是由inetd托管的,为了更直观的管理ftp服务,我们把pure-ftpd配置为独立运行的服务器。

  1. # nano /etc/default/pure-ftpd-common

复制代码




将"STANDALONE_OR_INETD=inetd"替换成"STANDALONE_OR_INETD=standalone"

  1. # nano /etc/inetd.conf

复制代码




找到下面一行并注释掉:


#ftp    stream  tcp     nowait  root    /usr/sbin/tcpd /usr/sbin/pure-ftpd-wrapper

  1. # /etc/init.d/pure-ftpd restart

复制代码

 
 

How to install extra True Type Fonts (TTF) in Linux (Ubuntu/Debian)

http://www.soslug.org/wiki/how_to_install_extra_true_type_fonts_ttf_in_linux_ubuntudebian

The problem

Whilst trying out new Conky config files on Crunchbang Linux (wiki to follow about this) I had a few problems that turned out to be fonts that were needed that I did not have installed.
A quick web search later and the fonts were downloaded, but how do I install them so the system knows about them??

Background

Fonts in general are stored within the root file system, but an extra folder is in the /usr/share/fonts in which extra fonts can be added. This is fine until you reinstall and then you have to add them all over again. A far better option is to add a ".fonts" folder in your home folder and place extras there, this way when you reinstall, as long as your home folder is a separate partition (which is a very good idea), they will still be there in the new install.
If you cant see any folders with a preceding . then make sure you have the show hidden folders ticked in your file browser.

The Solution

Once all the new fonts have been copied there, open a terminal and type

#> sudo fc-cache -f -v

followed by your password, this forces the system to look for new fonts and install any found.

Hope this helps, as it took me quite a bit of searching just to learn how to do this seemingly simple task!

These instructions are for a Debian based system (Ubuntu, Mint, #Crunchbang) but should work for most Linux distributions.

As usual thanks go to the folks on the ubuntu forums for their great wit and wisdom. :O)

Magento Checkout Page – Add Custom Fields

In this tutorial, we use Magento CE 1.7.0.2.

Step1: Adding HTML

 

persistent/checkout/onepage/billing.phtml

Find the code

<?php if ($this->canShip()): ?>

Add the following above the line

<li class="fields">
	<div class="field">
		<label for="billing:ssn" class="required"><em>*</em><?php echo $this->__('Pick a name') ?></label>
		<div class="input-box">
			<input type="text" name="custom[ssn]" value="<?php echo $this->htmlEscape($this->getQuote()->getSsn()) ?>" title="<?php echo $this->__('SSN') ?>" class="input-text required-entry" id="billing:ssn" />
		</div>
	</div>                 
</li>

You will see the field in Billing Information like this

Step 1-1. 激活这个module

/app/etc/modules/Excellence_Custom.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Excellence_Custom>
            <active>true</active>
            <codePool>local</codePool>
        </Excellence_Custom>
    </modules>
</config> 

Step2: Save the field in Quote and Order Tables

We need to create a database table 'sales_quote_custom', Put the following sql in your modules mysql-install file.

Which is 

/app/code/local/Excellence/Custom/sql/custom_setup/mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE IF NOT EXISTS {$this->getTable('sales_quote_custom')} (
  `id` int(11) unsigned NOT NULL auto_increment,
  `quote_id` int(11) unsigned NOT NULL,
  `key` varchar(255) NOT NULL,
  `value` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS {$this->getTable('sales_order_custom')} (
  `id` int(11) unsigned NOT NULL auto_increment,
  `order_id` int(11) unsigned NOT NULL,
  `key` varchar(255) NOT NULL,
  `value` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$installer->endSetup(); 

Here we create two tables, one for quote and the other for order.

Next we need to write some event observers to capture quote save, and load events. So open your modules config.xml file and inside the <global> tag put in

<events>
	 <sales_quote_save_before> <!-- Event Called Before Quote Object is saved -->
		 <observers>
				   <save_before>
					<type>singleton</type>
					<class>Excellence_Custom_Model_Observer</class> <!-- Over Model Class -->
					<method>saveQuoteBefore</method> <!-- name of function -->
				  </save_before>
		</observers>
	  </sales_quote_save_before>
	  <sales_quote_save_after> <!-- Event called After Quote Object is saved -->
		 <observers>
				   <save_after>
						<type>singleton</type>
						<class>Excellence_Custom_Model_Observer</class> <!-- Over Model Class -->
						<method>saveQuoteAfter</method> <!-- name of function -->
				  </save_after>
		</observers>
	  </sales_quote_save_after>
	  <sales_quote_load_after> <!-- Event called when Quote Object is loaded -->
			<observers>
				<load_after>
						<type>singleton</type>
						<class>Excellence_Custom_Model_Observer</class> <!-- Over Model Class -->
						<method>loadQuoteAfter</method> <!-- name of function -->
				 </load_after>
			 </observers>
	  </sales_quote_load_after>
	  <sales_model_service_quote_submit_after> <!-- Event called after order placed -->
			<observers>
				<sales_model_service_quote_submit_after>
						<type>singleton</type>
						<class>Excellence_Custom_Model_Observer</class> <!-- Over Model Class -->
						<method>saveOrderAfter</method> <!-- name of function -->
				 </sales_model_service_quote_submit_after>
			 </observers>
	  </sales_model_service_quote_submit_after>
	  <sales_order_load_after> <!-- Event called after Order Object is loaded -->
			<observers>
				<sales_order_load_after>
						<type>singleton</type>
						<class>Excellence_Custom_Model_Observer</class> <!-- Over Model Class -->
						<method>loadOrderAfter</method> <!-- name of function -->
				 </sales_order_load_after>
			 </observers>
	  </sales_order_load_after>
</events> 

Next we need to create our Observer classes in Model folder. So create an Observer.php in your modules Model folder.

<?php
class Excellence_Custom_Model_Observer{
    /**
     * This function is called just before $quote object get stored to database. 
     * Here, from POST data, we capture our custom field and put it in the quote object
     * @param unknown_type $evt
     */
    public function saveQuoteBefore($evt){
        $quote = $evt->getQuote();
        $post = Mage::app()->getFrontController()->getRequest()->getPost();
        if(isset($post['custom']['ssn'])){
            $var = $post['custom']['ssn'];
            $quote->setSsn($var);
        }
    }
    /**
     * This function is called, just after $quote object get saved to database.
     * Here, after the quote object gets saved in database
     * we save our custom field in the our table created i.e sales_quote_custom
     * @param unknown_type $evt
     */
    public function saveQuoteAfter($evt){
        $quote = $evt->getQuote();
        if($quote->getSsn()){
            $var = $quote->getSsn();
            if(!empty($var)){
                $model = Mage::getModel('custom/custom_quote');
                $model->deteleByQuote($quote->getId(),'ssn');
                $model->setQuoteId($quote->getId());
                $model->setKey('ssn');
                $model->setValue($var);
                $model->save();
            }
        }
    }
    /**
     * 
     * When load() function is called on the quote object, 
     * we read our custom fields value from database and put them back in quote object.
     * @param unknown_type $evt
     */
    public function loadQuoteAfter($evt){
        $quote = $evt->getQuote();
        $model = Mage::getModel('custom/custom_quote');
        $data = $model->getByQuote($quote->getId());
        foreach($data as $key => $value){
            $quote->setData($key,$value);
        }
    }
    /**
     * 
     * This function is called after order gets saved to database.
     * Here we transfer our custom fields from quote table to order table i.e sales_order_custom
     * @param $evt
     */
    public function saveOrderAfter($evt){
        $order = $evt->getOrder();
        $quote = $evt->getQuote();
        if($quote->getSsn()){
            $var = $quote->getSsn();
            if(!empty($var)){
                $model = Mage::getModel('custom/custom_order');
                $model->deleteByOrder($order->getId(),'ssn');
                $model->setOrderId($order->getId());
                $model->setKey('ssn');
                $model->setValue($var);
                $order->setSsn($var);
                $model->save();
            }
        }
    }
    /**
     * 
     * This function is called when $order->load() is done.
     * Here we read our custom fields value from database and set it in order object.
     * @param unknown_type $evt
     */
    public function loadOrderAfter($evt){
        $order = $evt->getOrder();
        $model = Mage::getModel('custom/custom_order');
        $data = $model->getByOrder($order->getId());
        foreach($data as $key => $value){
            $order->setData($key,$value);
        }
    }
 
}

Step3: Display Our Field in My Account -> View Order

After the order is placed by the customer, our custom fields needs to be visible in My Account. So to do this in our module fronted layout file, in my case its custom.xml.

/app/design/frontend/default/default/layout/custom.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <sales_order_view>
        <reference name="my.account.wrapper">
            <block type="custom/custom_order" name="custom.order" template="custom/order.phtml" after='sales.order.info' />
        </reference>
    </sales_order_view>
</layout> 

This layout file is simple and understandable. Basically, we are taking reference of my.account.wrapper block and adding a child block to it. Our block type is custom/order_view and template file is custom/order.phtml.
So we need to create our block class
/app/code/local/Excellence/Custom/Block/Custom/Order.php

<?php
class Excellence_Custom_Block_Custom_Order extends Mage_Core_Block_Template{
    public function getCustomVars(){
        $model = Mage::getModel('custom/custom_order');
        return $model->getByOrder($this->getOrder()->getId());
    }
    public function getOrder()
    {
        return Mage::registry('current_order');
    }
}

and our order.phtml file

/app/design/frontend/default/default/template/custom/order.phtml

<div class="col-set order-info-box">
    <div class="col">
        <div class="box">
            <div class="box-title">
                <h2><?php echo $this->__('Custom Fields') ?></h2>
            </div>
            <div class="box-content">
                
                	<?php
                		$custom = $this->getCustomVars();
                		foreach($custom as $key => $value){
                	?>
                		<b><?php echo $this->__($key);?></b> : <?php echo $value;?> <br/>
                	<?php } ?>
                
            </div>
        </div>
    </div>
</div>

 

lnmp 0.8版本drupal clean url和301重定向

http://bbs.vpser.net/thread-8527-1-9.html

 

问题:drupal 开启clean url后,图片不显示,每次需要关闭然后再重开才会显示。

经过几天的摸索,查阅无数资料终于得到解决,在此留作存档,也愿后来的朋友方便。

方法:

1.解决开启 drupal clean url 

vim /usr/local/nginx/conf/vhost/site.com.conf



在 root /home/wwwroot/site.com; 下面加上



try_files $uri @rewrite;

location @rewrite {

            rewrite ^/(.*)$ /index.php?q=$1;

        }



(修正一下,这种官方办法才是正确的。上面一种在开启CLEAN URL时图片会显示不正常)

一种官方推荐的代码:



if (!-e $request_filename) {

    rewrite ^/(.*)$ /index.php?q=$1 last;

}








2.解决图像不显示(这是已经集成在DP7里面的imagecache问题,花了我几天的时间)

/usr/local/nginx/conf/vhost下相应的.conf文件,加上:

# For Drupal7 use /styles instead of /imagecache

        location ~ ^/sites/.*/files/styles/ {

                try_files $uri @rewrite;

        }






3,解决301重定向到WWW 

把conf这里server_name www.domain.cn domain.cn; 的 domain.cn删除掉,

然后在代码的最下面再加上一个server段:

server {

server_name domain.cn;

rewrite ^(.*) http://www.domain.cn$1 permanent;







记得最后都要重启生效。



/root/lnmp restart

 

Unable to process payment. Please contact the merchant as the shipping address provided by the merchant is invalid

http://www.magentocommerce.com/boards/viewthread/20192/

http://www.magentocommerce.com/boards/viewthread/15688/P15/

 

The lines and files have changed though. What worked for me to fix the shipping address problem was this:

app/code/core/Mage/Paypal/Model/Api/Npv.php (not sure if this is necessary):

 

$request['ADDROVERRIDE'0;

(line 362)

 

app/code/core/Mage/Paypal/Model/api/Standard.php (this IS necessary):

 

$request['address_override'0;

(line 199)