문제

시나리오 :

  • Magento Store (상점 a) 2 개의 매장 조회수, 영어 및 프랑스어로

  • 많은 수의 제품 (10K +)

  • 새로운 스토어 (저장소 B) (동일 마젠토 설치)가 생성되었으며 와 동일한 제품을 모두 운반합니다

    문제 :

    저장소 a 저장소 b 에 저장된 모든 기존 제품을 할당 할 때 기본 정보가 어디에서 오는 위치를 묻는 메시지가 나타납니다. 이것은 하나의 상점보기 (영어)를 다루고 있습니다.

    원하는 결과 : 여기에 이미지 설명

    저장소 (프랑스어) 저장소 b (프랑스어) 에서 모든 설명을 어떻게 채우려면 어떻게합니까?

도움이 되었습니까?

해결책

관찰자가 작업을 할 수 있습니까?

e.g :

class My_Awesome_Model_Observer 
{
    public function syncDescriptions($observer)
    {
        $productId = $observer->getProduct()->getId();

        $storeAEnId = 1; //store view Id for English store A 
        $storeBEnId = 2; //as above for store B
        $storeAFrId = 2; //store A French view's id
        $storeBFrId = 4; //French store B
        //of course replace above with real store Ids

        $descAEn = Mage::getModel('catalog/product')->setStore($storeAEnId)->load($productId)->getData('description');

// Now we check if description in store B is up-to-date with store A's, if not, if yes, we leave, if not, it is updated
        if ($descAEn != Mage::getModel('catalog/product')->setStore($storeBEnId)->load($productId)->getData('description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBEnId)
                    ->load($productId)
                    ->getData('description', $descAEn)
                    ->save();
            }

        $shortDescAEn = Mage::getModel('catalog/product')->setStore($storeAEnId)->load($productId)->getData('short_description');

// Same check for short description
        if ($shortDescAEn != Mage::getModel('catalog/product')->setStore($storeBEnId)->load($productId)->getData('short_description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBEnId)
                    ->load($productId)
                    ->getData('short_description', $shortDescAEn)
                    ->save();
            }

        $descAFr = Mage::getModel('catalog/product')->setStore($storeAFrId)->load($productId)->getData('description');


// same for French view
        if ($descAFr != Mage::getModel('catalog/product')->setStore($storeBFrId)->load($productId)->getData('description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBFrId)
                    ->load($productId)
                    ->getData('description', $descAFr)
                    ->save();
            }

        $shortDescAFr = Mage::getModel('catalog/product')->setStore($storeAFrId)->load($productId)->getData('short_description');


// same for French short description
        if ($shortDescAFr != Mage::getModel('catalog/product')->setStore($storeBFrId)->load($productId)->getData('short_description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBFrId)
                    ->load($productId)
                    ->getData('short_description', $shortDescAFr)
                    ->save();
            }
    }
}
.

물론 모듈의 catalog_product_save_after에서 옵서버 클래스 및 메소드를 선택하는 config.xml 이벤트에 대한 관찰자를 선언해야합니다.예 :

<global>
    <events>
        <catalog_product_save_after>
            <observers>
                <awesome_observer>
                    <type>singleton</type>
                    <class>My_Awesome_Model_Observer</class>
                    <method>syncDescriptions</method>
                </awesome_observer>
            </observers>
        </catalog_product_save_after>
    </events>
</global>
.

문제를 해결하기위한 을 해결할 수있는 것입니다.너의 자신의 솔루션.:)

p.s : 관찰자의 루프를 조심하십시오.

다른 팁

i 상상해보십시오. 자체 동기화 모듈을 작성해야하며 프랑스어를 저장하기 위해 프랑스어를 저장하는 것에 대한 야간 가져 오기를 일정시킵니다.

제품의 'updated_at'필드를 사용하여 수행 해야하는 작업의 양을 최소화하십시오.

의사 코드

  • 야간 를 실행하는 Cron 작업 일정
  • 각 제품을 스캔
  • 직업이 마지막으로 실행 된 이후 업데이트 된 각 제품의 경우 마지막으로 업데이트 된 이후, 정보를 저장 (프랑스어)에서 저장 B (프랑스어) 를 저장하십시오.
  • 작업이 실행 된 시간을 ran

    이것은 당신이 즉각적인 제품의 즉각적인 동화가 필요 없다고 가정합니다.

    팁은 인덱싱 모델이 '저장시 업데이트'로 설정되지 않은지 확인하는 것입니다.

'질량 속성 업데이트'기능은 논리 제한으로 인해 한 상점보기에서 다른 상점보기에서 다른 값으로 값을 적용 할 수 없습니다.Magento는 새로 할당 된 저장소 뷰에 기본값 만 적용합니다.

순수한 SQL 해결 방법을 사용해보십시오.

INSERT INTO `catalog_product_entity_text` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) 
SELECT `entity_type_id`, `attribute_id`, '<target_store_id>' as `store_id`, `entity_id`, `value` 
FROM `catalog_product_entity_text` as `source`
WHERE `attribute_id` IN (
    SELECT  `attribute_id` 
    FROM  `eav_attribute` 
    WHERE  `entity_type_id` = 10 /* catalog_product */
    AND  `attribute_code` IN ( 'description', 'short_description' )
)  
AND store_id = '<source_store_id>'
ON DUPLICATE KEY UPDATE `value` = `source`.`value`;
.

'<source_store_id>'저장소보기에서 '설명'및 'Short_Description'속성의 값을 '<target_store_id>'저장소 뷰로 복사합니다.

'<target_store_id>'와 '<source_store_id>'상수를 대체하고 각 저장소보기에 대해이 스크립트를 별도로 실행하십시오.

이미 존재하는 값을 보존하려면 '중복 키 업데이트'에서 '삽입] 대신'INSERT INSING ... '구문을 사용하십시오.

다른 일부 속성 값을 복사하려면 스크립트를 그에 따라 수정해야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top