Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

ht_product_opengraph.php - price no tax included


Recommended Posts

Hi,

it seems to me that this part

if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
            $products_price = $this->format_raw($new_price);
          } else {
            $products_price = $this->format_raw($product_info['products_price']);
          }
          $data['product:price:amount'] = $products_price;

is missing to add taxes to the price which leads merchants.google to "adjust" from the price (with tax) given in product feed to the wrong one without tax using property="product:price:amount" in their listings.

Best regards

Christoph

Link to comment
Share on other sites

Quick and dirty solution, better more elegant way anyone?

     if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
          	$products_price_with_tax = $new_price + ($new_price * (tep_get_tax_rate($product_info['products_tax_class_id'])/100));
          
            $products_price = $this->format_raw($products_price_with_tax);
          } else {
         $products_price_with_tax = $product_info['products_price'] + ($product_info['products_price'] * (tep_get_tax_rate($product_info['products_tax_class_id'])/100));
            $products_price = $this->format_raw($products_price_with_tax);
          }

Oh and half off topic, I would also like to also add a tag for condition - hardcoded as all our products are new anyway, how should it look?

Best regards

Christoph

Link to comment
Share on other sites

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2018 osCommerce

  Released under the GNU General Public License
*/

  class ht_product_opengraph {
    var $code = 'ht_product_opengraph';
    var $group = 'header_tags';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;

    function __construct() {
      $this->title = MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_TITLE;
      $this->description = MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_DESCRIPTION;

      if ( defined('MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_STATUS') ) {
        $this->sort_order = MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_SORT_ORDER;
        $this->enabled = (MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_STATUS == 'True');
      }
    }

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

      if ($product_check['total'] > 0) {        
        $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_image, p.products_price, p.products_quantity, p.products_tax_class_id, p.products_date_available from products p, products_description pd where p.products_id = '" . (int)$_GET['products_id'] . "' and p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");

        if ( tep_db_num_rows($product_info_query) === 1 ) {
          $product_info = tep_db_fetch_array($product_info_query);

          $data = array('og:type' => 'product',
                        'og:title' => $product_info['products_name'],
                        'og:site_name' => STORE_NAME);

          $product_description = substr(trim(preg_replace('/\s\s+/', ' ', strip_tags($product_info['products_description']))), 0, 197) . '...';
          $data['og:description'] = $product_description;

          $products_image = $product_info['products_image'];
          $pi_query = tep_db_query("select image from products_images where products_id = '" . (int)$product_info['products_id'] . "' order by sort_order limit 1");
          if ( tep_db_num_rows($pi_query) === 1 ) {
            $pi = tep_db_fetch_array($pi_query);
            $products_image = $pi['image'];
          }
          $data['og:image'] = tep_href_link('images/' . $products_image, '', 'NONSSL', false, false);          

          if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
            $products_price = $currencies->display_raw($new_price, $product_info['products_tax_class_id']);
          } else {
            $products_price = $currencies->display_raw($product_info['products_price'], $product_info['products_tax_class_id']);
          }
          $data['product:price:amount'] = $products_price;
          $data['product:price:currency'] = $currency;

          $data['og:url'] = tep_href_link('product_info.php', 'products_id=' . $product_info['products_id'], 'NONSSL', false);

          $data['product:availability'] = ( $product_info['products_quantity'] > 0 ) ? MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_TEXT_IN_STOCK : MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_TEXT_OUT_OF_STOCK;

          $result = '';
          foreach ( $data as $key => $value ) {
            $result .= '<meta property="' . tep_output_string_protected($key) . '" content="' . tep_output_string_protected($value) . '" />' . PHP_EOL;
          }

          $oscTemplate->addBlock($result, $this->group);
        }
      }
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_STATUS');
    }

    function install() {
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Product OpenGraph Module', 'MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_STATUS', 'True', 'Do you want to allow Open Graph Meta Tags (good for Facebook and Pinterest and other sites) to be added to your product page?  Note that your product thumbnails MUST be at least 200px by 200px.', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_SORT_ORDER', '900', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    }

    function remove() {
      tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_STATUS', 'MODULE_HEADER_TAGS_PRODUCT_OPENGRAPH_SORT_ORDER');
    }
  }
  

 

Could you try that?

If you want to add in more data...copy one of the data lines making sure to change the KEY and the VALUE, eg;

$data['KEY'] = 'VALUE';

In your particular case;

$data['product:condition'] = 'new';  // one of 'new', 'refurbished', 'used'

Making *sure* that any new added data line is inserted before;

$result = '';
 

Link to comment
Share on other sites

Does Google take it in preference to Schema > Offer / Price or are you missing that code for some reason? 

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

OG for Facebook.  Turns the data into something FB can use for social interactions.
Schema for Google.  Turns the data into something Google and all the other engines can use to present better search results.

https://stackoverflow.com/questions/6402528/opengraph-or-schema-org

I have been planning for a long time to remove all the Schema stuff from product_info and instead have it all in one module. 
I think I even posted the code in the forum a year or three ago.

Link to comment
Share on other sites

@BrockleyJohn,

yes I visited merchants.google today, and it started to adjust prices saying Items updated because of wrong prices in the feed compared to website, they seem to use it since - you are right - I'm missing that code because of an old base price addon I have to use - so I will take care of that next. Thanks for pointing me there.

Best regards

Christoph

Link to comment
Share on other sites

45 minutes ago, burt said:

Could you try that?

 

Sorry, this is putting out still wrong prices, can't understand why as from what I understand this

$products_price = $currencies->display_raw($product_info['products_price'], $product_info['products_tax_class_id']);

should work.

Best regards and thanks for the condition hint

Christoph

Link to comment
Share on other sites

http://template.me.uk/234bs3/product_info.php?products_id=17

Product Price: 39.99
Opengraph:  39.99

If looking at a Special;

http://template.me.uk/234bs3/product_info.php?products_id=5

Product Price: 30.00
Opengraph: 30.00

This is using the Core module, untouched, unchanged.  It seems to be OK ?
Are you certain you have not made changes elsewhere that could affect things?

Could anyone else have a look on their own website?  Or if you like to...PM me and I will take a look.

Link to comment
Share on other sites

The error is not reproduced on http://bromleybr.co.uk/bsjc/

We're testing a bulk price/special update in admin so the prices look crazy but are consistent on the pages.

You may struggle to find one without a special, try http://bromleybr.co.uk/bsjc/product_info.php?cPath=3_15&products_id=14

Latest edge (bar this week's commits) with no catalog side changes at all

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

I'm just guessing but I'm getting strange results with this, as it does not show prices without tax(es) and is not adding 7 or 19 percent as it should. So my naive question would be have you more than one tax rates in use over there? Because this:

 if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
            $products_price = $currencies->display_raw($new_price, tep_get_tax_rate($product_info['products_tax_class_id']));
          } else {
            $products_price =  $currencies->display_raw($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
          }

works as it should.

Best regards

Christoph

Link to comment
Share on other sites

:blush: apologies to both... at some point the store location was changed outside the tax zone. It's back now and Christoph's error is reproduced.

I was convinced I had checked tax was included in both prices but I clearly conned myself. Tsk, must try harder.

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

@burt,

http://template.me.uk/234bs3/product_info.php?products_id=17  39,99 can't be wrong as you seem to be using prices without tax over there:

INSERT INTO products VALUES (17,10,'DVD-SPEED','dvd/speed.gif',39.99, now(),null,null,7.00,1,1,4,0,'');

display_raw($product_info['products_price'], $product_info['products_tax_class_id']);

can't work correctly because it uses the products_tax_class_id as tax percentage, which won't matter as long as tax for prices is not used.

But this lead to my strange results. So I assume this is correct in the end:

display_raw($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));

Best regards

Christoph

 

 

Link to comment
Share on other sites

yep - see http://bromleybr.co.uk/bsjc/product_info.php?products_id=20

Price without tax is $54.99 og now shows

<meta property="product:price:amount" content="58.84" />

code that is running is here:

https://github.com/BrockleyJohn/Responsive-osCommerce/tree/test_og_fix

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...