Friday, March 30, 2012

installing apc on kloxo

For Yum based OS:
sudo yum install pcre-devel
sudo pecl install apc

Then create /etc/php.d/apc.ini
insert content as follows:
extension=apc.so

then restart httpd

If you are still having some problem installing this, try refer here:

http://www.agileapproach.com/blog-entry/howto-install-pecl-apc-cache-centos-without-xampp

Tuesday, March 27, 2012

Magento Order status does not convert to Processing

Tinkering around to make a payment gateway integration for iPay88 took me some really significant time.
I've been using some method from paypal module to redirect the form to ipay88,
and does a re-query to ipay88 server to determine the approve of transaction from ipay88.
On done, created an invoice and saved the transaction for the invoice.
Payment paid appears correctly, but some how order status still remain "pending".
I realized that i did not set the cctransid to the payment in my controller, 
so one way to do it is to pass the TransId from controller to payment method model.
To do this, create a model class to accommodate values from request form passed in from ipay88,
then in payment method model capture function, retrieve the ipay88 returned model and setCcTransId(...).
When done, the order will now be shown as "processing", depending on the setting in the admin configuration for the payment status on payment.

Sample below:
//getting config saved in admin:
$aConfig = Mage::getStoreConfig("payment/Ipay88");
$merchantcode = $aConfig["merchantcode"];
$oResponse = Mage::getSingleton("Ipay88/Api_Response");
//convert data from postback of ipay88 into oResponse as object data
Varien_Object_Mapper::accumulateByMap($_REQUEST, $oResponse, array(
  "MerchantCode", "PaymentId", "RefNo", "Amount", "Currency", "TransId", "AuthCode", "Status",
  "ErrDesc", "Signature", "Remark")
);

//codes to requery ipay88 for actual transaction
//...
if ($iPayResult == "00") {
  //success
  //update order status and payment status
 if ($oOrder->canInvoice()) {
  $invoice = Mage::getModel('sales/service_order', $oOrder)->prepareInvoice();
  
  if (! $invoice->getTotalQty()) {
   Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
  }
  
  $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
  $invoice->setTransactionId($cctransid);
  //below this will trigger capture in method model
  $invoice->register();
  $transactionSave = Mage::getModel('core/resource_transaction')
  ->addObject($invoice)
  ->addObject($invoice->getOrder());
  
  $transactionSave->save();
 }
}
Next, in the payment method model capture:
public function capture(Varien_Object $payment, $amount)
{
 if (!$this->canCapture()) {
  Mage::throwException($this->_getHelper()->__('Capture action is not available.'));
 }
 
 $oResponse = Mage::getSingleton("Ipay88/Api_Response");
 $payment->setCcTransId($oResponse["TransId"]);
 return $this;
}
Sample of iPay88 Model to hold request data
class MercStudio_Ipay88_Model_Api_Response extends Varien_Object {
  
}
Yes, its an empty class which extends Varien_Object :) The Magic of Varien object is that it accept any data set to it (setVariablename(value) or setData("variablename", value)), and you may retrieve the data by calling getData("variablename")

Monday, March 26, 2012

jQuery .load complete did not fire

This happen when i was dealing with an upgrade from jQuery 1.5 to 1.7.2.
It took me some struggle to find out what happened, and finally, i found the issue.
It seems that the oncomplete function will not run if the document itself somehow contains javascript with syntax error in the script. It wasn't any problem for jQuery1.5, but for jQuery 1.7.2, it seems to halt execution after loading the content to the targeted dom.

MODx Return Error 400 in manager

The recent changes on MODx seems to create a new kind of error 400 on all the javascript used in the manager screen.
The problem comes from issue with minified index.php where it over replaced manager/assets with assets path, therefore doubling the path to the actual javascript file.
The solution have been resolved in the nightly build of MODx 2.2.1.pl

http://tracker.modx.com/issues/7418

Monday, March 19, 2012

Facebook integration hickup

After encountering some weird behaviour of facebook login session on client  side,
i just realized that the flow of the code have to be correct.

window.fbAsyncInit = function(...);

the code above should come first, before including facebook js file below:

[script]http://connect.facebook.net/en_US/all.js[/script]

Friday, March 16, 2012

Linux list top cpu hogging processes

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

Tuesday, March 13, 2012

Magento Export Sales Order Duplicate headers received from server

Its a bug which have been fixed in magento 1.7.
But for 1.6.2 users, you may change the core to fix this in:
app/code/core/Mage/Core/Controller/Varien/Action.php in function _prepareDownloadResponse:

By adding , true as the 3rd parameter in these lines:
->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true)
 ->setHeader('Content-Disposition', 'attachment; filename="'.$fileName.'"', true)
 ->setHeader('Last-Modified', date('r'), true);

Sencha Touch Carousel force slide

var carousel = Ext.getCmp("IDOfCarousel");
carousel.next(); // .previous();

//to get active item
// but note that caroisel.next or previous will take time to animate and reflect.
//  therefor, to jump 3 slide away, just call 3 times and dont expect activeIndex to reflect directly after the call.
carousel.activeIndex


Thursday, March 8, 2012

magento error in admin

by default, magento does not show any error exception in admin / backend.
To enable error, go to :

duplicate errors/local.xml.sample as local.xml

Then you will have the error exception been printed.

Next, if you encounter unable to determine cache_dir,
you may follow the instruction here:
http://www.designersandbox.com/magento/%E2%80%9Ccould-not-determine-temp-directory-please-specify-a-cache_dir-manually%E2%80%9D-after-magento-is-installed/

Wednesday, March 7, 2012

deploying magento live

Backup the local db from magento backend: system > tools > backup

Restore the database and files to server

edit core_config_data (table)
update setting for path: (take note of tailing /)
web/cookie/cookie_domain: [your domain]
web/secure/base% [https://www.yourdomain/]
web/unsecure/base% [http://www.youdomain/]

set permission to og+w
app/etc
var

set permission to og+w
media

Thursday, March 1, 2012

modx package management could not install

After dabling around on my new server,
i realize that the package installer did not work.
Further examination reviewed the error "package could not be found".

So i went into the core/packages and found that the extraction process did not complete.
After searching around, 1 way to work around it is to set under setting,
search for "archive_with" and change it to true.

Make sure to delete the package with "force deletion" and redownload and try install again...
hope it works for you... :)