Skip to content

Instantly share code, notes, and snippets.

@amacgregor
Created June 10, 2011 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amacgregor/1019729 to your computer and use it in GitHub Desktop.
Save amacgregor/1019729 to your computer and use it in GitHub Desktop.
Media Phtml file
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category design
* @package base_default
* @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
/**
* Product media data template
*
* @see Mage_Catalog_Block_Product_View_Media
*/
?>
<?php
$_product = $this->getProduct();
$_helper = $this->helper('catalog/output');
$img_url='';
$_moreShow=0;
?>
<?php
foreach ($this->getGalleryImages() as $_image):
if (($_image->disabled)!=1) {
$_moreShow++;
}
if ($_image->getLabel() == 'pop' || $_image->getLabel() == 'pop-up') { // we want it
$img_url = $this->helper('catalog/image')->init($_product, 'image', $_image->getFile());
}
endforeach;
?>
<?php
$_categories = $_product->getCategoryIds();
if($_product->getParentCategoryid()){
$_category = Mage::getModel('catalog/category')->load($_product->getParentCategoryid());
}else {
$_category = Mage::getModel('catalog/category')->load($_categories[0]);
}
$products = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter($_category)
->addAttributeToSelect('*');
?>
<?php if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
<p class="product-image">
<a href="<?php echo $img_url; ?>" rel="lightbox[gallery]" title="<?php echo $_product->getArtistFname()." ".$_product->getArtistLname();?><br /><?php echo $this->htmlEscape($_product->getName()) ?>, <?php echo $this->htmlEscape($_product->getArtworkCreationDate()) ?>"> <?php
$_img = '<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($_product->getName()).'" title="'.$this->htmlEscape($_product->getName()).'" />';
echo $_helper->productAttribute($_product, $_img, 'image');
?></a>
<?php foreach ( $products as $productModel ):
$_product2 = Mage::getModel('catalog/product')->load($productModel->getId()); ?>
<?php foreach ($_product2->getMediaGalleryImages() as $_image): ?>
<?php
if ($_image->getLabel() == 'pop' || $_image->getLabel() == 'pop-up') { // we want it
$img_url = $this->helper('catalog/image')->init($_product2, 'image', $_image->getFile());
} ?>
<?php if($_product->getSku() != $_product2->getSku()): ?>
<a href="<?php echo $img_url; ?>" style="display:none;" rel="lightbox[gallery]" title="<?php echo $_product2->getArtistFname()." ".$_product2->getArtistLname();?><br /><?php echo $this->htmlEscape($_product2->getName()) ?>, <?php echo $this->htmlEscape($_product2->getArtworkCreationDate()) ?>"> <?php
$_img = '<img id="image" src="'.$this->helper('catalog/image')->init($_product2, 'image').'" alt="'.$this->htmlEscape($_product2->getName()).'" title="'.$this->htmlEscape($_product2->getName()).'" />';
echo $_helper->productAttribute($_product2, $_img, 'image');
?></a>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</p>
<?php else: ?>
<p class="product-image">
<?php
$_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($_product->getName()).'" title="'.$this->htmlEscape($_product->getName()).'" />';
echo $_helper->productAttribute($_product, $_img, 'image');
?>
</p>
<?php endif; ?>
</p><div class="edition_caption"> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"></a> <?php echo $_product->getArtistFname().' '.$_product->getArtistLname();?><br />
<?php echo $this->htmlEscape($_product->getName()) ?>, <?php echo $this->htmlEscape($_product->getArtworkCreationDate()) ?><br />
</div>
<!-- Begin List Previous Next Nav -->
<div class="cg_nav_product">
<?php
/**
* Determine the previous/next link and link to current category
*/
$_categories = $_product->getCategoryIds();
//$_ccat = Mage::getModel('catalog/category')->load($_categories[0]);
$_ccat = Mage::getModel('catalog/category')->load($_product->getParentCategoryid());
$ppos = $_ccat->getProductsPosition();
//print_r($ppos);
$current_pid = $this->helper('catalog/data')->getProduct()->getId();
//echo $current_pid;
// build array from products positions
$plist = array();
foreach ($ppos as $pid => $pos) {
$plist[] = $pos;
}
//print_r($plist);
$curpos = array_search($current_pid, $plist);
//echo $curpos;
// get link for prev product
$previd = isset($plist[$curpos+1])? $plist[$curpos+1] : $current_pid;
$product = Mage::getModel('catalog/product')->load($previd);
$prevpos = $curpos;
while (!$product->isVisibleInCatalog()) {
$prevpos += 1;
$nextid = isset($plist[$prevpos])? $plist[$prevpos] : $current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
}
$prev_url = $product->getProductUrl();
// get link for next product
$nextid = isset($plist[$curpos-1])? $plist[$curpos-1] : $current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
$nextpos = $curpos;
while (!$product->isVisibleInCatalog()) {
$nextpos -= 1;
$nextid = isset($plist[$nextpos])? $plist[$nextpos] : $current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
}
$next_url = $product->getProductUrl();
// get link for current category
$more_url = $_ccat->getUrl();
?>
<?php
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
?>
<span class="sub_nav_item">
<?php if( $url <> $next_url ) { echo '<a id="nextUrl" href="' . $next_url . '">' . $this->__('Previous') . '</a> | '; } ?>
</span>
<span class="sub_nav_item">
<?php if( $url <> $prev_url ) { echo '<a id="prevUrl" href="' . $prev_url . '">' . $this->__('Next') . '</a>'; } ?>
</span>
</div>
<!-- End List Previous Next Nav -->
<?php $stockStatus = clean_num(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()); ?>
<?php if($stockStatus == 0): ?>
<h1>Place the other code here </h1>
<?php else: ?>
<!-- Begin Buy button -->
<div class="edition_buy_button">
<div id="bbn" class="buy-button-new"><a id="buybtn" href="javascript:void(0)"></a></div>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
var api = jQuery("ul.tabs").data("tabs");
jQuery("#buybtn").click(function() {
api.click(1);
});
});
</script>
<?php endif; ?>
<!-- End Buy button -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment