상품 및 주문 상품을 인용하는 상품 속성


25

Magento에서 상품을 자동으로 유지하여 상품을 인용 한 다음 상품을 주문하는 올바른 방법은 무엇입니까?

작은 구성 XML만큼 간단합니까, 아니면 이벤트 등을 저장하기 전에 살펴 보는 수동 프로세스입니까?

답변:


21

한 가지 방법은 관찰자와 변환기를 사용하는 것입니다.

관찰자는 'test'라는 속성을 사용하여 제품에서 견적으로 속성을 가져오고, 변환기는 견적에서 주문으로 속성을 가져옵니다.

당신의 설정에서 :

<global>
    <fieldsets>
        <sales_convert_quote_item>
            <test>
                <to_order_item>*</to_order_item>
            </test>
        </sales_convert_quote_item>
    </fieldsets>

    <sales>
        <quote>
            <item>
                <product_attributes>
                    <test />
                </product_attributes>
            </item>
        </quote>
    </sales>

    <events>
        <sales_quote_item_set_product>
            <observers>
                <YOUR_MODULE>
                    <class>YOUR_MODULE/observer</class>
                    <method>setTestAttribute</method>
                </YOUR_MODULE>
            </observers>
        </sales_quote_item_set_product>
    </events>
</global>

관찰자에서 :

public function setTestAttribute(Varien_Event_Observer $observer) {

    $item = $observer->getQuoteItem();
    $product = $observer->getProduct();
    $item->setTest($product->getTest());
    return $this;
}

1
잘 했어요 !!!.
— philwinkle

6
향후 Google 직원을위한 경고 :이를 테스트하기 전에 캐시 폴더를 수동으로 삭제하십시오. 백엔드를 통해 인덱스와 캐시를 지우고이 답변에 많은 변형을 테스트하는 데 많은 시간을 보냈습니다. 내가 무엇을 했든, 사용자 정의 속성은 db에 저장되지 않았지만 quote_item의 제목을 변경해도 정상적으로 작동했습니다. / var / cache를 삭제 하여 수동으로 캐시를 지울 때까지 ... Crazy!
— Maurice

판매 주문 세부 정보 페이지의 sku 옆뿐만 아니라 백엔드 패널에서이 사용자 정의 속성을 원합니다. 친절하게 제안하는 방법?
— inrsaurabh

21

이것은 관찰자와 config.xml에 대한 지식을 결합하여 수행됩니다. Config.xml은 견적 항목에 대한 사용자 정의 속성 정의 제공을 관리하며, 관찰자는 견적에 추가 될 때 견적에 제품 속성 저장을 처리합니다.

여기에서, 당신은 변환을 처리 할 FIELDSET 정의, 전화 config.xml 파일을 사용 quote_item하는 방법에 대해 order_item.

전체 공개 : 아래 내용은 Atwix의 내용입니다. 답변 아래 링크.

먼저 sales->quote->item->product_attributes노드 에 사용자 정의 속성을 추가해야 합니다.

<sales>
    <quote>
        <item>
            <product_attributes>
                <custom_attribute />
            </product_attributes>
        </item>
    </quote>
</sales>

이를 통해 상품을 상품에서 상품으로 복사 할 때 속성에 액세스 할 수 있습니다. 이는 다음 단계입니다. 이 작업에는 관찰자가 사용되며 이벤트는 다음과 같이 호출됩니다 sales_quote_item_set_product.

<sales_quote_item_set_product>
    <observers>
        <yourmodule_customattribute>
            <class>yourmodule_customattribute/observer</class>
            <method>salesQuoteItemSetCustomAttribute</method>
        </yourmodule_customattribute>
    </observers>
</sales_quote_item_set_product>

관찰자:

public function salesQuoteItemSetCustomAttribute($observer)
{
    $quoteItem = $observer->getQuoteItem();
    $product = $observer->getProduct();
    $quoteItem->setCustomAttribute($product->getCustomAttribute());
}

마지막으로주의해야 할 것은 속성을에서 로 변환quote_item 하는 것 order_item입니다. 그리고 이것은 XML로 수행 할 수 있습니다 :

<fieldsets>
    <sales_convert_quote_item>
        <custom_attribute>
            <to_order_item>*</to_order_item>
        </custom_attribute>
    </sales_convert_quote_item>
    <sales_convert_order_item>
        <custom_attribute>
            <to_quote_item>*</to_quote_item>
        </custom_attribute>
    </sales_convert_order_item>
</fieldsets>

출처 : Atwix (승리로 가득한 사람) : http://www.atwix.com/magento/custom-product-attribute-quote-order-item/


2
+1. 나는 내가 +1 한 것처럼 느낀다. veeeery와 비슷한 것을 제출하려고 할 때 '이 질문에는 새로운 답이 있습니다'라는 메시지가 나타났습니다. fast :)
— Marius

하하하-그것은 실제로 Atwix입니다.
— philwinkle

@philwinkle, 위의 작업은 잘 수행되지만 사용자 정의 속성은 수량에 따라 제품 포인트라고 가정합니다. 제품 A의 점수가 50 점이고 수량이 2 인 경우 총점은 50 * 2 = 100이어야합니다. 따옴표 항목 100대신 값을 어떻게 설정 50합니까? 속성 값이 업데이트되면 관리자가 설정 한 값이 아닌 업데이트 된 값을 저장하는 방법
— Slimshadddyyy
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.