I am using an attribute to show an attribute value in the product page using this code:
<?php if ($_product->getProductShipping()):?>
<p>Shipping Charges : Rs.<?php echo $_product->getProductShipping(); ?>
<?php endif;?>
It is showing Shipping Charges : Rs. 20. What is the value of this attribute? If some products have no value in this product then nothing is showing there but I want to show Free shipping if no value is there.
just simple if/else condition can do work for you
<?php if ($_product->getProductShipping()){?>
<p>Shipping Charges : Rs.<?php echo $_product->getProductShipping(); ?>
<?php }else { ?>
<p>Shipping Charges : Free Shipping
<?php } ?>
let me know if you face any problem in this code.
Related
I'm trying to check whether product has custom options or not in code (my code runs sales_order_place_after event).
I have try below code but it does not returning anything.
$product->hasCustomOptions()
and
$product->hasOptions()
Please let me know what I'm missing.
I've encountered this error more times than I care to count. Either $_product->hasOptions() or $_product->hasCustomOptions() always returns false. I still don't know why this error occurs.
Anyway, you can get the same result by doing the following. For configurable products:
<?php if ( $_product->getData('has_options') ): ?>
<!-- do something -->
<?php endif; ?>
And to get the same result for simple products with custom options:
<?php if ( $_product->getData('has_options') && ($_product->getTypeID() == 'simple') ): ?>
<!-- do something -->
<?php endif; ?>
I hope that helps a future adventurer!
EDIT
The solution above does not work in loops when the flat category data option is enabled in Magento, and we don't want to reload the product inside the foreach loop!!
Instead, we can check for custom options using the following singleton inside the loop:
$opts = Mage::getSingleton('catalog/product_option')->getProductOptionCollection($_product);
$optsSize = $opts->getSize();
if ( $optsSize ) {
... // go go go
}
use the method $product->getHasOptions()
How to disable particular layout(example:menus.phtml) for particular pages in controller in ZF2?? In the below example menus.phtml should be disable for specific pages. Remaining pages must contain menus.phtml like header and footer.
<div>
header.phtml
</div>
<div>
menus.phtml
</div>
<div>
<?php echo $this->content; ?>
</div>
<div>
footer.phtml
</div>
There are various aproaches to this. Also modules.zendframework has quite a few modules here that may help you out.
If you are still keen on writing that yourself you could add variables to your layout within your controllers like so:
<?php
//YourController.php
public function someAction()
{
...
$this->layout()->footer = 'default';
...
}
//layout.phtml
<?php if ($this->footer === 'default') : ?>
//show the footer
<?php endif; ?>
Doing this is pretty inefficient though. Just imagine you'd need to do this to every action in all the controllers... I sure would not like to do that.
Now zf2 has a service and event layer that could help us out quite a bit here. This is a pretty nice read and introduction to it. You'd just write a service and trigger a event on your controllers/routes/whatever. Now you would also probably like to configure what is shown and what is hidden right? Thats pretty easy, too. Just write yourself a config file and merge it with the global.config like so:
<?php
//CustomModule/module.php
public function getConfig() {
$config = array();
$configFiles = array(
include __DIR__ . '/config/module.config.php',
include __DIR__ . '/config/module.customconfig.php',
);
foreach ($configFiles as $file) {
$config = \Zend\Stdlib\ArrayUtils::merge($config, $file);
}
return $config;
}
Source: Where to put custom settings in Zend Framework 2?
First, get the controller or action name:
$controllerName =$this->params('controller');
$actionName = $this->params('action');
then in your layout/view script add a simple logic.
<?php if ($actionName != 'action that you want to disable the layout/menu'): ?>
echo $this->render('menus.phtml');
<?php endif; ?>
Please help...anyone
I have a problem with hiding some configurable attributes:
These are my configurable attributes at the back-end:
Shape/Type
Grit & Colour
Shank
Items pack
Diameter
Supplier
My client wants to hide the "Manufacturer" attribute on the front-end
but wants to import the supplier at the back-end.
Please see the website I am working:
http://ridental.com.au/newsite/polishers.html/
I managed to hide it from front-end by just adding some if statement
like this: in the app\design\frontend\default\MYTEMPLATE\template\catalog\product\view\type\options\configurable.phtml
<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<dl class="outer">
<dl class="inner">
<?php foreach($_attributes as $_attribute): ?>
<?php $attCode = $_attribute->getProductAttribute()->getFrontend()->getAttribute()->getAttributeCode(); ?>
<?php if($attCode != "manufacturer"):?>
<div class="dtdd-wrapper<?php if ($_attribute->decoratedIsLast){echo " last";}?>">
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
</div>
<?php endif; ?>
<?php endforeach; ?>
</dl>
</dl>
<script type="text/javascript">
[b]var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);[/b]
</script>
The Manufacturer will not be displayed on the front-end.
But when I click Add to Cart button I got the error:
Please specify the product's option(s).
I noticed that in:
var spConfig = new Product.Config(<?php echo $this->getJsonConfig()
It is still referring to the attribute "supplier" and waiting for the user response to choose Manufacturer in the drop down.
that's why I get the error: Please specify the product's option(s).
My question:
Is it possible to filter the function getJsonConfig()?
let say not include the:
if ($attributecode != 'manufacturer'){
do some stuff.....
}
I copied a local version of this function and now found in: app\code\local\Mage\Catalog\Block\Product\View\Type\Configurable.php
Please help...if anyone accomplished this kind of problem.
I tried extending getJsonConfig() to filter some attribute like "supplier" but to no avail.
Am I doing the right thing?
Chances are, from what you are describing, you should remake the configurable product without using the "Supplier" attribute.
When you make a configurable product, the first screen that allows you to mark attributes with check boxes is meant to define what the configurable product will be filtering, the attributes will still be attached to the product information.
I'm trying to implement pagination in a custom WP-Query. The pagination is done correctly, but the links are wrong. If I have, for example, 10 posts and 8 posts per page, I have a page 1 with 8 posts (OK for now), a page 2 with 2 posts (still OK), but I can access a page 3 with 0 posts, and so on...
I'm trying also to implement wp_navi an I'm having an infinite navigation menu for only 10 posts.
The code used is the following:
<?php next_posts_link('« Previous') ?>
<?php previous_posts_link('Next') ?>
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$featuredPosts = new WP_Query("category_name=Destacadas&paged=".get_query_var('paged'));
while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>
<div class="post_container">
<?php include ('post-info-reduced.php'); ?>
</div>
<?php endwhile; ?>
Have you had this problem?
I've found the solution for using it with WP-PageNavi:
http://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html
I want to display subcategories under artist category in one layout and design and other categories in another layout and design in Magento 1.4.1.1.
In the web admin, under Manage Categories, select the categories you want to be different and navigate to the Custom Design tab. You can enter layout updates or select alternative skin/themes.
The best way to do this is to use static blocks.
1) Create phtml file in /template/catalog/navigation
<?php $_categories = $this->getCurrentChildCategories(); ?>
<ul>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<li>
<?php echo $this->htmlEscape($_category->getName()) ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
2) Create static block "Subcategories"
{{block type="catalog/navigation" template="catalog/navigation/subcategory.phtml"}}
3) Assign static block for needed category ("Display Settings" tab -> Display Mode = Static block only and select CMS Block "Subcategories")