Bug in views template

feyisayo's picture
feyisayo
Thu, 06/08/2017 - 04:32
#1
Bug in views template

Hello there. Thanks for the work on this theme. It looks really good.

While I was setting up the theme for a site when I noticed an issue: once the price of a product is 1,000 and above then price in the various product sliders views become zero.

For example, on the demo at http://demo.megadrupal.com/d7/md-delphinus/  look at the section titled "Product Slider" at the top. In that view, the product "JDWA concrete lamp" is $340.00. If you increase the price of the product to 3,400 then the price will appear as $0 in the view.

I found the cause. If you locate this file in the theme md_delphinus/templates/views/product/product_slider_1/views-view-fields--product--product-slider-1.tpl.php and look at line 5 you should see the following code:

$price = commerce_currency_convert(substr($fields['commerce_price']->content, 1), commerce_default_currency(), $cur)

The function substr($fields['commerce_price']->content, 1) assumes that the numeric part of the price starts after the currency symbol. This is true for prices less than 1,000. However once the price is 1,000 and above the function returns a non-numeric value.

Here is the workaround I used (since I did not want to edit the view). I replaced line 5 with these two lines:

$v_price = (int) preg_replace('/\D/', '', $fields['commerce_price']->content) / 100;
$price = commerce_currency_convert($v_price, commerce_default_currency(), $cur);

This issue is also present in a number of views template files:

md_delphinus/templates/views/product/product_slider_2/views-view-fields--product--product-slider-2.tpl.php
md_delphinus/templates/views/product/product_for_bed_room/views-view-fields--product--product-br.tpl.php
md_delphinus/templates/views/product/product_4_cols/views-view-fields--product--product-4-cols.tpl.php
md_delphinus/templates/views/product/wishlist_block/views-view-fields--product--wishlist-block.tpl.php
md_delphinus/templates/views/product/product_2_cols/views-view-fields--product--product-2-cols.tpl.php
md_delphinus/templates/views/product/product_for_dining_room/views-view-fields--product--product-dr.tpl.php
md_delphinus/templates/views/product/latest_product/views-view-fields--product--product-latest.tpl.php
md_delphinus/templates/views/product/product_grid_gallery/views-view-fields--product--product-grid-gallery.tpl.php
md_delphinus/templates/views/product/product_slider_1/views-view-fields--product--product-slider-1.tpl.php
md_delphinus/templates/views/product/product_grid_2/views-view-fields--product--product-grid-2.tpl.php
md_delphinus/templates/views/product/product_grid/views-view-fields--product--product-grid.tpl.php
md_delphinus/templates/views/product/product_by_taxonomy/views-view-fields--product--taxonomy-product.tpl.php
md_delphinus/templates/views/product/compare/views-view-table--product--compare.tpl.php
md_delphinus/templates/views/product/product_3_cols/views-view-fields--product--product-3-cols.tpl.php
md_delphinus/templates/views/product/product_masonry/views-view-fields--product--product-masonry.tpl.php
md_delphinus/templates/views/product/product_for_living_room/views-view-fields--product--product-lr.tpl.php
md_delphinus/templates/views/product/product_slider_4/views-view-fields--product--product-slider-4.tpl.php
md_delphinus/templates/views/product/wishlist/views-view-fields--product--wishlist.tpl.php
md_delphinus/templates/views/product/product_slider_3/views-view-fields--product--product-slider-3.tpl.php

To keep things DRY, you should consider putting the buggy line in a function in your template.php

I hope this helps.

Thanks again for this good looking theme. My client liked it a lot.

Have More Idea?

We are here to build your website!

No Universal solution fits all special business requirements. Our experienced team is ready with ideas and state-of-the-art technical solutions to consult the best solution within your budget.