HTML/JavaScript

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);
   

?>