get magento product info by passing sku


function get_product_info_bysku($product_sku) {
            $product_obj = Mage::getModel('catalog/product')->loadByAttribute('sku',$product_sku);

            if($product_obj)
            {
            $product_id = $product_obj->getId();
            $stock_obj = Mage::getModel('cataloginventory/stock_item')->load($product_id);  /*load the stock*/
            $product_sku = $product_obj->getSku();
            $product_name = $product_obj->getName();
            $product_qty = $stock_obj->getQty();
            $product_is_in_stock = $stock_obj->getIs_in_stock();
            $product_price = $product_obj->getPrice();
            $product_has_option = $product_obj->getAssociatedProducts();
            $product_type = $product_obj->getTypeId();
            $product_created_at = $product_obj->getCreatedAt();
            $product_updated_at = $product_obj->getUpdatedAt();
            $product_asin = $product_obj->gethpc_asin();
            $product_category_ids = $product_obj->getCategoryIds();
            $amazon_results = $this->fetch_browsenode($product_category_ids);
            $amz=explode("##",$amazon_results);
            $product_amazon_browsenodeid = $amz[0];
            $product_amazon_browsenodename = $amz[1];
            //ebay part
            $ebay_results = $this->fetch_ebaycategory($product_category_ids);
            $ebay=explode("##",$ebay_results);
            $product_ebay_catid1 = $ebay[0];
            $product_ebay_catid2 = $ebay[1];
            $product_websiteid = $product_obj->getWebsiteIds();
            $product_storeid = $product_obj->getStoreIds();
            $product_description = $product_obj->getDescription();
            $product_info = array(
            "product_id" => $product_id,
            "product_sku" => $product_sku,
            "product_name" => $product_name,
            "product_qty" => $product_qty,
            "product_is_in_stock" => $product_is_in_stock,
            "product_price" => $product_price,
            "product_created_at" => $product_created_at,
            "product_updated_at" => $product_updated_at,
            "product_type" => $product_type,
            "product_has_option" => $product_has_option,
            "product_attribute" => $product_attribute,
            "product_websiteid" => $product_websiteid,
            "product_storeid" => $product_storeid,
            "childProducts" => $childProducts,
            "product_description" => $product_description,
            "product_asin" => $product_asin,
            "product_category_ids" => $product_category_ids,
            "product_amazon_browsenodeid" => $product_amazon_browsenodeid,
            "product_amazon_browsenodename" => $product_amazon_browsenodename,
            "product_ebay_catid1" => $product_ebay_catid1,
            "product_ebay_catid2" => $product_ebay_catid2
            );
            return $product_info;
            }
            else
            {
                return "SKU NOT FOUND";
            }
        }

Share on Facebook




About Pragnesh Karia

Pragnesh Karia, Open Source Enthusiast, Software Professional, Software Developer, Technical Lead ,Magento, Joomla ,Joomla LMS , Moodel LMS ,PHP ,Mysql, Ajax, Javascript, Jquery, Linux, Fan of Open Sources , Annet Technologies , SEO Analyst , Mootools