HTML/JavaScript

Wednesday, December 30, 2015

Fixing Magento Catalog Price Rules Issue

try {
Mage::getConfig()->init()->loadEventObservers('crontab');
Mage::app()->addEventArea('crontab');
Mage::dispatchEvent('default');
$observ = Mage::getModel('catalogrule/observer');
$observ->dailyCatalogUpdate("0 1 * * *");
} catch (Exception $e) {
Mage::printException($e);
}

Custom column layout

Learn how easy it is to create a custom column layout for Magento. The tutorial is based on the Magento Enterprise Edition but also applies to the Magento Community Edition. A custom column layout is helpful if you want for instance a "left" column to only appear on certain pages.

To create a new custom column layout, you need to place a new file in the Magento theme. With the Magento default theme, you could use the folder app/design/frontend/default/default/template/page, but of course - when building your own site - it is recommended to have your own theme-directory.

In the tutorial, the file 1column.phtml is copied to the file 1columnfp.phtml (where "fp" stands for the front page). To make this new page reckognizable you wll need to add a new XML-definition. In the tutorial the following code is added to the file app/code/core/Mage/Page/etc/config.xml this needs to be copied into app/code/local/Mage/Page/etc/config.xml


<one_column_fp module="page" translate="label">
    <label>1 column (frontpage)</label>
    <template>page/1columnfp.phtml</template>
    <layout_handle>page_one_column_fp</layout_handle>
</one_column_fp>

However, with a Magento upgrade this change could be gone. The same XML could also be added to your app/etc/local.xml file instead:

<config>
    <global>
        <page>
            <layouts>
                <one_column_fp module="page" translate="label">
                    <label>1 column (frontpage)</label>
                    <template>page/1columnfp.phtml</template>
                    <layout_handle>page_one_column_fp</layout_handle>
                </one_column_fp>
            </layouts>
        </page>
    </global>
</config>

Monday, December 28, 2015

Remove maintenance mode in magento 2

Removing Maintenance mode in Magento 2 is extremely simple as in previous Magento versions.

The .maintenance.flag file is located under var folder in Magento 2. Delete this file to remove the maintenance mode.

Wednesday, October 21, 2015

Add Custom Field in Registration Form and in Admin Side

Here I am add the Custom Field for the Customer Registration Form using the database,

It's very simple to add Custom Field in Registration Form and also in Manage Customer Account Information of Admin,

This is the easiest way to Create field using Database Query !!!!!

A) First, Open your Database of Magento

    Click on SQL tab of  your Database and simplly write Below Query in that

    1)  Insert into eav_attribute set      entity_type_id="1",attribute_code="occupation",
backend_type="text",frontend_input="text",
frontend_label="Occupation",is_required=0,is_user_defined=0,is_unique=0

   2) Copy the Last inserted Id of  "Eav_attribute" table

   3)  Insert into `eav_entity_attribute` set entity_type_id=1,attribute_set_id=1, attribute_group_id=1,attribute_id=134,sort_order=111

   Here, you mention that change your attribute id with the Last inserted id of Eav_attribute table.

   attribute_id = "Last Inserted Id of Eav_attribute" table

   4) insert into  `customer_eav_attribute` set attribute_id="134",is_visible=1,multiline_count=1,is_system=0,sort_order=111

  same as Point (3) change attribute_id

  5) insert into  `customer_form_attribute` set form_code="adminhtml_customer",attribute_id=134

 same as Point (3) change attribute_id

  6) insert into  `customer_form_attribute` set form_code="checkout_register",attribute_id=134

  same as Point (3) change attribute_id

 7) insert into  `customer_form_attribute` set form_code="customer_account_create",attribute_id=134

 same as Point (3) change attribute_id

8) insert into  `customer_form_attribute` set form_code="customer_account_edit",attribute_id=134

 same as Point (3) change attribute_id



B) Now, some code for Create Field to saw in Front end,

   1) open Customer/Form/registration.phtml

   simply Copy-Paste below code

 Copy this .......

   <li>
        <label for="occupation"><em></em><?php echo $this->__('Occupation') ?></label>

        <div class="input-box">

         <input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getCustomer()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text" />

         </div>
    </li>

   2) open Customer/Form/edit.phtml

    simply Copy-Paste below code

    Copy this .......

   <li>
        <label for="occupation"><em></em><?php echo $this->__('Occupation') ?></label>

        <div class="input-box">

         <input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getCustomer()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text" />

         </div>
    </li>

Thursday, October 1, 2015

Magento: How to get controller, module, action and router name?

You can easily get controller name, action name, router name and module name in any template file or class file.

IN TEMPLATE FILES

$this->getRequest() can be used in template (phtml) files.

Here is the code:

/**
 * get Controller name
 */
$this->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
$this->getRequest()->getActionName();

/**
 * get Router name
 */
$this->getRequest()->getRouteName();

/**
 * get module name
 */
$this->getRequest()->getModuleName();

/**
 * get Controller name
 */
$this->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
$this->getRequest()->getActionName();

/**
 * get Router name
 */
$this->getRequest()->getRouteName();

/**
 * get module name
 */
$this->getRequest()->getModuleName();

IN CLASS FILES

Here is the code:

/**
 * get Controller name
 */
Mage::app()->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
Mage::app()->getRequest()->getActionName();

/**
 * get Router name
 */
Mage::app()->getRequest()->getRouteName();

/**
 * get module name
 */
Mage::app()->getRequest()->getModuleName();

/**
 * get Controller name
 */
Mage::app()->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
Mage::app()->getRequest()->getActionName();

/**
 * get Router name
 */
Mage::app()->getRequest()->getRouteName();

/**
 * get module name
 */
Mage::app()->getRequest()->getModuleName();

The above functions (getControllerName, getActionName, getRouteName, getModuleName) are present in the class Mage_Core_Model_Url.

You can explore all requests with print_r.

echo "<pre>"; print_r(Mage::app()->getRequest());  
  
echo "<pre>"; print_r(Mage::app()->getRequest());   

Thursday, August 6, 2015

Magento-Set category Is Anchor =”Yes”

First identify the attribute id of the is_anchor attribute:
SELECT * FROM eav_attribute where attribute_code = ‘is_anchor’;
Get the attribute id (for me is 51).
Now run the following query
UPDATE catalog_category_entity_int set value = 1 where attribute_id = 51;
replace 51 with your own attribute id.

Thursday, July 23, 2015

Magento Transactional Emails

Magento Provide Transitional emails which will allow to create or customize our won email template
Some of the Template variable which we can used in our customization or which are widely used and some magento provide by default
- For registration:
{{var customer}}
{{var customer.ID}}
{{var customer.email}}
{{var customer.firstname}}
{{var customer.lastname}}
{{var customer.name}}
{{var customer.password}}
{{var customer.created_in}} Store Name
{{var customer.dob}} Date of Birth
{{var customer.password_hash}}
{{var customer.prefix}}
{{var customer.middlename}} Initial
{{var customer.suffix}}
{{var customer.group_id}}
{{var customer.taxvat}}
{{var customer.store.name}}
{{var customer.store.group.name}}
- To subscribe/unsubscribe newsletter:
{{var subscriber.getConfirmationLink()}}
{{var subscriber.getUnsubscriptionLink()}}
{{var subscriber.email}}
- Send to a friend:
{{var product_image}}
{{var name}} Recipient’s Name
{{var email}} Recipient’s Email
{{var product_name}} Product Name
{{var product_url}} Product Url
{{var message}} Message Text
{{var sender_name}} Sender’s Name
{{var sender_email}} Sender’s Email
{{var product_image}} Product Image
- Depend Condition
{{depend order.getIsNotVirtual()}}
{{/depend}}
{{depend salable}}
{{/depend}}
- If Condition
{{if order.getIsNotVirtual()}}
{{else}}
{{/if}}
(else is optional)
- Skin
{{skin url=”‘}}
- Store
{{store url=””}}
- New order : Shipping Address
{{var order.getShippingAddress().format(‘html’)}}
Items of the shipping address :
{{var order.getShippingAddress().getName()}} Get the first and last name
{{var order.getShippingAddress().getPrefix()}}
{{var order.getShippingAddress().getFirstName()}}
{{var order.getShippingAddress().getMiddleName()}}
{{var order.getShippingAddress().getLastName()}}
{{var order.getShippingAddress().getSuffix()}}
{{var order.getShippingAddress().getStreet1()}}
{{var order.getShippingAddress().getStreet2()}}
{{var order.getShippingAddress().getCity()}}
{{var order.getShippingAddress().getRegion()}}
{{var order.getShippingAddress().getPostcode()}}
{{var order.getShippingAddress().getCountry()}} Get the country’s ID
{{var order.getShippingAddress().getCountryModel().getName()}} Get the country’s full name
{{var order.getShippingAddress().getRegion()}}
{{var order.getShippingAddress().getTelephone()}}
- Other
{{var addAllLink}}
{{var alertGrid}}
{{var billingAddress.format(‘html’)}}
{{var checkoutType}}
{{var comment}}
{{var creditmemo.id}}
{{var creditmemo.increment_id}}
{{var data.comment}}
{{var data.email}}
{{var data.name}}
{{var data.telephone}}
{{var dateAndTime}}
{{var invoice.id}}
{{var invoice.increment_id}}
{{var invoice.created_at}}
{{var items}}
{{var items_html}}
{{var message}}
{{var name}}
{{var order.customer_email}}
{{var order.getBillingAddress().format(‘html’)}}
{{var order.getBillingAddress().getName()}}
{{var order.getCreatedAtFormated(‘long’)}}
{{var order.getCustomerName()}}
{{var order.getCustomerFirstname()}}
{{var order.getCustomerLastname()}}
{{var order.getEmailCustomerNote()}} Currently unknwon how to test this variable for being set/empty
{{var order.getShippingDescription()}}
{{var order.getStatusLabel()}}
{{var order.getStoreGroupName()}}
{{var order.id}}
{{var order.increment_id}}
{{var password}}
{{var payment_html}}
{{var paymentMethod}}
{{var product_name}}
{{var product_url}}
{{var reason}} Reason for payment failure
{{var shipment.increment_id}}
{{var shippingAddress.format(‘html’)}}
{{var shippingMethod}}
{{var total}}
{{var user.name}}
{{var viewOnSiteLink}}
{{var warnings}}
{{var billing.name}}

Monday, July 20, 2015

How to use Collection in Magento

A collection is basically a Model type containing other Models, it is basically used in Magento to handle product lists (ie. from a category or a bundle option), but not only.

Product Collection class in magento is Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.

Here is some Sort of code snippet for Magento Collection(s).

Get All Products of a category

$collection = Mage::getResourceModel('catalog/product_collection')
->setStoreId($this->getStoreId())
->addCategoryFilter($category);

Tn this the addCategoryFilter() function, is used to get all products of a particular category. So, if you want to get all products of a certain category use this function.

Visibility Filter
———————
$collection = Mage::getResourceModel('catalog/product_collection');
Mage::getSingleton('catalog/product_visibility')
->addVisibleInCatalogFilterToCollection($collection);

The addVisibleFilterToCollection() adds visibility filter to a product collection i.e only products which are visible in frontend. The product which have “Not Visible Individually” selected in admin are removed.

Status Filter
—————–
$collection = Mage::getResourceModel('catalog/product_collection');
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);

This basically filters out products which are “Disabled”. Only “Enabled” products remain in the collection.

Add Product Price To Collection
——————————————–
$collection = Mage::getResourceModel('catalog/product_collection');
$collection ->addMinimalPrice()
->addFinalPrice()
->addTaxPercents();

This adds the product prices, i.e base price, final price etc to the collection. Also, price after tax, if applicable.

Filter By Ids
—————–
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addIdFilter(array(1,2,3));
//$collection->addIdFilter(array(1,2,3),false);

This puts an id filter, only product with ids 1,2,3 remain in the collection. The function parameter is true/false, this means include/exclude products from collection.

Add Website ID to the collection
——————————————–
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addWebsiteNamesToResult();

This adds website_id of each product to that collection. Only useful when using multiple websites in magento.

Filter Current Store Products
—————————————
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addStoreFilter();

Filter Current Website Products
——————————————-
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addWebsiteFilter();

Get All Products Ids
—————————
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->getAllIds();

This returns an array with only products ids of collection.

Add SEO Product URL
——————————
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addUrlRewrite();

This adds SEO friends urls to our product collection.

Add Category Ids
————————
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addCategoryIds();

This will add category ids to the products.

Add Tier Pricing
————————
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addTierPriceData();

This added tier pricing data to each product in the collection.While we are on this subject, let look at some important function of the Product Object as well.

Want to add to cart configrurable product instead of drop down--


<!-- FOR THE ASSOCIATED PRODUCTS-->
<?php  $config_product_id = Mage::registry('current_product')->getId();?>
<?php  //if ($_product->isSaleable() && count($_attributes)):?>
<?php
 $product=Mage::getModel('catalog/product')->load($config_product_id);
  $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
   $attributeOptions = array();
     $ids = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($product->getId()); //get the children ids through a simple query
$_subproducts = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('entity_id', $ids)
    ->addAttributeToSelect('*');
    $prod_img=array();
   foreach($_subproducts as $_sub_prod){
    $prod_name [] = $_sub_prod->getName();
//    echo  Mage::helper('catalog/image')->init($_sub_prod, 'small_image')->resize(50,50);;
    $prod_img[] = $_sub_prod->getImageUrl();
    $asso_prod_id[] = $_sub_prod->getId();
    }
 //  print_r($img);die;
    $i=0;$j=0;
   foreach ($productAttributeOptions as $productAttribute) {
    foreach ($productAttribute['values'] as $attribute) {?>
     <form id="childproduct_addtocart_form_<?php echo $config_product_id?>" onsubmit="return addToCart(this);" method="post" action="<?php echo Mage::getBaseUrl();?>checkout/cart/add?product=<?php echo $config_product_id?>&super_attribute[<?php echo $productAttribute['attribute_id']; ?>]=<?php echo $attribute['value_index']?>">
       <?php echo $this->getBlockHtml('formkey') ?>
<?php

      echo $prod_name[$i];
    //  echo $prod_img[$j].'-'.$i;
      echo  "<img src=".$prod_img[$j]." width='100px'>";
    echo "price: ".$attribute['pricing_value']. "---". " Color: ".$attribute['store_label']." ---- "."" ;
      
     ?>   
     <input id="qty-<?php echo $asso_prod_id;?>" class="input-text qty" type="number" title="Aantal" value="1" maxlength="12" max="100" min="0" name="qty">
       <input type="hidden" value="<?php echo $config_product_id?>" name="product">
       <input type="hidden" value="" name="related_product">
        <input type="hidden" value="<?php echo $attribute['value_index']?>" name="super_attribute[<?php echo $productAttribute['attribute_id']; ?>]">
     <button class="cart_button" title="In winkelwagen" type="submit">Add To Cart</button>
     </form>
<?php
    $i++;$j++;}
}
//echo '<pre>';


    //print_r($_subproducts);
   

?>

Tuesday, June 16, 2015

Category Custom attribute

<?php

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->removeAttribute('catalog_category','category_color');

$setup->addAttribute('catalog_category', 'category_color', array(
    'group'         => 'General Information',
    'input'         => 'select',
    'type'          => 'varchar',
    'label'         => 'Select Product Layout',
    'option'        => array (
                              'value' => array('optionone'=>array(0=>'2 Products'),'optiontwo'=>array(0=>'3 Products'))
                       ),

    'backend'        => 'eav/entity_attribute_backend_array',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
    'default'      =>3,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$installer->endSetup();
?>