News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Availibility condition in snippets.php file

Started by amlil71, November 27, 2016, 18:10:53 PM

Previous topic - Next topic

amlil71

Hello,

i want to add availibility information in the snippets.php file.

i try to add this code :

"availability":{
   "@type": "availability",
   <?php if ($product->product_in_stock 0) { ?>
                    "availability" = '<meta itemprop="availability" content="http://schema.org/InStock" ';
               "availability" = '<meta itemprop="availability" content="http://schema.org/OutOfStock"';  <?php ?>



i'm not developer. I want to improve virtuemart SEO options. Is someone know how to add availbility condition on the snippet.php files.


Thank you.


Regards.

Ghost

Use this to get availability link:

if($product->stock->stock_level == 'nostock')
{
$stock = 'http://schema.org/OutOfStock';
} elseif($product->stock->stock_level == 'lowstock')
{
$stock = 'http://schema.org/LimitedAvailability';
}
else{
$stock = 'http://schema.org/InStock';
}


and then add this to the snippet inside Offer type:

"availability": "<?php echo $stock ?>",

amlil71

#2
Hello,

thank you very much for your answer.

I put your code in the snippets.php file as you can see it in the snippets.txt attached files.

When i test i have this result : availibility = " "


What can explain this ?

Thank you.

Regards.

Ghost

It's ecause you put the first block inside this statement if($viewData['showRating']){...}

amlil71

Hello,

thank you very much. It work's fine now with this code .

<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
$product $viewData['product'];
$currency $viewData['currency'];
$view vRequest::getCmd('view');
if(
$viewData['showRating']){
  
$ratingModel VmModel::getModel('Ratings');
  
$productrating $ratingModel->getRatingByProduct($product->virtuemart_product_id);
  
$productratingcount = isset($productrating->ratingcount) ? $productrating->ratingcount:'';}

if (
$product->product_in_stock 1){   
$stock 'http://schema.org/OutOfStock';}
else{
$stock 'http://schema.org/InStock';}

?>


<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "Product",
  "name": "<?php echo htmlspecialchars($product->product_name); ?>",
  <?php if ( $product->images[0]->virtuemart_media_id 0) { ?>
  "image": "<?php echo JURI::root().$product->images[0]->file_url?>",
  <?php ?>
  <?php if (!empty($product->product_s_desc)) { ?>
  "description": "<?php echo htmlspecialchars(strip_tags($product->product_s_desc)); ?>",
  <?php } elseif (!empty($product->product_desc)) { ?>
  "description": "<?php echo htmlspecialchars(strip_tags($product->product_desc)); ?>",
  <?php ?>
  <?php if ($viewData['showRating'] && !empty($product->rating)) { ?>
  "aggregateRating":{
    "@type": "AggregateRating",
    "ratingValue": "<?php echo $product->rating?>",
    "reviewCount": "<?php echo $productratingcount?>"
  },
  <?php ?>
  "offers":{
    "@type": "Offer",
    "priceCurrency": "<?php echo $currency->_vendorCurrency_code_3?>",
    "price": "<?php echo $product->prices['salesPrice']; ?>",
    "availability": "<?php echo $stock ?>"
  }
}
</script>



Regards.