Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microdata Price Fixes & Optimisation #387

Merged
merged 6 commits into from Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions includes/classes/currencies.php
Expand Up @@ -72,5 +72,24 @@ function get_decimal_places($code) {
function display_price($products_price, $products_tax, $quantity = 1) {
return $this->format($this->calculate_price($products_price, $products_tax, $quantity));
}

function format_raw($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
global $currency;

if (empty($currency_type)) $currency_type = $currency;

if ($calculate_currency_value == true) {
$rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];
$format_string = number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], '.', '');
} else {
$format_string = number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], '.', '');
}

return $format_string;
}

function display_raw($products_price, $products_tax, $quantity = 1) {
return $this->format_raw($this->calculate_price($products_price, $products_tax, $quantity));
}
}
?>
2 changes: 1 addition & 1 deletion includes/functions/general.php
Expand Up @@ -1379,4 +1379,4 @@ function tep_convert_linefeeds($from, $to, $string) {
return str_replace($from, $to, $string);
}
}
?>
2 changes: 1 addition & 1 deletion includes/modules/content/index/cm_i_new_products.php
Expand Up @@ -33,7 +33,7 @@ function __construct() {
}

function execute() {
global $oscTemplate, $new_products_category_id, $languages_id, $currencies, $PHP_SELF;
global $oscTemplate, $new_products_category_id, $languages_id, $currencies, $PHP_SELF, $currency;

$content_width = MODULE_CONTENT_NEW_PRODUCTS_CONTENT_WIDTH;
$product_width = MODULE_CONTENT_NEW_PRODUCTS_DISPLAY_EACH;
Expand Down
2 changes: 1 addition & 1 deletion includes/modules/content/index/templates/new_products.php
Expand Up @@ -25,7 +25,7 @@
<div class="caption">
<p class="text-center"><a itemprop="url" href="<?php echo tep_href_link('product_info.php', 'products_id=' . (int)$new_products['products_id']); ?>"><span itemprop="name"><?php echo $new_products['products_name']; ?></span></a></p>
<hr>
<p class="text-center" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><span itemprop="price"><?php echo $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])); ?></span></p>
<p class="text-center" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><meta itemprop="priceCurrency" content="<?php echo tep_output_string($currency); ?>" /><span itemprop="price" content="<?php echo $currencies->display_raw($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])); ?>"><?php echo $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])); ?></span></p>
<div class="text-center">
<div class="btn-group">
<a href="<?php echo tep_href_link('product_info.php', tep_get_all_get_params(array('action')) . 'products_id=' . (int)$new_products['products_id']); ?>" class="btn btn-default" role="button"><?php echo MODULE_CONTENT_NEW_PRODUCTS_BUTTON_VIEW; ?></a>
Expand Down
Expand Up @@ -33,7 +33,7 @@ function __construct() {
}

function execute() {
global $oscTemplate, $current_category_id, $languages_id, $currencies, $PHP_SELF;
global $oscTemplate, $current_category_id, $languages_id, $currencies, $PHP_SELF, $currency;

$content_width = MODULE_CONTENT_IN_NEW_PRODUCTS_CONTENT_WIDTH;
$product_width = MODULE_CONTENT_IN_NEW_PRODUCTS_DISPLAY_EACH;
Expand Down
Expand Up @@ -25,7 +25,7 @@
<div class="caption">
<p class="text-center"><a itemprop="url" href="<?php echo tep_href_link('product_info.php', 'products_id=' . (int)$new_products['products_id']); ?>"><span itemprop="name"><?php echo $new_products['products_name']; ?></span></a></p>
<hr>
<p class="text-center" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><span itemprop="price"><?php echo $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])); ?></span></p>
<p class="text-center" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><meta itemprop="priceCurrency" content="<?php echo tep_output_string($currency); ?>" /><span itemprop="price" content="<?php echo $currencies->display_raw($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])); ?>"><?php echo $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])); ?></span></p>
<div class="text-center">
<div class="btn-group">
<a href="<?php echo tep_href_link('product_info.php', tep_get_all_get_params(array('action')) . 'products_id=' . (int)$new_products['products_id']); ?>" class="btn btn-default" role="button"><?php echo MODULE_CONTENT_IN_NEW_PRODUCTS_BUTTON_VIEW; ?></a>
Expand Down
2 changes: 1 addition & 1 deletion includes/modules/new_products.php
Expand Up @@ -29,7 +29,7 @@
$new_prods_content .= ' <div class="caption">';
$new_prods_content .= ' <p class="text-center"><a itemprop="url" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '"><span itemprop="name">' . $new_products['products_name'] . '</span></a></p>';
$new_prods_content .= ' <hr>';
$new_prods_content .= ' <p class="text-center" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><span itemprop="price">' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '</span></p>';
$new_prods_content .= ' <p class="text-center" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><span itemprop="price" content="' . $currencies->display_raw($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '">' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '</span></p>';
$new_prods_content .= ' <div class="text-center">';
$new_prods_content .= ' <div class="btn-group">';
$new_prods_content .= ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'products_id=' . $new_products['products_id']) . '" class="btn btn-default" role="button">' . SMALL_IMAGE_BUTTON_VIEW . '</a>';
Expand Down
4 changes: 2 additions & 2 deletions includes/modules/product_listing.php
Expand Up @@ -159,9 +159,9 @@

if (PRODUCT_LIST_PRICE > 0) {
if (tep_not_null($listing['specials_new_products_price'])) {
$prod_list_contents .= ' <div class="col-xs-6" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><meta itemprop="priceCurrency" content="' . tep_output_string($currency) . '" /><div class="btn-group" role="group"><button type="button" class="btn btn-default"><del>' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</del></span>&nbsp;&nbsp;<span class="productSpecialPrice" itemprop="price" content="' . preg_replace('/[^0-9.]*/', '', $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id']))) . '">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></button></div></div>';
$prod_list_contents .= ' <div class="col-xs-6" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><meta itemprop="priceCurrency" content="' . tep_output_string($currency) . '" /><div class="btn-group" role="group"><button type="button" class="btn btn-default"><del>' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</del></span>&nbsp;&nbsp;<span class="productSpecialPrice" itemprop="price" content="' . $currencies->display_raw($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></button></div></div>';
} else {
$prod_list_contents .= ' <div class="col-xs-6" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><meta itemprop="priceCurrency" content="' . tep_output_string($currency) . '" /><div class="btn-group" role="group"><button type="button" class="btn btn-default"><span itemprop="price" content="' . preg_replace('/[^0-9.]*/', '', $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id']))) . '">' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></button></div></div>';
$prod_list_contents .= ' <div class="col-xs-6" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><meta itemprop="priceCurrency" content="' . tep_output_string($currency) . '" /><div class="btn-group" role="group"><button type="button" class="btn btn-default"><span itemprop="price" content="' . $currencies->display_raw($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '">' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></button></div></div>';
}
}

Expand Down
4 changes: 2 additions & 2 deletions product_info.php
Expand Up @@ -44,9 +44,9 @@
tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . (int)$languages_id . "'");

if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
$products_price = '<del>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</del> <span class="productSpecialPrice" itemprop="price" content="' . preg_replace('/[^0-9.]*/', '', $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id']))) . '">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
$products_price = '<del>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</del> <span class="productSpecialPrice" itemprop="price" content="' . $currencies->display_raw($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
} else {
$products_price = '<span itemprop="price" content="' . preg_replace('/[^0-9.]*/', '', $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']))) . '">' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
$products_price = '<span itemprop="price" content="' . $currencies->display_raw($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '">' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
}

if ($product_info['products_date_available'] > date('Y-m-d H:i:s')) {
Expand Down