0

I am trying to create a store using Magento ver. 1.8.1.0. My programming capabilities are not great. I am an electronics engineer and I know embedded C properly, only. So, please treat me well.

I have installed the theme Shoes Store from here. The theme works fine for now, but I have ran into the problem that near the price, there is a text "undefined", as it can be seen in the below screenshot clip.

enter image description here

I have used my browser to check the code of this block and it is like this:

<div class="price-box">
   <span class="regular-price" id="product-price-1">
   <span class="price">
      <span class="cur_sym">1</span>
      <span class="price_int">9,99&nbsp;TL.</span>
      <span class="price_deci">undefined</span></span>
   </span>
</div>
<div class="actions">
   <a class="details" href="http://www.myurl.com/store/denek-urun.html" title="Details">Details</a>
</div>

And this HTML code is generated by new_products.phtml page which is a part of the theme and which uses following to print the above HTML code:

<?php echo $this->getPriceHtml($_product, true) ?>

As far as I understand, the "undefined" comes from the decimal part of the price. I have checked app/design/frontend/base/default/template/catalog/product/price.phtml but couldn't understand anything.

How can I get rid of the "undefined" text?

  • I don't think the undefined comes from a php code. My money is on a javascript code that is trying to "beautify" the prices to transform the price from '19.99E' to '19<sup>.99</sup>E' and failing. A link to your website would be nice so we can see what's happening. – Marius May 8 '14 at 7:21
  • @Marius Thanks for the comment. Sure, let me share: halkbebe.com/store – abdullah kahraman May 8 '14 at 7:26
2

As I suspected (see the comment) the problem comes from a javascript.
If you look at the page source you will see the price section looks like this

<span class="regular-price" id="product-price-4">
     <span class="price">19,99 TL</span>
</span>

The javascript that changes it is located in the <head>. This is it:

var price, sepstr, firstpart, secondpart, currency;

jQuery(document).ready(function() {
     jQuery('.newproducts .price-box .regular-price .price, .newproducts .old-price .price, .newproducts .special-price .price, .category-products .price-box .regular-price .price, .category-products .old-price .price, .category-products .special-price .price, .product-shop .price-box .regular-price .price, .product-shop .old-price .price, .product-shop .special-price .price').each(function(){
        price = jQuery.trim(jQuery(this).text());
        sepstr = price.split('.');
        firstpart = sepstr[0];
        secondpart = sepstr[1];
        currency = firstpart[0];
        firstpart = firstpart.replace(currency,'');
        jQuery(this).html('<span class="cur_sym">'+ currency +'</span><span class="price_int">'+ firstpart +'.</span><span class="price_deci">'+ secondpart +'</span>');
    });
});

It assumes that your price uses . as a decimal separator and the currency symbol is placed at the beginning of the price and has only one symbol.
So it looks for something like this: E12.99 but your prices look like 19,99 TL.

Either remove that script completely or try to adapt it for your price format.
This is my attempt on the script but not sure if it's ok.

jQuery(document).ready(function() {
     jQuery('.newproducts .price-box .regular-price .price, .newproducts .old-price .price, .newproducts .special-price .price, .category-products .price-box .regular-price .price, .category-products .old-price .price, .category-products .special-price .price, .product-shop .price-box .regular-price .price, .product-shop .old-price .price, .product-shop .special-price .price').each(function(){
        price = jQuery.trim(jQuery(this).text());
        sepstr = price.split(','); //replace dot with comma
        firstpart = sepstr[0];
        secondpart = sepstr[1];
        currency = secondpart.substr(-2); //get the last 2 characters as currency
        secondpart= secondpart.replace(currency,'');
        jQuery(this).html('<span class="cur_sym">'+ currency +'</span><span class="price_int">'+ firstpart +'.</span><span class="price_deci">'+ secondpart +'</span>');
    });
});
| improve this answer | |
  • Wow, thanks for your fast answer. I hope this will help other users of this theme. – abdullah kahraman May 8 '14 at 9:04
0

Thanks to Marius, I have solved my problem.

Below is my solution. I have changed the script part on file /app/design/frontend/default/shoe_store/template/page/html/head.phtml as follows:

var price, sepstr, firstpart, secondpart, currency;

jQuery(document).ready(function ()
{

    jQuery(
        '.newproducts .price-box .regular-price .price, .newproducts .old-price .price, .newproducts .special-price .price, .category-products .price-box .regular-price .price, .category-products .old-price .price, .category-products .special-price .price, .product-shop .price-box .regular-price .price, .product-shop .old-price .price, .product-shop .special-price .price'
    ).each(function ()
    {

        price = jQuery.trim(jQuery(this).text());

        if(price.indexOf("TL") > -1) // The currency is TL
        {
            sepstr = price.split(',');

            firstpart = sepstr[0];

            secondpart = sepstr[1];

            currency = secondpart[3] + secondpart[4];

            secondpart = secondpart.replace(currency, '');

            jQuery(this).html('<span class="price_int">' + firstpart +
                ',</span><span class="price_deci">' + secondpart + '</span>' + '<span class="price_int">' + currency + '</span>');
        }


        else
        {
            sepstr = price.split('.');

            firstpart = sepstr[0];

            secondpart = sepstr[1];

            currency = firstpart[0];

            firstpart = firstpart.replace(currency, '');

            jQuery(this).html('<span class="cur_sym">' + currency + '</span><span class="price_int">' + firstpart +
                '.</span><span class="price_deci">' + secondpart + '</span>');
        }
    });

});

The result is:

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.