PHP SOLUTIONS

This is the blog for getting Idea regarding PHP, Magento, jQuery and JavaScript for Customization.

Wednesday 16 July 2014

jQuery : Remove space form string using JQUERY

HI, Some time we need to remove the Space from the String,

Here the Code for remove Special Characters and Space between string


var Demo = new String('This :::  is / the Test');
temp =  temp.replace(/[^a-zA-Z 0-9]+/g,'');
console.log(temp.replace(/ +/g, ""));





/*Best Seller base on order */


<?php

$storeId    = Mage::app()->getStore()->getId();

$product = Mage::getResourceModel('reports/product_collection')
            ->addOrderedQty()
            ->addAttributeToSelect(array('name', 'price', 'small_image')) //edit to suit tastes
            ->setStoreId($storeId)
            ->addStoreFilter($storeId)
            ->setOrder('ordered_qty', 'desc'); //best sellers on top

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($product);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($product);

$count = 0;
foreach($products as $pro)
{
$count++;
if($count <= 3)
echo $pro->getorder_items_name();
}

?>
,

Wednesday 9 July 2014

Magento : Add Meta Title field in CMS pages

In this Blog I written about to set the Meta title field inside the CMS Page.

Here, Some steps need to follow for Meta Title Field

1) Open File Meta.php

   Location = /app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php

2) Copy - Paste this code after

    $fieldset = $form->addFieldset('meta_fieldset', array('legend' => Mage::helper('cms')->__('Meta Data'), 'class' => 'fieldset-wide'));

    /*Copy*/

    $fieldset->addField('meta_title', 'text', array(
            'name' => 'meta_title',
            'label' => Mage::helper('cms')->__('Title),
            'title' => Mage::helper('cms')->__('Meta Title'),
            'disabled'  => $isElementDisabled
        ));

3)  Open Database - Go to table - cms_page

4)  write this query

     ALTER TABLE `cms_page` ADD `meta_title` VARCHAR(100) NOT NULL AFTER `root_template`;


Now, Check any CMS page in admin side !!


Monday 31 March 2014

Magento Images not displayed in Admin

HI,

    Some times in Magento create amazing issues, in admin or for fornt end also

    Recently, I am getting this type of issue, In side admin I can't see the product images after the Inserting the product

Product Images no display in admin


for solve this type of issue

Just open media directory using FTP and just change the name of .htaccess to .htaccess_old

And you have solve the Image issue.

Enjoy::::
,

Friday 28 March 2014

PHP : Read CSV file line by line

There are 2 type for read CSV file using PHP script.

Method 1 ::

Using this can read CSV line by line, can get any number of cell value

$line = 1;
$csv = array(); //new array.
if (($handle = fopen("test.csv", "r")) !== FALSE) { // Read csv file
    while (($obj = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($obj);
        echo "<label> $num fields in line $row: <br /></label>\n";
        $line++;
        for ($i=0; $i < $num; $i++) {
            echo $obj[$i] . "<br />\n";
        }
        $csv[] = $obj;
    }
    fclose($handle);
}
echo $csv[2][1]; //prints the 3th row, second column.



If want to get Array of the CSV then use Method 2 here,