generated from silverstripe/silverstripe-module
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added a schema for products * schema now uses the currency code set in shopify - stored in site config - updated automatically when a fetch occurs
- Loading branch information
Showing
6 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Dynamic\Shopify\Extension; | ||
|
||
use SilverStripe\ORM\DataExtension; | ||
|
||
/** | ||
* Class ShopifySiteConfigExtension | ||
* @package Dynamic\Shopify\Extension | ||
* | ||
* @property string ShopCurrencyCode | ||
*/ | ||
class ShopifySiteConfigExtension extends DataExtension | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private static $db = [ | ||
'ShopCurrencyCode' => 'Varchar', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Dynamic\Shopify\SEO; | ||
|
||
use Broarm\Schema\Builder\SchemaBuilder; | ||
use Broarm\Schema\Type\OfferSchema; | ||
use Broarm\Schema\Type\ProductSchema; | ||
use Dynamic\Shopify\Model\ShopifyFile; | ||
use Dynamic\Shopify\Page\ShopifyProduct; | ||
use SilverStripe\SiteConfig\SiteConfig; | ||
|
||
/** | ||
* Class ProductSchemaBuilder | ||
* @package Dynamic\Shopify\SEO | ||
*/ | ||
class ProductSchemaBuilder extends SchemaBuilder | ||
{ | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getSchema($page) | ||
{ | ||
/** @var ShopifyProduct $page */ | ||
$images = []; | ||
foreach ($page->Files() as $file) { | ||
if ($file->Type === ShopifyFile::IMAGE) { | ||
$images[] = $file->getURL(); | ||
} | ||
} | ||
|
||
return new ProductSchema( | ||
$page->Title, | ||
$page->Content, | ||
new OfferSchema( | ||
number_format($page->getPrice()->getValue(), 2), | ||
SiteConfig::current_site_config()->ShopCurrencyCode, | ||
$page->ProductActive ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock' | ||
), | ||
$page->getSKU(), | ||
null, | ||
null, | ||
$images | ||
); | ||
} | ||
} |