Friday, 18 July 2014

Magento fedex SoapFault exception

Well, when it comes to any third party Shipping API's it a big headache for the developers. Especially when the worlds largest Shipping company FedEx changed their URL for the webservice request without any prior notification and the URL's are hardcoded.

So, How does it affect Magento ?

I was using the FedEx shipping method and everything works good in the Frontend of the website. But when i create a Shipping Label from the Admin i got an error message "An error occured while creating shipping label". And when i checked the LOG file, there was only EXCEPTION log created.

Ok, so after checking the exception log i found that there was a "SoapFault exception" error.
Later i found that it was the FedEx the culprit.

FIXES

Go to the path: app/code/core/Mage/Usa/Model/Shipping/Carrier
open Fedex.php file

On the line number 135 you will find such code with the fedex webservice url hardcoded

$client->__setLocation($this->getConfigFlag('sandbox_mode')
            ? 'https://wsbeta.fedex.com:443/web-services/rate'
            : 'https://ws.fedex.com:443/web-services/rate'
        );

Replace this with this new code.

$client->__setLocation($this->getConfigFlag('sandbox_mode')
            ? 'https://wsbeta.fedex.com:443/web-services'
            : 'https://ws.fedex.com:443/web-services'
        );


and that's it. The error must be Fixed. If it still exists please check your server configuration for the SOAP and WSDL configuration. It must be using older version. Try upgrading it.

NOTE: If you are creating Shipping Labels you Need to change the URL on the WSDL file also. The URL will be found at the very bottom of the code. 

Tuesday, 1 July 2014

Magento Add to cart not working for new products block

I came across this Add to cart issue after upgrading from version 1.7.2 to 1.8.1.
Then after a long time search, luckly i found the cause.

In Magento version 1.8.1 there was an update to the add to cart feature with the inclusion of "Form keys". Magento has implemented this feature to prevent XSS attacks.

To know more about Form keys click here.

SOLUTION : Change the button type from "button" to "submit"

NOTE : Enabling All cache type may not solve the issue. Disable only "Blocks HTML output", you can enable other cache types.

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

Monday, 2 December 2013

[SOLVED] Magento - fedex not showing all the shipping methods


I was wondering why all the Shipping methods in FedEx which i have selected is not shown on the frontend. Well here is the answer.

FedEx returns the list of shipping methods as a response for our API call. The response is based on the total products weight (sum of all the products weight in cart).

So if the total weight is upto 70lbs Ground Shipping will be shown. If the weight is more than 70lbs you can use Home delivery. And if the weight is above 150lbs you can use freight methods.

Friday, 8 November 2013

Magento- Fedex shipping methods service codes.

There is no proper documentation available for FedEx web services API. I wanted to know the different service codes for shipping. Took a long search, but its is not available even in Fedex website which has examples only with priority shipping methods. So i went on a deep search and found this.

These are the list of FedEx web services API service code values for different shipping methods.

'INTERNATIONAL_PRIORITY'
'EUROPE_FIRST_INTERNATIONAL_PRIORITY'
'INTERNATIONAL_ECONOMY'
'STANDARD_OVERNIGHT'
'FIRST_OVERNIGHT'
'PRIORITY_OVERNIGHT'
'FEDEX_2_DAY'
'FEDEX_GROUND'
        
'GROUND_HOME_DELIVERY'
'INTERNATIONAL_GROUND'
'FEDEX_EXPRESS_SAVER'
'FEDEX_FREIGHT'
    
'FEDEX_NATIONAL_FREIGHT'
'FEDEX_1_DAY_FREIGHT'
'FEDEX_2_DAY_FREIGHT'
'FEDEX_3_DAY_FREIGHT'
'INTERNATIONAL_ECONOMY_FREIGHT'
'INTERNATIONAL_PRIORITY_FREIGHT'
 'SMART_POST'