Question

Je remarque que le "produit vedette" attribut existe dans la dernière version de Magento.Comment puis-je faire ma sélection de produits d'affichage sur la page d'accueil dans le RWD thème?

Merci

Était-ce utile?

La solution

Je ne vois pas cet attribut comme valeur par défaut ajouté à Magento 1.9.x Il est également très facile de créer une collection de produits basée sur un attribut de produit personnalisé I.E. 'Featured_Product'.

Une fois que vous avez construit la collection, vous pouvez créer le HTML que vous souhaitez afficher via un fichier de modèle, c'est-à-dire une fonction de produit unique ou un curseur multi-produit.

Les étapes pour faire ceci sont

  • Créer une nouvelle méthode de collecte de produits personnalisée
  • Créer un nouveau bloc de mise en page
  • Créer un nouveau modèle

Par exemple, si je veux créer une collection de produits pour des produits visibles avec l'attribut 'FeatureD_ProduCuCoduc' i Créez un nouveau fichier appelé Featured.php in Magento / App / Code / Local / Mage / Catalogue / Produit / Produit

<?php
class Mage_Catalog_Block_Product_Featured extends mage_Catalog_Block_Product_Abstract
{
    protected $_productsCount = null;
    protected $_categoryId = null;

    const DEFAULT_PRODUCTS_COUNT = 12;

/**
 * Initialize block's cache
 */
protected function _construct()
{
    parent::_construct();

    $this->addColumnCountLayoutDepend('empty', 6)
        ->addColumnCountLayoutDepend('one_column', 5)
        ->addColumnCountLayoutDepend('two_columns_left', 4)
        ->addColumnCountLayoutDepend('two_columns_right', 4)
        ->addColumnCountLayoutDepend('three_columns', 3);

    $this->addData(array(
        'cache_lifetime'    => 86400,
        'cache_tags'        => array(Mage_Catalog_Model_Product::CACHE_TAG),
    ));
}

/**
 * Get Key pieces for caching block content
 *
 * @return array
 */
public function getCacheKeyInfo()
{
    return array(
       'CATALOG_PRODUCT_NEW',
       Mage::app()->getStore()->getId(),
       Mage::getDesign()->getPackageName(),
       Mage::getDesign()->getTheme('template'),
       Mage::getSingleton('customer/session')->getCustomerGroupId(),
       'template' => $this->getTemplate(),
       $this->getProductsCount(),
       Mage::app()->getStore()->getCurrentCurrencyCode(),
       empty($this->_categoryId) ? "ALL" : $this->_categoryId
    );
}

/**
 * Prepare collection with new products and applied page limits.
 *
 * return Mage_Catalog_Block_Product_New
 */
protected function _beforeToHtml()
{
    $collection = Mage::getResourceModel('catalog/product_collection');
    $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());

    $collection = $this->_addProductAttributesAndPrices($collection)
        ->addStoreFilter()
        ->addAttributeToSelect('featured_product')
        ->addFieldToFilter(array(
            array('attribute'=>'ext_enable','eq'=>'1'),
        ))
        ->addAttributeToSort('name', 'desc')
        ->setPageSize($this->getProductsCount())
        ->setCurPage(1)
    ;

    // Limit to a specific category
    //if(!empty($this->_categoryId)) $collection->addCategoryFilter(Mage::getModel("catalog/category")->load($this->_categoryId));

    $this->setProductCollection($collection);

    return parent::_beforeToHtml();
}

/**
 * Set a specific category to take the products from.
 *
 * @param $catid
 * @return Mage_Catalog_Block_Product_New
 */
public function setCategory($catid)
{
    $this->_categoryId = (int)$catid;
    return $this;
}

/**
 * Set how much product should be displayed at once.
 *
 * @param $count
 * @return Mage_Catalog_Block_Product_New
 */
public function setProductsCount($count)
{
    $this->_productsCount = $count;
    return $this;
}

/**
 * Get how much products should be displayed at once.
 *
 * @return int
 */
public function getProductsCount()
{
    if (null === $this->_productsCount) {
        $this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
    }
    return $this->_productsCount;
    }
}

Alors j'ajouterai ce qui suit à ma mise en page, par exemple Si je veux que le bloc apparaisse sur la page d'accueil, je peux le placer dans la section cms_index_index

            <block type="catalog/product_featured" name="catalog.product.featured" alias="featured_products">
            <action method="setTemplate"><template>catalog/product/featured.phtml</template></action>
        </block>

Puis dans mon modèle, je crée un nouveau fichier dans le catalogue / produit appelé Featured.Phtml, ici, je peux ici itérer via la collection de produits et créer le HTML que je souhaite afficher, par ex. Voici une simple liste à bulleted.

    <?php
    $_helper = $this->helper('catalog/output');
    $_productCollection = $this->getProductCollection();
?>
<div class="featured-products">
    <p>Featured Products - <?php echo count($_productCollection) ?></p>
    <ol class="featured-products-list" id="featured-products-list">
    <?php foreach ($_productCollection as $_product): ?>
        <li><?php echo $_product->getName() ?></li>
    <?php endforeach; ?>
    </ol>
</div>

Lorsque je rafraîchis mes caches de magasin et goto la page d'accueil Le produit vedette HTML sera affiché.

Il y a beaucoup de modules qui vous aideront à le faire, mais vous pouvez l'atteindre rapidement avec cet exemple ou en créant votre propre module.

Voici un lien vers une solution similaire à partir du magentato wiki https://wiki.magento.com/display/m1wiki/how+to+create+a+feature+Product

Autres conseils

Suivez ce lien pour récupérer la Fonctionnalité du produit sur la page d'accueil http://inchoo.net/magento/featured-products-on-magento-frontpage-tutorial/

http://inchoo.net/magento/featured-products-on-magento-frontpage/

Ce tutoriel, j'explique comment présenter un produit à la page d'accueil de Magento.

dans le fichier PHTML:

<?php
$featuredProducts = Mage::getModel('catalog/category')->load($category_id)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('featured_product', 1)
->addAttributeToFilter('status', 1);

?> Dans local.xml

<cms_index_index>
<reference name="content">
    <block type="core/template" name="home.featured.product" template="custom/featuredproduct.phtml"/>
</reference>

Veuillez référer le tutoir pour une explication étape par étape. http://www.pearlbells.co.uk/adding-Custom-product-Attributs-in-Magento /

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top