Get simple product id from Configurable Product in Wishlist Cart


Hey Guys,

Today i am going to give the code to get the choosed simple product id from configurable product in Wishlist.

$item object should be instance of this class Mage_Wishlist_Model_Item

$item->getOptionByCode('simple_product')->getValue()

Thank you.

Multi Email Validation Class for Magento Prototype JS


Hi All,

Today i am going give the multi email validation class added to the form in magento prototype js. Some of the email fields need multi email features, But they dont know how to validate the multi email address using prototype javascript. Here is the code, Add it to any one of the js or customized js. Then put this “validate-multi-email” class to input fields like other validation classes.


/*
* Add Multi email validation to Default Prototype Validator Class
* return bool
*/
Validation.add('validate-multi-email','Please enter a valid email address. For example johndoe@domain.com.',function(emails){
emails = emails.split(',');
for(var i = 0;i<emails.length;i++){
if( Validation.get('validate-email').test(emails[i]) == false){
return false;
}
}
return true;
});

I hope some one can get this thing.

Thank you.

How to assign bundle items to the bundle product programmatically


Today I am going to explain about the Magento Bundle Option, selection and Items with Bundle Product. Some of the guys know about the all types for products in magento. But I will list it out.

1. Simple
2. Virtual
3. Configurable
4. Grouped
5. Bundle
6. Downloadable
Bundle Product can allow simple and virtual product types only. I will show you how the code looks.
Create bundle option programmatically
$bundle – Object instance of Bundle Product

$optionModel =
Mage::getModel('bundle/option')
->addSelection('op111')
->setTitle('op111')
->setDefaultTitle('op111')
->setParentId($bundle -> getId())
->setStoreId(0)->save();

Store ID should be current store id.

Create bundle selection programmatically.

$values = array(
'option_id' => $ optionModel -> getOptionId(),
'parent_product_id' => $bundle -> getId(),
'product_id' => $curProduct -> getId(),
'position' => 0,
'is_default' => 0,
'selection_price_type' => 0,
'selection_price_value' => 0.0000,
'selection_qty' => 1.0000,
'selection_can_change_qty' => 1
);

$curProduct – Object instance of simple product or virtual product.

Mage::getModel('bundle/selection') -> setStoreId($curProduct -> getStoreId()) -> setData($values) -> save();

You can use this code with the Model and Controllers. Especially for the Magento Observers Methods.

I hope it helps some of the Magento Developers.

Comments Welcome.

Thanks Guys. Magento Rocks.

Programmatically Add Magento Admin User Roles and Resources


Hi all again,

Today i would like to share, how to add magento admin user roles and resources using code.


/* 4 Roles Creation Default*/
$roles = array('User Role 1','User Role 2','User Role 3','User Role 4');
$roleIds = array();
$resources = explode(',', '__root__,admin/sales,admin/sales/order,admin/sales/order/actions,admin/sales/order/actions/hold,admin/sales/order/actions/creditmemo,admin/sales/order/actions/unhold,admin/sales/order/actions/ship,admin/sales/order/actions/comment,admin/sales/order/actions/invoice,admin/sales/order/actions/capture,admin/sales/order/actions/email,admin/sales/order/actions/view,admin/sales/order/actions/reorder,admin/sales/order/actions/edit,admin/sales/order/actions/review_payment,admin/sales/order/actions/cancel,admin/sales/order/actions/create,admin/dashboard,admin/catalog,admin/catalog/products,admin/cms,admin/cms/page,admin/cms/page/save,admin/system,admin/system/acl,admin/system/acl/users');
foreach($roles as $role){
$col = Mage::getModel('admin/role')->setRoleName($role)->setRoleType('G')->setTreeLevel(1)->save();
if($col->getRoleId()){
if( in_array($role, $enabledRoles) )
$roleIds[] = $col->getRoleId();
$rules = Mage::getModel('admin/rules')->setRoleId($col->getRoleId())->setResources($resources);
$rules = Mage::getModel('admin/resource_rules')->saveRel($rules);
}
}

We are created a new user roles(User Role 1, User Role 2, User Role 3 and User Role 4). Then we have to update the Role Resources. I have checked with Magento Version 1.7.0.2.

You can get the Resources list in the backend of the magento roles area.

If any suggestions welcome with comments area below.

Thank you.

Advanced Custom Fields(ACF Add On) Add Ons Hack Tip


Hi there,

Today i would like to explain about Advanced Custom Fields(ACF Add On) Add On activation for Free. You have append a one line to the specific file of the ACF WordPress Plugin.

/plugins/advanced-custom-fields/acf.php

Find this function:

function is_field_unlocked($field_name){
$hashes = array(
'repeater' => 'bbefed143f1ec106ff3a11437bd73432',
'options_page' => '1fc8b993548891dc2b9a63ac057935d8',
'flexible_content' => 'd067e06c2b4b32b1c1f5b6f00e0d61d6',
'gallery' => '69f4adc9883195bd206a868ffa954b49',
);

Append this row like this:

function is_field_unlocked($field_name){
return true;
$hashes = array(
'repeater' => 'bbefed143f1ec106ff3a11437bd73432',
'options_page' => '1fc8b993548891dc2b9a63ac057935d8',
'flexible_content' => 'd067e06c2b4b32b1c1f5b6f00e0d61d6',
'gallery' => '69f4adc9883195bd206a868ffa954b49',
);

You have to add this line return true; first line of the is_field_unlocked function.

I hope it helps some one. If any suggestion, welcome to our comments area(Just bottom of this page).

If you like this post, please like me via Facebook Like Box.

Thank you.

How to add a shortcode for custom menu item in WordPress


Hi Guys,

Today i will explain how to use short code for custom menu item in navigation.

I have tried and got the result for it. Here i explained how i did it.

First you have to install the this plugin for url short-code -> http://wordpress.org/extend/plugins/peters-blog-url-shortcodes/

Add this code to your functions.php file with your theme.


class description_walker extends Walker_Nav_Menu{
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

$class_names = $value = '';

$classes = empty( $item->classes ) ? array() : (array) $item->classes;

$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';

$output .= $indent . '

  • ID . '"' . $value . $class_names .'>';

    $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
    $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
    $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';

    //echo $item->url;
    $string = explode('::', $item->url, 3);
    if($string[1]){
    $string[1] = str_replace('-',' ', $string[1] );
    $item->url = do_shortcode("[$string[1]]");
    }

    $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';

    $prepend = '';
    $append = '
    ';
    $description = ! empty( $item->description ) ? ''.esc_attr( $item->description ).'' : '';

    if($depth != 0)
    {
    $description = $append = $prepend = "";
    }

    $item_output = $args->before;
    $item_output .= '';
    $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
    $item_output .= $description.$args->link_after;
    $item_output .= '
    ';
    $item_output .= $args->after;

    $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
    }
    }

    Then you have to call this function from wp_nav_menu from the templates files.


    $arg = array( 'menu' => "main-menu", 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'depth' => 0, 'walker' => new description_walker() );

    wp_nav_menu( $arg );

    Thats it. Then go to the back-end with menu section.

    For example i want to give the page URL to custom link.

    I will add like this —–> http://::blogurl-id=’1302′::

    That’s All.

    Now you can go to the front-end and check the shortcode will work.

    Thanks.

  • Remove a sentence from files in linux using SED command


    Hi to all,

    Today we are going to see the how to remove a sentence or word from any type of files in the linux server. Especially Website developers should know this information.

    Sometimes hackers can enter append his code to all index files or all type of files. If suppose our website files are too large. So we could not remove the unwanted script code one by one from each file. But We have solution for this type of bugs. We can remove any of sentence or word using a single line of command in linux operating system. Now we can see how it will work.

    If we want to remove a sample sentence for root and sub directory files.
    Example folder:

    /home/manimaran/public_html/training/
    /home/manimaran/public_html/training/test1/
    /home/manimaran/public_html/training/test2/
    /home/manimaran/public_html/training/test3/

    We have remove this sentence to all folders.
    Example sentence:
    DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmIChzdHJpc3RyKCRyZWZlcmVyLCJ5YWhvbyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsImJpbmciKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJyYW1ibGVyIikgb3Igc3RyaXN0cigkcmVmZXJlciwiZ29nbyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsImxpdmUuY29t

    Just connect with your server via Shell Terminal. Putty software for windows and Linux for g-nome terminal.

    Just do this way.

    > first_string = DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmIChzdHJpc3RyKCRyZWZlcmVyLCJ5YWhvbyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsImJpbmciKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJyYW1ibGVyIikgb3Igc3RyaXN0cigkcmVmZXJlciwiZ29nbyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsImxpdmUuY29t

    > second_string = KC4qPylcJmxyXD0vIiwkcmVmZXJlcikgb3IgcHJlZ19tYXRjaCAoIi9nb29nbGVcLiguKj8pXC91cmwvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vY29zdGFicmF2YS5iZWUucGwvIik7DQpleGl0KCk7DQp9DQp9DQp9DQp9

    > find /home/manimaran/public_html/training/. -type f | while read -r file
    > do
    > sed -i "s/$first_string//g" "$file"
    > sed -i "s/$second_string//g" "$file"
    > sed -i 's/sample//g' "$file"
    > done

    Thats it. You can remove a word like this way
    > sed -i 's/sample//g' "$file"
    sample

    Now all matched patterns are replaced by empty value.

    I hope this helps some one.

    If you have any clarifications you can comment here.

    Thanks.

    Joomla password check for wordpress


    Hi to All,

    Today we will see about joomla password check method for wordpress side.

    Normally most of joomla website owners moving to wordpress. Joomla Users Migrating to wordpress users. I think most of the developers did joomla users to wordpress users. Like Firstname, Lastname, username and all information. But when we login from wordpress site, it does not work. So we have to use joomla MD5 password with SALT method. After you migrating the joomla users and wordpress users table. You need to put these code to wordpress includes directory.

    Step 1: You have to open this file – /wp-includes/class-phpass.php. Check the end of the code with function. You have to replace this.

    function CheckPassword($password, $stored_hash)
    {
    $hash = $this->crypt_private($password, $stored_hash);
    if ($hash[0] == '*')
    $hash = crypt($password, $stored_hash);

    return $hash == $stored_hash;
    }

    to replace this code.

    function CheckPassword($password, $stored_hash)
    {
    $password_for_check = $password;
    if( @count( $pass_array = @explode(':',$stored_hash) ) == 2 ){
    $joomla_pass = $pass_array[0];
    $joomla_salt = $pass_array[1];
    if($joomla_pass == md5($password_for_check.$joomla_salt))
    return 1;
    }

    $hash = $this->crypt_private($password, $stored_hash);
    if ($hash[0] == '*')
    $hash = crypt($password, $stored_hash);

    return $hash == $stored_hash;
    }

    Thats it. Now you can login with joomla username and password.

    Before you migrating the joomla users to wordpress users, you have check the wp_users table column password. Because joomla MD5 password length is little high. but wordpress table column password length is too short. You have to increase it.

    Note:
    If we upgrade wordpress, password length again changed to too short. You have to increase the password column limit to 256 varchar.

    That’s ALL. If anything you want to know, please comment here.

    Thank you.

    CS CART Vendor user creation via custom code – Multi Vendor Version


    Hi there,

    Today we will take a look about the user creation via code.

    create a php file what ever you wants from the root of the cs cart folder.


    define('AREA', 'A');
    define('AREA_NAME', 'admin');
    define('ACCOUNT_TYPE', 'admin');
    require dirname(__FILE__) . '/prepare.php';
    require dirname(__FILE__) . '/init.php';
    $user_data['company'] = "Test";
    $user_data['status'] = "D";
    $user_data['company'] = "Test";
    $user_data['lang_code'] = "EN";
    $user_data['commission'] = "";
    $user_data['commission_type'] = "";
    $user_data['email'] = "manisanjai@gmail.com";
    $user_data['phone'] = "9944509663";
    $user_data['url'] = "";
    $user_data['fax'] = "";
    $user_data['address'] = "test, Test street";
    $user_data['country'] = "IN";
    $user_data['state'] = "Tamilnadu";
    $user_data['zipcode'] = "6000028";
    $user_data['company_description'] = "Test Company";
    $user_data['categories'] = "";
    $user_data['shippings'] = '';
    $result = fn_update_company($user_data);
    echo $result; // You can get the results.
    }

    Just copy and paste this code to your php file. Then execute the file from the browser. You can get the result as an array with user id and profile id.

    That’s All.

    I hope it helps some one.

    Thanks.