0

I have used the tutorial https://www.byte.nl/blog/magento-rich-snippets-made-easy/ to implement most of the rich snippets I want and just need to put in the markup for height, depth and width.

I am editing the view.phtml file found in the directory: /html/app/design/frontend/default/onlinebiz_store/template/catalog/product

The section of code I believe I need to edit is:

<div class="box-attribute row">             

                    <?php if ($_product->getHeight()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Height') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getHeight(); ?></span>
                        </div>  
                    <?php endif; ?>


                </div>

After checking this solution here Product size: width, height and depth I tried to work in code for height that I would be able to modify for depth and width if it worked.

I changed the code to read:

<div class="box-attribute row" itemscope itemtype="http://schema.org/Product">              

                        <?php if ($_product->getHeight()): ?>
                            <div class="item col-xs-12">
                                <span class="label col-xs-4"><?php echo $this->__('Height') ?></span>
                                <span itemprop="width" itemscope itemtype="http://schema.org/Distance" class="value col-xs-6"><?php echo $_product->getHeight(); ?></span>
                            </div>  
                        <?php endif; ?>


                    </div>

Unfortunately when tested the height value didn't show at all in Google's Structured Data Testing Tool, it also didn't show any errors either to say I'd got it wrong.

I am aware of the Magento extensions to do this for me but it's always nice to try to understand more and I feel like I've learnt a lot getting the other rich snippets in, so any help at all would be most appreciated.

The entire code for my view.phtml is:

<?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) 2013 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Product view template
 *
 * @see Mage_Catalog_Block_Product_View
 * @see Mage_Review_Block_Product_View
 */
?>
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<div class="product-view" itemscope itemtype="http://schema.org/Product">
    <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; ?>>
        <?php echo $this->getBlockHtml('formkey') ?>
        <div class="no-display">
            <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
            <input type="hidden" name="related_product" id="related-products-field" value="" />
        </div>

        <div class="row">
            <div class="product-img-box col-sm-4 col-xs-12">
                <?php echo $this->getChildHtml('media') ?>

            </div>
            <div class="product-shop col-sm-7 col-xs-12">
                <div class="product-name">
                    <h1 itemprop="name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
<?php if($_product->isAvailable()): ?>
<div class="no-display" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<meta itemprop="priceCurrency" content="<?php echo $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode(); ?>"/>
     <span itemprop="price"><?php echo Mage::helper('core')->currency($_product->getFinalPrice()); ?></span>
     <link itemprop="availability" href="http://schema.org/InStock" />
</div>
<?php endif; ?>


                </div>

                <?php echo $this->getChildHtml('alert_urls') ?>                           
                <?php echo $this->getChildHtml('product_type_data') ?>
                <?php echo $this->getTierPriceHtml() ?> 
                <?php echo $this->getChildHtml('extrahint') ?>

                <?php if ($_product->getShortDescription()):?>
                    <div class="short-description">
                        <div class="std" itemprop="description"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
                    </div>
                <?php endif;?>
                <div class="box-attribute row">
                    <?php if ($_product->getData('period')): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('period') ?></span>
                            <span class="value col-xs-6"><?php echo nl2br($_product->getResource()->getAttribute('period')->getFrontend()->getValue($_product)) ?></span>
                        </div>  
                    <?php endif; ?>

                    <?php if ($_product->getData('country')): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('country of origin') ?></span>
                            <span class="value col-xs-6"><?php echo nl2br($_product->getResource()->getAttribute('country')->getFrontend()->getValue($_product)) ?></span>
                        </div>  
                    <?php endif; ?>

                    <?php if ($_product->getData('condition')): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('condition') ?></span>
                            <span class="value col-xs-6"><?php echo nl2br($_product->getResource()->getAttribute('condition')->getFrontend()->getValue($_product)) ?></span>
                        </div>
                    <?php endif; ?>

                    <?php if ($_product->getHeight()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Height') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getHeight(); ?></span>
                        </div>  
                    <?php endif; ?>
                    <?php if ($_product->getDepth()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Depth') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getDepth(); ?></span>
                        </div>  
                    <?php endif; ?>


                    <?php if ($_product->getLength()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Length') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getLength(); ?></span>
                        </div>  
                    <?php endif; ?>                                     

                    <?php if ($_product->getReferenceInfo()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Reference Info') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getReferenceInfo(); ?></span>
                        </div>  
                    <?php endif; ?> 

                    <?php if ($_product->getCirca()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Circa') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getCirca(); ?></span>
                        </div>  
                    <?php endif; ?>


                    <?php if ($_product->getMaterials()): ?>
                        <div class="item col-xs-12">
                            <span class="label col-xs-4"><?php echo $this->__('Materials') ?></span>
                            <span class="value col-xs-6"><?php echo $_product->getMaterials(); ?></span>
                        </div>  
                    <?php endif; ?>

                </div>
                <div class="aditional-info">
                    <?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
                        <div class="box-collateral <?php echo "box-{$alias}"?>">
                            <?php if ($title = $this->getChildData($alias, 'title')):?>
                            <h2><?php echo $this->escapeHtml($title); ?></h2>
                            <?php endif;?>
                            <?php echo $html; ?>
                        </div>
                    <?php endforeach;?>
                </div>
                <?php if($_product->getReserveStatus()): ?>
                    <?php if (!$this->hasOptions()):?>
                        <div class="add-to-box">
                            <?php if($_product->isSaleable()): ?>
                                <?php echo $this->getChildHtml('addtocart') ?>
                            <?php endif; ?>
                        </div>
                    <?php echo $this->getChildHtml('extra_buttons') ?>
                    <?php endif; ?>
                <?php else:?>
                    <p></p>
                <?php endif; ?>

                <?php echo $this->getChildHtml('other');?>

                <?php if ($_product->isSaleable() && $this->hasOptions()):?>
                    <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
                <?php endif;?>
                <!-- AddThis Button BEGIN -->
                <div class="addthis_toolbox addthis_default_style ">
                <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
                <a class="addthis_button_tweet"></a>
                <a class="addthis_button_pinterest_pinit" pi:pinit:layout="horizontal"></a>
                <a class="addthis_button_google_plusone" g:plusone:size="horizontal"></a>
                <a class="addthis_counter addthis_pill_style"></a>
                </div>
                <script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script>
                <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5138d1b905e0a287"></script>
                <!-- AddThis Button END -->
            </div>


        </div>

        <div class="clearer"></div>
        <?php if ($_product->isSaleable() && $this->hasOptions()):?>
            <?php echo $this->getChildChildHtml('container2', '', true, true) ?>
        <?php endif;?>
    </form>
    <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>

    <div class="product-collateral">
            <?php echo $this->getChildHtml('info_tabs') ?>
            <?php echo $this->getChildHtml('product_additional_data') ?>

    </div>

</div>
<?php echo $this->getChildHtml('related-products') ?>

I've had a further play around and manage to get the Google tester to accept the following:

<?php if ($_product->getHeight()): ?>
                    <div class="item col-xs-12" itemprop="height">
                        <span class="label col-xs-4"><?php echo $this->__('Height') ?></span>
                        <span class="value col-xs-6"><?php echo $_product->getHeight(); ?></span>
                    </div>
Community
  • 1
  • 1
  • Is your 'height' attribute in magento admin including the unit of measure as the XML Schema referenced is suggesting ? -> `Properties that take Distances as values are of the form ' '. E.g., '7 ft'` from http://schema.org/Distance – β.εηοιτ.βε Jan 12 '15 at 15:25
  • The attribute includes the unit of measure. So when I input the height I would put the unit of measure in at the same time. Eg 103cm. Without me explicitly stating the unit of measurement (cm) when entering in the height it would just show the value 103. – Joe Duckworth Jan 12 '15 at 16:27
  • I've only just started with rich snippets so can't help directly. What I would suggest is use the google tools and paste in your html directly and edit it there and keep testing each tweak. If you can find another website that has the same snippets that work, that should give you the target you're aiming for. Once you've worked it out, you can then update the view.phtml file. – PedroKTFC Jan 12 '15 at 23:13
  • I'll keep at it, one of the combinations has to work, I've just not cracked it yet. The tool sounds like a good quick way to test it though. – Joe Duckworth Jan 13 '15 at 19:11

0 Answers0