Apache2 changing charset using .htaccess

If you do not wish to change character encoding for the entire server, but only one site (or only one directory) then this is possible to do using .htaccess.

AddDefaultCharset UTF-8

If you only wish to do this to php or htm files (and not all files)

<FilesMatch "\.(htm|php)$">
AddDefaultCharset UTF-8
</FilesMatch>

If you wish to modify the mime-type as well as the encoding (on html files in this example)

AddType 'text/html; charset=UTF-8' html

Magento: Magento connect broken after moving to another path (www.example.com/test -> www.example.com)

The Magento Connect uses values stored in the directory downloader to know where to connect, where to save files etc. The problem is that these paths are hard coded into files at the installation of Magento.

If you wish to move your installation to a new path then this will break the Magento Connect in the admin panel.

The version that I find easiest to do on the new server is to log in using ssh and then run “./pear mage-setup .” That will reset the aboslute paths that are stored in the downloader directory.

Another option would be to re install magneto:

  • Upload a fresh copy of Magento onto the new server (don’t run the installer yet)
  • Copy over your Themes/Templates, Skins, Images, and Custom Modules
  • Dump the database from the original, and import the database to the new site
  • Run the installer – and enter all the necessary info
  • Go into the Magento Connect Manager, and install this extension: magento-core/Mage_All_Latest
  • Magento: Set shipping address to billing address by default (but retain the possibility to change it)

    This will set the delivery address to the billing address and with no other changes to the code, the user will still be able to change the delivery address by using the right menu. This simply updates the default behavior of what needs to be entered.

    In “app/design/frontend/default/blank/template/checkout/onepage/billing.phtml”
    Find the section that looks like:

    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    
        <?php if ($this->canShip()): ?>
            <li>
                <<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes" value="1"<?php if ($this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> onclick="$('shipping:same_as_billing').checked = true;" class="radio" /><label for="billing:use_for_shipping_yes"><?php echo  $this->__('Ship to this address') ?></label>
                <input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_no" value="0"<?php if (!$this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> onclick="$('shipping:same_as_billing').checked = false;" class="radio" /><label for="billing:use_for_shipping_no"><?php echo $this->__('Ship to different address') ?></label>
            </li>
        <?php endif; ?>
        </ul>
        <?php if (!$this->canShip()): ?>
            <input type="hidden" name="billing[use_for_shipping]" value="1" />
        <?php endif; ?>

    And simply replace it by;

    123
    124
    
        </ul>
        <input type="hidden" name="billing[use_for_shipping]" value="1" />

    Magento: Changing the url “continue shopping” points at

    If you wish to repoint the “continue shopping” button in the shopping cart, then the file
    app/code/core/Mage/Checkout/Block/Cart.php (and don’t forget that the modified file should be copied to app/code/local/Mage/Checkout/Block/Cart.php ) is one place to do that from. (The code example below gives different results based on if the cart is empty or not)

    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    
        public function getContinueShoppingUrl()
        {
    	//Mage::getUrl(page name in CMS under admin)
           //if the cart is not empty, return the user to the shop
    	if (Mage::helper('checkout/cart')->getCart()->getItemsCount() > 0)
    		$url = Mage::getUrl('home');
    	//if the cart is empty, return the user to the portal home.
    	else
    		$url = Mage::getUrl('portal');
            $this->setData('continue_shopping_url', $url);
     
            return $url;
        }

    Also you should edit the file app/design/frontend/default/blank/template/checkout/cart/noItems.phtml (blank is my skin)

    33
    
    <p><?php echo $this->__('Please <a href="%s">continue shopping</a>.', Mage::getUrl('portal')) ?></p>

    [This was done to Magento version 1.3.2.4]

    Magento: Send a email to store owner when a order is placed.

    It is not hard to set up a Magento multi store environment so when a order is placed in a store, a owner (one owner per store) gets a order confirmation email.
    Doing like this will give a copy of the mail that is sent to the customer, and that might not be nice – but this is quick.

    In admin, select the store you wish to enter the email address to, and under system > config > sales > sales e-mail override the site default with the email address you would like for this store.

    It is also possible to send copies of shipment notices, credit mails etc (basically all mail that is sent from the store).

    [Tested with v1.3.2.4]

    Gallery2flickr add pagination buttons at the bottom (of the search results) as well.

    Gallery2flickr is a gallery2 plugin that acts as a bridge between gallery2 and flickr.

    The search page normally only has the next and previous page buttons as the top (and not at the bottom).
    In order to add these buttons to the bottom as well, edit modules\Gallery2Flickr\templates\FlickrSearch.tpl and just before the div with the copyright info, enter the following (or find it earlier in the file).

    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    
    {if isset($Flickr.pages)}
    <div class="gbBlock">
      <h4>
       {if ($Flickr.pages > 0)}
         {g->text text="Results %d - %d of %d, Page %d of %d"
         arg1=$Flickr.pages.start arg2=$Flickr.pages.end
         arg3=$Flickr.pages.total arg4=$form.page arg5=$Flickr.pages.pages}
       {/if}
       {if ($form.page > 1)}
         <input type="submit" class="inputTypeSubmit"
           name="{g->formVar var="form[action][previousPage]"}"
           value="{g->text text="&laquo; Back"}"/>
       {/if}
       {if ($form.page < $Flickr.pages.pages)}
         <input type="submit" class="inputTypeSubmit"
           name="{g->formVar var="form[action][nextPage]"}"
           value="{g->text text="Next &raquo;"}"/>
       {/if}
       <input 
          type="submit" 
          class="inputTypeSubmit"
          name="{g->formVar var="form[action][importpage]"}" value="{g->text text="Import this page"}"/>
       <input 
          type="submit" 
          class="inputTypeSubmit"
          name="{g->formVar var="form[action][importresults]"}" value="{g->text text="Import all results"}"/>
     </h4>
    </div>
    {/if}

    Magento: Problem with the Fontis WYSIWYG editor (FCKeditor) and {{store url=””}}

    The problem is that a link like <a href="{{store url=""}}"> gets converted to <a href="{{store url="> and that is a problem (it makes the link much longer and the page seams to be lacking a lot of text.

    One solution is to replace the "" (2 ") where the second disappears with ” (2 ‘).

    It is probably a very good idea to make this change on all " inside {{ }} to ‘s.

    However it is still a good idea to do this change in the code mode of the editor or it will do some of its magic on it.

    Apache2 virtualhosts

    In order to bind a virtualhost to only one ip (if the server has several) add the ip in the VirtualHost tag, to make it listen on all ips – use *
    To make the server respond to several names, use the ServerAlias and ServerAlias supports wildcards.

    See the examples below for more.

    <VirtualHost 111.22.33.55>
        DocumentRoot /www/subdomain
        ServerName www.sub.domain.tld
        ServerAlias *.sub.domain.tld
        ...
    </VirtualHost>
    
    
    <VirtualHost *>
        DocumentRoot /www/domain
        ServerName www.domain.tld
        ...
    </VirtualHost>

    500 internal sever error after moving CakePHP

    If the CakePHP is run in production mode (debug =0), then it is not possible to move the CakePHP to another folder – after the move the site will simply give an error 500. This is since a number of things are cached in CackePHP and if the app is in production mode, then some of the cache is not checked if it needs to be updated.

    So if you intend to move a CakePHP directory that is setup as a production environment, then you will need to turn up debug to at least 1 , load the site – then it can be turned back down again.