Merge branch 'master' into package-reference
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Product {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('acf/save_post', array(__CLASS__, 'wiaas_my_save_post'), 20, 1);
|
||||
add_action('woocommerce_after_register_post_type', array(__CLASS__, 'wiaas_register_product_status'));
|
||||
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'wiaas_modify_product'));
|
||||
add_action('add_meta_boxes', array(__CLASS__, 'wiaas_maybe_remove_metaboxes'), 999);
|
||||
add_filter('wp_insert_post_data', array(__CLASS__, 'wiaas_maybe_set_no_country_status'), 999, 2);
|
||||
add_action('acf/render_field/type=taxonomy', array(__CLASS__, 'wiaas_render_field'), 10, 1);
|
||||
|
||||
}
|
||||
|
||||
public static function wiaas_modify_product($args) {
|
||||
$args['supports'] = array('title');
|
||||
return $args;
|
||||
}
|
||||
|
||||
public static function wiaas_register_product_status() {
|
||||
register_post_status('_wiaas_no_country', array(
|
||||
'label' => _x('No Country', 'Product status', 'wiaas'),
|
||||
'public' => false,
|
||||
'exclude_from_search' => false,
|
||||
'show_in_admin_all_list' => false,
|
||||
'show_in_admin_status_list' => false,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public static function wiaas_render_field($field) {
|
||||
|
||||
if ($field['_name'] === '_wiaas_product_country') {
|
||||
?>
|
||||
<div id="submitpost" style="padding: 20px;">
|
||||
<input style="float:right;" name="save" id="save-post" class="button" type="submit" value="Choose"/>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function wiaas_maybe_remove_metaboxes() {
|
||||
$screen = get_current_screen();
|
||||
$screen_id = $screen ? $screen->id : '';
|
||||
|
||||
if ($screen_id !== 'product') {
|
||||
return;
|
||||
}
|
||||
global $post;
|
||||
|
||||
$post_id = $post->ID;
|
||||
|
||||
if ($post_id === 0 ||
|
||||
($post->post_status !== 'publish' && !(Wiaas_Countries::get_package_country(wc_get_product($post_id))))) {
|
||||
|
||||
remove_meta_box('woocommerce-product-data', 'product', 'normal');
|
||||
remove_meta_box('submitdiv', 'product', 'side');
|
||||
remove_meta_box('slugdiv', 'product', 'normal');
|
||||
remove_meta_box('wiaas_upload_and_link_document', 'product', 'normal');
|
||||
remove_meta_box('postexcerpt', 'product', 'normal');
|
||||
remove_meta_box('template_product_meta_box', 'product', 'normal');
|
||||
remove_meta_box('postimagediv', 'product', 'normal');
|
||||
remove_meta_box('woocommerce-product-images', 'product', 'normal');
|
||||
remove_meta_box('wc-jetpack-product_by_user_role', 'product', 'normal');
|
||||
|
||||
|
||||
remove_meta_box('groups-permissions', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-product_tag', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-template_category', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-supplier', 'product', 'side');
|
||||
remove_meta_box('postimagediv', 'product', 'side');
|
||||
remove_meta_box('woocommerce-product-images', 'product', 'side');
|
||||
remove_meta_box('submitdiv', 'product', 'side');
|
||||
remove_meta_box('wiaas_upload_and_link_document', 'product', 'side');
|
||||
remove_meta_box('radio-tagsdiv-product_country', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-_wiaas_shop_prices', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-wiaas_units', 'product', 'side');
|
||||
}
|
||||
|
||||
//Always hide product category, it is added wit advanced custom fields plugin for simple product
|
||||
remove_meta_box('radio-product_catdiv', 'product', 'side');
|
||||
|
||||
}
|
||||
|
||||
public static function wiaas_maybe_set_no_country_status($data, $postarr) {
|
||||
if ($postarr['post_type'] === 'product' && (!isset($postarr['ID']) || !$postarr['ID'])) {
|
||||
$data['post_status'] = '_wiaas_no_country';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for post status and and if there is country available
|
||||
* Set post status to draft if the country is added
|
||||
*
|
||||
* @param $post_id
|
||||
*/
|
||||
|
||||
public static function wiaas_my_save_post($post_id) {
|
||||
|
||||
global $post;
|
||||
$status = get_post_status( $post->ID);
|
||||
|
||||
$value = get_field('_wiaas_product_country', $post_id, true);
|
||||
$type = get_field('_wiaas_product_type', $post_id, true);
|
||||
|
||||
error_log($status);
|
||||
error_log($value);
|
||||
|
||||
|
||||
if (!empty($value) && $status === '_wiaas_no_country' ) {
|
||||
|
||||
wp_set_object_terms($post_id, $value, 'product_country', true);
|
||||
wp_set_object_terms($post_id, $type, 'product_type', true);
|
||||
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'draft'
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Admin_Product::init();
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Simple_Product {
|
||||
|
||||
public static function init() {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/simple-product/class-wiaas-admin-product-additional-info.php';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Simple_Product::init();
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Product_Additional_Info {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('woocommerce_product_options_general_product_data', array(__CLASS__, 'display_additional_fields'));
|
||||
add_action('woocommerce_process_product_meta', array(__CLASS__, 'save_additional_fields'));
|
||||
add_filter('woocommerce_json_search_found_products', array(__CLASS__, 'filter_product_by_country'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add Manufacturer product and Supplier product number fields to
|
||||
* Simple product general tab
|
||||
*
|
||||
*/
|
||||
public static function display_additional_fields() {
|
||||
|
||||
global $post;
|
||||
$product = wc_get_product( $post->ID );
|
||||
|
||||
if ($product->get_type() === 'simple') {
|
||||
|
||||
echo '<div class=" product_custom_field ">';
|
||||
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_manufacturer_product_no',
|
||||
'label' => __('Manufacturer product number', 'woocommerce'),
|
||||
'type' => 'text'
|
||||
)
|
||||
);
|
||||
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_supplier_product_no',
|
||||
'label' => __('Supplier product number', 'woocommerce'),
|
||||
'type' => 'text'
|
||||
)
|
||||
);
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
public static function filter_product_by_country($search_results) {
|
||||
|
||||
$url = wp_get_referer();
|
||||
|
||||
if (strpos($url, 'post') === false) {
|
||||
return $search_results;
|
||||
}
|
||||
|
||||
$post_param = explode("&", parse_url($url, PHP_URL_QUERY))[0];
|
||||
$post_id = explode("=", $post_param)[1];
|
||||
$country_id = wp_get_post_terms($post_id, 'product_country', array('fields' => 'ids'))[0];
|
||||
|
||||
if (!empty($search_results)) {
|
||||
$search_result_objects = array_map('wc_get_product', array_keys($search_results));
|
||||
|
||||
foreach ($search_result_objects as $result_id => $producta) {
|
||||
if (Wiaas_Countries::get_product_country_term_id($producta) !== $country_id) {
|
||||
unset($search_results[$producta->get_id()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $search_results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Manufacturer product and Supplier product number fields to
|
||||
* Simple product meta data
|
||||
*
|
||||
*/
|
||||
public static function save_additional_fields($post_id) {
|
||||
|
||||
$manufacturer_product_no = $_POST['_manufacturer_product_no'];
|
||||
if (!empty($manufacturer_product_no))
|
||||
update_post_meta($post_id, '_manufacturer_product_no', esc_attr($manufacturer_product_no));
|
||||
|
||||
$supplier_product_no = $_POST['_supplier_product_no'];
|
||||
if (!empty($supplier_product_no))
|
||||
update_post_meta($post_id, '_supplier_product_no', esc_attr($supplier_product_no));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Product_Additional_Info::init();
|
||||
@@ -12,6 +12,7 @@ class Wiaas_Admin {
|
||||
require_once dirname(__FILE__) . '/admin/template/class-wiaas-admin-template-selection.php';
|
||||
require_once dirname(__FILE__) . '/admin/template/class-wiaas-template-products.php';
|
||||
require_once dirname(__FILE__) . '/admin/template/class-wiaas-template-admin-ajax.php';
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-simple-product.php';
|
||||
|
||||
// Admin order projects interface
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-order-projects.php';
|
||||
@@ -22,6 +23,8 @@ class Wiaas_Admin {
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-cl.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-product.php';
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
}
|
||||
|
||||
|
||||
@@ -114,12 +114,25 @@ class Wiaas_Countries {
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function get_product_country($product) {
|
||||
public static function get_product_country($product) {
|
||||
$product_country = get_the_terms($product->get_id(), 'product_country');
|
||||
return is_array($product_country) && isset($product_country[0]) ?
|
||||
self::$available_countries[$product_country[0]->name] :
|
||||
null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves country term id from db for provided product
|
||||
* @param $product
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public static function get_product_country_term_id($product) {
|
||||
$product_country = get_the_terms($product->get_id(), 'product_country');
|
||||
return is_array($product_country) && isset($product_country[0]) ?
|
||||
$product_country[0]->term_id :
|
||||
null;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Countries::init();
|
||||
|
||||
@@ -22,6 +22,8 @@ class Wiaas_DB_Update {
|
||||
'201810180444700' => 'wiaas_db_setup_create_customer_commercial_lead_table',
|
||||
'201810180544702' => 'wiaas_db_update_update_commercial_lead_capabilities',
|
||||
'201810180644703' => 'wiaas_db_update_add_organization_info_ui_fields',
|
||||
'201910190145700' => 'wiaas_db_update_add_general_ui_fields',
|
||||
'201910190146700' => 'wiaas_db_update_add_product_properties_ui_fields'
|
||||
'201810190644704' => 'wiaas_db_update_add_reference_ui_field'
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bbf694106e34",
|
||||
"title": "General",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bc0965a35406",
|
||||
"label": "Type",
|
||||
"name": "_wiaas_product_type",
|
||||
"type": "select",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"choices": {
|
||||
"simple": "Simple",
|
||||
"bundle": "Bundle",
|
||||
"wiaastemplate": "Template"
|
||||
},
|
||||
"default_value": [],
|
||||
"allow_null": 0,
|
||||
"multiple": 0,
|
||||
"ui": 1,
|
||||
"ajax": 0,
|
||||
"return_format": "value",
|
||||
"placeholder": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bbf899bba1af",
|
||||
"label": "Country",
|
||||
"name": "_wiaas_product_country",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": [
|
||||
[
|
||||
{
|
||||
"field": "field_5bc0965a35406",
|
||||
"operator": "!=",
|
||||
"value": "wiaastemplate"
|
||||
}
|
||||
]
|
||||
],
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "product_country",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 0,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "post_type",
|
||||
"operator": "==",
|
||||
"value": "product"
|
||||
},
|
||||
{
|
||||
"param": "post_status",
|
||||
"operator": "==",
|
||||
"value": "_wiaas_no_country"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "acf_after_title",
|
||||
"style": "default",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,113 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bc864b78434b",
|
||||
"title": "Product properties",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bc8653baeafb",
|
||||
"label": "Supplier",
|
||||
"name": "supplier",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "category",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 1,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
},
|
||||
{
|
||||
"key": "field_5bc86761aeafc",
|
||||
"label": "Unit",
|
||||
"name": "unit",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "wiaas_units",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 1,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
},
|
||||
{
|
||||
"key": "field_5bc867c3aeafd",
|
||||
"label": "Product category",
|
||||
"name": "category",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "product_cat",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 1,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
},
|
||||
{
|
||||
"key": "field_5bc8743b099a8",
|
||||
"label": "Template category",
|
||||
"name": "template_category",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "template_category",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 1,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "post_taxonomy",
|
||||
"operator": "==",
|
||||
"value": "product_type:simple"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "side",
|
||||
"style": "default",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -108,4 +108,22 @@ function _wiaas_import_field_group($json) {
|
||||
acf_import_field_group( $field_group );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_general_ui_fields() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-general.json' );
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
acf_import_field_group($ui_json[0]);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_product_properties_ui_fields() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-product-properties.json' );
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
acf_import_field_group($ui_json[0]);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ class Wiaas_Product_Supplier {
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'meta_box_cb' => false,
|
||||
'query_var' => true,
|
||||
'rewrite' => array('slug' => 'template_category'),
|
||||
);
|
||||
|
||||
@@ -41,6 +41,7 @@ class Wiaas_Template_Category {
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'meta_box_cb' => false,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'template_category' ),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements available wiaas countries
|
||||
*
|
||||
* Class Wiaas_Measurement_Units
|
||||
*/
|
||||
class Wiaas_Measurement_Units {
|
||||
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_measurement_units_taxonomy'));
|
||||
}
|
||||
|
||||
private static $available_units = array(
|
||||
'Piece' => array(
|
||||
'id' => 1,
|
||||
'name' => 'piece',
|
||||
'unit' => 'piece',
|
||||
),
|
||||
'Meter' => array(
|
||||
'id' => 1,
|
||||
'name' => 'meter',
|
||||
'unit' => 'm',
|
||||
),
|
||||
'Square' => array(
|
||||
'id' => 1,
|
||||
'name' => 'square_meter',
|
||||
'unit' => 'm2',
|
||||
),
|
||||
'Centimeter' => array(
|
||||
'id' => 1,
|
||||
'name' => 'centimeter',
|
||||
'unit' => 'cm',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Registers product taxonomy for avaiable countries
|
||||
*/
|
||||
public static function register_measurement_units_taxonomy() {
|
||||
|
||||
$labels = array(
|
||||
'name' => _x('Unit', 'taxonomy general name', 'wiaas'),
|
||||
'singular_name' => _x('Unit', 'taxonomy singular name', 'wiaas'),
|
||||
'menu_name' => _x('Unit', 'Admin menu name', 'wiaas'),
|
||||
'search_items' => __('Search Units', 'wiaas'),
|
||||
'all_items' => __('All Units', 'wiaas'),
|
||||
'parent_item' => __('Parent Unit', 'wiaas'),
|
||||
'parent_item_colon' => __('Parent Unit:', 'wiaas'),
|
||||
'edit_item' => __('Edit Unit', 'wiaas'),
|
||||
'update_item' => __('Update Unit', 'wiaas'),
|
||||
'add_new_item' => __('Add New Unit', 'wiaas'),
|
||||
'new_item_name' => __('New Unit Name', 'wiaas'),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'label' => __('Units', 'wiaas'),
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'meta_box_cb' => false,
|
||||
'query_var' => true,
|
||||
'rewrite' => array('slug' => 'wiaas_units'),
|
||||
);
|
||||
|
||||
register_taxonomy('wiaas_units', array('product'), $args);
|
||||
|
||||
foreach (self::$available_units as $available_unit) {
|
||||
if (!term_exists($available_unit, 'wiaas_units')) {
|
||||
wp_insert_term($available_unit['unit'], 'wiaas_units');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Measurement_Units::init();
|
||||
@@ -57,6 +57,8 @@ include_once WIAAS_DIR . '/includes/class-wiaas-api.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiass-templates.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/wiaas-class-measurement-units.php';
|
||||
|
||||
function wiaas_redirect_to_login() {
|
||||
wp_safe_redirect(get_site_url('', 'wp-login.php'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user