Wednesday 19 February 2014

USPS API update january 2014

Usps have updated their API on January 2014. You can find the details of it here

And for those who have registered for the USPS developer or production account you would have been received mail from Usps about the API update.

According to the new update the shipping method "Standard Post" has been eliminated for Zones      1 to 4

Usps separates zipcodes with their zones. You can find your zone from here. FIND USPS ZONES
Go to "Get Zone for ZIP Code Pair" tab and enter your Origin and Destination zip code.

If your zone is numbered from 1 to 4, the "Standard Post" shipping method will not be applicable for you zipcode. Exception is given when you ship hazardous materials, live animals or other ground only items.

You can find more info about the API changes. 2014 January Release Notes (RTF)

Thursday 6 February 2014

Magento change product image on view page to associated product image

Magento's configurable product does not load its associated product image when we change the attribute value. To change the image of the product respective to the selected attribute value i have used this code. Magento website also offers a wiki to achieve this, but its pretty old and its written for magento version 1.5 and below. Link to wiki

I have tested this code in recent magento version which is 1.8 and the most famous 1.7.

Here is the code.

STEP 1:

Open template/catalog/product/view.phtml

and find the line var productAddToCartForm = new VarienForm('product_addtocart_form'); on the bottom of the page.

Add these code on top of that line.

var mainProductImgSrc = document.getElementById("image").src;
var assocIMG =

<?php
if ($_product->getTypeId() == "configurable") {
echo "{";
$associated_products = $_product->loadByAttribute('sku', $_product->getSku())->getTypeInstance()->getUsedProducts();
foreach ($associated_products as $assoc)
$dados[] = $assoc->getId().":'".($assoc->image == "no_selection" || $assoc->image == "" ? $this->helper('catalog/image')->init($_product, 'image', $_product->image)->resize(365,400) : $this->helper('catalog/image')->init($assoc, 'image', $assoc->image)->resize(365,400))."'";
} else {
$dados[] = "";
}
echo implode(',', $dados );
if ($_product->getTypeId() == "configurable") {
echo "}";
}

?>


STEP 2:

open js/varien/product.js and find the line

}.bind(this));
for (var i = 0; i < this.tierPrices.length; i++) {


and add the below given code above  this-> " }.bind(this)); " line.

//to change product image based on option select for configurable product
settings = $$('.super-attribute-select');
imgSrc = mainProductImgSrc;
settings.each(function(element)
 {
   attributeId = element.attributeId;
   if(element.options[element.selectedIndex].config)
   imgSrc = assocIMG[element.options[element.selectedIndex].config.products];
   $('image').src = imgSrc;
 });

//ends

Your are done now. Do remember to select the base image for the associated product. If there is no image set for the associated product and when you change the option the configurable product image will be used instead.

Saturday 1 February 2014

Magento import products with custom product type via csv

I was assigned a job to import products with custom product types through CSV

Magento's default product types are
  1. simple
  2. configurable
  3. virtual
  4. grouped
But when you import products with new product type other than the above mentioned. you will get this error

Product Type is invalid or not supported in rows... 

To overcome this error and import products with your custom product type you must follow these two steps.

1. Now am going to assume you have created an extension. On the config.xml file of your extension place this code under <global> tag.

<importexport>
    <import_product_types>
         <YOUR_MODULE>yourModule/import_entity_product_type_
YOUR_MODULE</YOUR_MODULE>
    </import_product_types>

</importexport>

Replace YOUR_MODULE with you module name.

2. Create a new model class to do the import. For this create this folder structure inside your model structure
Import\Entity\Product\Type\NEW-PRODUCT-TYPE

In my case i have a new product type "subscription_simple". so my folder structure will be
Import\Entity\Product\Type\Subscription\

Inside the folder i have a model class Simple.php file extending the magneto import class.\

place this code inside Simple.php file.

class NAMESPACE_MODULE_Model_Import_Entity_Product_Type_Subscription_Simple
    extends Mage_ImportExport_Model_Import_Entity_Product_Type_Abstract
{

}

Now you can do the import with your custom product type.

you can check out one of the inbuilt classes for an example Mage_ImportExport_Model_Import_Entity_Product_Type_Simple

INFO: http://stackoverflow.com/questions/8909405/product-type-is-invalid-or-not-supported-in-rows-for-custom-product-type