Monday, May 20, 2013

Published 2:17 AM by with 0 comment

Unable to fetch all items of an order in Magento?

I used this in my module. it may help you.

Load Magneto Order and Product Collection

$resource_model = Mage::getResourceModel('sales/order_collection');
$product_model = Mage::getModel('catalog/product');

Loop through order collection

$records = 0;
    $productData = array();
    $orderProductArr = array();

    foreach($resource_model as $all_orders)
    { 
        if($all_orders['status']!="canceled" && $all_orders['status']!="fraud")
        {  
            $i = 0;
            $items = $all_orders->getAllVisibleItems();

            foreach($items as $item)
            {
                $_product = $product_model->load($item->getProductId()); // getting product details here to get description

                $taxClassId = $_product->getData("tax_class_id");
                $taxClass = $_product->getData("tax_class_name");

                $taxRate = $order['tax_amount'];

                $orderProductArr[$i]['web_id'] = $item->getProductId();
                $orderProductArr[$i]['quantity'] = $item->getQtyToInvoice();
                $orderProductArr[$i]['price'] = $item->getPrice();
                $orderProductArr[$i]['description'] = $_product->getDescription();
                $orderProductArr[$i]['currency'] = $order['order_currency_code'];
                $orderProductArr[$i]['tax_id'] = $taxClassId;
                $orderProductArr[$i]['tax_amt'] = $taxRate;
                $orderProductArr[$i]['total_amt'] = ($item->getPrice()*$item->getQtyToInvoice())+($taxRate);

                $productData[$i]['title'] = $item->getName();
                $productData[$i]['web_product_id'] = $item->getProductId();
                $productData[$i]['price'] = $item->getPrice();
                $productData[$i]['product_sku'] = $item->getSku();
                $productData[$i]['tax_class'] = $taxClassId;
                $productData[$i]['description'] = $_product->getDescription();

                $tax_arr[$i]['tax_id'] = $taxClassId;
                $tax_arr[$i]['tax_class'] = $taxClassId;
                $tax_arr[$i]['tax_amt'] = $taxRate;

                $i++;
                unset($items);
            }   
            $data[$records]['order_data']['product_details'] = $orderProductArr;
            $data[$records]['order_data']['order_product_details'] = $productData;
            $data[$records]['order_data']['tax_arr'] = $tax_arr;
            unset($orderProductArr);
            unset($productData);
            unset($tax_arr);
            $records++;
        }   
    }
Read More
    email this       edit

Tuesday, May 14, 2013

Published 9:21 PM by with 0 comment

I changed the {{base url}} in the config and I can not revert it back



I have faced a problem changing {{base url}} through the magento admin portal and I can’t change it back. I can’t connect to admin area either. 

I found a solution and it can be change in DB. 





UPDATE core_config_data
SET value = '
correct URL here'
WHERE config_id = 7




Read More
    email this       edit

Monday, May 13, 2013

Published 9:47 PM by with 0 comment

Magento: The requested URL /Index/index.php was not found on this server.










Magento: The requested URL /Index/index.php was not found on this server.


Solution is modifying the .htaccess file.
------
Order deny,allow
Deny from all

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|php)$ index.php
php_flag magic_quotes_gpc off
php_flag register_globals off
Read More
    email this       edit

Wednesday, May 8, 2013

Published 9:50 PM by with 0 comment

Template Method Pattern



Template Method Pattern

Definition
Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

abstract class AbstractClass
    {
        public abstract void PrimitiveOperation1();
        public abstract void PrimitiveOperation2();

        public void TemplateMethod()
        {
            PrimitiveOperation1();
            PrimitiveOperation2();
            Console.WriteLine("Call Template Method");
        }
    }

    //Concrete Class A
    class ConcreteClassA : AbstractClass
    {
        public override void PrimitiveOperation1()
        {
            Console.WriteLine("concreate A primi 1");
        }

        public override void PrimitiveOperation2()
        {
            Console.WriteLine("concreate A primi 2");
        }
    }

    //Concrete Class B
    class ConcreteClassB : AbstractClass
    {
        public override void PrimitiveOperation1()
        {
            Console.WriteLine("concreate B primi 1");
        }

        public override void PrimitiveOperation2()
        {
            Console.WriteLine("concreate B primi 2");
        }
    }

//calling…
            //Template Method
            AbstractClass a = new ConcreteClassA();
            a.TemplateMethod();

            AbstractClass b = new ConcreteClassB();
            b.TemplateMethod();

Read More
    email this       edit
Published 1:44 AM by with 0 comment

Composite Pattern - [Structural Patterns]


Definition
[Download cs c#]
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

    //Component class
    abstract class Component
    {
        protected string name;

        public Component(string name)
        {
            this.name = name;
        }

        public abstract void Add(Component c);
        public abstract void Remove(Component c);
        public abstract void Display(int Dept);
    }

    //Composite Class
    class Composite : Component
    {
        private List<Component> _com = new List<Component>();

        public Composite(string name):base(name)
        {

        }
        public override void Add(Component c)
        {
            _com.Add(c);
        }
        public override void Remove(Component c)
        {
            _com.Remove(c);
        }
        public override void Display(int Dept)
        {
            Console.WriteLine(new String('-',Dept)+name);

            foreach (Component component in _com)
            {
                component.Display(Dept + 2);
            }
        }
    }

        //Leaf Class
        class Leaf : Component
        {
            public Leaf(string name):base(name)
            {

            }
            public override void Add(Component c)
            {
                Console.WriteLine("Can not add to a leaf");
            }
            public override void Remove(Component c)
            {
                Console.WriteLine("Can not remove from a leaf");
            }
            public override void Display(int Dept)
            {
                Console.WriteLine(new String('-', Dept) + name);
            }
        }


            //---Composite Calling...
            Composite root = new Composite("root");
            root.Add(new Leaf("Leaf A"));
            root.Add(new Leaf("Leaf B"));

            Composite comp = new Composite("Composite X");
            comp.Add(new Leaf("Leaf XA"));
            comp.Add(new Leaf("Leaf XAB"));

            root.Add(comp);
            root.Add(new Leaf("Leaf C"));

            // Add and remove a leaf
            Leaf leaf = new Leaf("Leaf D");
            root.Add(leaf);
            root.Remove(leaf);

            // Recursively display tree
            root.Display(1);



Read More
    email this       edit