Jake Vanderwerf
3 hours ago cf7c6dae604a0bbd471afa156f82555a5a2e9ab7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?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',
//    ];
//}