0

What I tried to archive is: Display a product list in a slider on product view page. The product list is from another category and all products in this list are not related to any other products. I have tried so far:

catalog.xml

<reference name="content">
<block type="cms/block" name="block_accessories_list">
  <action method="setBlockId">
      <block_id>block_accessories_list</block_id>
  </action>
</block>
</reference>

template/catalog/product/widget/new/content/accessories.phtml

<?php if (($_products = $this->getProductCollection()) && 

$_products->getSize()): ?>
<?php
  $_productCollection = $this->getItems();
  $theme = $this->helper('ultimo');
  $helpImg = $this->helper('infortis/image');
  $i = 0;
  $sliderClasses = '';
  $gridClasses = '';

  //Additional parameters
  $isResponsive = true;
  if ($_collectionSize <= $productCountInSlide)
  {
      //If total number of products is smaller than number of products displayed in a single slide
      $isResponsive = false;
  }
  //Slider parameters
  //--------------------------------------------------------------

  $sliderId = "itemslider-related-multi";

  //Responsive mode on/off
  $isResponsive = true;

  //Assign number of items in a row to specific viewport width
  $breakpoints = '[0, 1], [480, 2], [768, 4]';

  //Pagination on/off
  $pagination = false;

  //Slider timeout. Set to enable automatic scrolling.
  $timeout = intval($theme->getCfg('product_page/related_timeout'));

  //Number of items that should move on scrolling
  $move = 0;

  //If set, slider will loop
  $loop = $theme->getCfg('product_slider/loop');

  //Speed (arrows / touch swipe)
  $speed = intval($theme->getCfg('product_slider/speed'));

  //Speed (automatic scrolling / pagination)
  $autoSpeed = intval($theme->getCfg('product_slider/auto_speed'));

  //Pause slider on mouse hover
  $pause = $theme->getCfg('product_slider/pause');
?>
<div class="widget widget-new-products">
    <div class="widget-title">
        <h2><?php echo $this->__('') ?></h2>
    </div>
    <div class="widget-products">
    <?php echo $this->getPagerHtml() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <div class="itemslider-wrapper itemslider-related-wrapper slider-arrows1 slider-arrows1-pos-top-right slider-pagination1">
    <?php if ($i++%$_columnCount==0): ?>
    <ul id="<?php echo $sliderId; ?>" class="itemslider <?php if($sliderClasses) echo $sliderClasses; ?> extra-product-slider">
    <?php endif; ?>

        <?php $i=0; foreach ($_products->getItems() as $_product): ?>

            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a class="product-link"
                href="<?php echo $_product->getProductUrl() ?>"
                title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
                <div class="product-image" style="background-image: url(<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize() ?>)">

                </div>
                  <div class="product-info-box">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
                      <h3 class="product-name"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></h3>
                      <p>
                        <?php echo $this->getPriceHtml($_product, true, '-widget-new-grid') ?>
                      </p>
                    </a>
                  </div>
                </a>
            </li>
        <?php endforeach; ?>

        <?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
        </ul>
      <?php endif; ?>
    </div>
    </div>
</div>
<?php endif; ?>
<script type="text/javascript">
//<![CDATA[
    jQuery(function($) {

        var owl = $('#<?php echo $sliderId; ?>');
        owl.owlCarousel({

        <?php if(!$isResponsive): ?>
            responsive: false,
            items: <?php echo $showItems; ?>,
        <?php else: ?>
            itemsCustom: [ <?php echo $breakpoints; ?> ],
            responsiveRefreshRate: 50,
        <?php endif; ?>

        <?php if ($speed): ?>
            slideSpeed: <?php echo $speed; ?>,
        <?php endif; ?>

        <?php if ($autoSpeed): ?>
            paginationSpeed: <?php echo $autoSpeed; ?>,
        <?php endif; ?>

        <?php if ($move !== 1): ?>
            scrollPerPage: true,
        <?php endif; ?>

        <?php if ($timeout): ?>
            autoPlay: false<?php //echo $timeout; ?>,
        <?php endif; ?>

        <?php if ($pause): ?>
            stopOnHover: true,
        <?php endif; ?>

        <?php if ($loop): ?>
            rewindNav: true,
            rewindSpeed: 1000,
        <?php else: ?>
            rewindNav: false,
        <?php endif; ?>

        <?php if ($pagination): ?>
            pagination: true,
        <?php else: ?>
            pagination: false,
        <?php endif; ?>

            navigation: true,
            navigationText: false

        }); //end: owl

    });
//]]>
</script>

This code shows the latest added products from all categories. How do i change it, so it only display new products from one specific category?

0

1 Answer 1

1

Found a solution by myself. I added this code at the top of accessories.phtml.

$categoryId = 10; 
$category = Mage::getModel('catalog/category')->load($categoryId);


$collection = $category->getProductCollection()->addAttributeToSelect(array('name', 'image', 'price'));

And replace

if (($_products = $getProductCollection) && $_products->getSize()):

with

if (($_products = $collection) && $_products->getSize()):

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.