Coding

Mysql: Create new user and database

Mysql: Create new user and database

 To login into MySQL as root user, you can use:   mysql -u root -p   and then enter your MySQL password.   To login as another user, you will have to create that user first and grant him privileges.   Create the user using - change newuser to the username you want and password to your...

Read more

How to create and update drop down type attribute using SOAP API in Magento?

How to create and update drop down type attribute using SOAP API in Magento?

 <?php  require_once('app/Mage.php'); Mage::app(); class APIS  {     public function index()     {              try {             $optionLable = 'Red';             $optionValue...

Read more

Magento: Get Multi-Select Attribute Values text

Magento: Get Multi-Select Attribute Values text

$values=explode(',',$_product->getResource()->getAttribute('attribute_name')->getFrontend()->getValue($_product));$result=implode(",",$values);

Read more

PHP: conect to sftp

PHP: conect to sftp

I'd recommend using phpseclib, a pure PHP SSH2 implementation. Example:  <?php include('Net/SSH2.php'); $ssh = new Net_SSH2('www.domain.tld'); if (!$ssh->login('username', 'password')) {     exit('Login Failed'); } echo $ssh->exec('pwd'); echo $ssh->exec('ls -la'); ?...

Read more

PHP: fix error of path when using include files

PHP: fix error of path when using include files

set_include_path('/home/test/www/test/lib/'); require_once('phpseclib/Net/SFTP.php');   http://phpseclib.sourceforge.net/

Read more

PHP: fix error of path when using include files

PHP: fix error of path when using include files

set_include_path('/home/test/www/test/lib/'); require_once('phpseclib/Net/SFTP.php');   http://phpseclib.sourceforge.net/

Read more

Magento: Deleting All Products from a magento database with SQL

Magento: Deleting All Products from a magento database with SQL

It doesn’t happen often, but sometimes I need to wipe all products from a magento database during development. Either an import was written slightly off, or it was just full of test data and it’s cleaner to wipe the products instead of deleting them through the admin. A simple script for this found in a few...

Read more

Magento: Separate read and write databases in Magento

Magento: Separate read and write databases in Magento

 In your app/etc/local.xml fill <resources> in next way: <resources> <db> <table_prefix><![CDATA[]]></table_prefix> </db> <core_read> <connection> <use /> ...

Read more

Magento: get product by a attribute

Magento: get product by a attribute

 Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getSku())

Read more

php shell_exec() vs exec()

php shell_exec() vs exec()

 shell_exec returns all of the output stream as a string. exec returns the last line of the output by default, but can provide all output as an array specifed as the second parameter. See http://php.net/manual/en/function.shell-exec.php http://php.net/manual/en/function.exec.php

Read more

DEPENDENCY INJECTION VÀ INVERSION OF CONTROL – PHẦN 2: ÁP DỤNG DI VÀO CODE

DEPENDENCY INJECTION VÀ INVERSION OF CONTROL – PHẦN 2: ÁP DỤNG DI VÀO CODE

  Dependency là gì? Dependency là những module cấp thấp, hoặc cái service gọi từ bên ngoài. Với cách code thông thường, các module cấp cao sẽ gọi các module cấp thấp. Module cấp cao sẽ phụ thuộc và module cấp thấp, điều đó tạo ra các dependency.   Để...

Read more

khái niệm DEPENDENCY INJECTION VÀ INVERSION OF CONTROL

khái niệm DEPENDENCY INJECTION VÀ INVERSION OF CONTROL

Mình cũng thấy vài bạn đã đi làm 1, 2 năm mà vẫn còn “ngáo ngơ” về DI, IoC, chỉ biết sử dụng nhưng không hiểu rõ bản chất của nó. Do đó, mình viết bài này nhằm giải thích một cách đơn giản dễ hiểu về Dependency Injection. Các bạn junior nên...

Read more

Magento: how to override a controller in Adminhtml

Magento: how to override a controller in Adminhtml

Put your controller file under an Admintml folder. Better to use a similar folder path of the class which you are going to override.   config.xml   <?xml version="1.0" ?> <config>     [...]     <admin>         <routers>    ...

Read more

Magento: how to add Admin controller in Magento

Magento: how to add Admin controller in Magento

1) Add a frontName for the module  <config>....      <admin>         <routers>             <navison>                 <use>admin</use>          ...

Read more

Magento: How to add new button to order view in Magento admin?

Magento: How to add new button to order view in Magento admin?

Use an observer to add the button to the order in etc/config.xml of your module   <adminhtml>     <events>         <adminhtml_widget_container_html_before>             <observers>              ...

Read more

Likipe command-line - what is the purpose of “&&” and "||"?

Likipe command-line - what is the purpose of “&&” and

"&&" lets you do something based on whether the previous command completed successfully - that's why you tend to see it chained as do_something && You also have || which is the logical or, and also ; which is just a separator which doesn't care what happend to the command before.   $...

Read more

Magento: how to add a more attribute for customer

Magento: how to add a more attribute for customer

 <?php $installer = $this; $installer->startSetup(); $connection = $this->getConnection();   $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $entity = $setup->getEntityTypeId('customer'); $setup->addAttribute($entity, 'new_attribute', array(     'type' => 'int',  ...

Read more

how to use IF else in Mysql

how to use IF else in Mysql

  IF(expr1,expr2,expr3) If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns expr2; otherwise it returns expr3. IF() returns a numeric or string value, depending on the context in which it is used. mysql> SELECT...

Read more

Async javascript

Async javascript

 1) Add async to <script> tag, it means equivalent make script to the end of <body>, it helps speed up <script src="..." sync /> 2) Make script inline into DOMContentLoaded: document.addEventListener("DOMContentLoaded", function(event) {    //do work });

Read more

$(document).ready equivalent without jQuery

$(document).ready equivalent without jQuery

There is a standards based replacement,DOMContentLoaded that is supported by over 90%+ of browsers, though not IE8: document.addEventListener("DOMContentLoaded", function(event) {    //do work }); 

Read more

Magento: adding, move CSS and JS includes to the footer

Magento: adding, move CSS and JS includes to the footer

The first step is to create a block called "foot" which is essentially the same as "head" but you'll output it in a different spot. You can add this to your page.xml:       <block type="page/html_head" name="foot" as="foot" template="page/html/foot.phtml"/> Now...

Read more

Magento: Customers by Orders Total only shows 5

Magento: Customers by Orders Total only shows 5

 This is a hard limit imposed by Magento in the Mage_Adminhtml_Block_Report_Grid class - though it can be overridden.   If you'd like to change it there aren't really a bunch of options. I would rewrite the report grid itself:   Create a module which rewrites Mage_Adminhtml_Block_Report_Customer_Totals_Grid...

Read more

Magento: error when merging - jQuery plugin error - intermediate value(…) is not a function

Magento: error when merging - jQuery plugin error - intermediate value(…) is not a function

"TypeError: (intermediate value)(...) is not a function" pops up as the result of missing a semi colon on the function BEFORE the one it throws an error on. It might be as simple as:   jQuery(function($){$(document).ready(function(){ $('textarea').autosize(); }   ); //<----- or it could be...

Read more

Magento: Change “Shipping & Handling” text in checkout review

Magento: Change “Shipping & Handling” text in checkout review

you need to edit or overwrite with a custom extension the following file: "app/code/core/Mage/Sales/Model/Quote/Address/Total/Shipping.php"   around line 184 (Magento 1.7.0.2) you'll find the method "fetch(Mage_Sales_Model_Quote_Address $address)" here you'll find "Mage::helper('sales')->__('Shipping...

Read more

Magento: change stock availability programmatically

Magento: change stock availability programmatically

$stock_item = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product_id); if (!$stock_item->getId()) {     $stock_item->setData('product_id', $product_id);     $stock_item->setData('stock_id', 1);  }   $stock_item->setData('is_in_stock', 1); // is 0 or...

Read more

Magento: How can I change a product's attribute value without loading the entire product model? update the attribute value directly

Magento: How can I change a product's attribute value without loading the entire product model? update the attribute value directly

You can do this by simulating what the 'Update attributes' action:   Mage::getModel('catalog/product_action')->updateAttributes(array($productId), array('my_attr_code'=>'Some value here'), 0);

Read more

$this->renderTotals() which renders block?

$this->renderTotals() which renders block?

 For instance, to change the "Grand Total" edit the file: /app/design/frontend/yourtheme/default/template/tax/checkout/grandtotal.phtml

Read more

Magento: HOW TO OVERRIDE MAGENTO EVENT OBSERVER

Magento: HOW TO OVERRIDE MAGENTO EVENT OBSERVER

For example, i want to rewrite an observer from a test module:             <catalog_product_prepare_save>                 <observers>                     <test_inventory_catalog_product_prepare_save>  ...

Read more

How to resize image coming from media in frontend?

How to resize image coming from media in frontend?

foreach($this->myBanners() as $_testing_banners){       $img_location = Mage::getBaseDir('media'). 'Banners/images/demand/'.$_testing_banners['bannerimage'];       $imageResized = Mage::getBaseDir('media'). 'Banners/images/demand/resized/'.$_testing_banners['bannerimage'];    ...

Read more

Magento: get Full product's image url

Magento: get Full product's image url

 Mage::getModel('catalog/product_media_config')->getMediaUrl($_product->getSmallImage())

Read more

How to find backdoor PHP shell scripts on a server

How to find backdoor PHP shell scripts on a server

When hackers get access to your website server, they sometimes install a backdoor shell script designed to allow them to regain entry even after you’ve cleaned up the site, repaired the original security hole that allowed the hack to occur, otherwise improved site security, and even installed measures to try to lock...

Read more

Install compass on linux

Install compass on linux

 linux: - install gem: apt-get install ruby-dev - install compass: sudo gem install compass  

Read more

Magento: How to create custom adminhtml theme magento

Magento: How to create custom adminhtml theme magento

create a file in: app/design/adminhtml/default/myTheme And also create a new module   <?xml version="1.0"?> <config>   <modules>     <Foo_myTheme>       <version>0.0.1</version>     </Foo_myTheme>   </modules>  ...

Read more

Modman: symlink(): Cannot create symlink, error code(1314) on window

Modman: symlink(): Cannot create symlink, error code(1314) on window

In Windows 10, 8, 7, or Vista In Windows Vista and 7, we’ll use the mklink command to create symbolic links.  To use it, we have to open an administrator Command Prompt.  Enter “command” in your start menu search, right-click on Command Prompt, and select “Run as administrator”....

Read more

Mysql: Add full permission for an user

Mysql: Add full permission for an user

GRANT ALL PRIVILEGES ON *.* TO 'master-test'@'localhost' WITH GRANT OPTION;

Read more

Automatically adjusting to match the tallest DIV in the row. Setting equal heights for div's with jQuery

Automatically adjusting to match the tallest DIV in the row. Setting equal heights for div's with jQuery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <script>$(document).ready(function(){       // Select and loop the container element of the elements you want to equalise     $('.container').each(function(){    ...

Read more

Magento: how to install a module via modman

Magento: how to install a module via modman

All AOE modules (and many other community provided Magento modules) come with a modman file in the module's root folder. This indicates that this module can be installed using the modman script.   Modman will parse the modman configuration file and will create symlinks (or copies if you prefer) from within the...

Read more

Magento: Adding new mass action to admin grid in Magento

Magento: Adding new mass action to admin grid in Magento

Introduction   The purpose of mass action allowing to have mass operation on the selected rows at once. Some popular mass action are: Delete, Update Status etc.       Mass Action (Sales > Order Grid) Mass Action (Sales > Order Grid)   This is an often requirement that you may need...

Read more

Magento: Create your own controller

Magento: Create your own controller

Start by creating your module:   1 – Create the folder /app/code/local/Pfay/Test/   This create your namespace Pfay and your module Test .   2 – Enable the module in Magento:   Add a file Pfay_all.xml /app/etc/module/   And insert the following code in it   <?xml...

Read more

Magento: What is the purpose of Mage_Core_Block_Template_Facade

Magento: What is the purpose of Mage_Core_Block_Template_Facade

Mage_Core_Block_Template_Facade, is actually quite simple to understand. It..   Allows a value to be set on the block Allows layout to specify an attribute/value from a registry object to be set on the block Allows the equality of the two values above to be evaluated Essentially, this is what makes the Facade...

Read more

Magento: what is container1 and container2 in product view page in magento

Magento: what is container1 and container2 in product view page in magento

These relate to the position in which the product's custom options are displayed.   See app/code/core/Mage/Catalog/etc/config.xml:   <design>     <options_container>         <option1 translate="label">             <value>container1</value>  ...

Read more

Magento - error of Upload HTTP Error

Magento - error of Upload HTTP Error

 If the images are large enough, you may be restricted by your PHP settings: Identify your loaded php.ini: <?php phpinfo(); // Look for "Loaded Configuration File" Edit your php.ini (if you're on Ubuntu it was probably in /etc/php5/apache2/php.ini):   sudo vi /path/to/php.ini   # Make...

Read more

Increase file upload size limit in PHP-Nginx

Increase file upload size limit in PHP-Nginx

 If Nginx aborts your connection when uploading large files, you will see something like below in Nginx’s error logs: [error] 25556#0: *52 client intended to send too large body: This means, you need to increase PHP file-upload size limit. Following steps given below will help you troubleshoot this! Changes...

Read more

Angular JS: Pretty URLs in AngularJS: Removing the #

Angular JS: Pretty URLs in AngularJS: Removing the #

By default, AngularJS will route URLs with a hashtag.   For example:   http://example.com/ http://example.com/#/about http://example.com/#/contact It is very easy to get clean URLs and remove the hashtag from the URL.   There are 2 things that need to be done.   Configuring $locationProvider Setting...

Read more

Angular JS custom delimiter, use $interpolateProvider to change start / end symbols used for AngularJS expressions

Angular JS custom delimiter, use $interpolateProvider to change start / end symbols used for AngularJS expressions

var myApp = angular.module('myApp', [], function($interpolateProvider) {     $interpolateProvider.startSymbol('[[');     $interpolateProvider.endSymbol(']]'); }); and then, in your template:   Hello, [[name]]   Example: http://jsfiddle.net/Bvc62/3/

Read more

Knockout : Communication between multiple View Models in KnockoutJS (MVVM), the right approach!

Knockout : Communication between multiple View Models in KnockoutJS (MVVM), the right approach!

Maintaining master View Model First way of achieving communication between multiple view models is to introduce master view model. HTML: <div data-bind="with: viewModel1"> <p>&nbsp;</p> <h1>Hello ,</h1> <p>&nbsp;</p> </div> <div data-bind="with:...

Read more

Magento: where does is_salable come from?

Magento: where does is_salable come from?

 grep -r setIsSalable * app/code/core/Mage/CatalogInventory/Model/Stock/Status.php:        $product->setIsSalable($stockStatus); app/code/core/Mage/CatalogInventory/Model/Stock/Status.php:                    $product->setIsSalable($statu...

Read more

How to Optimize MySQL

 How to Optimize MySQL

vi /etc/my.cnf [ENTER]  skip-locking query_cache_limit=1M query_cache_size=32M query_cache_type=1 max_connections=500 interactive_timeout=100 wait_timeout=100 connect_timeout=10 thread_cache_size=128 key_buffer=16M join_buffer=1M max_allowed_packet=16M table_cache=1024 record_buffer=1M sort_buffer_size=2M read_buffer_size=2M max_connect_errors=10 #...

Read more

Magento: How To Turn Off Cache For An Individual Block In Magento

Magento: How To Turn Off Cache For An Individual Block In Magento

Have you ever felt a need where one or many of your individual blocks shouldn’t be cached by Magento automatically? We are talking about any individual block and not the entire “block html” caching.       Lets me first tell you how Magento works. Magento uses construct functions within...

Read more

MAGENTO: ADD NEW TOTAL ROW TO MAGENTO SHOPPING CART / CHECKOUT

MAGENTO: ADD NEW TOTAL ROW TO MAGENTO SHOPPING CART / CHECKOUT

Example: If you need to add an additional fee to your total price, you need to add your own total item to the collection of totals.   To do this you need to add the following code to your main config.xml file:   <global>      <sales>          <quote>  ...

Read more