Home > Magento, Programming > Magento: Curl Inside Pdf Fcall

Magento: Curl Inside Pdf Fcall

December 19th, 2009

We have added a CURL code snippet to approve affiliate sales when an invoice is created. However it does not seem to work, any idea if this is wrong altogether, or how we can get the right code for including the orderId?

We have almost no way of testing as we have no test envrionment for this. You must have good knowlegde in programming and how these calls to pdf invoice creating works, as it never sees the browser, yet is need to execute the curl (or filegetcontents) for each created invoice/order#. I bet if you know how this works, you don’t even need knowledge of Magento and you can just tell me what i need to do.

Please bid if you know how to fix.

[code]
class Mage_Sales_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Abstract
{
public function getPdf($invoices = array())
{
$this->_beforeGetPdf();
$this->_initRenderer('invoice');

$pdf = new Zend_Pdf();
$style = new Zend_Pdf_Style();
$this->_setFontBold($style, 10);

foreach ($invoices as $invoice) {
$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')->__('Product'), 35, $this->y, 'UTF-8');
$page->drawText(Mage::helper('sales')->__('SKU'), 240, $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;
}

$shift = array();
if ($this->y<15) {
/* Add new table head */
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
$this->y = 800;

$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');
$page->drawText(Mage::helper('sales')->__('SKU'), 240, $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;
}

/* Draw item */
$this->_drawItem($item, $page, $order);
}

/* Add totals */
$this->insertTotals($page, $invoice);
}

$this->_afterGetPdf();

// START APPROVING COMMISSION:
$ch = curl_init();
$timeout = 10; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://www..com/API/scripts/approve_commission.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, "secret=44ℴ_number=".$order->getOrderId()."");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
// END APPROVING COMMISSION

return $pdf;
}
}
[/code]


Magento: Curl Inside Pdf Fcall

Categories: Magento, Programming Tags: , , , , , ,
Comments are closed.
Bear