久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

按類(lèi)別 ID 顯示 magento 產(chǎn)品

Display magento products by category ID(按類(lèi)別 ID 顯示 magento 產(chǎn)品)
本文介紹了按類(lèi)別 ID 顯示 magento 產(chǎn)品的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我需要知道如何在頁(yè)面中顯示產(chǎn)品,例如(購(gòu)物車(chē),低于總數(shù))僅按 ID 顯示少數(shù)產(chǎn)品.例如:id 為 2、3、4 和 5 的產(chǎn)品.

<?php$categoryid = 64;$category = new Mage_Catalog_Model_Category();$category->load($categoryid);$collection = $category->getProductCollection();$collection->addAttributeToSelect('*');foreach ($collection as $_product) { ?><a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>"width="200" height="200" alt=""/></a><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName();?></a><?php } ?>

此時(shí)我可以看到每個(gè)產(chǎn)品的圖片和標(biāo)題.我需要顯示添加到購(gòu)物車(chē)和價(jià)格.

有人可以幫忙嗎?

解決方案

從特定類(lèi)別獲取產(chǎn)品

$categoryIds = array(2,4);//類(lèi)別id$collection = Mage::getModel('目錄/產(chǎn)品')->getCollection()->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')->addAttributeToSelect('*')->addAttributeToFilter('category_id', array('in' => $categoryIds))

獲取特定產(chǎn)品 ID 的產(chǎn)品

$productids = array(52,62);//產(chǎn)品id$collection = Mage::getResourceModel('catalog/product_collection');$collection->addFieldToFilter('entity_id',array('in' => $productids));

然后在 phtml 中寫(xiě)這個(gè)

count() ?><?php//$_columnCount = $this->getColumnCount();?><?php $i=0;foreach ($collection 作為 $product): ?><?php if ($i++%4==0): ?><ul class="products-grid"><?php endif ?><li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>"><a href="<?php echo $product->getProductUrl()?>"title="<?php echo $product->getName()?>"><img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(197, 167); ?>"alt="<?php echo $product->getName()?>"邊框="0"/></a><h2 class="product-name"><a href="<?php echo $product->getProductUrl()?>"title="<?php echo $product->getName()?>"><?php echo $product->getName() ?></a></h2><div class="price-box"><?php echo Mage::helper('core')->currency($product->getPrice(),true,false);?>

<div class="actions"><?php if($product->isSaleable()): ?><button class="button" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add/')?>product/<?php echo $product->getId() ?>/')" title="<?php echo $this->__('K?p');?>"type="submit"><span><span><?php echo $this->__('K?p');?></span></span></button><?php 其他:?><p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p><?php endif;?>

<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?><?php endif ?><?php endforeach ?>

希望對(duì)你有幫助

I need to know how can I display products in a page like (cart, below total) only few products by ID. Eg: products with id 2,3,4 and 5.

<div class="freeProducts voucher code">
    <?php

    $categoryid = 64;

    $category = new Mage_Catalog_Model_Category();
    $category->load($categoryid);
    $collection = $category->getProductCollection();
    $collection->addAttributeToSelect('*');

    foreach ($collection as $_product) { ?>

    <a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="" /></a> <a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a>

    <?php } ?>
</div>

At this moment I can see the image for each product, and the title. I need to display the ADD TO CART and price.

Anyone can help please?

解決方案

get Product from specific category

$categoryIds = array(2,4);//category id

$collection = Mage::getModel('catalog/product')
                             ->getCollection()
                             ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
                             ->addAttributeToSelect('*')
                             ->addAttributeToFilter('category_id', array('in' => $categoryIds))

get Product for specific product id

$productids = array(52,62);//product ids
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addFieldToFilter('entity_id',array( 'in' => $productids));

then write this in phtml

<?php $_collectionSize = $collection->count() ?>
    <?php //$_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($collection as $product): ?>
        <?php if ($i++%4==0): ?>
        <ul class="products-grid">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $product->getProductUrl()?>" title="<?php echo $product->getName()?>">
                        <img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(197, 167); ?>" alt="<?php echo $product->getName()?>" border="0" />
                    </a>
                <h2 class="product-name"><a href="<?php echo $product->getProductUrl()?>" title="<?php echo $product->getName()?>"><?php echo $product->getName() ?></a></h2>
               <div class="price-box">
               <?php echo Mage::helper('core')->currency($product->getPrice(),true,false);?>
               </div>
                <div class="actions">
                    <?php if($product->isSaleable()): ?>
                        <button class="button" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add/')?>product/<?php echo $product->getId() ?>/')" title="<?php echo $this->__('K?p');?>" type="submit"><span><span><?php echo $this->__('K?p');?></span></span></button>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>

                </div>
            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>

hope this help you

這篇關(guān)于按類(lèi)別 ID 顯示 magento 產(chǎn)品的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動(dòng)填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱(chēng) ASC)
主站蜘蛛池模板: 亚洲 欧美 综合 | 国产福利91精品 | 亚洲国产高清在线 | 欧美激情免费在线 | 亚洲人免费视频 | 久久久久国产一级毛片 | 成人黄色在线视频 | 欧美成年网站 | 亚洲一级视频在线 | 日本a视频 | 亚洲一二三区精品 | 亚洲成人精品久久 | 91一区 | 中文字幕一区二区三区四区五区 | 成人免费xxxxx在线视频 | 在线91 | 久久一区| 亚洲码欧美码一区二区三区 | 亚洲视频在线免费观看 | 欧美日一区二区 | 国产精品99久久久久久宅男 | 欧美一区二区在线播放 | 中文字幕日韩在线观看 | 精品一区二区观看 | 欧美久久久网站 | a在线视频 | 9久9久9久女女女九九九一九 | 91精品国产91久久久久久密臀 | 欧美日韩国产中文 | 国产91在线 | 中日 | 国产精品亚洲综合 | 福利久久| 久久久片 | 国产精品网址 | 老牛影视av一区二区在线观看 | 欧美日韩在线国产 | 精品久久久网站 | 中文字幕在线观看国产 | 国产成都精品91一区二区三 | 中文字幕成人av | 国产精品不卡一区二区三区 |