Skip to content

Instantly share code, notes, and snippets.

@cgi-caesar
Last active December 17, 2019 10:51
Show Gist options
  • Save cgi-caesar/20be74337aa2a48983c93306c02e396b to your computer and use it in GitHub Desktop.
Save cgi-caesar/20be74337aa2a48983c93306c02e396b to your computer and use it in GitHub Desktop.
aMember (site.php): add Open Graph Meta to Product Page
<?php
Am_Di::getInstance()->blocks->add('cart/product/title', new Am_Block_Base(null, 'ogp-me', null, function(Am_View $v) {
if ($v->displayProductDetails) {
/** @var Product $product */
$product = $v->product;
$product_url = $product->path ?
$v->surl('product/' . urlencode($product->path), false) :
$v->surl("cart/index/product/id/{$product->pk()}", false);
$meta = [
'og:type' => 'og:product',
'og:title' => $product->title,
'og:image' => $v->surl("data/public/{$product->img_path}", false),
'og:description' => $product->getDescription(false),
'og:url' => $product_url,
'product:price:amount' => $product->getBillingPlan()->first_price,
'product:price:currency' => $product->getBillingPlan()->currency,
];
$out = '';
foreach ($meta as $property => $content) {
$out .= sprintf(
'<meta property="%s" content="%s" />%s',
Am_Html::escape($property),
Am_Html::escape($content),
"\n"
);
}
$v->placeholder("head-start")->append($out);
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment