PHP: link a Block - php

quick question, i want to link the BLOCK1 to another page. Is it possible? do anyone got a solution? i have tried abit and my brain is going mad T_T. there are 5 other blocks that i which to link to other pages aswell.
this is the code below:
<div class="midrow_block axn_block1">
<div class="mid_block_content">
<!--BLOCK1 IMAGE-->
<?php if(!empty($optimizer['block1_image']['url']) && empty($optimizer['block1_img_bg'])){ ?>
<div class="block_img"><img src="<?php echo $optimizer['block1_image']['url']; ?>" width="<?php echo $optimizer['block1_image']['width']; ?>" height="<?php echo $optimizer['block1_image']['height']; ?>" /></div>
<?php } ?>
<div class="block_content">
<h3>
<?php echo do_shortcode( $optimizer['block1_text_id']); ?>
</h3>
<?php echo do_shortcode($optimizer['block1_textarea_id']); ?>
</div>
</div>
</div>
</div>
<?php } ?>
<!--BLOCK1 END-->

Just put a <a>-Tag arount the block you want to link:
<a href="'your link here'"> <!-- start link here -->
<div class="midrow_block axn_block1">
<div class="mid_block_content">
<!--BLOCK1 IMAGE-->
<?php if(!empty($optimizer['block1_image']['url']) && empty($optimizer['block1_img_bg'])){ ?>
<div class="block_img"><img src="<?php echo $optimizer['block1_image']['url']; ?>" width="<?php echo $optimizer['block1_image']['width']; ?>" height="<?php echo $optimizer['block1_image']['height']; ?>" /></div>
<?php } ?>
<div class="block_content">
<h3>
<?php echo do_shortcode( $optimizer['block1_text_id']); ?>
</h3>
<?php echo do_shortcode($optimizer['block1_textarea_id']); ?>
</div>
</div>
</div>
</a> <!-- end link here -->
Or put it around any other part you want to have the link on. It's just basic HTML and has nothing to do with PHP.

here is the fullcode of the block. i missed to copy the top of it:
<?php if ((!empty ($optimizer['block1_text_id'])) || (!empty ($optimizer['block1_textarea_id'])) ) { ?>
<div class="midrow_block axn_block1">
<div class="mid_block_content">
<!--BLOCK1 IMAGE-->
<?php if(!empty($optimizer['block1_image']['url']) && empty($optimizer['block1_img_bg'])){ ?>
<div class="block_img"><img src="<?php echo $optimizer['block1_image']['url']; ?>" width="<?php echo $optimizer['block1_image']['width']; ?>" height="<?php echo $optimizer['block1_image']['height']; ?>" /></div>
<?php } ?>
<div class="block_content">
<h3>
<?php echo do_shortcode( $optimizer['block1_text_id']); ?>
</h3>
<?php echo do_shortcode($optimizer['block1_textarea_id']); ?>
</div>
</div>
</div>

You can use with this JS
<div class="midrow_block axn_block1" onclick="location.href='url'">content</div>
jQuery:
$("div").click(function(){
window.location=$(this).find("a").attr("href"); return false;
});

Related

Magento - related product color swatches

I'm working with Magento EE v1.14 and i'm looking for a solution for when a user is viewing a product page to then drop swatches of related product colors if they are out of stock.
Screenshot: Highlighted out of stock related product color
Screenshot of HTML
PHP + HTML code:
<?php
$_base_product = $this->getProduct();
$base_product = Mage::getModel('catalog/product')->load($_base_product->getId());
$base_product_id = $base_product->getId();
$base_name = $base_product->getName();
$base_url = Mage::getBaseUrl();
$product_colors = Mage::getModel('catalog/product')->getCollection();
$product_colors->addAttributeToFilter('status',1); // 1 or 2
$product_colors->addAttributeToFilter('visibility',4); // 1.2.3.4
$product_colors->addAttributeToFilter('name', array('eq' => $base_name));
$product_colors->addAttributeToFilter('sku', array('neq' => $base_product->getSku()));
$product_colors_ids = $product_colors->getAllIds(); // get all products from the category
sort($product_colors_ids);
?>
<?php if(count($product_colors_ids) > 0) : ?>
<div id="product-color-options-wrapper">
<div id="product-color-options-container">
<label><?php echo $this->__('Color') ?> / <span style="font-weight: normal;"><?php echo $base_product->getAttributeText('color'); ?></span></label>
<div id="color-options-wrapper">
<?php $_swatch_img = $base_product->getMediaGalleryImages(false)->getItemByColumnValue('label', 'swatch') ?>
<?php if($_swatch_img) : ?>
<div class="current-product-wash-wrapper wash-wrapper">
<div class="current-product-wash-container wash-container">
<img src="<?php echo $this->helper('catalog/image')->init($base_product, 'small_image', $_swatch_img->getFile())->resize(33,30) ?>" alt="" title="<?php echo $base_product->getAttributeText('color') ?>" />
</div>
</div>
<?php else : ?>
<!-- <span><?php echo $base_product->getColor() ?></span> -->
<?php endif ?>
<?php foreach($product_colors_ids as $prod_id) : ?>
<?php $_sister_product = Mage::getModel('catalog/product')->load($prod_id) ?>
<?php
$_sister_prod_imgs = $_sister_product->getMediaGallery('images');
foreach($_sister_prod_imgs as $_sister_prod_img):
if($_sister_prod_img['label'] == 'swatch'):
$_swatch_img = $_sister_prod_img['file'];
endif;
endforeach;
?>
<?php if($_swatch_img): ?>
<div class="sister-product-wrapper wash-wrapper">
<div class="sister-product-container wash-container">
<a href="<?php echo $base_url ?><?php echo $_sister_product->getUrlKey() ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_sister_product, 'small_image', $_swatch_img)->resize(33,30); ?>" alt="" title="<?php echo $_sister_product->getAttributeText('color') ?>">
</a>
</div>
</div>
<?php endif; ?>
<?php endforeach ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php endif ?>
Any help would be appreciated! :D
**Solution:**Added an if statement to check for stock availability using the isAvailable() function, shown in screenshot.
Link to screenshot: https://gyazo.com/abf07ba0373877836571858ee129cc22

Arrange divs on new row every third time

I have this most annoying problem; I'm trying to arrange three divs on a row, and then new row, and another three divs and so on, like this:
<div class="container">
<div class="row">
<div class="col-sm-1">1</div>
<div class="col-sm-1">2</div>
<div class="col-sm-1">3</div>
</div>
<div class="row">
<div class="col-sm-1">4</div>
<div class="col-sm-1">5</div>
<div class="col-sm-1">6</div>
</div>
</div>
As for this accepted answer,
There is one catch: 0 % 3 is equal to 0. This could result in
unexpected results if your counter starts at 0.
So how would i implement this into this code:
<div class="col-md-8">
<?php
foreach($this->movies->movie_data as $key => $movie){
$string = file_get_contents("http://example.com/?t=" . urlencode($movie->movie_titel). "&y=&plot=short&r=json");
$result = json_decode($string);
if($result->Response == 'True'){
?>
<div class="col-sm-4">
<?php if($result->Poster == 'N/A') : ?>
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
<?php else: ?>
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo $result->Poster; ?>" class="img-responsive img-thumbnail"></a>
<?php endif; ?>
<div><b><?php echo $result->Title; ?></b></div>
<div><i><?php // echo $result->Plot; ?></i></div>
</div>
<?php }else{ ?>
<div class="col-sm-4">
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
<div><b><?php echo $movie->movie_titel ?></b></div>
<div class="plot"><i><?php //echo 'N/A' ?></i></div>
</div>
<?php }}} ?
</div>
For some reason, divs is arranged like this:
My question: How do I arrange thumbnails on a new row, every third time?
Found the answer in the other Q... Didn't read, sorry about that.
<?php }
if (($key + 1) % 3 == 0) { ?>
</div>
<?php }
}} ?>

After implementing new template in opencart,homepage slideshow not view

In default theme all are fine and showing the homepage slideshow,but implementing other theme not showing the homepage slideshow.Checked the admin panel,there are all exactly same as default theme.How to show the slider?
theme/module/Slideshow.tpl
<div class="slideshow">
<div id="slideshow<?php echo $module; ?>" class="nivoSlider">
<?php foreach ($banners as $banner) { ?>
<?php if ($banner['link']) { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
<?php } else { ?>
<img src="<?php echo $banner['image']; ?>" alt="<?php echo $banner['title']; ?>" />
<?php } ?>
<?php } ?>
</div>
</div>
<script type="text/javascript"><!--
$(document).ready(function() {
$('#slideshow<?php echo $module; ?>').nivoSlider();
});
--></script>
slideshow modules are not viewed any kind of images.when <?php echo $slideshow;?>.its showing array().
header.tpl
<?php $slideshow = $modules->getModules('slideshow'); ?>
<?php if(count($slideshow)) { ?>
<!-- Slider -->
<div id="slider" class="<?php if($theme_options->get( 'slideshow_layout' ) == 2) { echo 'fixed'; } else { echo 'full-width'; } ?>">
<div class="background-slider"></div>
<div class="background">
<div class="shadow"></div>
<div class="pattern">
<?php foreach($slideshow as $module) { ?>
<?php echo $module; ?>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
Thanks for share code with me, You are missed to define content_top area in your theme, you have to go here
catalog/view/theme/yourtheme/template/common/home.tpl
go to line no 18 & add this line just below the line 18
<?php echo $content_top; ?>
and your slider will come on your home page.

Multilingual slideshow

I have this code for a slideshow in my Drupal 7, Nexus 7.x-1.3 theme.
My website is multilingual and I need to use a different image for every language, eg. I would like to change slide-image-1.jpg (en language) with other image-name for (gr language).
My code:
<?php if ($is_front): ?>
<?php if (theme_get_setting('slideshow_display','nexus')): ?>
<?php
$slide1_head = check_plain(theme_get_setting('slide1_head','nexus')); $slide1_desc = check_markup(theme_get_setting('slide1_desc','nexus'), 'full_html'); $slide1_url = check_plain(theme_get_setting('slide1_url','nexus'));
$slide2_head = check_plain(theme_get_setting('slide2_head','nexus')); $slide2_desc = check_markup(theme_get_setting('slide2_desc','nexus'), 'full_html'); $slide2_url = check_plain(theme_get_setting('slide2_url','nexus'));
$slide3_head = check_plain(theme_get_setting('slide3_head','nexus')); $slide3_desc = check_markup(theme_get_setting('slide3_desc','nexus'), 'full_html'); $slide3_url = check_plain(theme_get_setting('slide3_url','nexus'));
?>
<div id="slidebox" class="flexslider">
<ul class="slides">
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-1.jpg'; ?>"/>
<?php if($slide1_head || $slide1_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide1_head; ?></h2><?php print $slide1_desc; ?>
<a class="frmore" href="<?php print url($slide1_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-2.jpg'; ?>"/>
<?php if($slide2_head || $slide2_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide2_head; ?></h2><?php print $slide2_desc; ?>
<a class="frmore" href="<?php print url($slide2_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-3.jpg'; ?>"/>
<?php if($slide3_head || $slide3_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide3_head; ?></h2><?php print $slide3_desc; ?>
<a class="frmore" href="<?php print url($slide3_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
</ul><!-- /slides -->
<div class="doverlay"></div>
</div>
<?php endif; ?>
<?php endif; ?>
Is there any solution for that? Thank you.
There is a Drupal connector from Smartling that may be of help. Here is a video showing how the connector works.
Many sites running on Smartling do language/country-specific image replacement, which is explained here.
Hope this helps,
Nataly
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<SCRIPT>
function english(){
$(#image).attr('src','http://link.to.your/english/image.png')
}
function greek(){
$(#image).attr('src','http://link.to.your/greek/image.png')
}
</SCRIPT>
<IMG id="image" src="http://link.to.your/greek/image.png">
Change to English<BR>
Change to Greek
Finally I fixed it in page.tpl with php code. One if/else on your page language to set you picture path.
Regards, HashKey

Echo short description for related products

Is there a way to echo the short description foreach related product?
I've tried to use this code but it doesn't display the description of each product:
<?php echo nl2br($this->getProduct()->getDescription()) ?>
also
<?php echo $_helper->productAttribute($_item, nl2br($_item->getShortDescription()), 'short_description') ?>
Is there a way to do this for related products? If anyone knows please point me in the right direction.
<?php if($this->getItems()->getSize()): ?>
<div class="block block-related">
<div class="block-title">
<strong><span><?php echo $this->__('Related Products') ?></span></strong>
</div>
<div class="block-content">
<p class="block-subtitle"><?php echo $this->__('Check items to add to the cart or add to your wishlist') ?> <br /></p>
<div class="form-horizontal">
<?php foreach($this->getItems() as $_item): ?>
<div class="control-group">
<label for="related-checkbox<?php echo $_item->getId() ?>" class="control-label">
<a class="fancybox static-thumbs pull-left" href="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(500, 450); ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" ><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(135, 135) ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
</label>
<div class="controls">
<label class="checkbox">
<?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
<?php if (!$_item->getRequiredOptions()): ?>
<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox<?php echo $_item->getId() ?>" name="related_products[]" value="<?php echo $_item->getId() ?>" />
<?php endif; ?>
<?php endif; ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<span class="icon-check"></span>
<p class="product-name span6">
<?php echo $this->htmlEscape($_item->getName()) ?>
<br />
<?php echo nl2br($this->getProduct($_item)->getDescription()) ?>
</p>
<form action="<?php echo $this->getAddToCartUrl($_item) ?>" method="post">
<fieldset>
<label class="product-name"><?php echo $this->__('Quantity:'); ?></label>
<select name="qty" class="span1">
<?php $i = 1 ?>
<?php do { ?>
<option value="<?php echo $i?>">
<?php echo $i?>
<?php $i++ ?>
</option>
<?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getMaxSaleQty()) ?>
</select>
<div class="clearfix"></div>
<button class="btn btn-danger" data-loading-text="PLease wait..."><span><?php echo $this->__('Add to Cart') ?></span></button>
<span id='ajax_loader' style='display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>
</fieldset>
</form>
<?php endif; ?>
<?php echo $this->getPriceHtml($_item, true, '-related') ?>
</label>
</div>
</div>
<hr />
<?php endforeach ?>
</div>
</div>
Have you tried nl2br($this->getProduct($_item)->getShortDescription()) ?
It might be that the value for short description isn't loaded for related products by default. You could try to do a $_item->load($_item->getId()) and then use $_item->getShortDescription().
after TRYING $_item->load($_item->getId()) and echoing the shortDescription, you should look for the Collection where the related products are loaded. In this collection the attribute short_description is not loaded with.
If you load every product, you make a lot of queries to the database which will cost a lot of performance. This is not needed. The alternative is:
$relatedProductCollection->addAttributeToSelect('short_description');
The question is to find the $relatedProductCollection.
UPDATE:
I dug into the code (Reference is v. 1.7.0.2):
// app/code/core/Mage/Catalog/Block/Product/List/Related.php:61
$this->_addProductAttributesAndPrices($this->_itemCollection);
// app/code/core/Mage/Catalog/Block/Product/Abstract.php:410
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
// app/code/core/Mage/Catalog/Model/Config.php:260
$this->getAttributesUsedInProductListing()
This should be interpreted as: When the "related products" are loaded, all attributes are loaded, which are used in the product listing as well. The problem might be: short_desciption is loaded by default. So remove the load() call and check, wether the attribute short_description is "Used in Product Listing". If this is set to yes, My interpretation is wrong.
None the less, the solution by loading every product is crap.
EDIT:
I have added the following line to Related.php
$this->_itemCollection = $product->getRelatedProductCollection()
->addAttributeToSelect('required_options')
->addAttributeToSelect('short_description')
->setPositionOrder()
->addStoreFilter()
And using this line does echo a descrtiption foreach product but it is the Same description getProduct()->getDescription()) ?>
You need to <?php echo ($this->getProduct()->getShortDescription()) ?>
But editing the core code is a bad way to change the magento behaviour as well. Here is described how to rewrite a block, but I don't think this is necessary. http://prattski.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/

Categories