Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 05-26-2014 15:52:42

Graham
Member
Registered: 09-30-2004
Posts: 981
Website

Rich pins using Open Graph

I've seen that Pinterest is now doing  which is a way of including more information into Pinterest.

To do this would require modifying this section in jslib.php

Code:

     // +--
     // | Print OpenGraph tags.
     // +--

     $opengraph_title       = $meta_title;
     $opengraph_image       = $this->xhtml_encode($this->globals('core.opengraph_image'));
     $opengraph_sitename    = $this->xhtml_encode($site_name);
     $opengraph_description = $meta_description;

     if (!(empty($opengraph_title)))       {print '<meta property="og:title" content="' . $opengraph_title . '" />' . $eol;}
     if (!(empty($opengraph_image)))       {print '<meta property="og:image" content="' . $opengraph_image . '" />' . $eol;}
     if (!(empty($opengraph_sitename)))    {print '<meta property="og:site_name" content="' . $opengraph_sitename . '" />' . $eol;}
     if (!(empty($opengraph_description))) {print '<meta property="og:description" content="' . $opengraph_description . '" />' . $eol;}

Including og:type would be simple, but I don't know how to read the product price (and allow for discounts if offered), location of image, related products etc.

It would probably be too much for me, but someone who knows v8 well enough could probably figure out the code easily enough...

Offline

 

#2 05-27-2014 09:43:26

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Rich pins using Open Graph

Code:

if ($this->globals('core_cgi.app') == 'ecom' && $this->globals('core_cgi.ns') == 'prodshow') {

     $prod = $this->globals('ecom.prod_proddetail');

     // You can pull the pricing from the $prod array at this point.

} // End of if statement.

Nick Hendler

Offline

 

#3 05-28-2014 05:38:19

Graham
Member
Registered: 09-30-2004
Posts: 981
Website

Re: Rich pins using Open Graph

Sorry, but I'm not sure how to pull the pricing from the $prod array.

If you can give an example I should be able to use that as a model to get all the relevant data.

Offline

 

#4 06-06-2014 16:08:05

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Rich pins using Open Graph

print_r($prod['core.priceinfo']);


Nick Hendler

Offline

 

#5 05-05-2015 16:43:56

CrownRoyal
Member
Registered: 01-10-2009
Posts: 716

Re: Rich pins using Open Graph

Would this work?

Code:

    // +--
     // | Print OpenGraph tags.
     // +--

//HACK FOR RICH TAGS 2015-05-05 
//Pinterest Rich Tags requirements from https://developers.pinterest.com/rich_pins_product/
//<meta property="og:title" content="Name of your product" />  ----- ALREADY PRESENT IN CODE
//<meta property="og:type" content="product" />
//<meta property="og:price:amount" content="1.00" />
//<meta property="og:price:currency" content="USD" />
 
//SOURCED from https://forum.kryptronic.com/viewtopic.php?id=31914
if ($this->globals('core_cgi.app') == 'ecom' && $this->globals('core_cgi.ns') == 'prodshow') {

     $prod = $this->globals('ecom.prod_proddetail');

     // You can pull the pricing from the $prod array at this point.
     $opengraph_price = $prod['core.priceinfo'];
}

     $opengraph_type = '<meta property="og:type" content="product" />';

     if (!(empty($opengraph_type)))       {print '<meta property="og:type" content="' . $opengraph_type . '" />' . $eol;}

     if (!(empty($opengraph_price)))       {print '<meta property="og:price:amount" content="' . $opengraph_price . '" />' . $eol;}

     $opengraph_currency = '<meta property="og:currency" content="USD" />';

     if (!(empty($opengraph_currency)))       {print '<meta property="og:price:currency" content="' . $opengraph_currency . '" />' . $eol;}

//END HACK

     $opengraph_title       = $meta_title;
     $opengraph_image       = $this->xhtml_encode($this->globals('core.opengraph_image'));
     $opengraph_sitename    = $this->xhtml_encode($site_name);
     $opengraph_description = $meta_description;

     if (!(empty($opengraph_title)))       {print '<meta property="og:title" content="' . $opengraph_title . '" />' . $eol;}
     if (!(empty($opengraph_image)))       {print '<meta property="og:image" content="' . $opengraph_image . '" />' . $eol;}
     if (!(empty($opengraph_sitename)))    {print '<meta property="og:site_name" content="' . $opengraph_sitename . '" />' . $eol;}
     if (!(empty($opengraph_description))) {print '<meta property="og:description" content="' . $opengraph_description . '" />' . $eol;}

} // End of if statement.

Offline

 

#6 05-06-2015 06:40:12

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Rich pins using Open Graph

The syntax is off.  Try this:

Code:

// BEGIN HACK FOR RICH TAGS 2015-05-05 
// Pinterest Rich Tags requirements from https://developers.pinterest.com/rich_pins_product/
// <meta property="og:title" content="Name of your product" />  ----- ALREADY PRESENT IN CODE
// <meta property="og:type" content="product" />
// <meta property="og:price:amount" content="1.00" />
// <meta property="og:price:currency" content="USD" />
// SOURCED from https://forum.kryptronic.com/viewtopic.php?id=31914

if ($this->globals('core_cgi.app') == 'ecom' && $this->globals('core_cgi.ns') == 'prodshow') {

     print '<meta property="og:type" content="product" />' . $eol;

     if ($this->globals('ecom.prod_priceinfo')) {

          $ogprice = $this->globals('ecom.prod_priceinfo');

          print '<meta property="og:price:amount" content="' . $this->xhtml_encode($ogprice['actualb'])  . '" />' . $eol;
          print '<meta property="og:price:currency" content="USD" />' . $eol;

     } // End of if statement.

} // End of if statement.

// END HACK

Nick Hendler

Offline

 

#7 05-06-2015 07:09:30

CrownRoyal
Member
Registered: 01-10-2009
Posts: 716

Re: Rich pins using Open Graph

I got this error on product display pages:

Parse error: syntax error, unexpected $end in /home/woodwork/public_html/core-private/core/CORE/includes/jslib.php on line 598

Offline

 

#8 05-06-2015 07:21:25

CrownRoyal
Member
Registered: 01-10-2009
Posts: 716

Re: Rich pins using Open Graph

Ok, so I went back to what I suggested and had to fix a few things. I can get the og:price:currency and and og:type to work but the og:price:amount does not work.

Code:

//HACK FOR RICH TAGS 2015-05-05 
//Pinterest Rich Tags requirements from https://developers.pinterest.com/rich_pins_product/
//<meta property="og:title" content="Name of your product" />  ----- ALREADY PRESENT IN CODE
//<meta property="og:type" content="product" />
//<meta property="og:price:amount" content="1.00" />
//<meta property="og:price:currency" content="USD" />
 
//SOURCED from https://forum.kryptronic.com/viewtopic.php?id=31914
if ($this->globals('core_cgi.app') == 'ecom' && $this->globals('core_cgi.ns') == 'prodshow') {

     $prod = $this->globals('ecom.prod_proddetail');

     // You can pull the pricing from the $prod array at this point.
     $opengraph_price = $prod['core.priceinfo'];
}

     $opengraph_type = 'product';

     if (!(empty($opengraph_type)))       {print '<meta property="og:type" content="' . $opengraph_type . '" />' . $eol;}

     if (!(empty($opengraph_price)))       {print '<meta property="og:price:amount" content="' . $opengraph_price . '" />' . $eol;} 

     $opengraph_currency = 'USD';

     if (!(empty($opengraph_currency)))       {print '<meta property="og:price:currency" content="' . $opengraph_currency .'" />' . $eol;}

//END HACK

     $opengraph_title       = $meta_title;
     $opengraph_image       = $this->xhtml_encode($this->globals('core.opengraph_image'));
     $opengraph_sitename    = $this->xhtml_encode($site_name);
     $opengraph_description = $meta_description;

     if (!(empty($opengraph_title)))       {print '<meta property="og:title" content="' . $opengraph_title . '" />' . $eol;}
     if (!(empty($opengraph_image)))       {print '<meta property="og:image" content="' . $opengraph_image . '" />' . $eol;}
     if (!(empty($opengraph_sitename)))    {print '<meta property="og:site_name" content="' . $opengraph_sitename . '" />' . $eol;}
     if (!(empty($opengraph_description))) {print '<meta property="og:description" content="' . $opengraph_description . '" />' . $eol;}

} // End of if statement.

produces

<meta property="og:type" content="product" />
<meta property="og:price:amount" content="Array" />
<meta property="og:price:currency" content="USD" />
<meta property="og:title" content="MY PRODUCT TITLE" />

So all that's left to get is the price. Something in here needs to change?

Code:

//SOURCED from https://forum.kryptronic.com/viewtopic.php?id=31914
if ($this->globals('core_cgi.app') == 'ecom' && $this->globals('core_cgi.ns') == 'prodshow') {

     $prod = $this->globals('ecom.prod_proddetail');

     // You can pull the pricing from the $prod array at this point.
     $opengraph_price = $prod['core.priceinfo'];
}

Last edited by CrownRoyal (05-06-2015 07:23:19)

Offline

 

#9 05-07-2015 05:57:42

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Rich pins using Open Graph

Get the price with this:

Code:

          $ogprice = $this->globals('ecom.prod_priceinfo');

          print '<meta property="og:price:amount" content="' . $this->xhtml_encode($ogprice['actualb'])  . '" />' . $eol;

Nick Hendler

Offline

 

#10 05-07-2015 06:21:52

CrownRoyal
Member
Registered: 01-10-2009
Posts: 716

Re: Rich pins using Open Graph

Thanks Nick. Seems to work. Produced in the current selling price, reg price 18.50, sale price 14.95.

<meta property="og:price:amount" content="14.9500" />

Only question I have is if the 4 decimal places might be acceptable or not? Is there a way to round it down?

Offline

 

#11 05-07-2015 06:28:26

CrownRoyal
Member
Registered: 01-10-2009
Posts: 716

Re: Rich pins using Open Graph

A followup, I entered a product url into the Rich Pins validate page at Pinterest and it passed the test.

A person is then offered the ability to validate their domain.  Waiting now to see if Pinterest approves the store.

Offline

 

#12 05-07-2015 06:31:14

CrownRoyal
Member
Registered: 01-10-2009
Posts: 716

Re: Rich pins using Open Graph

And just like that domain is approved, pins from our products on Pinterest mostly show pricing and proper trademark branding. Nice.  Not all show pricing and branding. Pinterest says: For older Pins, it may take a few weeks for them to appear as Rich Pins.

Thanks Nick!

So to review for others, this is the finished code used:

Code:

     // +--
     // | Print OpenGraph tags.
     // +--

//HACK FOR RICH TAGS 2015-05-05 
//Pinterest Rich Tags requirements from https://developers.pinterest.com/rich_pins_product/
//<meta property="og:title" content="Name of your product" />  ----- ALREADY PRESENT IN CODE
//<meta property="og:type" content="product" />
//<meta property="og:price:amount" content="1.00" />
//<meta property="og:price:currency" content="USD" />
 
//SOURCED from https://forum.kryptronic.com/viewtopic.php?id=31914
if ($this->globals('core_cgi.app') == 'ecom' && $this->globals('core_cgi.ns') == 'prodshow') {

     $prod = $this->globals('ecom.prod_proddetail');

     // You can pull the pricing from the $prod array at this point.
     $ogprice = $this->globals('ecom.prod_priceinfo');
     
}

     $opengraph_type = 'product';

     if(!(empty($ogprice)))      {print '<meta property="og:price:amount" content="' . $this->xhtml_encode(sprintf("%.2f",round($ogprice['actualb'],2)))  . '" />' . $eol;}

     if (!(empty($opengraph_type)))       {print '<meta property="og:type" content="' . $opengraph_type . '" />' . $eol;}

     if (!(empty($opengraph_price)))       {print '<meta property="og:price:amount" content="' . $opengraph_price . '" />' . $eol;}

     $opengraph_currency = 'USD';

     if (!(empty($opengraph_currency)))       {print '<meta property="og:price:currency" content="' . $opengraph_currency .'" />' . $eol;}

//END HACK

Last edited by CrownRoyal (05-07-2015 06:42:09)

Offline

 

#13 05-07-2015 06:31:31

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Rich pins using Open Graph

Code:

$this->xhtml_encode($ogprice['actualb'])

Becomes:

Code:

$this->xhtml_encode(sprintf("%.2f",round($ogprice['actualb'],2)))

Nick Hendler

Offline

 

#14 05-07-2015 06:41:34

CrownRoyal
Member
Registered: 01-10-2009
Posts: 716

Re: Rich pins using Open Graph

that worked Nick, I'll update the code above.

Offline

 

Board footer