torvista / Zen_Cart-Structured_Data

Plugin that adds Schema, Facebook and Twitter structured markup to all pages
GNU General Public License v3.0
9 stars 6 forks source link

Missing field "hasMerchantReturnPolicy" (in "offers") #39

Closed Nicksab82 closed 10 months ago

Nicksab82 commented 1 year ago

Would it be possible to add these 2 new field as per Google new requirements:

Here is the only example I could find from Google themselves:

"offers": { "@type": "Offer", "url": "https://www.example.com/trinket_offer", "itemCondition": "https://schema.org/NewCondition", "availability": "https://schema.org/InStock", "priceSpecification": { "@type": "PriceSpecification", "price": 39.99, "priceCurrency": "CHF" }, "hasMerchantReturnPolicy": { "@type": "MerchantReturnPolicy", "applicableCountry": "CH", "returnPolicyCategory": "https://schema.org/MerchantReturnFiniteReturnWindow", "merchantReturnDays": 60, "returnMethod": "https://schema.org/ReturnByMail", "returnFees": "https://schema.org/FreeReturn" } }

torvista commented 1 year ago

Try this branch: https://github.com/torvista/Zen_Cart-Structured_Data/tree/hasMerchantReturnPolicy

and report

Nicksab82 commented 1 year ago

Gave it at try and I am getting the following error when accessing product page:

[31-May-2023 19:15:55 America/Los_Angeles] PHP Fatal error: Uncaught TypeError: substr() expects parameter 1 to be string, null given in /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php:847 Stack trace:

0 /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php(847): substr(NULL, 0, 10)

1 /includes/templates/bootstrap/common/html_header.php(190): require('/home/zch1akhw6...')

2 /index.php(43): require('/home/zch1akhw6...')

3 {main}

thrown in /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php on line 847

torvista commented 1 year ago

Did you fill in the empty defines at the top of the page for the countries?

Nicksab82 commented 1 year ago

You lost me here. defines at the top of the page? I must have done something wrong then.

I replaced my previous jscript with the updated one on here. Hence got the error right after and blank product info page.

Did I miss a step? Any other file need to be replaced?

Thank you for the assist

torvista commented 1 year ago

As I can't be arsed to bugger about with installers (and think that the whole list of stuff in the admin should be removed and go in a configure file, as it never changes), I add define() statements at the start of the script where you have to insert your site specific stuff:

//* SITE-SPECIFIC constants additional to the Admin constants ****

i.e.

// Merchant Return Policy
// https://schema.org/MerchantReturnPolicy
// https://developers.google.com/search/docs/appearance/structured-data/product#returns
// applicableCountry
define('PLUGIN_SDATA_RETURNS_APPLICABLE_COUNTRY', ''); // country to which the returns policy applies: 2-char ISO. I failed to figure out a structure where multiple countries can be used.
define('PLUGIN_SDATA_RETURNS_POLICY_COUNTRY', ''); // country to which the product is to be returned/STORE Country: 2-char ISO.
// returnPolicyCategory
define('PLUGIN_SDATA_RETURNS_POLICY', 'finite'); // 'finite' / 'not_permitted' / 'unlimited':  the returns category as per key of $returnPolicyCategory defined below.
// merchantReturnDays.  Only required if PLUGIN_SDATA_RETURNS_POLICY = finite
define('PLUGIN_SDATA_RETURNS_DAYS', '14'); // limit of period (days) within which a product can be returned.
// returnMethod
define('PLUGIN_SDATA_RETURNS_METHOD', 'mail'); // 'kiosk' / 'mail' / 'store': method of returning a product, as per key in $returnMethod defined below.
// returnShippingFeesAmount
define('PLUGIN_SDATA_RETURNS_FEES', '0'); // cost to return a product. Use 0 or a decimal.

These deliberately have no defaults so they create errors when not completed. You probably have not set the country codes.

Nicksab82 commented 1 year ago

Thank you for pointing me in the right direction. I did define these, but I am still getting the same error. ( blank product info page)

I believe it has something to do with this line:

"datePublished" : "<?php echo substr($reviewsArray[$i]['dateAdded'], 0, 10); ?>",

If I manually insert a date there, it works but i don t see the new field ([hasMerchantReturnPolicy)

For example: "datePublished" : "06/03/2023",

Not sure why as it is the same in the previous jscript.

Below are my define that were missing:

`//* SITE-SPECIFIC constants additional to the Admin constants ****

// Fallback/default Google category ID (up to 6 digits). eg. '5613' = Vehicles & Parts, Vehicle Parts & Accessories // This is used if a product does not have a specific category defined https://www.google.com/basepages/producttype/taxonomy-with-ids.en-US.xls define('PLUGIN_SDATA_GOOGLE_PRODUCT_CATEGORY', '2899');

//REVIEWS // If there are no reviews for a product, use a default value to stop Google warnings define('PLUGIN_SDATA_REVIEW_USE_DEFAULT', 'true'); // If there are no reviews for a product, average rating define('PLUGIN_SDATA_REVIEW_DEFAULT_VALUE', '3');

// Fallback/default weight if product weight in database is not set define('PLUGIN_SDATA_DEFAULT_WEIGHT', '0.3');

// ItemAvailability // https://developers.google.com/search/docs/appearance/structured-data/product // It seems there is no option for an Out Of Stock product that is only ordered from the supplier on demand...best option seems to be backorder... but this needs a date. Use today's date + some days delay. define('PLUGIN_SDATA_OOS_DEFAULT', 'BackOrder'); // as per key in $itemAvailability below //Days to add to today's date for BackOrder/PreOrder define('PLUGIN_SDATA_OOS_AVAILABILITY_DELAY', '10');

// Merchant Return Policy // https://schema.org/MerchantReturnPolicy // https://developers.google.com/search/docs/appearance/structured-data/product#returns // applicableCountry define('PLUGIN_SDATA_RETURNS_APPLICABLE_COUNTRY', 'US'); // country to which the returns policy applies: 2-char ISO. I failed to figure out a structure where multiple countries can be used. define('PLUGIN_SDATA_RETURNS_POLICY_COUNTRY', 'US'); // country to which the product is to be returned/STORE Country: 2-char ISO. // returnPolicyCategory define('PLUGIN_SDATA_RETURNS_POLICY', 'finite'); // 'finite' / 'not_permitted' / 'unlimited': the returns category as per key of $returnPolicyCategory defined below. // merchantReturnDays. Only required if PLUGIN_SDATA_RETURNS_POLICY = finite define('PLUGIN_SDATA_RETURNS_DAYS', '1'); // limit of period (days) within which a product can be returned. // returnMethod define('PLUGIN_SDATA_RETURNS_METHOD', 'store'); // 'kiosk' / 'mail' / 'store': method of returning a product, as per key in $returnMethod defined below. // returnShippingFeesAmount define('PLUGIN_SDATA_RETURNS_FEES', '0'); // cost to return a product. Use 0 or a decimal.

//* eof SITE-SPECIFIC constants additional to the Admin constants ****`

torvista commented 1 year ago

This datePublished field comes from the review date: table reviews, field date_added. I see date_added has a default null value but in any case, that field should always be set. Look in your reviews table to see if any of the date_added values are null and change them to a real datetime.

torvista commented 1 year ago

I've added handling for null in the new branch

https://github.com/torvista/Zen_Cart-Structured_Data/tree/hasMerchantReturnPolicy

see the readme. You need to edit the new define for a default date.

torvista commented 1 year ago

Is this working for you?

Nicksab82 commented 1 year ago

Is this working for you?

Sorry for the delayed reply. I am still testing the last file provided but it seems to be working.

No error logs and the product are displaying.

Thank you for the help

torvista commented 1 year ago

ok, merged with main https://github.com/torvista/Zen_Cart-Structured_Data/pull/41

Nicksab82 commented 1 year ago

i haven t been getting another odd error since switching to thew new jscript:

`[08-Jun-2023 16:24:23 America/Los_Angeles] PHP Fatal error: Uncaught TypeError: htmlentities() expects parameter 1 to be string, null given in /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php:950 Stack trace:

0 /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php(950): htmlentities(NULL, 3, 'utf-8', false)

1 /includes/templates/bootstrap/common/html_header.php(190): require('/home/zch1akhw6...')

2 /index.php(43): require('/home/zch1akhw6...')

3 {main}

thrown in /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php on line 950

[08-Jun-2023 16:24:23 America/Los_Angeles] Request URI: /back-to-school/soft-persuasion-bouquet?cPath=75_76&, IP address: 66.249.79.168 --> PHP Fatal error: Uncaught TypeError: htmlentities() expects parameter 1 to be string, null given in /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php:950 Stack trace:

0 /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php(950): htmlentities(NULL, 3, 'utf-8', false)

1 /includes/templates/bootstrap/common/html_header.php(190): require('/home/zch1akhw6...')

2 /index.php(43): require('/home/zch1akhw6...')

3 {main}

thrown in /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php on line 950.`

but i am really confused with line 950:

<meta name="twitter:image:alt" content="<?php echo htmlentities($image_alt, ENT_QUOTES, CHARSET, false); ?>">

Also just heard back from google not validating the new field ( their system took awhile to re-validate)

Sorry for the long post. i just don't understand the twiiter related and when looking at the webpage source, i don t see the "hasMerchantreturnPolicy" field anywhere.

What am i missing?

Thank you again for your time and help.

torvista commented 1 year ago

post a link to the page that triggers one specific error, or pm through the forum if you prefer.

That $image_alt varies depending on whether it is a category or product page. It is initialised as empty at the start of the script so should never be null.

Nicksab82 commented 1 year ago

post a link to the page that triggers one specific error, or pm through the forum if you prefer.

That $image_alt varies depending on whether it is a category or product page. It is initialised as empty at the start of the script so should never be null.

Thanks again for helping with this.

There is few pages that create error logs.

Here are a few examples.

https://www.royal-fleur.com/get-well/hello-sunshine-fashion-bouquet/reviews?cPath=7_12&number_of_uploads=0& https://www.royal-fleur.com/everyday-occasions/get-well/lighthearted-moments-mini-rose-plant?cPath=3_12& https://www.royal-fleur.com/corsages-boutonnieres/pure-grace-wrist-corsage?cPath=8_17

The pages are coming up blank. However, if i remove the ?cPath part, the pages are loading properly but I have no ideas how the or why the cPath is being added. My site does use CEON URI plugin though if it helps.

torvista commented 1 year ago

Ok, I see the hole in the code, but this means the category 7_12 has no name defined?

Nicksab82 commented 1 year ago

Ok, I see the hole in the code, but this means the category 7_12 has no name defined?

this is really odd as I don t have a category 7_12.

I have a category with ID 7 but it has no subcategory or product with ID 12 in it.

Same applies to 8_17 or 3_12.

Not sure where or what is calling these pages. They should return a 404 error page if I am not mistaking.

Thanks again for taking the time to look into this.

torvista commented 1 year ago

try this to cure the white screens: https://github.com/torvista/Zen_Cart-Structured_Data/tree/bad_cpath I don't have time to rework the code as I'd wish. This plugin has evolved piecemeal over a long time and probably needs a major overhaul to make it more elegant....

Nicksab82 commented 1 year ago

try this to cure the white screens: https://github.com/torvista/Zen_Cart-Structured_Data/tree/bad_cpath I don't have time to rework the code as I'd wish. This plugin has evolved piecemeal over a long time and probably needs a major overhaul to make it more elegant....

Updated my jscript files and will report back if anything.

Thank you for taking the time to provide a fix.

Nicksab82 commented 1 year ago

ugh spoke to soon again.

Got 50+ identical error logs

`[11-Jun-2023 19:00:45 America/Los_Angeles] PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function zen_get_category_name(), 1 passed in /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php on line 528 and exactly 2 expected in /includes/functions/functions_lookups.php:397 Stack trace:

0 /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php(528): zen_get_category_name('109')

1 /includes/templates/bootstrap/common/html_header.php(190): require('/home/zch1akhw6...')

2 /index.php(43): require('/home/zch1akhw6...')

3 {main}

thrown in /includes/functions/functions_lookups.php on line 397

[11-Jun-2023 19:00:45 America/Los_Angeles] Request URI: /everyday-occasions/get-well/wondrous-nature-bouquet/reviews?cPath=109&number_of_uploads=0&, IP address: 176.9.50.244 --> PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function zen_get_category_name(), 1 passed in /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php on line 528 and exactly 2 expected in /includes/functions/functions_lookups.php:397 Stack trace:

0 /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php(528): zen_get_category_name('109')

1 /includes/templates/bootstrap/common/html_header.php(190): require('/home/zch1akhw6...')

2 /index.php(43): require('/home/zch1akhw6...')

3 {main}

thrown in /includes/functions/functions_lookups.php on line 397.`

torvista commented 1 year ago

Too few arguments to function zen_get_category_name(), 1 passed function zen_get_category_name in ZC158 only needs one parameter, older ZC need two. Are you not using ZC158? I've reverted the change in that branch,

Nicksab82 commented 1 year ago

Too few arguments to function zen_get_category_name(), 1 passed function zen_get_category_name in ZC158 only needs one parameter, older ZC need two. Are you not using ZC158? I've reverted the change in that branch,

i am on 1.5.7. Not ready to update to 1.5.8 yet.

torvista commented 1 year ago

So, no debugs now?

Nicksab82 commented 1 year ago

/back-to-school/soft-persuasion-bouquet

I had a couple of logs that came back. Unfortunately i deleted them by mistake.

So far logs are empty but i will post if something comes back.

The only thing is some of the product pages seems to be missing the new field and are failing "Rich Result Test" somehow but other product pages pass. For example:

https://www.royal-fleur.com/all-flowers/above-larkspur-sunset-bouquet fail the test and is lacking the MerchantReturnPolicy field.

but https://www.royal-fleur.com/wedding/bridal-bouquet/pink-cascade-bouquet has the "merchantReturnPolicy field

Isn't the structured data populated regardless of product?

I just don't understand why one product would have and not another.

Sorry for the long comment and hope it makes sense.

Thank again for everything

torvista commented 1 year ago

One is simple product and one has attributes, handled differently. I can't remember if I forgot to do it or didn't notice in the first place...what a state! It's done now.

Nicksab82 commented 1 year ago

One is simple product and one has attributes, handled differently. I can't remember if I forgot to do it or didn't notice in the first place...what a state! It's done now.

Thank you

torvista commented 1 year ago

Confirmed ok?

Nicksab82 commented 1 year ago

Confirmed ok?

Still getting a log but it is a warning and seems to be for only one product.

[16-Jun-2023 09:01:46 America/Los_Angeles] Request URI: /get-well/enduring-peace-basket, IP address: 73.92.10.199

1 min() called at [/includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php:374]

2 require(/includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php) called at [/includes/templates/bootstrap/common/html_header.php:190]

3 require(/includes/templates/bootstrap/common/html_header.php) called at [/index.php:43]

--> PHP Warning: min(): Array must contain at least one element in /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php on line 374.

[16-Jun-2023 09:01:46 America/Los_Angeles] Request URI: /get-well/enduring-peace-basket, IP address: 73.92.10.199

1 max() called at [/includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php:375]

2 require(/includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php) called at [/includes/templates/bootstrap/common/html_header.php:190]

3 require(/includes/templates/bootstrap/common/html_header.php) called at [/index.php:43]

--> PHP Warning: max(): Array must contain at least one element in /includes/templates/bootstrap/jscript/jscript_plugin_structured_data.php on line 375.

torvista commented 1 year ago

I see the attribute prices are all +something, but I see no base price on that product....

I'll be hiding in a Faraday cage for the next week, or trying to ...

Nicksab82 commented 1 year ago

coffee, coffee, coffee........I need coffee before i post anything.

All bugs free

Thanks for all the work.