2012-02-02 3 views
0

클라이언트 Magento 사이트 용 콜렉션 모듈을 개발했습니다. 이 모듈은 카테고리 목록 페이지에서 제품 세부 정보 (미디어, 설명, 속성)를 가져옵니다. 내가 만나는 문제는 모든 것이 로컬로 작동하더라도 (Magento CE 1.6), 내 블록이 클라이언트 사이트 (Magento EE 1.8)에서 렌더링되지 않는다는 것입니다.사용자 정의 블록이 렌더링되지 않습니다.

개발자 모드가 활성화되었지만 페이지에 아무런 오류가없는 것으로 나타났습니다. 시스템> 구성> 고급 아래 관리자에게 올바르게 표시되면서 Magento가 모듈을보고 있습니다.

우리는 우리가 app/design/frontend/enterprise/mytheme/layout/local.xml

<?xml version="1.0"?> 
<layout version="0.1.0"> 
    <catalog_category_view> 
     <reference name="product_list"> 
      <block type="mycompany_collections/collection" name="collection" template="collections/collection.phtml"> 
       <block type="mycompany_collections/product" name="add-to-cart" template="collections/product/add-to-cart.phtml" /> 
       <block type="mycompany_collections/product" name="description" template="catalog/product/view/description.phtml" /> 
       <block type="mycompany_collections/product_attributes" name="attributes" template="catalog/product/view/attributes.phtml" /> 
       <block type="mycompany_collections/product_media" name="media" template="catalog/product/view/media.phtml" /> 
      </block> 
     </reference> 
    </catalog_category_view> 
</layout> 

mycompany_collections/collection 블록 Mage_Catalog_Block_Product_List 확장의 레이아웃에 우리의 블록을 삽입하고 우리가 가져온이 있는지 확인하기 위해 제품을 다시로드 app/code/local/Mycompany/Collections/etc/config.xml

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Mycompany_Collections> 
      <version>0.1.0</version> 
     </Mycompany_Collections> 
    </modules> 
    <global> 
     <blocks> 
      <mycompany_collections> 
       <class>Mycompany_Collections_Block</class> 
      </mycompany_collections> 
     </blocks> 
    </global> 
</config> 

에서베이스 블록 클래스 이름을 설정 데이터베이스의 모든 관련 데이터.

class Mycompany_Collections_Block_Collection extends Mage_Catalog_Block_Product_List { 
    public function reloadProducts() { 
     // Fully reload each of the products in this category so that we have 
     // all the information required to display product details. 

     // TODO: find a more efficient way to grab all the info for all the 
     // products, as this would seem to add 1 (or more) additional 
     // query per product. 

     $reloaded = array(); 
     foreach($this->getParentBlock()->getLoadedProductCollection() as $product){ 
      $reloaded[] = Mage::getModel('catalog/product')->load($product->getId()); 
     } 
     return $reloaded; 
    } 
} 

mycompany_collections/product 블록은 사용자 정의 방법과 Mage_Catalog_Block_Product_Abstract 우리가 명시 적으로 블록에 제품을 설정하고 레지스트리에서 당겨없이 해당 제품을 반환 할 수 있도록 확장합니다.

class Mycompany_Collections_Block_Product extends Mage_Catalog_Block_Product_Abstract { 
    private $_product = null; 

    public function _prepareLayout() { 
     // We don't need to do anything here. 
    } 

    // NOTE: Must be called before ->toHtml() 
    public function setProduct($product) { 
     $this->_product = $product; 
     return $this; 
    } 

    public function getProduct() { 
     return $this->_product; 
    } 
} 

mycompany_collections/product_attributesmycompany_collections/product_media 블록 모두는 동등한 추상 상위 클래스에 대해 같은 GET/set_product 재 지정을한다. 우리 collection.phtml 템플릿 내부

, 우리는

<?php 
    $_productCollection = $this->reloadProducts(); 
?> 

<!-- Buy collection popup --> 
<div id="buy-collection" class="no-display"> 
    <h1>Buy Collection</h1> 
    <?php foreach($_productCollection as $_product): ?> 
     <div id="buy-collection-product-<?php echo $_product->getId(); ?>" class="product"> 
      <div class="media"><?php echo $this->getChild('media')->setProduct($_product)->toHtml(); ?></div> 
      <?php /* 
      <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(100); ?>" width="100" height="100" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a> 
      */ ?> 
      <a href="<?php echo $_product->getProductUrl() ?>" ><?php echo $_product->getName(); ?></a> 
      <?php if($_product->isSaleable()): ?> 
       <div class="add-to-cart"><?php echo $this->getChild('add-to-cart')->setProduct($_product)->toHtml(); ?></div> 
      <?php else: ?> 
       <div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div> 
      <?php endif; ?> 
      <div class="details"> 
       <div class="description"> 
        <?php echo $this->getChild('description')->setProduct($_product)->toHtml(); ?> 
       </div> 
       <div class="attributes"> 
        <?php echo $this->getChild('attributes')->setProduct($_product)->toHtml(); ?> 
       </div> 
      </div> 
     </div> 
    <?php endforeach; ?> 
</div> 

<!-- Product detail popups --> 
<div id="product-details" class="no-display"> 
    <?php foreach ($_productCollection as $_product): ?> 
    <div id="product-detail-<?php echo $_product->getId(); ?>" class="product"> 
     <div class="media"><?php echo $this->getChild('media')->setProduct($_product)->toHtml(); ?></div> 
     <div class="description"><?php echo $this->getChild('description')->setProduct($_product)->toHtml(); ?></div> 
     <div class="attributes"><?php echo $this->getChild('attributes')->setProduct($_product)->toHtml(); ?></div> 
    </div> 
    <?php endforeach; ?> 
</div> 

실제로 화재로 모든 (이러한 클릭에 활성화 JS 일러스트입니다) $this->reloadProducts()를 호출하고 제품 세부 정보를 표시하고 수집 팝업을 구입하는 제품 목록을 반복 컬렉션에서 표시하고자하는 제품 카테고리의 경우 관리자의 해당 카테고리의 맞춤 디자인 탭에있는 category.listingproduct_list 템플릿보다 우선 적용됩니다. 이러한 템플릿에는 디자인 변경 사항이 포함되어 있으며 product/list.phtml은 컬렉션 블록을 호출합니다.

<reference name="product_list"> 
    <action method="setTemplate"> 
     <template>catalog/collections/product/list.phtml</template> 
    </action> 
</reference> 

<reference name="category.products"> 
    <action method="setTemplate"> 
     <template>catalog/collections/category/view.phtml</template> 
    </action> 
</reference> 

product/list.phtml 내부에서 우리는 간단한 echo $this->getChildHtml('collection');으로 수집 블록을 호출합니다. 이 행에는 아무 것도 반환되지 않습니다. 템플릿 없음, PHP 오류 없음, 아무것도 없습니다. 위에서 언급했듯이이 모든 것은 내 로컬 개발 환경에서 아름답게 작동합니다.

이것이 어떻게 설정되는지 개요입니다.

Alan Storm의 Layoutviewer 모듈을 사용하여 블록이 ?showLayout=page에 나열되고 핸들 "catalog_category_view"가 ?showLayout=handles에 나열되어 있음을 확인했습니다. 그러나 product/list.phtml에 $this->getSortedChildren()을 인쇄하면 콜렉션 블록이 나열되지 않습니다.

layout.xml의 컬렉션 블록을 수퍼 단순 core/text 블록으로 바꾼 경우 으로 렌더링됩니다.

<?xml version="1.0"?> 
<layout version="0.1.0"> 
    <catalog_category_view> 
     <reference name="product_list"> 
      <block type="core/text" name="collection"><action method="setText"><text>This is a test</text></action></block> 
     </reference> 
    </catalog_category_view> 
</layout> 

이 문제는 내 자신의 코드에 더 깊은 믿고 나를 인도, 그래서 간단하고 완전히 기본적인 갔다 ... 나는 Mycompany_Collections_Block_Collection에서 reloadProducts 방법을 제거하고 있는지 확인하기 위해 한 줄의 텍스트에 collections.phtml 감소 템플릿 또는 하위 블록의 일부가 문제를 일으켰습니다. 불행히도 이것은 아무런 영향을 미치지 않았고 나는 결과물을 얻지 못했습니다.

왜 이것이 작동하지 않는지에 관해서는 정말 실망합니다. 처음에는 이것이 엔터프라이즈 에디션과 커뮤니티 에디션의 차이 일 수 있다고 생각했지만, 레이아웃/블록 시스템만큼 기본적인 것은 다를 수 있습니다. 분명히 뭔가 빠져있는 것처럼 보이고 누군가가 올바른 방향을 가리킬 수 있기를 바랍니다.

감사합니다.

+0

마젠타 캐시를 지우셨습니까? 항상 제일 먼저 확인하십시오. – ShaunOReilly

+0

예, 캐싱이 완전히 비활성화되었습니다. – dmpayton

+1

그럴 수도 있지만 여전히/var/cache 폴더를 지우십시오. 그 안에있는 모든 파일을 삭제하십시오. – ShaunOReilly

답변

0

/app/etc/modules 섹션에서 사용 가능한 Mycompany_Collections.xml과 codepool을 사용할 수 있는지 확인 했습니까?

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Mycompany_Collections> 
      <active>true</active> 
      <codePool>local</codePool> 
     </Mycompany_Collections> 
    </modules> 
</config> 
+0

예,'app/etc/modules/Mycompany_All.xml'에'Mycompany_Collections'을 추가했습니다. 활성화는 true로 설정되고 codePool은 로컬로 설정됩니다. – dmpayton

+0

내가 잘못 본 것이 아니라면 모듈 이름은 Mycompany_Collections입니다. 따라서 모듈은'/ app/code/local/Mymodule/Collections' 디렉토리에 있어야하며 xml 설정 파일은'app/etc/modules' 폴더의'Mymodule_Collections.xml'이어야합니다. –

관련 문제