Tuesday, 17 November 2015

How to add grouped products in Magento



In Magento, you can easily create a grouped product. Customers can choose this grouped product to buy all products in group or only buy some of the associated products.

Step 1: Login to your Magento Admin Panel, go to Catalog -> Manage Products




Step 2: On Manage Products page, choose Add Product



Step 3: In Product Type drop-down menu, choose Grouped Product option and then click Continue



Step 4: You should fill all necessary information and settings for this grouped product. Most of settings and information are configured in the same way as they are configured when add a simple product. There only have some differences in weight and price because they are managed by the products that are added into group. Besides, you should mark the checkbox of products you want to add to the grouped product in Associated Products



Finally, you should click Save button

How to Create Creditit Memo in Magento

Once transaction is processed and invoice created, you need to create credit memo if you want to refund the customer. In Magento, the best way to do it is to open order in question and go to the invoice list on the left side of the order form. Click on an invoice you want to refund. Invoice detail information will appear. Now click on 'Credit Memo...' button on top of the form. - See more at: http://www.magedevelopers.com/blog/magento-tutorials/refund-credit-memo-creation-magento/#sthash.R7HV0Ur1.dpuf

In list of products, you can choose quantity to refund and return to stock. Maximum qty is added by default. Additionally, you can specify 'Refund Shipping' amount and adjustment amounts which are added or subtracted from refund total. - See more at: http://www.magedevelopers.com/blog/magento-tutorials/refund-credit-memo-creation-magento/#sthash.R7HV0Ur1.dpuf

When you are satisfied with amount to refund, you can continue with credit memo process. There are two ways to refund, offline and online. Online refund is used if transaction is made through Authorize.net or similar payment gateway. This way Magento will try to automatically refund the customer credit cart trough gateway API. If you choose to refund custom by using offline refund it will only create internal Magento credit memo and not contact any payment gateway. This method is used for check / money transfers or if you used 'Authorize Only' payment type. Using this credit memo type will allow you to continue with Magento order process, but you will have to refund the money to customer manually trough payment gateways website if one is used. - See more at: http://www.magedevelopers.com/blog/magento-tutorials/refund-credit-memo-creation-magento/#sthash.R7HV0Ur1.dpuf

In list of products, you can choose quantity to refund and return to stock. Maximum qty is added by default. Additionally, you can specify 'Refund Shipping' amount and adjustment amounts which are added or subtracted from refund total. - See more at: http://www.magedevelopers.com/blog/magento-tutorials/refund-credit-memo-creation-magento/#sthash.R7HV0Ur1.dpuf

Once transaction is processed and invoice created, you need to create credit memo if you want to refund the customer. In Magento, the best way to do it is to open order in question and go to the invoice list on the left side of the order form. Click on an invoice you want to refund. Invoice detail information will appear. Now click on 'Credit Memo...' button on top of the form. - See more at: http://www.magedevelopers.com/blog/magento-tutorials/refund-credit-memo-creation-magento/#sthash.R7HV0Ur1.dpuf
Once transaction is processed and invoice created, you need to create credit memo if you want to refund the customer. In Magento, the best way to do it is to open order in question and go to the invoice list on the left side of the order form. Click on an invoice you want to refund. Invoice detail information will appear. Now click on 'Credit Memo...' button on top of the form. - See more at: http://www.magedevelopers.com/blog/magento-tutorials/refund-credit-memo-creation-magento/#sthash.R7HV0Ur1.dpuf
Once transaction is processed and invoice created, you need to create credit memo if you want to refund the customer. In Magento, the best way to do it is to open order in question and go to the invoice list on the left side of the order form. Click on an invoice you want to refund. Invoice detail information will appear. Now click on 'Credit Memo...' button on top of the form. - See more at: http://www.magedevelopers.com/blog/magento-tutorials/refund-credit-memo-creation-magento/#sthash.R7HV0Ur1.dpuf

Friday, 6 November 2015

Disable mod_rewrite for subdirectory OR Set Apache Password Protected Directories With .htaccess File OR API Protected


If you don't know the username and password to enter, then you can't access the page or site - it's "password protected". It's sometimes handy to be able to password protect your pages like this - for example:


  1. You're building a new site, but you only want yourself (and maybe a select few) to be able to view the work-in-progress.
  2. You have an area of your site that you never want the general public to have access to - for example, your web stats or private pages.
  3. You have some paid (subscription) content on your site that only subscribers should be able to access.
  4. Apache lets you password protect individual files, folders, or your entire site fairly easily. Read on to find out how it's done.


  1. Create a special file called .htaccess in the folder you want to protect.
ErrorDocument 401 "Unauthorized"
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/*/public_html/directory/.htpasswd
require user myusername_same_as_.htpasswd_file
     2. Creating the password file Called .htpasswd
The first step is to create a simple text file that will store your username and password, separated by a colon (:). The small catch is that the password must be encrypted. Luckily, there are many free web-based utilities that will encrypt the password for you. Try one of these:
myusername_same_as_.htaccess_file:$apr1$TSQAiMQm$MIJ.m3qpJ3mnY6NXdzppz. 

Tuesday, 29 September 2015

Custom Magento CMS page layout

Add new custom layout for few cms pages in one Magento shop. It’s really useful for different static pages of your shop. First create extension with only config file in it: app/code/local/Metizsoft/CmsPageLayout/etc/config.xml

<?xml version="1.0"?>
<config>
 <global>
  <page>
   <layouts>
    <custom_static_page_one>
     <label>Must Login Page</label>
     <template>page/mustloginpage.phtml</template>
    </custom_static_page_one>
   </layouts>
  </page>
 </global>
</config>
Then activate it: app/etc/modules/Metizsoft_CmsPageLayout.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Metizsoft_CmsPageLayout>
            <codePool>local</codePool>
            <active>true</active>
        </Metizsoft_CmsPageLayout>
    </modules>
</config>

Clear cache, add your page/mustloginpage.phtml template file (or copy some default one for start) to your current theme and you’re done

Monday, 28 September 2015

Creating xml file of all products fields in magento programmatically

I will be using Varien_Simplexml_Element class to read write xml nodes. The path to this class file is lib/Varien/Simplexml/Element.php

Here is a sample XML file which I am going to read through Magento code. I will also be adding an XML node to the following XML data.

$file = "products.xml";
        if (file_exists($file)) { unlink ($file); }
       
        $products = Mage::getModel('catalog/product')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addAttributeToFilter('status', array('eq' => '1'))
                    ->addAttributeToFilter('type_id', array('eq' => 'simple'));
       
        //process your product collection as per your bussiness logic
        $doc = new DOMDocument();
        $doc->formatOutput = true;
        $productsX = $doc->createElement( "products" );
        $doc->appendChild( $productsX );
        foreach($products as $_product){

            $product = $doc->createElement( "product" );

            $sku = $doc->createElement( "sku" );
            $sku->appendChild(
             $doc->createTextNode($_product->getSku())
            );
            $product->appendChild($sku);

            $name = $doc->createElement("name");
            $name->appendChild(
             $doc->createTextNode( trim($_product->getName()) )
            );
            $product->appendChild($name);

            $image = $doc->createElement( "image" );
            $image->appendChild(
             $doc->createTextNode( trim($_product->getData('image')) )
            );
            $product->appendChild( $image );

            $smallimage = $doc->createElement( "smallimage" );
            $smallimage->appendChild(
             $doc->createTextNode( trim($_product->getData('small_image')) )
            );
            $product->appendChild( $smallimage );

            $thumbnail = $doc->createElement( "thumbnail" );
            $thumbnail->appendChild(
             $doc->createTextNode( trim($_product->getData('thumbnail')) )
            );
            $product->appendChild( $thumbnail );

            $urlkey = $doc->createElement( "urlkey" );
            $urlkey->appendChild(
             $doc->createTextNode( trim($_product->getData('url_key')) )
            );
            $product->appendChild( $urlkey );

            $shippingdelivery = $doc->createElement( "shippingdelivery" );
            $shippingdelivery->appendChild(
             $doc->createTextNode( trim($_product->getShippingDelivery()) )
            );
            $product->appendChild( $shippingdelivery );

            $shippingweight = $doc->createElement( "shippingweight" );
            $shippingweight->appendChild(
             $doc->createTextNode( trim($_product->getShippingWeight()) )
            );
            $product->appendChild( $shippingweight );

            $alu = $doc->createElement( "alu" );
            $alu->appendChild(
             $doc->createTextNode( trim($_product->getAlu()) )
            );
            $product->appendChild( $alu );

            $upsize = $doc->createElement( "upsize" );
            $upsize->appendChild(
             $doc->createTextNode( trim($_product->getUpsize()) )
            );
            $product->appendChild( $upsize );

            $price = $doc->createElement( "price" );
            $price->appendChild(
             $doc->createTextNode( trim($_product->getPrice()) )
            );
            $product->appendChild( $price );

            $specialprice = $doc->createElement( "specialprice" );
            $specialprice->appendChild(
             $doc->createTextNode( trim($_product->getSpecialPrice()) )
            );
            $product->appendChild( $specialprice );

            $color = $doc->createElement( "color" );
            $color->appendChild(
             $doc->createTextNode( trim($_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product)))
            );
            $product->appendChild( $color );

            $status = $doc->createElement( "status" );
            $status->appendChild(
             $doc->createTextNode( trim($_product->getResource()->getAttribute('status')->getFrontend()->getValue($_product)) )
            );
            $product->appendChild( $status );

            $description = $doc->createElement( "description" );
            $description->appendChild(
             $doc->createTextNode( trim($_product->getDescription()) )
            );
            $product->appendChild( $description );

            $qty = $doc->createElement( "qty" );
            $qty->appendChild(
             $doc->createTextNode( trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()) )
            );
            $product->appendChild( $qty );

            $availability = $doc->createElement( "availability" );
            $availability->appendChild(
             $doc->createTextNode( trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock()) )
            );
            $product->appendChild( $availability );

            $productsX->appendChild($product); 
        }
        file_put_contents($file,$doc->saveXML(),FILE_APPEND);

Friday, 18 September 2015

Add product to cart but price getting 0 or NULL in magento API

I’m testing out the Cart API and it seems I cannot get any data related to price, total price, etc until I enter in customer information.  The variables are there, but all of the price values are null/0. Is this the intended functionality, or am I doing something wrong?

The code below works except any variable relating to the price is null.

<pre>
<?php
$client = new SoapClient('http://magento.com/api/soap/?wsdl');
$session = $client->login('jemsw','write');
$cartId = $client->call($session,'cart.create',array(0));
$result = $proxy->call($sessionId, 'cart_product.add', array($cartId, array("product_id" => 53,"qty" => 2)));
$result = $client->call($session,'cart.totals',array($cartId));
print_r($result);
?></pre>

Array(
    [0] => Array(
        [title] => Subtotal
        [amount] =>
        )
        [1] => Array(
        [title] => Grand Total
        [amount] =>
        )
    )

If I add this code in after add product to cart `cart_product.add` the price is reflected correctly.

<pre>
<?php

    $client = new SoapClient('http://magento.com/api/soap/?wsdl');$session = $client->login('jemsw','write');

    $cartId = $client->call($session,'cart.create',array(0));

    $result = $proxy->call($sessionId, 'cart_product.add', array($cartId, array("product_id" => 53,"qty" => 2)));


    ################################################################################


    $arrAddresses = array(

        array(

            "mode" => "shipping",

            "firstname" => "test",

            "lastname" => "test",

            "company" => "test",

            "street" => "test",

            "city" => "test",

            "region" => "test",

            "postcode" => "test",

            "country_id" => "id",

            "telephone" => "0123789",

            "fax" => "01234589",

            "is_default_shipping" => 0,

            "is_default_billing" => 0

        ),

        array(

            "mode" => "billing",

            "firstname" => "test",

            "lastname" => "test",

            "company" => "test",

            "street" => "test",

            "city" => "test",

            "region" => "test",

            "postcode" => "test",

            "country_id" => "id",

            "telephone" => "012356789",

            "fax" => "0123459",

            "is_default_shipping" => 0,

            "is_default_billing" => 0

        )

    );

    $resultCustomerAddresses = $client->call($session, "cart_customer.addresses", array($cartId, $arrAddresses));


    ################################################################################

    $result = $proxy->call($sessionId, "cart.info", array($cartId));

    print_r($result);

    ?>

    </pre>

Display Your Cart item with price. 

Saturday, 12 September 2015

Dump jquery object in an alert box

I am not quite adept in maneuvering jQuery, and it came to a point that I need to debug a program that was passed down from me without a documentation.
I have this var a, an object, that I really want to know the content of its collection. In my mind I need a function like foreach() in PHP to iterate over this object variable. Upon researching I end up in using jQuery.each(). Now I can clearly iterate and see what was inside var a.
However, it was kind of annoying to alert once every value on the var a. What I wanna know if it's possible to display all the contents in just one pop of alert box?

Here is my code:

var acc = []
$.each(a, function(index, value) {
    acc.push(index + ': ' + value);
});
alert(JSON.stringify(acc));