Mage_Catalog_Block_Product_View를 확장하려고합니다. 내 로컬 디렉토리에서 내 버전에 설치했는데 모든 것이 잘 작동하지만 점점 커지지 않았습니다. 내가 원하는 결과. 나는 또 다른 반이 그 반을 확장했다는 것을 알았다. 그것은 나의 수업에서 설정되었던 무엇이라도 고치는 것처럼 보였다. 나는 내 수업이 잘 작동하고 있다는 것을 압니다. 그 클래스의 하위 클래스 인 다른 클래스가 있습니다. parent 클래스를 호출하고있는 메소드와 동일한 메소드로 메소드를 호출합니다. 클래스를 오버라이드 할 때 클래스가 실행되고 클래스가 실행되면 원래 클래스가 실행됩니다. 방법 나는 무시하고 내 아니라고parent :: method를 사용하여 다른 클래스에서 호출 한 클래스를 어떻게 오버라이드합니까?
이 내가이 알고 명심, 다음과 같이 조금 수정하려고class Mage_Review_Block_Product_View extends Mage_Catalog_Block_Product_View
protected function _prepareLayout()
{
$this->getLayout()->createBlock('catalog/breadcrumbs');
$headBlock = $this->getLayout()->getBlock('head');
if ($headBlock) {
$title = $this->getProduct()->getMetaTitle();
if ($title) {
$headBlock->setTitle($title);
}
$keyword = $this->getProduct()->getMetaKeyword();
$currentCategory = Mage::registry('current_category');
if ($keyword) {
$headBlock->setKeywords($keyword);
} elseif($currentCategory) {
$headBlock->setKeywords($this->getProduct()->getName());
}
$description = $this->getProduct()->getMetaDescription();
if ($description) {
$headBlock->setDescription(($description));
} else {
$headBlock->setDescription($this->getProduct()->getDescription());
}
}
return parent::_prepareLayout();
}
는 제목 접두사와 접미사하지만이 기능을이다
제품 페이지에만 필요했고 설명에 텍스트를 추가해야했습니다.
class MyCompany_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_View
protected function _prepareLayout()
{
$storeId = Mage::app()->getStore()->getId();
$this->getLayout()->createBlock('catalog/breadcrumbs');
$headBlock = $this->getLayout()->getBlock('head');
if ($headBlock) {
$title = $this->getProduct()->getMetaTitle();
if ($title) {
if($storeId == 2){
$title = "Pool Supplies Fast - " .$title;
$headBlock->setTitle($title);
}
$headBlock->setTitle($title);
}else{
$path = Mage::helper('catalog')->getBreadcrumbPath();
foreach ($path as $name => $breadcrumb) {
$title[] = $breadcrumb['label'];
}
$newTitle = "Pool Supplies Fast - " . join($this->getTitleSeparator(), array_reverse($title));
$headBlock->setTitle($newTitle);
}
$keyword = $this->getProduct()->getMetaKeyword();
$currentCategory = Mage::registry('current_category');
if ($keyword) {
$headBlock->setKeywords($keyword);
} elseif($currentCategory) {
$headBlock->setKeywords($this->getProduct()->getName());
}
$description = $this->getProduct()->getMetaDescription();
if ($description) {
if($storeId == 2){
$description = "Pool Supplies Fast - ". $this->getProduct()->getName() . " - " . $description;
$headBlock->setDescription(($description));
}else{
$headBlock->setDescription(($description));
}
} else {
if($storeId == 2){
$description = "Pool Supplies Fast: ". $this->getProduct()->getName() . " - " . $this->getProduct()->getDescription();
$headBlock->setDescription(($description));
}else{
$headBlock->setDescription($this->getProduct()->getDescription());
}
}
}
return Mage_Catalog_Block_Product_Abstract::_prepareLayout();
}
이 잘 executs하지만 나는 다음 클래스 Mage_Review_Block_Product_View_List이 Mage_Review_Block_Product_View를 확장하고 그뿐만 아니라 Mage_Catalog_Block_Product_View을 확장하는 확장 알 수 있습니다. 이 클래스 내부 그들은뿐만 아니라 _prepareLayout를 호출하고 부모와 부모를 호출 :: _ prepareLayout()
class Mage_Review_Block_Product_View_List extends Mage_Review_Block_Product_View
protected function _prepareLayout()
{
parent::_prepareLayout();
if ($toolbar = $this->getLayout()->getBlock('product_review_list.toolbar')) {
$toolbar->setCollection($this->getReviewsCollection());
$this->setChild('toolbar', $toolbar);
}
return $this;
}
그래서 분명히 이것은 단지 내가 확장하고 같은 클래스를 호출하고 내가 overiding하고 기능을 실행하지만, 그렇지 않습니다 그것은 내 클래스 계층 구조에 없기 때문에 내 클래스에 도착하기 때문에 그것은 부모 클래스의 모든 물건이 내가 설정 한 것을 무시합니다.
이런 유형의 클래스와 메소드를 확장하는 가장 좋은 방법은 확실치 않습니다.이를 수행하는 좋은 방법이 있어야합니다. 이러한 메소드를 오버라이드하려고 할 때 문제가 있음을 계속 발견합니다. 추상 클래스에서 파생 된, 너무 많은 클래스를 무시하고 부모 호출 :: 메서드를 호출하는 것 같습니다.
이러한 기능을 무시하는 가장 좋은 방법은 무엇입니까?
감사합니다. Alan, 체인의 맨 아래에있는 하위 클래스를 재정의해야한다는 것을 이해합니다. 따라서 Mage_Catalog_Block_Product_View를 확장하는 대신 Mage_Review_Block_Product_View_List를 확장하는 것이 좋습니다. 리뷰에 포함 된 이후로 확장하는 것이 이상하게 보입니다. . 어떤 수업을 연장해야하는지 쉽게 알 수 있습니까? "하지만 클래스의 인스턴스화 만 재정의 할 수 있습니다."라는 말은 클래스를 호출하는 마지막 클래스를 의미하는 것입니까? 그런데 당신 기사에서 대부분의 Magento 개발을 배웠습니다 –
내가 무엇을 몰고 왔는지에 대한 소식을 업데이트하십시오. 다행이 유용하다고 생각합니다! –
아아 네, 그게 당신이 의미하는 줄 알았습니다. 그래서 유일한 옵션은 푸를 확장하는 것이 맞지 않을지라도 추측합니다. –