Coding

ADDATTRIBUTETOFILTER CONDITIONALS IN MAGENTO

ADDATTRIBUTETOFILTER CONDITIONALS IN MAGENTO

addAttributeToFilter is a function that can be called on a product collection in Magento. In short, it adds a condition to the WHERE part of the MySQL query used to extract a product collection from the database.   $_products = Mage::getModel('catalog/product')->getCollection()    ->addAttributeToSelect(array('name',...

Read more

Add default values for dropdown of configurable product

Add default values for dropdown of configurable product

<script type="text/javascript">                 var spConfig = new Product.Config(<?php echo $_jsonConfig ?>);                 spConfig.init = true;                 spConfig.values...

Read more

How to undo (almost) anything with Git

How to undo (almost) anything with Git

https://github.com/blog/2019-how-to-undo-almost-anything-with-git

Read more

Running PhantomJS from PHP with exec()

Running PhantomJS from PHP with exec()

Do not use exec(). Never. It's a bad way.   Use the php-phantomjs and PhantomJS Runner instead.

Read more

How can I setup & run PhantomJS on Ubuntu?

How can I setup & run PhantomJS on Ubuntu?

 sudo apt-get install phantomjs

Read more

jquery trigger change event on checkbox

jquery trigger change event on checkbox

 jQuery("input").attr('checked', true).trigger('change');

Read more

Magento: logException

Magento: logException

1) Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted  2) try { } catch (Exception $e ) { Mage::logException($e);  }

Read more

Magento: getBaseUrl – Magento URL Path

Magento: getBaseUrl – Magento URL Path

If you want to get the source url of an image, javascript or file, call one of this functions adding your own path at the end.   Under every function there is an example of the output value:   http://goweb.vn/ Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_DIRECT_LINK)http://goweb.vn/...

Read more

Magento: get directory paths, get Base URLs, get URLs in static block, get secure URL

Magento: get directory paths, get Base URLs, get URLs in static block, get secure URL

 This post help you to get url, directory path, to get module URL. This is very basic post, that will help to beginners.   Get Base URL    Mage::getBaseUrl() => Get base url path e.g. http://yourwebsite.com/  Mage::getBaseUrl('media') => Get MEDIA folder path e.g. http://yourwebsite.com/media/  Mage::getBaseUrl('js')...

Read more

Magento: Overriding Block, Helper, Model, Controller

Magento:  Overriding Block, Helper, Model, Controller

Blocks Suppose we have a requirement to make some changes or add a function in Mage_Catalog_Block_Product class. Since this a core file, what we will do is override this class so that there is no need to change the core file. To do this, in config.xml inside the tags. We write   <blocks> <catalog> ...

Read more

Magento: How to Allow more file types Magento

Magento: How to Allow more file types Magento

Allow more file types to Magento.   I wanted to add a PDF file to the product description but Magento just allow image file types.   Let’s get started.   Core Files   Look for the file: /app/code/Core/Mage/Cms/etc/config.xml   You should create the same folder structure inside /app/local/…   That’s...

Read more

3 Tips to write faster and more efficient code

3 Tips to write faster and more efficient code

  In this general programming article, I will show you some ways you can use to write faster code. These methods apply to almost any programming language out there, so I will go ahead and use pseudocode to demonstrate them.       Breaking out of loops early   When you are writing a loop,...

Read more

HTML: Special Characters

HTML: Special Characters

HTML Entities and/or ISO Latin-1 codes can be placed in source code like any otder alphanumeric characters to produce special characters and symbols tdat cannot be generated in HTML witd normal keyboard commands. For example, to render Düsseldorf tde HTML source should ...

Read more

Magento: Code to upload image base64

Magento: Code to upload image base64

 public function uploadMap($mapImg)     {         $baseMedia = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA);         $path = $baseMedia . DS . 'designengine/maps';  //desitnation directory             $theTime = str_replace(".",...

Read more

Varien_Image: The Heart of Magento’s Image Manipulation.

Varien_Image: The Heart of Magento’s Image Manipulation.

Most of you may have experience with Mage_Catalog_Helper_Image class. This class lets you manipulate Magento catalog images in various ways. The most common one is resizing the image and adding watermark. Do you know the majority of the function for this class is a proxy to Varien_Image class. Varien_Image class is also...

Read more

Magento: replaceItem Js, css Magento JavaScript Includes (addJs)

Magento: replaceItem Js, css  Magento JavaScript Includes (addJs)

You can implement a solution in a module that extends the Mage_Page_Block_Html_Head class like so:   Yourcompany/Layouthelper/etc/config.xml   <?xml version="1.0"?> <config>     <modules>         <Yourcompany_Layouthelper>    ...

Read more

html2canvas: Solve a problem to generate the image of map

html2canvas: Solve a problem to generate the image of map

Add this line:  useCORS: true,     $('#canvas').html2canvas({                 "logging": true,                  useCORS: true,                  onrendered: function...

Read more

Save google map as binary image

Save google map as binary image

 There are some situations we have to save google map as an image. It is always better to convert as a binary image and save to DB so that we can reuse very easily.     Here we are plotting the google map      <div id="googlemap"></div>   Here we are displaying...

Read more

Magento: Get current URL of the website

Magento: Get current URL of the website

Getting URL of a current page you are visiting or working on is a common requirement in any web development. There are plenty ways you can get the current URL of a page in Magento.   From Mage_Core_Helper_Url class   $currentUrl = Mage::helper('core/url')->getCurrentUrl(); From Mage_Core_Model_Store...

Read more

html2canvas- Take Screenshot of Web Page and Save It to Server (Javascript and PHP)

html2canvas- Take Screenshot of Web Page and Save It to Server (Javascript and PHP)

FeedBack is important. Usually, end-users struggle to clarify their problems. And you might be unreachable for a phone call or remote connection. That causes a huge need of visualization. First solution that appears in mind is to capture the current screen of user. However, when I tried to implement that, it wasn’t...

Read more

Convert html to image using JavaScript Canvas

Convert html to image using JavaScript Canvas

Convert html to image using JavaScript Canvas Đã bao giờ bạn nghĩ tới việc sẽ xuất các phần từ html thành 1 file ảnh chưa?trong bài viết này mình sẽ hướng dẫn các bạn làm việc này.Để thực hiện được bài này chúng ta sẽ sử dụng thư viện html2canvas (JavaScript...

Read more

Angular js : Uncaught ReferenceError: _ is not defined

Angular js : Uncaught ReferenceError: _ is not defined

 Try prepending this to your code, so you can see if it works. The reason is the lastest version of jQuery .   <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>  

Read more

Một số phương pháp để tăng perfomance PHP Web Server.

Một số phương pháp để tăng perfomance PHP Web Server.

Định nghĩa performace: Performace một hệ thống là khả năng đáp ứng yêu cầu của một hệ thống trong một khoảng thời gian. Để phân biệt với Scale, Performace thường nói đến việc làm sao để đáp ứng nhiều nhất yêu cầu đến hệ thống mà không cần phải...

Read more

Install npm and bowl for linux and windows

Install npm and bowl for linux and windows

1) npm - https://www.npmjs.com/package/npm 2) bower - https://github.com/bower/bower

Read more

Full documentation of angual Js

Full documentation of angual Js

http://www.w3schools.com/angular/default.asp

Read more

Magento: Fix error search is not correctly

Magento: Fix error search is not correctly

1) Go to system/configuration/catalog/catalog seach and change search type to text 2) Copy app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php to app/code/local/Mage/CatalogSearch/Model/Resource/Fulltext.php line 355 app/code/local/Mage/CatalogSearch/Model/Resource/Fulltext.php   if ($like) { $likeCond...

Read more

10 USEFULL PHP LIBRARIES YOU SHOULD KNOW ABOUT

10 USEFULL PHP LIBRARIES YOU SHOULD KNOW ABOUT

It is an exciting time to be a PHP developer. There are lots of Usefull PHP Libraries released every day, and with the help of Composer and Github, they are easy to discover and use. Here are 24 of the coolest that I’ve come across. Your favorite is not on the list? Share it in the comment section!   IMAGEWORKSHOP...

Read more

Magento: Customize router

Magento: Customize router

Creating the custom router could be very useful thing when we want to separate some business logic that can be applied on same route (url) without redirecting to different routes inside the controller. Let’s define our router inside: “…/app/code/local/Mynamespace/Myextension/etc/config.xml”: ...

Read more

CÁCH SỬ DỤNG SASS

CÁCH SỬ DỤNG SASS

 Bạn đã từng nghe về những CSS Preprocessors như Less, Sass hay Stylus.   CSS Preprocessor là gì?   CSS Preprocessor là một ngôn ngữ kịch bản mở rộng của CSS và được biên dịch thành cú pháp CSS.   Sau đây là một vài lợi ích của việc sử...

Read more

Magento: Overriding Abstract in Magento

Magento: Overriding Abstract in Magento

An "override" is where you copy a class from the Magento core into the local code pool. In other words, copy   app/code/core/Mage/Rule/Model/Abstract.php to app/code/local/Mage/Rule/Model/Abstract.php   An override is where you tell Magento "use this class file instead of the other class file"....

Read more

Magento : HOW TO SET UP AND USE THE MAGENTO PROFILER

Magento : HOW TO SET UP AND USE THE MAGENTO PROFILER

 Magento comes with a very useful tool called the Profiler. If you’ve ever wanted to know how long a piece of code takes to run, or which parts of your website are running slow, then the profiler is possibly the best tool for the job. Firstly, you have to turn it on. In your admin area, go to System >...

Read more

Magento : Editing Magento’s Top Links (The Better Way)

Magento : Editing Magento’s Top Links (The Better Way)

  You might need to read the post about using a local.xml file before this post makes much sense.   We offer all our clients a completely customized design from scratch, which means changing anything – including those annoying defaulted top links.  This post will show you how to edit your top links...

Read more

Git: Command line

Git: Command line

1) Add origin git remote add origin ssh://login@IP/path/to/repository    2) Pull Git pull --rebase origin develop or  git checkout develop git pull origin   3)Tag git tag 1.0.4   git push && git push --tags   4) check home path of privatekey on window echo $HOME   5)...

Read more

Zend: how to Use Zend Framework from the Command Line?

Zend: how to Use Zend Framework from the Command Line?

 Lets go ahead an create a simple IndexController and view so we have something to shoot for:   ./application/modules/default/controllers/IndexController.php   class IndexController extends Zend_Controller_Action {     public function indexAction() {} } ./application/modules/default/views/scripts/index/index.phtml   echo...

Read more

Automatically redirect to domain www. by htaccess

Automatically redirect to domain www. by htaccess

RewriteCond %{HTTP_HOST} ^surf.vn$ [NC] RewriteRule ^(.*)$ http://www.surf.vn/$1 [R=301,L]

Read more

Magento : Removing mandatory validation of telephone field

Magento : Removing mandatory validation of telephone field

1) Open table "eav_attribute" then try to search attribute_code = telephone, change column is_required from 1 to 0 2) Remove code requirement

Read more

A great tool for developers

A great tool for developers

 Link: http://devdocs.io/

Read more

Magento : Importing orders

Magento : Importing orders

  $id=1; // get Customer Id $customer = Mage::getModel('customer/customer')->load($id);   $transaction = Mage::getModel('core/resource_transaction'); $storeId = $customer->getStoreId(); $reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);   $order...

Read more

Magento: Script update websites for products

Magento: Script update websites for products

 <?php require_once 'abstract.php'; class Mage_Shell_OrderExport extends Mage_Shell_Abstract {       public function run() {         ini_set('memory_limit', "1024M");         $websiteIds = array(1,3);         $productIds=...

Read more

Magento : How to set category to a site in multistore in Magento

Magento : How to set category to a site in multistore in Magento

Assuming you have only one root category and you want to assign sub-categories to other store views.   All categories are active in all store by default. You have to deactivate the category that are not be shown for particular store. To do so, follow the steps below:   Admin -> Catalog -> Manage Categories   On...

Read more

Magento: HOW TO SHARE MAGENTO CART BETWEEN SEVERAL MAGENTO MULTI-STORES

Magento: HOW TO SHARE MAGENTO CART BETWEEN SEVERAL MAGENTO MULTI-STORES

 If you have multi-stores configured in your Magento and you want to have single cart for all multi-stores this article is what you need.   All your multi-stores will be not separate websites, they all will have single cart (share cart content between multi-stores). Also your customers will have single account...

Read more

Magento: set the base currency per store view

Magento: set the base currency per store view

  just enable the selector by adding this to your favourite system.xml testen in magento 1.9 (module Directory)        <sections>         <currency module="directory">             <groups>        ...

Read more

Magento: How display different price per store

Magento: How display different price per store

You can do this on a per website basis.   To do so, you need to go to System->Configuration->Catalog->Catalog.   Then in the tab "Price", set price scope to Website instead of global.   On the product edit page, you can then set the scope on the upper left side to your website and...

Read more

Magento : get product category by sku and update category by category tree by php script in magento

Magento : get product category by sku and update category by category tree by php script in magento

 error_reporting(E_ALL); ini_set('display_errors', '1');   require_once( 'app/Mage.php'); echo '<pre>'; $app = Mage::app();   $write = Mage::getSingleton('core/resource')->getConnection('core_write');        $readresult = $write->query("SELECT * FROM table limit...

Read more

Magento : Get all categories with tree model in magento

Magento : Get all categories with tree model in magento

 <?php    $rootCatId = Mage::app()->getStore()->getRootCategoryId();    $catlistHtml = getTreeCategories($rootCatId, false);    echo $catlistHtml;   function getTreeCategories($parentId, $isChild){     $allCats = Mage::getModel('catalog/category')->getCollection()  ...

Read more

Search closest store by google map

  Search closest store by google map

https://developers.google.com/maps/articles/phpsqlsearch_v3

Read more

Magento: Get Simple Product from Configurable in Cart

Magento: Get Simple Product from Configurable in Cart

 After taking a look at how Magento renders the items in your cart on the checkout/cart page, I was able to find this in app/code/core/Mage/Checkout/Block/Cart/Item/Renderer/Configurable.php   /**  * Get item configurable child product  *  * @return Mage_Catalog_Model_Product  */ public...

Read more

Magento : Change contact email template type text to html

Magento : Change contact email template type text to html

 Go to app/code/core/Mage/Contacts/etc/config.xml   <email>                <contacts_email_email_template translate="label" module="contacts">                    <label>Contact...

Read more

Magento : get attribute by ResourceModel

Magento : get attribute by ResourceModel

$productResource = Mage::getResourceModel('catalog/product'); $attribute_value = $productResource->getAttributeRawValue($_productId, 'attribute_name', $storeId);

Read more

Magento : Override the frontname for a existing Magento module

Magento : Override the frontname for a existing Magento module

 You will need a custom module that only changes the frontname of a module (Mage_Customer in this case.)   Let's name the module Easylife_UserThis module contains only 2 files.   app/etc/module/Easylife_User.xml - the declaration file   <?xml version="1.0"?> <config>  ...

Read more