Showing posts with label magento. Show all posts
Showing posts with label magento. Show all posts

Tuesday, May 29, 2012

Magento deleting an order

It have been some argument about able to cancel or delete a processed or shipped or completed order.
But by end of the day, there are reasons that people want to delete the order.
Be it by mistake, or due to testing the order.

I finally found a extension which works with magento 1.6.2, but it does not cover properly for 1.6.2.
http://www.magentocommerce.com/magento-connect/seamless-delete-order.html

So i ended up altering the module block to support it.
http://www.mercstudio.net/assets/files/EM_DeleteOrder-1.0.5.tar.gz


But due to the nature of the reporting in magento, its not possible to delete the cached reports in the database using this extension.
It can only be deleted based on date, but becareful with this procedures.
The reporting tables for sales order are:
sales_order_aggregated_created
sales_invoiced_aggregated_order
sales_refunded_aggregated
sales_refunded_aggregated_order
sales_shipping_aggregated

Please note that i do not responsible for any data lost in the extension. So do the original developer himself. Please remember to backup your database in system > tools > backup before applying this extension and deleting any order.

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")

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);

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/

Sunday, February 26, 2012

magento shipping table rates import

Magento shipping method have to be set in 2 different environment.
One on config, and another on site.
To import or export the rates, you will need to select "site" / "Default sites" to have the options to import the rates.
Before setting up these rates, you will have to ensure that you have setup the regions / states on your targeted countries to market.
Its can be set manually in database table on table:
directory_country_region.
Once you have set it, you may run this script to insert the name to the translation table for region name:
directory_country_region_name
If you are lazy like me, i will just run this SQL script below to populate the name to the directory_country_region_name table:

INSERT INTO `directory_country_region_name` (`locale`, `region_id`, `name`) 
SELECT 'en_US', `region_id` , `default_name`
FROM `directory_country_region`
WHERE country_id='ID';

You will have to make sure that the directory_country_region.code field contain a unique code for your state / region. It's a norm to use countrycode-statename to ensure it is unique for every states you setup.
Example: ID-SUMUTR
which represent indonesia: sumatera utara.
In the import CSV, this will be the format of the csv (as of magento 1.6):
Country, Region/State, Zip/Postal Code, Order Subtotal (and above), Shipping Price
Notes:
Country should contain short 2 alphabet code of the country, such as ID = Indonesia
Region/state field will be the field to contain the region/state code.
Order subtotal is optional (0)
Zip / Postal code is optional (empty)
Shipping price will be the price in shop currency.





Sunday, February 5, 2012

Magento inline popup for product

Took me several days and many hours of researching,
Finally, ive made it up to the stage where i can declare glory to my objective :)
Magento uses many combination of configuration to customize to your setting.

Okay, i needed to do a popup to view product without showing a full layout product viewing page.

I didn't wanted to alter the core functionality, as i wanted both:

  1. Exists magento product viewing page with full page layout
  2. A "quick view" button to show just the non-layout based popup


It would be much easier if i could just override the magento product view template by just copying existing template file into my template directory, and modify it as i needed. But this will override the entire product page, so we will no longer have access to the original full layout page.
Just for your reference, here is how its done:
--------------------
copy from:
app/design/frontend/base/default/template/catalog/product/view.phtml
to:
app/design/frontend/default/default/template/catalog/product/view.phtml


other optional files which you may override, but will need to have respective directories name, similar to the base template location:
app/design/frontend/base/default/template/catalog/product/view/*


---------------------

Now, i need to customize the base layout file for all my pages, the product listing, and product viewing page.
I need both, the base layout file to use 1column.phtml, listing page to use only category.phtml layout. And the full view product page to use product.phtml layout.
---------------------
create a file:
app/design/frontend/default/default/layout/local.xml
The content of the file can be edited as show in photo below.
Please take note on the tags: catalog_category_default (listing), catalog_product_view (view), checkout_onepage_index (checkout), default (default / base layout file)

Then upload the respective files to:
app/design/frontend/default/default/layout/template/page/category.phtml
~/product.phtml
~/1column.phtml
You may copy the layout files from app/design/frontend/base/default/template/page/1column.phtml to start out with.
----------------------

Next, i wanted to remove some of the items which i dont use.
So, edit the file app/design/frontend/default/default/layout/local.xml
And add in remove tags under default tag:


---------------------------

And here comes the difficult part, the standalone popup product viewing page, which does not replace existing product viewing full layout.
To do this, we will need to write our own customized module.
You may refer here to learn from begining:
http://magento4u.wordpress.com/2009/06/08/create-new-module-helloworld-in-magento/

Okay, how are we going to allow the user to choose our layout from the CMS module?
Do this, edit:
app/code/local/[namespace]/[module]/etc/config.xml
directly under config tag, add in these tree:
config > global > page > layouts > yourpagename
Make sure to add in all the layout that you wish to be available on the CMS module, such as category.phtml and product.phtml


Once you are familiar with how to write blocks, have it configured to be installed, and integrated with custom blocks, then we can begin writing a extended version of the Catalog/product/view functionality without full layout.

inside your module path:
app/code/local/[namespace]/[module]/etc/config.xml

Create these tags:
config > frontend > layout > updates > mylayout > file > mylayout.xml (content)
global > helpers > mymodule > class > namespace_mymodule_Helper (content)
global > blocks > mymodule > rewrite > myproductview > namespace_mymodule_block_product_view (content)


Notice that the class file is declared for our custom layout "myproductview" which will be seen declared on the next file (mylayouts.xml).
We shall need helper class declared, as default product controller of magento will need a helper class to render the page.

Next, the final layout file:
app/design/frontend/default/default/layout/mylayouts.xml

Create the nodes:
layout > mymodule_product_view (as shown on the photo below)
Then,

Take note that this will also need you to create the file:
app/design/frontend/default/default/template/page/inline.phtml
The file shall content a non html or body tags, to be displayed as popup using lightbox or colorbox.


Now, create the controller file to extend magento product controller:
app/code/local/Namespace/Mymodule/controllers/ProductController.php
Next, create the helper file to extend magento product helper:
app/code/local/Namespace/Mymodule/Helper/Product/View.php


And, create the Block handler file to handle block view for product
app/code/local/Namespace/Mymodule/Blocks/Product/View.php

And finally, duplicate the file
app/design/frontend/base/default/template/catalog/product/view.phtml
to
app/design/frontend/default/default/template/mymodule/product/view.phtml
and modify this file according to your requirement :)

to access the original product page from browser:
http://pathtomagento/catalog/product/view?id=[productid]&category=[categoryid]
to access your customized popup page (standalone) from browser:
http://pathtomagento/mymodule/product/view?id=[productid]&category=[categoryid]


Friday, January 27, 2012

magento enable cookie issue on chrome and ie

I came across this problem while trying to test my localhost machine for adding a product to cart.
it turn out to be some sort of cookie session issue on magento.

changing session length nor disabling cookie checking does not seems to work.
its suppose to only happen on localhost testing machine, might work well on actual domain.

Setting up vhost and pointing using hosts file shall do the trick...

magento 1.5

Magento 1.5 doesnt allow one to addjs or addskinjs with a custom sorting order...
its because the head.phtml file is doesn't support it in getCssJsHtml() and getIncludes();

One way to solve it is to inject script directly into head.phtml, but put it into your own template folder...
copy from app/design/frontend/base/default/template/page/html/head.phtml to
app/design/frontend/[yourtemplate]/default/template/page/html/

Another thing to take note is getUrl and getSkinURL gotcha...
Example:
$this->getSkinUrl("js/java.js"); // return skin/frontend/[base_or_yourtemplate]/default/js/java.js
but
$this->getUrl("js/java.js"); // return http://yourbasepath.com/js/java.js/


Work around will be using $this->getUrl(""). "js/java.js"

Friday, November 4, 2011

magento rant

First, their javascript validation for setup Fail big time!
once it failed to validate, no matter what you have change in that field, it will not validate anymore!
need to refresh the page, that sucks big time!

installation, took more than 2minutes!
200+tables, omg, do we need that much?

PHP Memory limit of 256MB ?? omg...