카테고리가 비어있을 때 카테고리 페이지의 2 열 레이아웃을 1 열로 변경하고 싶습니다. 왼쪽 열을 계층 적 탐색에 사용하고이 경우에는 아무 것도 없기 때문에 왼쪽 열이 비어 있고 좋지 않습니다.Magento : 카테고리에 제품이없는 경우 레이아웃을 변경하십시오.
조언이 있으십니까?
감사합니다.
카테고리가 비어있을 때 카테고리 페이지의 2 열 레이아웃을 1 열로 변경하고 싶습니다. 왼쪽 열을 계층 적 탐색에 사용하고이 경우에는 아무 것도 없기 때문에 왼쪽 열이 비어 있고 좋지 않습니다.Magento : 카테고리에 제품이없는 경우 레이아웃을 변경하십시오.
조언이 있으십니까?
감사합니다.
정확하게 똑같이하려고 했으므로이 문제가 발생했습니다. 불행히도,이 해결책은 효과가 없었지만 올바른 방향으로 나를 가리켰다. 최종 해결책이었다 :
<?xml version="1.0"?>
<config>
<modules>
<Branded3_Emptycategory>
<version>0.1.0</version>
</Branded3_Emptycategory>
</modules>
<global>
<models>
<branded3_emptycategory>
<class>Branded3_Emptycategory_Model</class>
<resourceModel>branded3_emptycategory_resource</resourceModel>
</branded3_emptycategory>
<branded3_emptycategory_resource>
<class>Branded3_Emptycategory_Model_Resource</class>
</branded3_emptycategory_resource>
</models>
<blocks>
<branded3_emptycategory>
<class>Branded3_Emptycategory_Block</class>
</branded3_emptycategory>
</blocks>
<helpers>
<branded3_emptycategory>
<class>Branded3_Emptycategory_Helper</class>
</branded3_emptycategory>
</helpers>
</global>
<frontend>
<events>
<controller_action_layout_generate_blocks_after>
<observers>
<branded3_default>
<class>branded3_emptycategory/observer</class>
<method>zeroproducts</method>
</branded3_default>
</observers>
</controller_action_layout_generate_blocks_after>
</events>
</frontend>
</config>
그리고 관찰자 :
class Branded3_Emptycategory_Model_Observer {
public function zeroproducts(Varien_Event_Observer $observer)
{
$controller = $observer->getAction();
//limit to the product view page
if ($controller->getFullActionName() != 'catalog_category_view')
{
return;
}
$_productCollection = $observer->getEvent()
->getLayout()->getBlock('product_list')->getLoadedProductCollection();
$products = clone $_productCollection;
if(!$products->count()):
$observer->getEvent()->getLayout()
->getBlock('root')
->setTemplate('page/1column.phtml');
endif;
}
}
응용 프로그램/코드/지역/미트/Custommodule을/etc/코드 및 코드
<?xml version="1.0"?>
<config>
<modules>
<Amit_Custommodule>
<version>1.0.0.0</version>
</Amit_Custommodule>
</modules>
<global>
<models>
<amitcustommodule>
<class>Amit_Custommodule_Model</class>
</amitcustommodule>
</models>
</global>
<frontend>
<events>
<controller_action_predispatch_catalog_category_default>
<observers>
<amitcustommodule_default>
<class>amitcustommodule/observer</class>
<method>logCartAdd</method>
</amitcustommodule_default>
</observers>
</controller_action_predispatch_catalog_category_default>
<controller_action_predispatch_catalog_category_layered>
<observers>
<amitcustommodule_default_2>
<class>amitcustommodule/observer</class>
<method>logCartAdd</method>
</amitcustommodule_default_2>
</observers>
</controller_action_predispatch_catalog_category_layered>
</events>
</frontend>
</config>
그리고 Observer.php에서 config.xml 파일을 응용 프로그램/코드/지역/미트/Custommodule 에서 모듈을 만들고 생성 app/code/local/Amit/Custommodule/Model/
<?php Amit_Custommodule_Model_Observer
public function logCartAdd(Varien_Event_Observer $observer)
{
$_productCollection=$observer->getEvent()
->getLayout()->getBlock('product_list')->getLoadedProductCollection();
if(!$_productCollection->count()):
$observer->getEvent()->getLayout()
->getBlock('root')
->setTemplate('page/1column.phtml');
endif;
}