<?php
|
// /content/product.php
|
|
use JVBase\registrar\Registrar;
|
|
add_action('jvbDefineRegistrar', 'ami_product');
|
add_action('jvbDefineRegistrarFields', 'ami_product_fields');
|
|
add_action('plugins_loaded', 'ami_product',1);
|
//Add fields later so we can verify taxonomies/post types exist
|
add_action('plugins_loaded', 'ami_product_fields', 2);
|
|
add_filter('ami_ProductSchemaDefault', 'ami_product_schema');
|
add_filter('ami_ProductMetaDefault', 'ami_product_meta');
|
add_filter('ami_ProductArchiveDefault', 'ami_product_archive');
|
|
function ami_product(){
|
if (!class_exists('JVBase\registrar\Registrar')) {
|
return;
|
}
|
$product = Registrar::forPost('product', 'Product', 'Products')
|
->setIcon('shopping-cart-simple')
|
->make([
|
'rewrite' => [
|
'slug' => 'products',
|
'with_front' => false,
|
],
|
'taxonomies' => [
|
'product_cat',
|
],
|
'rewrite_taxonomy' => 'product_cat'
|
])
|
->setAll([
|
'show_directory',
|
])
|
->setIntegration('helcim')
|
->setIntegration('facebook')
|
->setIntegration('instagram');
|
|
//$directory = $product->getConfig('directory');
|
|
}
|
|
function ami_product_fields():void
|
{
|
if (!class_exists('JVBase\registrar\Registrar')) {
|
return;
|
}
|
$product = Registrar::getInstance('product');
|
$breadcrumbs = $product->config('breadcrumbs');
|
$breadcrumbs->setCrumb('product_cat');
|
|
|
$fields = $product->fields();
|
$fields->addField('gallery', [
|
'type' => 'upload',
|
'subtype' => 'image',
|
'multiple' => true,
|
'label' => 'Gallery',
|
]);
|
$fields->addField('product_cat', [
|
'type' => 'selector',
|
'subtype' => 'taxonomy',
|
'taxonomy' => 'product_cat',
|
'label' => 'Categories'
|
]);
|
}
|
|
function ami_product_schema():array
|
{
|
return [
|
'type' => 'JVBase\managers\SEO\render\Thing\CreativeWork\CreativeWork',
|
'mainEntity' => [
|
'type' => 'JVBase\managers\SEO\render\Thing\Intangible\Service',
|
'name' => '{{post_title}}'
|
],
|
'name' => '{{post_title}}',
|
];
|
}
|
|
function ami_product_meta():array
|
{
|
return[
|
'name' => '{{post_title}}',
|
];
|
}
|
|
function ami_product_archive(array $defaults):array
|
{
|
return array_merge($defaults, [
|
]);
|
}
|
|
function ami_product_reference_schema(array $defaults):array
|
{
|
return $defaults;
|
}
|
|
|
|
//
|
//function ami_product():array
|
//{
|
// return [
|
// 'singular' => 'Product',
|
// 'plural' => 'Products',
|
// 'show_feed' => true,
|
// 'favouritable' => true,
|
// 'icon' => 'shopping-cart-simple',
|
// 'rewrite' => [
|
// 'slug' => 'products',
|
// 'with_front' => false,
|
// ],
|
// 'use_helcim' => true,
|
// 'fields' => [
|
// 'post_title' => [
|
// 'type' => 'text',
|
// 'label' => 'Title',
|
// ],
|
// 'featured_image' => [
|
// 'type' => 'image',
|
// 'label' => 'Image',
|
// ],
|
// 'gallery' => [
|
// 'type' => 'gallery',
|
// 'label' => 'Gallery',
|
// ],
|
// 'price' => [
|
// 'type' => 'number',
|
// 'label' => 'Price',
|
// ],
|
// 'post_content' => [
|
// 'type' => 'textarea',
|
// 'quill' => true,
|
// 'label' => 'Notes'
|
// ]
|
// ],
|
// 'single_image' => false,
|
// 'upload_title' => 'Upload Products',
|
// ];
|
//}
|