Friday, 1 July 2016

Tuesday, 28 June 2016

How to convert stdclass object to Array and Array To stdclass Object

//Object To Array

function object2Array($d)
{
if (is_object($d))
{
$d = get_object_vars($d);
}

if (is_array($d))
{
return array_map(__FUNCTION__, $d);
}
else
{
return $d;
}
}

//   After  This

  $attachments_id=$value -> attachments;
   $attachments_array = object2Array($attachments_id);
   foreach($attachments_array as $attachments_data)
   {
        echo "=====================Start Attachments  Data =================================<br/>";
echo "ID&nbsp; : ".$attachments_data['id']."<br/>";
echo "uploaded_name&nbsp; :".$attachments_data['uploaded_name']."<br/>";
echo "uploaded_extension&nbsp; : ".$attachments_data['uploaded_extension']."<br/>";
echo "mime_type&nbsp; : ".$attachments_data['mime_type']."<br/>";
echo "file_size&nbsp; :".$attachments_data['file_size']."<br/>";
echo "url&nbsp; : ".$attachments_data['url']."<br/>";
echo "=====================End Attachments Data =================================<br/>";
   }

// Array To Object

function array2Object($d)
{
if (is_array($d))
{
return (object) array_map(__FUNCTION__, $d);
}
else
{
return $d;
}
}

$object = array2Object($array);
print_r($object);
echo "\r\n";


Click  Here

Tuesday, 31 May 2016

PDF invoice for each order in magento

Step 1

Create the following three files in your Magento’s installation:
app/code/local/Inchoo/Invoice/Model/Order/Pdf/Items/Invoice/Default.php
app/code/local/Inchoo/Invoice/Model/Order/Pdf/Invoice.php
app/code/local/Inchoo/Invoice/etc/config.xml

Those will be used for our extension that will modify Magento’s core functionality.

Step 2

config.xml
=========

<?xml version="1.0"?> <config> <modules> <Inchoo_Invoice> <version>0.1.0</version> </Inchoo_Invoice> </modules> <global> <models> <sales> <rewrite> <order_pdf_invoice>Inchoo_Invoice_Model_Order_Pdf_Invoice</order_pdf_invoice> <order_pdf_items_invoice_default>Inchoo_Invoice_Model_Order_Pdf_Items_Invoice_Default</order_pdf_items_invoice_default> </rewrite> </sales> </models> </global> </config>


===========================================
Default.php

<?php /** * Inchoo PDF rewrite for custom attribute * Attribute "inchoo_warehouse_location" has to be set manually * Original: Sales Order Invoice Pdf default items renderer * * @category Inchoo * @package Inhoo_Invoice * @author Mladen Lotar - Inchoo <mladen.lotar@inchoo.net> */   class Inchoo_Invoice_Model_Order_Pdf_Items_Invoice_Default extends Mage_Sales_Model_Order_Pdf_Items_Invoice_Default { /** * Draw item line **/ public function draw() { $order = $this->getOrder(); $item = $this->getItem(); $pdf = $this->getPdf(); $page = $this->getPage(); $lines = array();   //Inchoo - Added custom attribute to PDF, first get it if exists $WarehouseLocation = $this->getWarehouseLocationValue($item);   // draw Product name $lines[0] = array(array( 'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true), 'feed' => 35, ));   //Inchoo - Added custom attribute //draw Warehouse Location $lines[0][] = array( 'text' => Mage::helper('core/string')->str_split($WarehouseLocation, 25), 'feed' => 245 );   // draw SKU $lines[0][] = array( 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 25), 'feed' => 325 );   // draw QTY $lines[0][] = array( 'text' => $item->getQty()*1, 'feed' => 435 );   // draw Price $lines[0][] = array( 'text' => $order->formatPriceTxt($item->getPrice()), 'feed' => 395, 'font' => 'bold', 'align' => 'right' );   // draw Tax $lines[0][] = array( 'text' => $order->formatPriceTxt($item->getTaxAmount()), 'feed' => 495, 'font' => 'bold', 'align' => 'right' );   // draw Subtotal $lines[0][] = array( 'text' => $order->formatPriceTxt($item->getRowTotal()), 'feed' => 565, 'font' => 'bold', 'align' => 'right' );   // custom options $options = $this->getItemOptions(); if ($options) { foreach ($options as $option) { // draw options label $lines[][] = array( 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true), 'font' => 'italic', 'feed' => 35 );   if ($option['value']) { $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']); $values = explode(', ', $_printValue); foreach ($values as $value) { $lines[][] = array( 'text' => Mage::helper('core/string')->str_split($value, 50, true, true), 'feed' => 40 ); } } } }   $lineBlock = array( 'lines' => $lines, 'height' => 10 );   $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true)); $this->setPage($page);   }   /* * Return Value of custom attribute * */ private function getWarehouseLocationValue($item) { $prod = Mage::getModel('catalog/product')->load($item->getProductId());   if(!($return_location = $prod->getInchooWarehouseLocation())) return 'N/A'; else return $return_location; } }

===============================================
Invoice.php

<?php /** * Inchoo PDF rewrite for custom attribute * * Attribute "inchoo_warehouse_location" has to be set manually * Original: Sales Order Invoice PDF model * * @category Inchoo * @package Inhoo_Invoice * @author Mladen Lotar - Inchoo <mladen.lotar@inchoo.net> */ class Inchoo_Invoice_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice { public function getPdf($invoices = array()) { $this->_beforeGetPdf(); $this->_initRenderer('invoice');   $pdf = new Zend_Pdf(); $this->_setPdf($pdf); $style = new Zend_Pdf_Style(); $this->_setFontBold($style, 10);   foreach ($invoices as $invoice) { if ($invoice->getStoreId()) { Mage::app()->getLocale()->emulate($invoice->getStoreId()); } $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page;   $order = $invoice->getOrder();   /* Add image */ $this->insertLogo($page, $invoice->getStore());   /* Add address */ $this->insertAddress($page, $invoice->getStore());   /* Add head */ $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()));   $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $this->_setFontRegular($page); $page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8');   /* Add table */ $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92)); $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5);   $page->drawRectangle(25, $this->y, 570, $this->y -15); $this->y -=10;   /* Add table head */ $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4)); $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8'); //Added for custom attribute "inchoo_warehouse_location" $page->drawText(Mage::helper('sales')->__('Warehouse Location'), 245, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('SKU'), 325, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');   $this->y -=15;   $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));   /* Add body */ foreach ($invoice->getAllItems() as $item){ if ($item->getOrderItem()->getParentItem()) { continue; }   if ($this->y < 15) { $page = $this->newPage(array('table_header' => true)); }   /* Draw item */ $page = $this->_drawItem($item, $page, $order); }   /* Add totals */ $page = $this->insertTotals($page, $invoice);   if ($invoice->getStoreId()) { Mage::app()->getLocale()->revert(); } } $this->_afterGetPdf();   return $pdf; }   public function newPage(array $settings = array()) { /* Add new table head */ $page = $this->_getPdf()->newPage(Zend_Pdf_Page::SIZE_A4); $this->_getPdf()->pages[] = $page; $this->y = 800;   if (!empty($settings['table_header'])) { $this->_setFontRegular($page); $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92)); $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 570, $this->y-15); $this->y -=10;   $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4)); $page->drawText(Mage::helper('sales')->__('Product'), 35, $this->y, 'UTF-8'); //Added for custom attribute "inchoo_warehouse_location" $page->drawText(Mage::helper('sales')->__('Warehouse Location'), 245, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('SKU'), 325, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');   $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->y -=20; } return $page; } }

==============

Step 3


Now, you’ve done it. Test it out by going to “Sales->Invoices->(View any of them)->Print”. You shoud be asked to download PDF, and when you do, it should contain “Warehouse Location” by each of order items.
All you have to do is test it out and / or change it according to your needs!
I hope this was of help to someone!

Wednesday, 2 March 2016

How to Registration and user chacked Api in PHP

<?php

// Include confi.php
include_once('../confi.php');
//$apikey = "123456789";
//if ($_GET['apikey'] == $apikey) {

if($_SERVER['REQUEST_METHOD'] == "POST"){
// Get data
$fname = isset($_POST['fname']) ? mysql_real_escape_string($_POST['fname']) : "";
$lname = isset($_POST['lname']) ? mysql_real_escape_string($_POST['lname']) : "";
$email= isset($_POST['email']) ? mysql_real_escape_string($_POST['email'])  : "";
$mobile_number = isset($_POST['mobile_number']) ? mysql_real_escape_string($_POST['mobile_number']) : "";
$house_number= isset($_POST['house_number']) ? mysql_real_escape_string($_POST['house_number']) : "";
$pass= isset($_POST['pass']) ? mysql_real_escape_string($_POST['pass']) : "";
$r_city= isset($_POST['r_city']) ? mysql_real_escape_string($_POST['r_city']) : "";
$r_socitey= isset($_POST['r_socitey']) ? mysql_real_escape_string($_POST['r_socitey']) : "";



// Insert data into data base
//$sql = "INSERT INTO `sub_category` (`subcat_id`,`sub_name`,`sub_description`,`category_id`) VALUES (NULL,'$subcat_name','$sub_description','$catgory_id');";
 $sql = "insert into register(r_id,fname,lname,email,mobile_number,house_number,pass,r_city,r_socitey) VALUES (NULL,'$fname','$lname','$email','$mobile_number','$house_number','$pass','$r_city',$r_socitey)";
$qur = mysql_query($sql);
$result =array();
if($qur){
$result[] = array("msg" => "Your Registration Has Completed Successfully","r_id" => mysql_insert_id(),"fname" => $fname,"lname" => $lname,"email" => $email,"mobile_number" => $mobile_number,"house_number" => $house_number,"r_city" => $r_city,"r_socitey" => $r_socitey);

$json = array("status" => 1, "info" => $result);
}else{
$json = array("status" => 0, "msg" => "Error Registration Form ");
}


}else{
$json = array("status" => 0, "msg" => "Request method not accepted");
}



@mysql_close($conn);

/* Output header */
header('Content-type: application/json');
echo json_encode($json);

Monday, 29 February 2016

HOw to Update Join Query in Mysql

Query
 ======
 $sql="Update sub_category as  sub,category as cat SET sub.sub_name='$itemname',sub.sub_description='$txtitemdesc',sub.stock_day='$txtstockday',cat.category_description='$txtcatdesc',cat.category_name='$txtcatname' where sub.category_id=cat.cat_id and sub.subcat_id='$idget'";

 Example
 ========
 Update sub_category as sub,category as cat SET sub.sub_name='poteto1',sub.sub_description='This is poteto1',sub.stock_day='71',cat.category_description='In everyday usage, a vegetable is any part of a plant that is consumed by humans as food as part of a savory meal.1',cat.category_name='Vegetables1' where sub.category_id=cat.cat_id and sub.subcat_id='5'

Thursday, 11 February 2016

How To bulk product import woocommerce Wordpress

Step-1  Installation This Plugin
        Name Import any XML or CSV File to WordPress
        Link

Step-2  Download  plugins
        Name WP All Import - WooCommerce Add-On
        Link

Friday, 29 January 2016

How to pagination and search,ascending or descending display data With javascript



This Code put Header Part 
=====================================
<link href='https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css' rel='stylesheet' type='text/css'>
<script src="//code.jquery.com/jquery-1.12.0.min.js" type="text/javascript"></script>
 <script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js" type="text/javascript"></script>
 <script>
$(document).ready(function() {
    $('#example').DataTable( {
        "order": [[ 3, "desc" ]]
    } );
} );
</script>
=====================================
This Code in your Body tag 
<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
        <tbody>
            <tr>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>
</tbody>
    </table>
=========================
 then Run Click here

Friday, 22 January 2016

How to Database copy to All table with Database in mysql

Step 1
    Go to your Old Database  then
Step 2
    select   oprations tab
Step 3   Copy database to:
         select Switch to copied database
select Add AUTO_INCREMENT value
select CREATE DATABASE before copying
select  Structure and data


Click Here

 

Friday, 8 January 2016

PayPal gateway has rejected request. Payment has already been made for this InvoiceID (#10412: Duplicate invoice) in magento



Step 1 > Enter your business account and go to Profile
Step 2 > payment Recieving  Preferences
Step 3 >and set Block accidental payments to No.

 Click