Tuesday, March 26, 2013

Daily AB Workout for Myself

I really do need some daily ab workout.
- 20 bicycle crunches
- 30 second plank
- 40 mountain climber
- 30 raised knee crunches
- 20 Russian twists
- 12 jack-knife sit-ups

ab-workout

Thursday, March 7, 2013

Programming Lectures from Stanford and MIT

These are programming lectures from Stanford University and MIT on Youtube.
These lectures are pretty basic but also very important for building fundamental concepts in computer science.
Now I'm re-taking these classes again online for free. :)
Thanks to Youtube, Stanford and MIT.



28 Lectures on Programming Methodology - Stanford University
https://www.youtube.com/watch?v=KkMDCCdjyW8&list=EC84A56BC7F4A1F852



27 Lectures on Programming Abstraction - Stanford University
https://www.youtube.com/watch?v=kMzH3tfP6f8&list=ECFE6E58F856038C69



27 Lectures on Programming Paradigms - Stanford University
https://www.youtube.com/watch?v=Ps8jOj7diA0&list=EC9D558D49CA734A02



23 Lectures on Introduction to Algorithms - MIT
https://www.youtube.com/watch?v=JPyuH4qXLZ0&list=EC8B24C31197EC371C

Monday, January 21, 2013

마젠토에서 손님의 Store Credit을 더하거나 빼는 방법

Customer Balance/Store Credit은 마젠토 엔터프라이즈 버전에 있는 기능입니다.
Customer Balance나 Store Credit은 마젠토에서 서로 같은 의미로 사용됩니다.
마젠토의 관리자 모드에서는 "Store Credit"이라는 어휘를 사용하지만, 마젠토 코어 코드에서는 "Customer Balance"라는 어휘를 사용합니다.
왜 그렇게 헷갈리게 해놓았는지는 모르지만.. 뭐.. 이유가 있겠죠.

기본적으로 이 기능은 손님이 계정에 스토어 크레딧을 저장해 두었다가 나중에 체크아웃할때 사용할수 있는 기능이며,
사이트 운영자가 손님에게 refund 해줄때도 크레딧카드에 해줄필요 없이 계정에 크레딧으로 돌려주게 되므로 운영자 입장에서는 여러모로 유용하게 사용될수 있습니다.

사실 스토어 크레딧은 마젠토의 관리자 모드에서 수동으로 조정할수 있지만, 여러명의 손님에게 벌크로 스토어 크레딧을 지정해 줄 경우 아래의 코드가 유용하게 사용될것 입니다.

[ccln_php]
// 스토어 크레딧을 주려는 손님의 이메일주소
$customerEmail = "email@email.com";
// 손님에게 주려는 크레딧의 양
$deltaAmount = 100;

// 커스토머 모델 로딩
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());

// $customer->load($customerId); 로 해도 무관함
$customer->loadByEmail($customerEmail);

if($customer->getId()) {
// 밸런스 모델 로딩
$balance = Mage::getModel('enterprise_customerbalance/balance')->setCustomer($customer);
$balance->setWebsiteId($customer->getWebsiteId());
$balance->loadByCustomer();

// 밸런스 값 세팅
$balance->setAmountDelta($deltaAmount);
// 밸런스 메모 입력
$balance->setUpdatedActionAdditionalInfo('Balance added by php script');
// 밸런스가 책정되면 자동으로 이메일이 보내지지만, 아래와같이 'false'를 세팅해두면 이메일을 보내지 않습니다.
$balance->setNotifyByEmail(false);
// 저장
$balance->save();
}
?>
[/ccln_php]

밸런스의 값을 세팅하는 $balance->setAmountDelta($deltaAmount); 에서 $deltaAmount 의 값은 -100을 지정하는 경우 현재 밸런스에서 100달러를 빼게 되고, 100을 지정하면 100달러를 더하게 됩니다.
그리고 $balance->setNotifyByEmail(false); 를 사용하지 않으면 기본적으로 자동 이메일을 보내게 되니 유념하시기 바랍니다.

Saturday, November 17, 2012

마젠토 region 과 country 코드

마젠토에는 국가별 코드와 이름이 이미 데이터베이스에 기본적으로 저장되어있고, 미국같은 경우는 state 코드/이름 또한 저장되어있습니다.
간혹 개발자가 커스텀으로 모듈이나 템플릿을 만드는 도중 마젠토 데이터베이스에 저장되어있는 국가(country)나 state(region)을 불러내야 할 경우가 있는 있는데, 아마도 아래 코드가 도움이 되리라 생각됩니다.

[ccln_php]
// 국가의 콜렉션 로딩
$countryCollection = Mage::getModel('directory/country_api')->items();

// 위의 콜렉션을 select dropdown box에 넣어야 할 경우
?>

[/ccln_php]

국가의 콜렉션을 사용하려면 directory/country_api 모델을 사용해야 합니다.
마찬가지로 region 콜렉션을 사용하려면 아래와 같이 directory/region_api 모델을 사용해야 합니다.

[ccln_php]
// region 콜렉션 로딩
// $counotryCode 는 국가 코드
$regionCollection = Mage::getModel('directory/region_api')->items($countryCode);

// 위의 콜렉션을 select dropdown box에 넣어야 할 경우
?>

[/ccln_php]


국가 코드로 국가 이름 불러오기
[ccln_php]
$countryName = Mage::getModel('directory/country')->load($countryCode)->getName();
?>
[/ccln_php]

Tuesday, October 30, 2012

Zend Framework 1 and Zend Framework 2

Zend, a PHP company, released Zend Framework 2 stable version recently and I started working on some projects using Zend Framework 2 right after it came out.
I've been working on Magento(an E-Commerce platform that is built on top of Zend Framework 1) for last 4 years.
At the time I started working on Magento, I knew what Zend Framework was but never had any experience with it.
I had more experience with CodeIgniter and I thought CodeIgniter would be a better platform for its simplicity.
However, after I worked on Magento for several months, I became a big fan of Magento and Zend Framework.
Of course, I've been struggling for first couple weeks because of its complexity - I wasn't familiar with Singleton pattern and EAV model.
Now I have more favor on Zend Framework over CodeIgniter.
I would say Zend Framework is complex and difficult to learn than any other PHP frameworks out there, but I think it's the best framework on the market right now.

Features and concepts overview on ZF1 and ZF2:

Main features on Zend Framework 1:

  • MVC(Model View Controller) architecture

  • Singleton

  • Registries

  • Hard & Soft coded Dependencies

  • Loosely coupled architecture



 

Zend Framework 2 resembles Zend Framework 1 in many ways, but it works differently.

Main features on Zend Framework 2:

  • Event Driven Services - Event Manager & Service Manager

  • Dependency Injection - to avoid dependencies, ZF2 uses events

  • Aspect Oriented Programming - shape the workflow using event manager

  • Namespaces - requires PHP 5.3

  • Lambda functions

  • developers can install only the components desired - don't need to install entire framework



 

Useful resources on ZF2: