如何为不同的视图使用不同的price.phtml文件?

时间:2014-07-31 11:50:11

标签: magento

我想为所有产品视图使用自定义new_price.phtml文件用于New Products块和price.phtml。我见过一些例子,但因为我很新,所以我不知道如何实现thrm。< / p>

任何人都可以告诉我正确的步骤。

以下是new.phtml的代码。

      <?php
                // some helpers
                $_helper = $this->helper('catalog/output');
                $storeId = Mage::app()->getStore()->getId();
                $catalog = $this->getLayout()->createBlock('catalog/product_list')->setStoreId($storeId);
                $productCount = $this->getData('num_products');
            ?>
<?php 
$visibility = array(
                      Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
                      Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
                  );
$collection = Mage::getResourceModel('reports/product_collection')
                        ->addAttributeToSelect('*')    
                        ->setStoreId($storeId)
                        ->addStoreFilter($storeId)
                        ->distinct(true) 
                       //->addAttributeToFilter('visibility', $visibility)
                       //  ->addFieldToFilter('qty', array('gteq' => 1))
                      // ->addAttributeToFilter('is_in_stock',0)              
                        //->addOrderedQty()
                          ->setOrder('entity_id', 'desc')
                        ->setPageSize($productCount);
                        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
                        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
                        Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
/* To display product by category id */
  if($categoryId=$this->getData('category_id')){
        $category = Mage::getModel('catalog/category')->load($categoryId);
        $collection->addCategoryFilter($category);
      }
                ?>
          <?php      // if no products are currently sell, display some text
                 if (!$collection->count()) :
        ?>
        <p class="note-msg"><?php echo $this->__('There are no products sell at the moment.') ?></p>
        <?php else : ?>

<div class="products_slider">
<div class="product-title pro-name">
  <span class=""><?php echo $this->__('New Products') ?></span>
</div> <!--product-title-->
<a id="products_slider_prev1" class="jcarousel-prev-horizontal" href="javascript:void(0)"></a>
<a id="products_slider_next1" class="jcarousel-next-horizontal" href="javascript:void(0)"></a>
<!-- BEGIN SLIDER CONTAINER -->
<div class="slider-container">
  <div class=" jcarousel-skin-tango">
    <div class="jcarousel-container jcarousel-container-horizontal" style="position: relative; display: block;">
      <div class="jcarousel-clip jcarousel-clip-horizontal" style="overflow: hidden; position: relative;">
        <ul class="products-grid-home jcarousel-list jcarousel-list-horizontal" id="products_slider1" style="overflow: hidden; position: relative; top: 0px; margin: 0px; padding: 0px; left: 0px; width: 2970px;">
        <?php
                $_collectionSize = $collection->count();
                $_columnCount = 4;
                $i = 0;
                $v8=1;
                foreach ($collection as $_product) :
                        $_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($_product->getId());
        ?>
            <?php if ($i++%$_columnCount==0): ?>

            <?php endif ?>

                <li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>" style="float: left; list-style: none outside none;"> 
                  <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                     <?php  //echo $this->helper('vistasettings')->getLabel($_product);  ?>
                     <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(228,319); ?>" class="small-image" width="228"  alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                   <?php /*?> <?php $product = Mage::getModel('catalog/product')->load($_product->getId());
                    foreach ($product->getMediaGalleryImages() as $image) {
                    ?>
                     <img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $image->getFile())->resize(228, 319); ?>" class="thumbnail" width="228"  alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"/>
                    <?php }  ?><?php */?>
                  </a>
            <script type="text/javascript">
             /*   jQuery(document).ready(function() {
                jQuery("#various8<?php echo $v8; ?>").fancybox({
                'transitionIn'  : 'elastic',
                'transitionOut' : 'elastic',
                'onClosed'      :  function() { }
                });
                });*/
            </script>
                <!--  <a href="#inline8<?php echo $v8; ?>" id="various8<?php echo $v8; ?>" title="<?php echo $this->__('Quick View') ?>" class="product-detail-bnt">&nbsp;</a>-->

<!-- POP UP --><div style="display: none;"><div id="inline8<?php echo $v8; ?>" class="info-box">
<div class="product-view">
  <div class="product-essential">
    <div class="product-img-box">
       <div class="product-image">
          <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class ="cloud-zoom" id="zoom1" rel="adjustX:10, adjustY:-2, zoomWidth:400, zoomHeight:400">
            <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(260,260); ?>" width="260" height="260" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />                 
          </a>
       </div> <!--product-image-->
       <div class="more-images">
        <div class="more-views">
        <div class="more-views thumbnailscroller carousel">
        <div style="overflow: hidden; position: relative;" class="thumbnail-viewport">
 <ul style="width: 1200%; transition-duration: 0s; transform: translate3d(0px, 0px, 0px);" id="thumbscroller<?php echo $v8; ?>" class="thumbscroller slides">

     <?php $product = Mage::getModel('catalog/product')->load($_product->getId());
          foreach ($product->getMediaGalleryImages() as $image) : ?>
        <li   style="width: 100px; float: left; display: block;">
          <a href="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $image->getFile()); ?>" class="cloud-zoom-gallery" rel="useZoom: 'zoom1', smallImage: '<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $image->getFile())->resize(260,260); ?>' ">
            <img class="zoom-tiny-image" src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $image->getFile())->resize(80, 80); ?>" width="80" height="80" alt=""/>
          </a>
        </li>
     <?php endforeach; ?>
    </ul>
    </div>

 <ul class="thumbnail-direction-nav"><li><a href="javascript:void(0)" class="thumbnail-prev"><?php echo $this->__('Previous');?></a></li>
 <li><a href="javascript:void(0)" class="thumbnail-next"><?php echo $this->__('Next');?></a></li></ul>
  </div><!--thumbnailscroller carousel-->
   </div><!--more-views-->

 <script type="text/javascript">
    $mtkb(window).load(function(){
        $mtkb('.thumbnailscroller').flexslider({
            namespace: "thumbnail-",
            animation: "slide",
            animationLoop: true,
            itemWidth: 250,
            itemMargin: 0,
            slideshow: true,
            minItems: 1,
            maxItems: 1,
            directionNav: true,
            controlNav: false,
            move: 1,
            touch: true,
        });
    });
</script>



 </div><!--more-images-->

    </div> <!--product-img-box-->
    <div class="product-shop">
      <div class="product-name">
        <h1><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
                    <?php echo $this->htmlEscape($_product->getName()); ?> 
            </a>
        </h1>
      </div> <!--product-name-->
      <div class="short-description"><?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?></div>
      <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
      <?php echo $this->getPriceHtml($_product, true) ?>
     <div class="add-to-box">
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
 <?php if(!$_product->isGrouped()): ?>
       <div class="add-to-cart">
          <label for="qty"><?php echo $this->__('Qty:') ?></label>        
              <input type="text" name="qty" id="qty"  maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty:') ?>" class="input-text qty" />
             <button class="button-arrow button-up" type="button"><?php echo $this->__('Increase');?></button>
             <button class="button-arrow button-down" type="button"><?php echo $this->__('Decrease');?></button>   
       </div> <!--add-to-cart-->
 <?php endif; ?>
         <div class="add-to-cart">
         <?php if($_product->isSaleable()): ?>
               <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="this.form.submit()"><span><?php echo $this->__('Add to Cart') ?></span></button>
         <?php else: ?>
               <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
         <?php endif; ?>
         </div><!-- add-to-cart-->
         <ul class="add-to-links">
            <?php if ($this->helper('wishlist')->isAllow()) : ?>
                  <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="button link-wishlist"><?php echo $this->__('Add to wishlist');?></a></li>
            <?php endif; ?>
           <?php /*?> <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                  <li><span class="separator">|</span><a href="<?php echo $_compareUrl ?>" class="button link-compare"><?php echo $this->__('Add to compare');?></a></li>
            <?php endif; ?><?php */?>
         </ul>
         <span class="email-friend"><a class="button link-friend" href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>" title="<?php echo $this->__('Email to a Friend') ?>"><?php echo $this->__('Email to a Friend') ?></a></span>

 </form>
     </div> <!--add-to-box-->

    </div> <!--product-shop-->
  </div> <!--product-essential-->
</div> <!--product-view-->
</div></div> <!-- End POP UP-->

<!-- BEGIN PROD IMAGE DETAIL -->
                  <div class="prod_image_detail">
                  <div class="inner">
                     <a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php //echo $this->htmlEscape($_product->getName()) ?>
                        <?php $prod_name = $this->htmlEscape($_product->getName()) ; 
                        /*if(strlen($prod_name) > 20) {echo substr($prod_name,0,20)."...";}else {echo $prod_name;}*/echo $prod_name;?></a>
                          <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                     <?php echo $this->getPriceHtml($_product, true) ?>
                     </div>
                     <div class="actions">
                        <?php if($_product->isSaleable()): ?>
                           <button type="button"  title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button>
                        <?php else: ?>
                           <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                    <span class="add-to-links"> <?php if ($this->helper('wishlist')->isAllow()) : ?>
                  <a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="button link-wishlist" title="<?php echo $this->__('Add to wishlist');?>"><?php echo $this->__('Add to wishlist');?></a>
            <?php endif; ?>
           <?php /*?> <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                  <a href="<?php echo $_compareUrl ?>" class="button link-compare" title="<?php echo $this->__('Add to compare');?>"><?php echo $this->__('Add to compare');?></a>
            <?php endif; ?><?php */?> </span><!--add-to-links-->

                     </div> <!--actions-->

                  </div> <!--prod_image_detail-->
                </li>

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

            <?php endif ?>
             <?php $v8++; ?>
                <?php endforeach ?>
          </ul>
       </div> <!--jcarousel-clip jcarousel-clip-horizontal-->
     </div> <!--jcarousel-container jcarousel-container-horizontal-->
  </div> <!-- jcarousel-skin-tango-->
</div> <!--slider-container-->
</div> <!--products_slider-->
        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script> 



<script type="text/javascript">
jQuery(document).ready(function($) {
        var jwidth=$('.products-grid-home').width();
        function mycarousel_initCallback(carousel) {
           $('#products_slider_next1').bind('click', function(event) {
                 carousel.next();
                 if(jwidth==2800){
                    return false;
                }
            });

            $('#products_slider_prev1').bind('click', function(event) {
                carousel.prev();
                return false;
            });
        };

    /*$('#products_slider1').jcarousel({
            scroll:1,
            visible:4,
            setupCallback: scrollCheck,
            initCallback: mycarousel_initCallback,
            buttonNextHTML: null,
            itemFallbackDimension:240,
            buttonPrevHTML: null,
            animation: {
            duration: 500,
            easing:   'linear',
            complete: function() {
            }
          }

    });*/
     $('#products_slider1').jcarousel({
            scroll: 1,
        initCallback:mycarousel_initCallback,
            buttonNextHTML: null,
            buttonPrevHTML: null
    });
    function scrollCheck(carousel) {
    if (carousel.options.size <= carousel.options.visible) {
        // If there is enough room to display all available items, then disable scrolling
        carousel.stopAuto();
    }
}
});
</script>

        <?php endif ?>

我对Magento很新。 谁能告诉我这个步骤呢?

1 个答案:

答案 0 :(得分:0)

您可以在产品的设计选项卡的后端指定它。如果您想以编程方式进行,请按照导入产品的方式确定问题...