zigojacko

ajax list

Aug 22nd, 2013
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 10.60 KB | None | 0 0
  1. <?php
  2.    $_productCollection=$this->getLoadedProductCollection();
  3.     $_helper = $this->helper('catalog/output');
  4.     $this->setData('column_count',2);
  5. ?>
  6. <?php if(!$_productCollection->count()): ?>
  7. <p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
  8. <?php else: ?>
  9. <div class="category-products">
  10.     <?php echo $this->getToolbarHtml() ?>
  11.     <?php // List mode ?>
  12.     <?php if($this->getMode()!='grid'): ?>
  13.     <?php $_iterator = 0; ?>
  14.     <ol class="products-list" id="products-list">
  15.     <?php foreach ($_productCollection as $_product): ?>
  16.         <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
  17.             <?php // Product Image ?>
  18.             <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
  19.             <?php // Product description ?>
  20.             <div class="product-shop">
  21.                 <div class="f-fix">
  22.                     <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
  23.                     <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2>
  24.                     <?php if($_product->getRatingSummary()): ?>
  25.                     <?php echo $this->getReviewsSummaryHtml($_product) ?>
  26.                     <?php endif; ?>
  27.                     <?php echo $this->getPriceHtml($_product, true) ?>
  28.                     <?php if($_product->isSaleable()): ?>
  29.                         <?php if ( !($_product->getTypeInstance(true)->hasRequiredOptions($_product) || $_product->isGrouped()) ) { ?>
  30.                         <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocationAjax('<?php echo $this->getAddToCartUrl($_product) ?>','<?php echo $_product->getId()?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
  31.                         <span id='ajax_loader<?php echo $_product->getId()?>' style='display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>
  32.                         <?php } else { ?>
  33.                             <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="showOptions('<?php echo $_product->getId()?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
  34.                             <a href='<?php echo $this->getUrl('ajax/index/options',array('product_id'=>$_product->getId()));?>' class='fancybox' id='fancybox<?php echo $_product->getId()?>' style='display:none'>Test</a>
  35.                         <?php }  ?>
  36.                     <?php else: ?>
  37.                         <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
  38.                     <?php endif; ?>
  39.                     <div class="desc std">
  40.                         <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
  41.                         <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>" class="link-learn"><?php echo $this->__('Learn More') ?></a>
  42.                     </div>
  43.                     <ul class="add-to-links">
  44.                         <?php if ($this->helper('wishlist')->isAllow()) : ?>
  45.                             <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
  46.                         <?php endif; ?>
  47.                         <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
  48.                             <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
  49.                         <?php endif; ?>
  50.                     </ul>
  51.                 </div>
  52.             </div>
  53.         </li>
  54.     <?php endforeach; ?>
  55.     </ol>
  56.     <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
  57.  
  58.     <?php else: ?>
  59.  
  60.     <?php // Grid Mode ?>
  61.  
  62.     <?php $_collectionSize = $_productCollection->count() ?>
  63.     <?php $_columnCount = $this->getColumnCount(); ?>
  64.     <?php $i=0; foreach ($_productCollection as $_product): ?>
  65.         <?php if ($i++%$_columnCount==0): ?>
  66.         <ul class="products-grid">
  67.         <?php endif ?>
  68.             <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
  69.                 <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
  70.                
  71.                 <?php echo $this->getPriceHtml($_product, true) ?>
  72.                
  73.                 <div class="actions">
  74.                     <?php if($_product->isSaleable()): ?>
  75.                         <?php if ( !($_product->getTypeInstance(true)->hasRequiredOptions($_product) || $_product->isGrouped()) ) { ?>
  76.                         <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocationAjax('<?php echo $this->getAddToCartUrl($_product) ?>','<?php echo $_product->getId()?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
  77.                         <span id='ajax_loader<?php echo $_product->getId()?>' class='loader' style='display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>
  78.                         <?php } else { ?>
  79.                             <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="showOptions('<?php echo $_product->getId()?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
  80.                             <a href='<?php echo $this->getUrl('ajax/index/options',array('product_id'=>$_product->getId()));?>' class='fancybox' id='fancybox<?php echo $_product->getId()?>' style='display:none'></a>
  81.                         <?php }  ?>
  82.                     <?php else: ?>
  83.                         <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
  84.                     <?php endif; ?>
  85.                     <ul class="add-to-links">
  86.                         <?php if ($this->helper('wishlist')->isAllow()) : ?>
  87.                             <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
  88.                         <?php endif; ?>
  89.                         <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
  90.                             <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
  91.                         <?php endif; ?>
  92.                     </ul>
  93.                    
  94.                     <?php if($_product->getRatingSummary()): ?>
  95.                     <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
  96.                     <?php endif; ?>
  97.                    
  98.                 </div>
  99.                
  100.                 <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
  101.                
  102.                 <p class="sku"><?php echo $this->__('SKU Code: ') ?><span><?php echo $this->htmlEscape($_product->getSku()); ?></span></p>
  103.                
  104.             </li>
  105.         <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
  106.         </ul>
  107.         <?php endif ?>
  108.         <?php endforeach ?>
  109.         <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
  110.     <?php endif; ?>
  111.  
  112.     <div class="toolbar-bottom">
  113.         <?php echo $this->getToolbarHtml() ?>
  114.     </div>
  115. </div>
  116. <?php endif; ?>
  117.  
  118. <div id="fancybox<?php echo $_product->getId()?>" class="fancybox fancy-popupbox" style="position:absolute; display:none;">
  119. <div class="popup-text"></div>
  120. <div class="popup-buttons">
  121.     <div style="float:left">
  122.         <button onclick="setLocation('')" class="button btn-shop" title="Continue Shopping" type="button"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
  123.     </div>
  124.     <div style="float:right">
  125.         <button onclick="setLocation('<?php echo $this->getBaseUrl();?>checkout/onepage')" class="button btn-checkout" title="Proceed to Checkout" type="button"><span><span><?php echo $this->__('Proceed to Checkout') ?></span></span></button>
  126.     </div>
  127. </div>
  128. </div>
  129.  
  130. <script type="text/javascript">
  131.     jQuery.noConflict();
  132.     jQuery(document).ready(function(){
  133.         jQuery('.fancybox').fancybox(
  134.             {
  135.                hideOnContentClick : true,
  136.                width: 382,
  137.                autoDimensions: true,
  138.                type : 'iframe',
  139.                showTitle: false,
  140.                scrolling: 'no',
  141.                onComplete: function(){
  142.                 jQuery('#fancybox-frame').load(function() { // wait for frame to load and then gets it's height
  143.                     jQuery('#fancybox-content').height(jQuery(this).contents().find('body').height()+30);
  144.                     jQuery.fancybox.resize();
  145.                  });
  146.  
  147.                }
  148.             }
  149.         );
  150.     });
  151.     function showOptions(id){
  152.         jQuery('#fancybox'+id).trigger('click');
  153.     }
  154.     function setAjaxData(data,iframe){
  155.         if(data.status == 'ERROR'){
  156.             alert(data.message);
  157.         }else{
  158.             if(jQuery('.block-cart')){
  159.                 jQuery('.block-cart').replaceWith(data.sidebar);
  160.             }
  161.             if(jQuery('.header .links')){
  162.                 jQuery('.header .links').replaceWith(data.toplink);
  163.             }
  164.             jQuery.fancybox.close();
  165.         }
  166.     }
  167.     function setLocationAjax(url,id){
  168.         url += 'isAjax/1';
  169.         url = url.replace("checkout/cart","ajax/index");
  170.         jQuery('#ajax_loader'+id).show();
  171.         try {
  172.             jQuery.ajax( {
  173.                 url : url,
  174.                 dataType : 'json',
  175.                 success : function(data) {
  176.                     jQuery('#ajax_loader'+id).hide();
  177.                     jQuery('.popup-text').html(data.message);
  178.                     jQuery('.fancy-popupbox').show();
  179.                     setAjaxData(data,false);          
  180.                 }
  181.             });
  182.         } catch (e) {
  183.         }
  184.     }
  185. </script>
Advertisement
Add Comment
Please, Sign In to add comment