1
제품보기 (view.phtml)에서 "이전/다음"버튼을 구현했으며 정상적으로 작동합니다. 문제는 상태가 "사용 중지됨"인 제품을 표시하려고하는 것입니다. 그러면 404 Not Found 페이지가 나타납니다.Magento - 제품 페이지의 이전 및 다음 제품 링크
이 문제를 해결할 수있는 방법이나 문제가 있습니까? 어떤 도움을 주시면 감사하겠습니다
<?php // Previous and Next product links in product page
$_product = $this->getProduct();
if (!$_product->getCategoryIds())
return; // Don't show Previous and Next if product is not in any category
$cat_ids = $_product->getCategoryIds(); // get all categories where the product is located
$cat = Mage::getModel('catalog/category')->load($cat_ids[0]); // load first category, you should enhance this, it works for me
$order = Mage::getStoreConfig('catalog/frontend/default_sort_by');
$direction = 'asc'; // asc or desc
$category_products = $cat->getProductCollection()->addAttributeToSort($order, $direction);
$category_products->addAttributeToFilter('status', 1); // 1 or 2
$category_products->addAttributeToFilter('visibility', 4); // 1.2.3.4
$cat_prod_ids = $category_products->getAllIds(); // get all products from the category
$_product_id = $_product->getId();
$_pos = array_search($_product_id, $cat_prod_ids); // get position of current product
$_next_pos = $_pos + 1;
$_prev_pos = $_pos - 1;
// get the next product url
if (isset($cat_prod_ids[$_next_pos])) {
$_next_prod = Mage::getModel('catalog/product')->load($cat_prod_ids[$_next_pos]);
} else {
$_next_prod = Mage::getModel('catalog/product')->load(reset($cat_prod_ids));
}
// get the previous product url
if (isset($cat_prod_ids[$_prev_pos])) {
$_prev_prod = Mage::getModel('catalog/product')->load($cat_prod_ids[$_prev_pos]);
} else {
$_prev_prod = Mage::getModel('catalog/product')->load(end($cat_prod_ids));
}
?>
:
이 내 코드입니다.
감사합니다.
이 코드를보기 페이지에서 사용하려면 다음 코드를 사용하십시오. http://cmsblogheart.wordpress.com/2014/01/30/previousnext-product-in-magento/ –