마젠토는 EAV(Entity Attribute Value) 모델을 사용함으로써 각각의 객체모델에 attribute과 attribute의 값어치(value)를 생성시킬수 있습니다.
예를들어 product model 같은경우 마젠토 admin에서 새로운 product attribute을 생성시킬수 있습니다. 그리고 그 attribute의 갯수는 얼마든지 무한대로 늘일수 있습니다.
하지만 category model의 경우 마젠토 admin에서 새로운 category attribute을 생성시키는 기능이 없기 때문에 새로운 attribute을 카테고리에 더하고 싶어도 할수가 없습니다.
사실 마젠토 admin에서 category attribute을 생성시키는 기능이 없는 것일뿐 못하는것은 아닙니다.
마젠토는 EAV 모델을 사용하고 있고 product model과 마찬가지로 category model 또한 entity이며 그 entity에는 attribute과 value를 생성시킬수 있기 때문에 category attribute도 생성시킬수 있습니다.
그렇다고 이것을 phpMyAdmin 이나 adminer 같은 데이터베이스 툴을 사용해서 데이터베이스에 직접 attribute을 생성시키는것은 많은 위험이 따르구요,
아래와 같은 코드로 손쉽게 생성 및 삭제시킬수 있습니다.
category attribute 생성
[ccln_php]
// 마젠토 로딩
Mage::app();
// EAV 모델 셋업 model
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
// 이미지 셀렉터 생성
$setup->addAttribute('catalog_category', 'extra_image', array(
'group' => 'General',
'input' => 'image',
'type' => 'varchar',
'label' => 'Slider Image',
'backend' => 'catalog/category_attribute_backend_image',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
// 텍스트 필드 생성
$setup->addAttribute('catalog_category', 'extra_text', array(
'group' => 'General',
'input' => 'textarea',
'type' => 'text',
'label' => 'SEO Text',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
// Yes, No같은 boolean value 생성
$setup->addAttribute('catalog_category', 'extra_boolean', array(
'group' => 'General',
'input' => 'select',
'type' => 'int',
'label' => 'Yes or No',
'backend' => '',
'source' => 'eav/entity_attribute_source_boolean',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
?>
[/ccln_php]
위의 코드는 extra_image, extra_text 그리고 extra_boolean 이란 category attribute을 생성시키는 코드구요, 마젠토 admin에서 category로 들어가시면 각각의 카테고리에 3개의 새로생긴 필드를 찾을수 있습니다.
각각의 attribute에서
group은 attribute이 나오는 그룹
input은 input 필드의 타입
type은 데이터베이스에 저장되는 value의 type
label은 admin에 나오는 텍스트 레이블
backend는 input 필드가 사용할 model
source는 기본적으로 데이터베이스에 저장되어 있는 값어치
를 나타냅니다.
반대로 생성된 attribute을 삭제하는 방법은 아래 코드를 참조하세요.
[ccln_php]
// 마젠토 로딩
Mage::app();
// EAV 모델 셋업 model
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
// category attribute 삭제
$setup->removeAttribute('catalog_category', 'extra_image');
$setup->removeAttribute('catalog_category', 'extra_text');
$setup->removeAttribute('catalog_category', 'extra_boolean');
?>
[/ccln_php]
위의 코드는 새로 생성된 3개의 category attribute을 삭제시킵니다.
Saturday, August 18, 2012
Wednesday, March 28, 2012
마젠토 콜렉션(Collection) 사용하기
마젠토 콜렉션(Collection)은 한번에 여러개의 객체(product, customer, category 등등)를 불러오는데 사용됩니다.
예를들어 카테고리 페이지에있는 모든 제품을 불러온다던지, 모든 커스토머(customer) 정보를 불러올때 유용하게 쓰입니다.
아래와 같은 php코드를 루트에 올려놓고 시험해 보세요.
[ccln_php]
require_once "app/Mage.php";
Mage::app();
// 모든 제품 불러오기
$collection = Mage::getResourceModel('catalog/product_collection'); // 첫번째 방법
$collection = Mage::getModel('catalog/product')->getCollection(); // 두번째 방법
// 모든 제품이 필요하지는 않으므로 5개만 로드합니다.
$collection->getSelect()->limit(5);
$collection->load(); // 콜렉션을 불러옵니다.
foreach($collection AS $product) {
// 제품의 모든 데이터 출력
print_r($product->getData());
}
[/ccln_php]
위의 코드를 실행해 보시면 제품의 모든 데이터가 출력이 됩니다.
콜렉션 객체를 불러올때 두가지 방법을 보여드렸는데 첫번째 방법과 두번째 방법의 결과가 약간은 틀린걸 확인할수 있습니다.
첫번째 방법은 최소한의 데이터만 로드함으로써 메모리의 사용을 최대한 줄이는 방법이고,
$collection = Mage::getResourceModel('catalog/product_collection');
두번째 방법은 제품의 모든 데이터를 불러옴으로써 메모리 사용에 상관없이 콜렉션을 사용하는 방법입니다.
$collection = Mage::getModel('catalog/product')->getCollection();
개인적으로 메모리 사용이 적은 첫번째 방법을 선호합니다.
그렇다고 필요한 제품의 데이터를 불러오지 못하는것은 아닙니다.
아래와 같이 addAttributeToSelect()을 사용해서 필요한 Attribute을 불러올수 있습니다.
[ccln_php]
require_once "app/Mage.php";
Mage::app();
$collection = Mage::getResourceModel('catalog/product_collection');
// 아래처럼 원하는 attribute을 콜렉션에 포함시킬수 있습니다.
$collection->addAttributeToSelect('price');
$collection->addAttributeToSelect('weight');
// 모든 제품이 필요하지는 않으므로 5개만 로드합니다.
$collection->getSelect()->limit(5);
$collection->load(); // 콜렉션을 불러옵니다.
foreach($collection AS $product) {
// 제품의 모든 데이터 출력
print_r($product->getData());
}
[/ccln_php]
Attribute으로 불러올 데이터를 addAttributeToFilter()를 사용해서 걸러낼수도 있습니다.
예를들어 id가 10보다 커야 한다던지 sku가 'abcd'를 포함해야 하는경우 아래와 같이 콜렉션을 설정할수 있습니다.
[ccln_php]
require_once "app/Mage.php";
Mage::app();
$collection = Mage::getResourceModel('catalog/product_collection');
// 아래처럼 원하는 attribute을 콜렉션에 포함시킬수 있습니다.
// product entity_id가 10보다 커야하는경우
$collection->addAttributeToFilter('entity_id', array('gt' => 10));
// price가 $100 이하여야 하는 경우
$collection->addAttributeToFilter('price', array('lt' => 100));
// sku가 'abcd'를 포함해야 하는 경우
$collection->addAttributeToFilter('sku', array('like' => '%abcd%'));
// sku가 'zzz1'이 아니어야 하는 경우
$collection->addAttributeToFilter('sku', array('neq' => 'zzz1'));
// description이 아무것도 없는 제품을 포함하는 경우
$collection->addAttributeToFilter('description', 'null');
$collection->load(); // 콜렉션을 불러옵니다.
foreach($collection AS $product) {
// 제품의 모든 데이터 출력
print_r($product->getData());
}
[/ccln_php]
이런식으로 addAttributeToSelect()나 addAttributeToFilter()를 사용해서 원하는 attribute을 콜렉션에 포함시키거나 필터를 적용해서 걸러낼수 있습니다.
콜렉션의 사용은 한번에 많은 객체를 불러와야 할때, 또 한번에 여러 객체의 정보를 수정해야할때 유용하게 쓰입니다.
예를들어 카테고리 페이지에있는 모든 제품을 불러온다던지, 모든 커스토머(customer) 정보를 불러올때 유용하게 쓰입니다.
아래와 같은 php코드를 루트에 올려놓고 시험해 보세요.
[ccln_php]
require_once "app/Mage.php";
Mage::app();
// 모든 제품 불러오기
$collection = Mage::getResourceModel('catalog/product_collection'); // 첫번째 방법
$collection = Mage::getModel('catalog/product')->getCollection(); // 두번째 방법
// 모든 제품이 필요하지는 않으므로 5개만 로드합니다.
$collection->getSelect()->limit(5);
$collection->load(); // 콜렉션을 불러옵니다.
foreach($collection AS $product) {
// 제품의 모든 데이터 출력
print_r($product->getData());
}
[/ccln_php]
위의 코드를 실행해 보시면 제품의 모든 데이터가 출력이 됩니다.
콜렉션 객체를 불러올때 두가지 방법을 보여드렸는데 첫번째 방법과 두번째 방법의 결과가 약간은 틀린걸 확인할수 있습니다.
첫번째 방법은 최소한의 데이터만 로드함으로써 메모리의 사용을 최대한 줄이는 방법이고,
$collection = Mage::getResourceModel('catalog/product_collection');
두번째 방법은 제품의 모든 데이터를 불러옴으로써 메모리 사용에 상관없이 콜렉션을 사용하는 방법입니다.
$collection = Mage::getModel('catalog/product')->getCollection();
개인적으로 메모리 사용이 적은 첫번째 방법을 선호합니다.
그렇다고 필요한 제품의 데이터를 불러오지 못하는것은 아닙니다.
아래와 같이 addAttributeToSelect()을 사용해서 필요한 Attribute을 불러올수 있습니다.
[ccln_php]
require_once "app/Mage.php";
Mage::app();
$collection = Mage::getResourceModel('catalog/product_collection');
// 아래처럼 원하는 attribute을 콜렉션에 포함시킬수 있습니다.
$collection->addAttributeToSelect('price');
$collection->addAttributeToSelect('weight');
// 모든 제품이 필요하지는 않으므로 5개만 로드합니다.
$collection->getSelect()->limit(5);
$collection->load(); // 콜렉션을 불러옵니다.
foreach($collection AS $product) {
// 제품의 모든 데이터 출력
print_r($product->getData());
}
[/ccln_php]
Attribute으로 불러올 데이터를 addAttributeToFilter()를 사용해서 걸러낼수도 있습니다.
예를들어 id가 10보다 커야 한다던지 sku가 'abcd'를 포함해야 하는경우 아래와 같이 콜렉션을 설정할수 있습니다.
[ccln_php]
require_once "app/Mage.php";
Mage::app();
$collection = Mage::getResourceModel('catalog/product_collection');
// 아래처럼 원하는 attribute을 콜렉션에 포함시킬수 있습니다.
// product entity_id가 10보다 커야하는경우
$collection->addAttributeToFilter('entity_id', array('gt' => 10));
// price가 $100 이하여야 하는 경우
$collection->addAttributeToFilter('price', array('lt' => 100));
// sku가 'abcd'를 포함해야 하는 경우
$collection->addAttributeToFilter('sku', array('like' => '%abcd%'));
// sku가 'zzz1'이 아니어야 하는 경우
$collection->addAttributeToFilter('sku', array('neq' => 'zzz1'));
// description이 아무것도 없는 제품을 포함하는 경우
$collection->addAttributeToFilter('description', 'null');
$collection->load(); // 콜렉션을 불러옵니다.
foreach($collection AS $product) {
// 제품의 모든 데이터 출력
print_r($product->getData());
}
[/ccln_php]
이런식으로 addAttributeToSelect()나 addAttributeToFilter()를 사용해서 원하는 attribute을 콜렉션에 포함시키거나 필터를 적용해서 걸러낼수 있습니다.
콜렉션의 사용은 한번에 많은 객체를 불러와야 할때, 또 한번에 여러 객체의 정보를 수정해야할때 유용하게 쓰입니다.
Tuesday, March 20, 2012
네이버 미국,캐나다 지역 키워드광고 대행
네이버 미국,캐나다 지역 키워드광고 대행
네이버가 미주(미국,캐나다)지역으로 영역을 넓히면서(http://us.naver.com) 광고영업 또한 확장하고 있습니다.
네이버의 주된 광고상품은 크게 디스플레이 광고(배너 광고)와 키워드 광고가 있는데 이번에 제가 네이버 미주지역의 키워드 광고 대행을 맡았습니다.
미주지역에서의 네이버 광고는 크게 디스플레이광고와 키워드광고로 나뉠수 있는데요,
디스플레이광고는 주로 가격이 비싼 배너광고이고, 키워드광고는 키워드 검색결과내에 보여지는 좀더 저렴한(월$100부터) 광고입니다.
미주지역의 키워드 광고는 한국내 키워드광고 같은 PPC(Pay Per Click)나 CPC(Cost Per Click)이 아닌 CPM(Cost Per Milli)의 성격을 가집니다.
쉽게말해 한국에서의 키워드 광고는 사용자가 클릭하는 숫자 만큼 지불해야하지만, 미주지역의 키워드 광고는 사용자의 클릭수와 관계없이 정해진 금액으로 일정한 광고위치를 구매하는것입니다.
NHN USA Inc. 관계자에 따르면 아직 시작하는 단계이기 때문에 단순한 모델로 시작한다고 하는데요, 결국엔 미주지역의 키워드 광고도 한국의 키워드 광고처럼 PPC/CPC 모델로 바뀐다고 합니다.
미주지역 네이버 키워드 광고에 대한 자세한 내용 및 문의는 아래 링크를 참조해 주시기 바랍니다.
네이버 미주 키워드 광고 문의
Tuesday, March 6, 2012
Magento Certified Developer PLUS
Magento Certified Developer PLUS
I just passed the Magento Certified Developer Plus exam.
It's wasn't easy but I would say it wasn't too difficult either.
Probably that's because I've seen a lot of postings and comments on other websites and blogs about Certified Developer PLUS exam being too intense, and to be honest, I didn't feel like I was ready and I thought I would fail the exam even before I take it.
Overall, if you're familiar with the Magento fundamentals, have good enough experience on Magento and confident about custom module/extension development, you don't have to worry about the exam.
If you don't have much experience with Magento, but you studied the Magento Certification Study Guide thoroughly, you might be ok, but at the same time, you could feel that exam questions are tricky and confusing.
Other than that, don't take it until you feel comfortable with Magento.
P.S
I have 3+ years of experience with Magento from version 1.3 to 1.11, and have worked on more than 25+ Magento websites.
For more information about the certification: Magento Developer Certification
Thursday, January 19, 2012
준비하는 자가 승리한다
준비하는 자가 승리한다
불길이 무섭게 타올라도 끄는 방법이 있고
물결이 하늘을 뒤덮어도 막는 방법이 있으니
화는 위험한 때 있는 것이 아니고
편안할 때 있으며
복은 경사 때 있는 것이 아니라
근심할 때 있는 것이다.
- 매월당 김시습 -
불길이 무섭게 타올라도 끄는 방법이 있고
물결이 하늘을 뒤덮어도 막는 방법이 있으니
화는 위험한 때 있는 것이 아니고
편안할 때 있으며
복은 경사 때 있는 것이 아니라
근심할 때 있는 것이다.
- 매월당 김시습 -
Subscribe to:
Posts (Atom)