Add code

Thursday 31 May 2018

Magento 1 : Hide other shipping methods when free shipping is available

To prevent other shipping options to display when Free Shipping is available, add the following code to your template:



Open :
/app/design/frontend/[Your_package]/[Your_theme]/template/checkout/onepage/shipping_method/available.phtml




<?php
if ( array_key_exists('freeshipping', $_shippingRateGroups )) {
unset($_shippingRateGroups["flatrateperproduct"]);
}
?>

Then ,  flatrateperproduct Method will be remove from the shipping method.

Tuesday 15 May 2018

How to add Buy Now At Product Page in Magento - 1 version ?

If you want both Add to Cart and Buy now, add the buy now button to addtoCart.phtml

Go to
/app/design/frontend/[package name]/[themename]/template/ajaxcart/catalog/product/view/addtoCart.phtml

<button type="button" 
        title="<?php echo $buttonTitle ?>"
        class="button btn-cart" 
        onclick="productBuyNowForm.submit(this)">
    <span><span>Buynow</span></span>
</button>

On that buttons onlick event, a custom VarienForm is used, productBuyNowForm.submit(this), which will submit this form and redirect to checkout onepage.

To define this custom form, add the following JavaScript code at view.phtml

Go to
/app/design/frontend/[package name]/[theme name]/template/catalog/product/view.phtml

<script>
var productBuyNowForm = new VarienForm('product_addtocart_form');
productBuyNowForm.submit = function (button, url) {
    if (this.validator.validate()) {
        var form = this.form;
        var oldUrl = form.action;
        alert(form.action);
        if (url) {
            form.action = url;
        }

        /* add return Url */
        var inputreturn= document.createElement("input");
        inputreturn.type = "hidden";
        inputreturn.name = "return_url";
        inputreturn.value = "<?php echo Mage::getUrl('checkout/onepage')?>";
        document.getElementById('product_addtocart_form').appendChild(inputreturn);
        /* add return Url */
        // Append a line break 
        var e = null;
        try {
            this.form.submit();
        } catch (e) {
        }
        this.form.action = oldUrl;
        if (e) {
            throw e;
        }

        if (button && button != 'undefined') {
            button.disabled = true;
        }
    }
}.bind(productBuyNowForm);

</script>

Magento : 404 error is showing admin page

Hello, Sometimes we may get the error on admin page once done with the Magento installation. In that scenario, we have to do the following: ...