Magento ajax
\!h ----- ajax по скролу
<?php
$current_url = $this->helper('core/url')->getCurrentUrl();
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$products_per_page = Mage::getModel('core/variable')->loadByCode('products_per_page')->getValue('html');
if( empty( $products_per_page ) ){
$products_per_page = 16;
}
?>
<?php if ( $this->getRequest()->isAjax() and !empty( $_GET['offset'] ) and !empty( $_GET['last_product_id'] ) ): ?>
<?php
$_collectionSize = $_productCollection->count();
$_columnCount = $this->getColumnCount();
$offset = $_GET['offset'];
$newoffset = $offset+$products_per_page;
$previous_product_id = 0;
?>
<ul class="products-grid products-grid--max-4-col">
<?php $conter = 0; $per_page_counter = 0; foreach ($_productCollection as $k => $_product): ++$conter; ?>
<?php
if( $conter > $offset ): ++$per_page_counter;
if( $_GET['last_product_id'] == $_product->getId() ){
$_product = Mage::getModel('catalog/product')->load( $last_product_id );
}
?>
<li>
<?php
if( $label = $_product->getlabel() ){
if( strtolower( $_product->getAttributeText('label') ) == 'nouveautés' ){
echo '<i class="icon icon-label-new"></i>';
}elseif( strtolower( $_product->getAttributeText('label') ) == 'promotions' ){
echo '<i class="icon icon-label-promo"></i>';
}elseif( strtolower( $_product->getAttributeText('label') ) == 'meilleures vente' ){
echo '<i class="icon icon-label-topvente"></i>';
}
}
?>
<a href="<?php echo $_product->getProductUrl() ?>" class="product-image">
<picture>
<source srcset="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(232,284); ?>, <?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(464,568); ?> 2x">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(232,284); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
</picture>
</a>
<h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h3>
<div class="info">
<?php echo $this->getPriceHtml($_product, true) ?>
<?php $poidsnet = $_product->getpoidsnet(); if(!empty($poidsnet)){ echo '<span class="weight">'.$poidsnet.'</span>'; } ?>
<?php if( $_product->isSaleable() && !$_product->canConfigure() ): ?>
<button onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')" class="button add-to-cart"></button>
<?php elseif( $_product->isSaleable() ): ?>
<button onclick="setLocation('<?php echo $_product->getProductUrl() ?>')" class="button add-to-cart"></button>
<?php endif; ?>
</div>
</li>
<?php endif; ?>
<?php $last_product_id = $_product->getId(); if( $per_page_counter == $products_per_page ){ break; } endforeach; ?>
</ul>
<?php if( $_collectionSize > $newoffset ): ?>
<?php
$load_more_url = '';
$url_arr = parse_url( $current_url );
if( $url_arr['query'] )
{
$current_url_query = explode( '&', $url_arr['query'] );
foreach ( $current_url_query as $k => $url_var) {
if( stripos( $url_var, 'offset' ) !== false ){
$current_url_query[$k] = 'offset='.$newoffset;
}
if( stripos( $url_var, 'last_product_id' ) !== false ){
$current_url_query[$k] = 'last_product_id='.$last_product_id;
}
}
$current_url_query = implode( '&', $current_url_query );
$load_more_url = $url_arr['scheme'] . '://' . $url_arr['host'] . $url_arr['path'].'?'.$current_url_query;
}else{
$filter_url = $url_arr['scheme'] . '://' . $url_arr['host'] . $url_arr['path'].'?offset='.$newoffset.'&last_product_id'.$last_product_id;
}
?>
<a class="load" href="<?php echo $load_more_url; ?>"><?php echo $this->__('Load More'); ?></a>
<?php endif; ?>
<?php else: ?>
<div class="category-products">
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<?php echo $this->getToolbarHtml() ?>
<div class="load-more-holder">
<?php
$_collectionSize = $_productCollection->count();
$_columnCount = $this->getColumnCount();
$offset = 0;
?>
<ul class="products-grid products-grid--max-4-col">
<?php foreach ($_productCollection as $_product): ++$offset; ?>
<li>
<?php
if( $label = $_product->getlabel() ){
if( strtolower( $_product->getAttributeText('label') ) == 'nouveautés' ){
echo '<i class="icon icon-label-new"></i>';
}elseif( strtolower( $_product->getAttributeText('label') ) == 'promotions' ){
echo '<i class="icon icon-label-promo"></i>';
}elseif( strtolower( $_product->getAttributeText('label') ) == 'meilleures vente' ){
echo '<i class="icon icon-label-topvente"></i>';
}
}
?>
<a href="<?php echo $_product->getProductUrl() ?>" class="product-image">
<picture>
<source srcset="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(232,284); ?>, <?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(464,568); ?> 2x">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(232,284); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
</picture>
</a>
<h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h3>
<div class="info">
<?php echo $this->getPriceHtml($_product, true) ?>
<?php $poidsnet = $_product->getpoidsnet(); if(!empty($poidsnet)){ echo '<span class="weight">'.$poidsnet.'</span>'; } ?>
<?php if( $_product->isSaleable() && !$_product->canConfigure() ): ?>
<button onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')" class="button add-to-cart"></button>
<?php elseif( $_product->isSaleable() ): ?>
<button onclick="setLocation('<?php echo $_product->getProductUrl() ?>')" class="button add-to-cart"></button>
<?php endif; ?>
</div>
</li>
<?php $last_product_id = $_product->getId(); if( $offset == $products_per_page ){ break; } endforeach; ?>
</ul>
<?php if($_collectionSize > $offset): ?>
<?php if(strrpos($current_url,'catalogsearch/result') != false or strrpos($current_url,'catalogsearch/advanced') != false): ?>
<a class="load" href="<?php echo $current_url.'&offset='.$offset.'&last_product_id='.$last_product_id; ?>"><?php echo $this->__('Load More'); ?></a>
<?php else:
if( strpos( $current_url, '?' ) !== false )
{
$current_url = $current_url.'&offset='.$offset.'&last_product_id='.$last_product_id;
}else{
$current_url = $current_url.'?offset='.$offset.'&last_product_id='.$last_product_id;
}
?>
<a class="load" href="<?php echo $current_url; ?>"><?php echo $this->__('Load More'); ?></a>
<?php endif; ?>
<?php endif; ?>
</div>
<?php echo $this->getChildHtml('home-payment') ?>
<?php endif; ?>
<?php
//set product collection on after blocks
$_afterChildren = $this->getChild('after')->getSortedChildren();
foreach($_afterChildren as $_afterChildName):
$_afterChild = $this->getChild('after')->getChild($_afterChildName);
$_afterChild->setProductCollection($_productCollection);
?>
<?php echo $_afterChild->toHtml(); ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
———————
<?php if (!$this->getRequest()->isAjax()): ?>
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(isset($_GET['ajax']) && !empty($_GET['ajax']) && isset($_GET['offset']) && !empty($_GET['offset'])): ?>
<?php
$_collectionSize = $_productCollection->count();
$_columnCount = 10;
$offset = $_GET['offset'];
$newoffset = $offset+10;
if(strrpos($this->helper('core/url')->getCurrentUrl(),'catalogsearch/result') != false || strrpos($this->helper('core/url')->getCurrentUrl(),'catalogsearch/advanced') != false){
$url = substr($this->helper('core/url')->getCurrentUrl(), 0, strpos($this->helper('core/url')->getCurrentUrl(),'&ajax'));
}
else{
$url = substr($this->helper('core/url')->getCurrentUrl(), 0, strpos($this->helper('core/url')->getCurrentUrl(),'?ajax'));
}
?>
<div>
<?php $i=0; $conter = 0; foreach ($_productCollection as $_product): ++$conter; ?>
<?php if($conter > $offset): ?>
<li class="item">
<?php $sale = $_product->getsale(); ?>
<?php $colors = $_product->getcolors(); ?>
<?php $_gallery = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php $imgcount = $_gallery->count();?>
<div class="product-img-holder">
<?php if(!empty($colors)): ?>
<a class="product-image color1" href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
<?php $counter = 0; $setcounter = 1; foreach ($_gallery as $_image ): ++$counter; ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->resize(124,310); ?>" class="<?php if($counter%2 == 0){echo 'img-on';}else{echo 'img';} ?>" alt="image description" width="124" height="310" />
<?php if($counter%2 == 0 && $counter != 0 && $imgcount != $counter): ++$setcounter; ?>
</a>
<a class="product-image color<?php echo $setcounter; ?>" href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
<?php endif; ?>
<?php endforeach; ?>
</a>
<?php else: ?>
<a class="product-image" href="<?php echo $_product->getProductUrl(); ?>" title="Product title">
<?php if($imgcount > 0): ?>
<?php $counter = 0; foreach ($_gallery as $_image ): ++$counter; ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->resize(124,310); ?>" class="<?php if($counter == 1){echo 'img';}else{echo 'img-on';} ?>" alt="image description" width="124" height="310" />
<?php if($counter == 2){break;} endforeach; ?>
<?php else: ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(124,310); ?>" width="124" height="310" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<?php endif; ?>
</a>
<?php endif; ?>
<a class="view lightbox" href="#product-<?php echo $_product->getId(); ?>"><?php echo $this->__('quick view'); ?></a>
<?php if(!empty($sale)): ?>
<span class="label-sale"><?php echo $this->__('Sale'); ?></span>
<?php endif; ?>
<?php
$newFromDate = Mage::getModel('catalog/product')->load($_product->getID())->getNewsFromDate();
$newToDate = Mage::getModel('catalog/product')->load($_product->getID())->getNewsToDate();
$now = date("Y-m-d H:m(worry)");
if($newFromDate < $now && $newToDate > $now):
?>
<span class="label-sale"><?php echo $this->__('New'); ?></span>
<?php endif; ?>
</div>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<a class="link-wishlist" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>"><?php echo $this->__('save to wishlist') ?></a>
<?php endif; ?>
<h3 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></h3>
<?php echo $this->getPriceHtml($_product, false) ?>
<?php if(!empty($colors)){ echo $_helper->productAttribute($_product, $colors, 'colors'); } ?>
<div class="popup-holder">
<?php $_product = Mage::getModel('catalog/product')->load($_product->getId()); ?>
<div class="popup popup-product" id="product-<?php echo $_product->getId(); ?>">
<div class="product-essential">
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field<?php echo $_product->getId(); ?>" value="" />
</div>
<?php $bigcolors = $_product->getbigcolors(); ?>
<div class="product-img-box">
<p class="product-image">
<img class="product-img" src="<?php echo $this->helper('catalog/image')->init($_product, 'image')->resize(216,446); ?>" width="216" height="446" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'image'), null, true) ?>" />
</p>
</div>
<div class="product-shop">
<div class="product-name">
<h1><?php echo $_product->getName(); ?></h1>
</div>
<div class="add-info">
<?php $sku = $_product->getsku(); if(!empty($sku)){ echo '<p>'.$this->__('Style').' '.$sku.'</p>'; } ?>
<?php if($_product->isSaleable()): ?>
<p class="availability in-stock"><?php echo $this->__('Availability') ?>: <span><?php echo $this->__('In stock') ?></span></p>
<?php else: ?>
<p class="availability out-of-stock"><?php echo $this->__('Availability') ?>: <span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
<div id="product-options-wrapper" class="product-options">
<dl class="last">
<?php if(!empty($bigcolors)): ?>
<dt><strong class="label"><?php echo $this->__('Colors') ?></strong></dt>
<dd>
<?php echo $_helper->productAttribute($_product, $bigcolors, 'colors') ?>
</dd>
<?php endif; ?>
<?php if($_product->getTypeId() == "configurable"): ?>
<?php $attValConfig = $_product->getTypeInstance()->getConfigurableAttributesAsArray(); ?>
<?php if(sizeof($attValConfig)): ?>
<?php foreach($attValConfig as $attValConfigSingle): ?>
<dt><label for="attribute<?php echo $_product->getId() ?>" class="required"><?php echo $attValConfigSingle['label']; ?></label></dt>
<dd class="last">
<div class="input-box">
<select name="super_attribute[<?php echo $attValConfigSingle['attribute_id'] ?>]" id="attribute<?php echo $_product->getId() ?>" class="required-entry super-attribute-select">
<?php foreach($attValConfigSingle['values'] as $attValConfigSingleVal): ?>
<option value="<?php echo $attValConfigSingleVal['value_index'] ?>"><?php echo $attValConfigSingleVal['label'] ?></option>
<?php endforeach; ?>
</select>
</div>
</dd>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
</dl><a href="mailto:"></a>
</div>
<div class="add-to-box">
<div class="add-to-cart">
<div class="holder">
<label for="qty"><?php echo $this->__('Qty'); ?>:</label>
<input type="text" name="qty" id="qty" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<input type="submit" class="no-display" value="Sub"/>
</div>
<button class="button btn-cart" title="<?php echo $this->__('add to basket') ?>" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')" type="button"><span><span data-bg-hover="#000"><?php echo $this->__('add to basket') ?></span></span></button>
</div>
<?php $_wishlistSubmitUrl = $this->helper('wishlist')->getAddUrl($_product); ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<ul class="add-to-links-alt">
<li><a href="<?php echo $_wishlistSubmitUrl ?>" onclick="productAddToCartForm.submitLight(this, '<?php echo $_wishlistSubmitUrl ?>'); return false;" data-hover="#484848" class="link-wishlist-alt"><?php echo $this->__('save to wishlist') ?></a></li>
</ul>
<?php endif; ?>
</div>
<?php $description = $_product->getdescription(); if(!empty($description)): ?>
<div class="short-description">
<div class="std">
<?php echo $_helper->productAttribute($_product, $_product->getDescription(), 'description') ?>
</div>
</div>
<?php endif; ?>
<p class="more"><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $this->__('view full details'); ?> ></a></p>
</div>
</form>
</div>
</div>
</div>
</li>
<?php endif ?>
<?php if($conter == $newoffset){break;} endforeach ?>
<?php if($_collectionSize > $newoffset): ?>
<?php if(strrpos($this->helper('core/url')->getCurrentUrl(),'catalogsearch/result') != false || strrpos($this->helper('core/url')->getCurrentUrl(),'catalogsearch/advanced') != false): ?>
<a class="next-load" href="<?php echo $url.'&ajax=1&offset='.$newoffset; ?>"><?php echo $this->__('next load'); ?></a>
<?php else: ?>
<a class="next-load" href="<?php echo $url.'?ajax=1&offset='.$newoffset; ?>"><?php echo $this->__('next load'); ?></a>
<?php endif; ?>
<?php endif ?>
</div>
<?php else: ?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="products-box">
<?php
$_collectionSize = $_productCollection->count();
$_columnCount = 10;
$offset = 0;
?>
<?php $i=0; foreach ($_productCollection as $_product): ++$offset; ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item">
<?php $sale = $_product->getsale(); ?>
<?php $colors = $_product->getcolors(); ?>
<?php $_gallery = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php $imgcount = $_gallery->count();?>
<div class="product-img-holder">
<?php if(!empty($colors)): ?>
<a class="product-image color1" href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
<?php $counter = 0; $setcounter = 1; foreach ($_gallery as $_image ): ++$counter; ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->resize(124,310); ?>" class="<?php if($counter%2 == 0){echo 'img-on';}else{echo 'img';} ?>" alt="image description" width="124" height="310" />
<?php if($counter%2 == 0 && $counter != 0 && $imgcount != $counter): ++$setcounter; ?>
</a>
<a class="product-image color<?php echo $setcounter; ?>" href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
<?php endif; ?>
<?php endforeach; ?>
</a>
<?php else: ?>
<a class="product-image" href="<?php echo $_product->getProductUrl(); ?>" title="Product title">
<?php if($imgcount > 0): ?>
<?php $counter = 0; foreach ($_gallery as $_image ): ++$counter; ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->resize(124,310); ?>" class="<?php if($counter == 1){echo 'img';}else{echo 'img-on';} ?>" alt="image description" width="124" height="310" />
<?php if($counter == 2){break;} endforeach; ?>
<?php else: ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(124,310); ?>" width="124" height="310" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<?php endif; ?>
</a>
<?php endif; ?>
<a class="view lightbox" href="#product-<?php echo $_product->getId(); ?>"><?php echo $this->__('quick view'); ?></a>
<?php if(!empty($sale)): ?>
<span class="label-sale"><?php echo $this->__('Sale'); ?></span>
<?php endif; ?>
<?php
$newFromDate = Mage::getModel('catalog/product')->load($_product->getID())->getNewsFromDate();
$newToDate = Mage::getModel('catalog/product')->load($_product->getID())->getNewsToDate();
$now = date("Y-m-d H:m(worry)");
if($newFromDate < $now && $newToDate > $now):
?>
<span class="label-sale"><?php echo $this->__('New'); ?></span>
<?php endif; ?>
</div>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<a class="link-wishlist" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>"><?php echo $this->__('save to wishlist') ?></a>
<?php endif; ?>
<h3 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></h3>
<?php echo $this->getPriceHtml($_product, false) ?>
<?php if(!empty($colors)){ echo $_helper->productAttribute($_product, $colors, 'colors'); } ?>
<div class="popup-holder">
<?php $_product = Mage::getModel('catalog/product')->load($_product->getId()); ?>
<div class="popup popup-product" id="product-<?php echo $_product->getId(); ?>">
<div class="product-essential">
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field<?php echo $_product->getId(); ?>" value="" />
</div>
<?php $bigcolors = $_product->getbigcolors(); ?>
<div class="product-img-box">
<p class="product-image">
<img class="product-img" src="<?php echo $this->helper('catalog/image')->init($_product, 'image')->resize(216,446); ?>" width="216" height="446" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'image'), null, true) ?>" />
</p>
</div>
<div class="product-shop">
<div class="product-name">
<h1><?php echo $_product->getName(); ?></h1>
</div>
<div class="add-info">
<?php $sku = $_product->getsku(); if(!empty($sku)){ echo '<p>'.$this->__('Style').' '.$sku.'</p>'; } ?>
<?php if($_product->isSaleable()): ?>
<p class="availability in-stock"><?php echo $this->__('Availability') ?>: <span><?php echo $this->__('In stock') ?></span></p>
<?php else: ?>
<p class="availability out-of-stock"><?php echo $this->__('Availability') ?>: <span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
<div id="product-options-wrapper" class="product-options">
<dl class="last">
<?php if(!empty($bigcolors)): ?>
<dt><strong class="label"><?php echo $this->__('Colors') ?></strong></dt>
<dd>
<?php echo $_helper->productAttribute($_product, $bigcolors, 'colors') ?>
</dd>
<?php endif; ?>
<?php if($_product->getTypeId() == "configurable"): ?>
<?php $attValConfig = $_product->getTypeInstance()->getConfigurableAttributesAsArray(); ?>
<?php if(sizeof($attValConfig)): ?>
<?php foreach($attValConfig as $attValConfigSingle): ?>
<dt><label for="attribute<?php echo $_product->getId() ?>" class="required"><?php echo $attValConfigSingle['label']; ?></label></dt>
<dd class="last">
<div class="input-box">
<select name="super_attribute[<?php echo $attValConfigSingle['attribute_id'] ?>]" id="attribute<?php echo $_product->getId() ?>" class="required-entry super-attribute-select">
<?php foreach($attValConfigSingle['values'] as $attValConfigSingleVal): ?>
<option value="<?php echo $attValConfigSingleVal['value_index'] ?>"><?php echo $attValConfigSingleVal['label'] ?></option>
<?php endforeach; ?>
</select>
</div>
</dd>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
</dl><a href="mailto:"></a>
</div>
<div class="add-to-box">
<div class="add-to-cart">
<div class="holder">
<label for="qty"><?php echo $this->__('Qty'); ?>:</label>
<input type="text" name="qty" id="qty" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<input type="submit" class="no-display" value="Sub"/>
</div>
<button class="button btn-cart" title="<?php echo $this->__('add to basket') ?>" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')" type="button"><span><span data-bg-hover="#000"><?php echo $this->__('add to basket') ?></span></span></button>
</div>
<?php $_wishlistSubmitUrl = $this->helper('wishlist')->getAddUrl($_product); ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<ul class="add-to-links-alt">
<li><a href="<?php echo $_wishlistSubmitUrl ?>" onclick="productAddToCartForm.submitLight(this, '<?php echo $_wishlistSubmitUrl ?>'); return false;" data-hover="#484848" class="link-wishlist-alt"><?php echo $this->__('save to wishlist') ?></a></li>
</ul>
<?php endif; ?>
</div>
<?php $description = $_product->getdescription(); if(!empty($description)): ?>
<div class="short-description">
<div class="std">
<?php echo $_helper->productAttribute($_product, $_product->getDescription(), 'description') ?>
</div>
</div>
<?php endif; ?>
<p class="more"><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $this->__('view full details'); ?> ></a></p>
</div>
</form>
</div>
</div>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php if($offset == 10){break;} endforeach; ?>
<?php if($_collectionSize > $offset): ?>
<?php if(strrpos($this->helper('core/url')->getCurrentUrl(),'catalogsearch/result') != false || strrpos($this->helper('core/url')->getCurrentUrl(),'catalogsearch/advanced') != false): ?>
<a href="<?php echo $this->helper('core/url')->getCurrentUrl().'&ajax=1&offset='.$offset; ?>" class="load-more"><?php echo $this->__('Lorem Ipsum Dolor'); ?></a>
<?php else: ?>
<a href="<?php echo $this->helper('core/url')->getCurrentUrl().'?ajax=1&offset='.$offset; ?>" class="load-more"><?php echo $this->__('Lorem Ipsum Dolor'); ?></a>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
</script>
</div>
<?php endif; ?>
\!h ----- не забудь сделать проверку в шаблонах старниц и во всех шаблонах которые идут выше пример : 1column.phtml
\!h ----- Добавление продукта в корзину с кастомным квонтити аяксом
<?php if(strtolower($cur_category->getName()) != $this->__('nyinkommet')): ?>
<?php if($productModel->isSaleable()): ?>
<div class="add-to-box">
<div class="add-to-cart">
<div class="qty-box">
<?php if(!$productModel->isGrouped()): ?>
<form action="<?php echo $this->helper('checkout/cart')->getAddUrl($productModel) ?>" method="post" id="product_addtocart_form_<?php echo $categoryId ?>_<?php echo $productModel->getId(); ?>"<?php if($productModel->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $productModel->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field<?php echo $productModel->getId(); ?>" value="" />
</div>
<a onclick="change_qty_<?php echo $categoryId ?>_<?php echo $productModel->getId(); ?>(-1)" class="min"><span>-</span></a>
<input type="text" name="qty" id="qty<?php echo $categoryId ?>_<?php echo $productModel->getId(); ?>" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="text qty" />
<a class="max" onclick="change_qty_<?php echo $categoryId ?>_<?php echo $productModel->getId(); ?>(1)"><span>+</span></a>
<script type="text/javascript">
function change_qty_<?php echo $categoryId ?>_<?php echo $productModel->getId(); ?>(x) {
var qty = parseInt(jQuery('#qty<?php echo $categoryId ?>_<?php echo $productModel->getId(); ?>').val());
qty = qty + x;
if (qty < 1) { qty = 1; }
jQuery('#qty<?php echo $categoryId ?>_<?php echo $productModel->getId(); ?>').val(qty);
}
</script>
<input type="submit" class="no-display" value="Sub"/>
</form>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
<div class="product-bottom">
<div class="price-box">
<span class="regular-price">
<?php echo Mage::helper('core')->currency($productModel->getPrice()); ?>
</span>
</div>
<?php if(strtolower($cur_category->getName()) == $this->__('nyinkommet')): ?>
<div class="actions">
<button class="button btn" type="button" onclick="setLocation('<?php echo $productModel->getProductUrl() ?>')"><span><span><?php echo $this->__('Read more'); ?></span></span></button>
</div>
<?php else: ?>
<div class="actions">
<?php if($productModel->isSaleable()): ?>
<?php if( $productModel->getTypeId() == 'simple' ): ?>
<button type="button" title="Add to Cart" class="button btn-cart" onclick="productAddToCartForm<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>.submit(this)"><span><span><?php echo $this->__('Buy'); ?></span></span></button>
<span id='ajax_loader<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>' style='display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>
<?php else: ?>
<button class="button btn-cart" title="Add to Cart" type="button" onclick="product_addtocart_form_<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>.submit()"><span><span><?php echo $this->__('Buy'); ?></span></span></button>
<?php endif; ?>
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm<?php echo $categoryId ?>_<?php echo $productModel->getId() ?> = new VarienForm('product_addtocart_form_<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>');
productAddToCartForm<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
//Start of our new ajax code
if(!url){
url = jQuery('#product_addtocart_form_<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>').attr('action');
}
var data = jQuery('#product_addtocart_form_<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>').serialize();
data += '&isAjax=1';
jQuery('#ajax_loader<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>').show();
try {
jQuery.ajax({
url: url,
dataType: 'json',
type : 'post',
data: data,
success: function(data){
jQuery('#ajax_loader<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>').hide();
//alert(data.status + ": " + data.message);
if(jQuery('.block-cart')){
jQuery('.block-cart').replaceWith(data.cart_html_contents);
jQuery('.block-cart').openClose({
activeClass: 'active',
opener: '.block-content',
slider: '.drop-cart',
event:'over',
animSpeed: 400,
effect: 'slide'
});
}
if(jQuery('.header .links')){
jQuery('.header .links').replaceWith(data.toplink);
}
}
});
} catch (e) {
}
//End of our new ajax code
this.form.action = oldUrl;
if (e) {
throw e;
}
}
}.bind(productAddToCartForm<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>);
productAddToCartForm<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm<?php echo $categoryId ?>_<?php echo $productModel->getId() ?>);
//]]>
</script>
<?php else: ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<button class="button btn2" type="button" onclick="setLocation('<?php echo $this->helper('wishlist')->getAddUrl($productModel) ?>')"><span><span><?php echo $this->__('Watch'); ?></span></span></button>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
------------------------------------------------
<li><a href="<?php echo $this->getUrl('checkout/cart').'?ajax=1'; ?>" class="link-popup">CHECKOUT</a></li>
// init popup
function initPopup(){
jQuery('.link-popup').each(function() {
var btn = jQuery(this);
btn.colorbox({
inline: !!this.hash,
innerWidth: 1145,
opacity: 0.7,
data: "ajax=1",
onComplete: function() {
jQuery('#colorbox .btn-hide').click(function() {
jQuery.colorbox.close();
return false;
});
}
});
});
}
if($_POST['ajax'] == 1):
\!h ----- Ajax для каждой категории табами по 3 продукта + все продукты в первом табе
<?php if(isset($_GET['ajax']) && $_GET['ajax'] == 1): ?>
<?php
$nav = new Mage_Catalog_Block_Navigation;
$cats = $nav->getStoreCategories();
$cats_arr = array();
foreach($cats as $item)
{
if($item->getIsActive())
{
$cats_arr[] = $item->getId();
$children = $item->getChildren();
if($children)
{
foreach($children as $item)
{
if($item->getIsActive())
$cats_arr[] = $item->getId();
}
}
}
}
?>
<div class="products-view gallery">
<div class="gholder">
<span class="gmask"></span>
<ul>
<?php if(isset($_GET['cat'])):
$catajax = $_GET['cat']; if(isset($_GET['posts'])){ $posts = $_GET['posts']; }else{ $posts = 1; }
global $catcount;
$catcount = 0;
?>
<?php foreach($cats_arr as $item): ?>
<?php
$_category = Mage::getModel('catalog/category')->load($item);
if(strtolower($_category->getName()) == $catajax || $catajax == 'all'):
?>
<?php
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToFilter('visibility', array('neq' => 1))
->addAttributeToSelect('*')
->addCategoryFilter($_category)
->setOrder('created_at', 'desc');
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($_productCollection);
$_helper = $this->helper('catalog/output');
?>
<?php
$_collectionSize = $_productCollection->count();
if($catajax == 'all'){
$catcount += $_productCollection->count();
}
else{
$catcount = $_productCollection->count();
}
?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php global $postcounter; $postcounter = 0; foreach($_productCollection as $_product): ++$postcounter; ?>
<?php if($posts > 1 && $postcounter > $posts || $posts == 1): ?>
<?php $_product = Mage::getModel('catalog/product')->load($_product->getId()) ?>
<?php $_gallery = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php $imgcount = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages()->count();?>
<li title="<?php echo strtolower($_category->getName()); ?>">
<div class="item">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image'); ?>" alt="#" width="283" height="385" />
<?php if($imgcount > 1): ?>
<?php $j = 0; foreach ($_gallery as $_image ): ++$j; if($j > 1 && $j < 3): ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'store_view', $_image->getFile())->resize(); ?>" alt="#" width="283" height="385" class="show-product" />
<?php endif; endforeach; ?>
<?php endif; ?>
</a>
<div class="body">
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></h2>
<?php echo $this->getPriceHtml($_product, false) ?>
</div>
</div>
</li>
<?php endif; ?>
<?php if($posts == 1 && $postcounter == 3){ break; } if($posts > 1 && ($posts+3) == $postcounter){ break; } endforeach; ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
<?php if($catajax == 'all'){ break; } endforeach; ?>
<?php endif; ?>
</ul>
</div>
<a href="#" class="link-prev">prev</a>
<a href="<?php echo '?ajax=1&cat='.$catajax.'&posts='.$postcounter; ?>" class="link-next">next</a>
<div class="toolbar">
<ul>
<li><span class="cur-num">1-3</span> of <span class="all-num"><?php echo $catcount; ?></span></li>
<li><a href="#"> <?php echo $this->__('View All'); ?></a></li>
</ul>
</div>
</div>
<?php else: ?>
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$currentcategory = Mage::registry('current_category');
?>
<div class="category-products">
<ul id="categories">
<?php $nav_class = new Mage_Catalog_Block_Navigation; ?>
<?php foreach ($nav_class->getStoreCategories() as $_category):
if ($_category->getIsActive()): $li_class = ''; ?>
<li class="active">
<a href="<?php echo $this->helper('core/url')->getCurrentUrl().'?ajax=1&cat=all&posts=1'; ?>" class="all tab">
<?php echo $this->__('all'); ?></a>
</li>
<?php
if(method_exists($_category, 'getChildrenCategories'))
$childrens = $_category->getChildrenCategories();
else
$childrens = $_category->getChildren();
if($childrens && $childrens->count()): ?>
<?php $i = 1; foreach ($childrens as $children): ++$i;?>
<?php if ($children->getIsActive()):?>
<?php
$products = '';
$empty = '';
if(!empty($children)){
$cur_category = Mage::getModel('catalog/category')->load($children->getId());
$products = $cur_category->getProductCollection();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
}
foreach ( $products as $productModel )
{
$empty = Mage::getModel('catalog/product')->load($productModel->getId());
$empty = $empty->getProductUrl();
break;
}
if(!empty($empty)) :
?>
<li>
<a href="<?php echo $this->helper('core/url')->getCurrentUrl().'?ajax=1&cat='.strtolower($children->getName()).'&posts=1'; ?>" class="<?php echo strtolower($children->getName()); ?> tab">
<?php echo strtolower($children->getName()); ?>
</a>
</li>
<?php endif;?>
<?php endif;?>
<?php endforeach;?>
<?php endif;?>
<?php endif;?>
<?php endforeach;?>
</ul>
<div class="tabs-content">
</div>
</div>
<?php endif; ?>