Django 1.2.3 – for what I loving it

In Django, Publisy on June 28th, 2011

Django 1.2 - for what I am loving it

Magento – Discount Coupon in quick checkout review step

In Magento on June 15th, 2011

For Magento 1.4.1
———–

If you configure onepage checkout in Magento store, buyers will have no chance to use discount coupon. However, there’s way to do so with little customization. I have implemented coupon in review step of onepage checkout.
Magento - discount coupon in onepage checkout

1. Override Onepage checkout model – core/Mage/Checkout/controllers/OnepageController.php. Here mainly you have to override _getReviewHTML() function and add function to save/remove coupon code.

  1. function _getReviewHtml()
  2. {
  3.  $text = $this->getLayout()->getBlock('root')->toHtml();
  4.  
  5.  $text .= '<form id="discount-coupon-form" action="/checkout/onepage/coupon/" method="post">';
  6.  $text .= '<label for="coupon_code"> ' . $this->__('Enter your coupon code if you have one.') . '</label><br />';
  7.  //$text .= '<input type="hidden" name="remove" id="remove-coupone" value="0" />';
  8.  //if(!strlen($this->getCouponCode()))
  9.  $text .= '<input class="input-text" id="coupon_code" name="coupon_code" value="' . $this->_getQuote()->getCouponCode() . '"/>';
  10.  $text .= '<input type="hidden" id="coupon" name="coupon" value="1"/>';
  11.  $text .= '&nbsp;&nbsp;&nbsp;<button type="button" class="button" onclick="updateCupon()" value="' . $this->__('Apply Coupon') .'"><span>' . $this->__('Apply Coupon') .'</span></button>';
  12.  $text .= '</form>';
  13.  
  14.  return $text;
  15. }
  16.  
  17. /**
  18.  * Coupon check
  19.  */
  20. function couponAction()
  21. {
  22.  $this->loadLayout('checkout_onepage_review');
  23.  
  24.  $this->couponCode = (string) $this->getRequest()->getParam('coupon_code');
  25.  
  26.  Mage::getSingleton('checkout/cart')->getQuote()->getShippingAddress()->setCollectShippingRates(true);
  27.  Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode(strlen($this->couponCode) ? $this->couponCode : '')
  28.    ->collectTotals()
  29.    ->save();
  30.  
  31.  $result['goto_section'] = 'review';
  32.  $result['update_section'] = array(
  33.   'name' => 'review',
  34.   'html' => $this->_getReviewHtml()
  35.  );
  36.    
  37.  $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
  38. }

couponAction() update cart validating coupon number. May be you want to improve _getReviewHTML(), but I wanted quick solution, and without modifying core.

2. Edit onepage.phtml template. You need to add some javascript code.

  1. <script type="text/javascript">
  2. //<![CDATA[
  3. function updateCupon() {
  4.  $('discount-coupon-form').request({
  5.   method: 'post',
  6.   onComplete: payment.onComplete,
  7.   onSuccess: payment.onSave,
  8.   onFailure: checkout.ajaxFailure.bind(checkout),
  9.  })
  10. }
  11. //]]>
  12. </script>

This script will submit coupon with ajax using post method. And it will update review HTML using regular checkout function.

For Magento 1.4.1

Nepal Unites – Social Enterprise?

In EMBA on June 14th, 2011

Nepal UnitesAmong those slogans of New Nepal and Nepal Divides, there’s social forum which talk about Nepal Unites. The group is non-other than Nepal Unites. If you have facebook account, you might already have know it. They are pretty pioneer to run facebook campaign. Campaign like Die Nepal Bandha Die, No to Bandha – Yes to Constitution, Stop Funding International Travel of for all CA Lawmakers are few to name.

I have participated some of its campaign physically and most virtually (virtually? Yes, that’s what they do). However, today I had chance to learn more about it. Anil Chitrakar and Ujjwol Thapa, early initiators, had given guest lecturer as part EMBA course. Basically it’s open social forum where any people can participate with idea of uniting against social problem. Group claim that it is not organization but it is an idea and it does not have formal leader. As currently country is facing political crisis with nearing deadline of constitutions preparation, high focus of group is political issues. So any one easily mis-interpret about group. But that’s not the case in real. Mr. Chitrakar said any one can come with idea and use platform to voice against social problem. For example, one can make group Nepal Unites against Corruption, Nepal Unites for Better Education.

Forum has fairly grown since inception of idea. Some of successful campaign are bike rally against Bandha, Stopping CA Lawmakers travelling abroad. There’s inclusion of different demographic and involvement of self-motivated people. Some examples are New Generation Rock Singer, Abhaya Subbha lunching music for campaign, painters painting Nepal Unites slogan in street wall. He re-call memory of high-involvement of people, where they have been able to build fund of Rs. 1 million. Money will be used to pay as compensation to those bikers who participate in bike rally against bandha in case of bike is destroyed by bandha organizers. Not only within Nepal, but also Nepal Unites has reach overseas like Nepal Unites UK, Nepal Unites Australia.

From view point of a student, question raised in my mind “Is Nepal Unites social enterprise?”. After the class, I went to Wikepedia and learn that social entrepreneurship recognize social problem and and uses entrepreneurial principles to organize, create and manage a venture to achieve social change. Although mostly social enterprises is non-profit like NGOs, INGOs, some profit making business also falls under this category. Wikipedia further cite the example contemporary social entrepreneurs like Muhammad Yunus of Grameen Bank, Vikas Sutaria of Bhookh.com.

Again, lets come to the point of Nepal Unite. It’s not NGO, it does not have formal leader, it doesn’t talk about financial profit. But it address social problem, it talk about change (change within). For those non-MBA people, there’s lot questions which is challenge for group. Is it political pressure group? Is it politically affiliated? Where does it go in long-run? Few people blame it being focus on political issues, city-focused. But, again is “can we call Nepal Unites social enterprises?” What’s your thought?