|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Product Data Store |
| 4 | + * Inventory with pass-thru |
| 5 | + * |
| 6 | + * @package WooCommerce Product Inventory Data Store |
| 7 | + * @author Automattic |
| 8 | + */ |
| 9 | +if ( ! defined( 'ABSPATH' ) ) { |
| 10 | + return; |
| 11 | +} |
| 12 | +/** |
| 13 | + * WC_Product_Inventory_Datastore. |
| 14 | + */ |
| 15 | +class WC_Product_Inventory_Data_Store |
| 16 | + implements WC_Object_Data_Store_Interface, WC_Product_Data_Store_Interface { |
| 17 | + |
| 18 | + public function __construct( &$parent_data_store ) { |
| 19 | + $this->parent_instance = $this->create_parent_instance( $parent_data_store ); |
| 20 | + } |
| 21 | + |
| 22 | + private function create_parent_instance( $store ) { |
| 23 | + if ( is_object( $store ) ) { |
| 24 | + if ( ! $store instanceof WC_Object_Data_Store_Interface || |
| 25 | + ! $store instanceof WC_Product_Data_Store_Interface ) { |
| 26 | + throw new Exception( __( 'Invalid parent product data store.', 'woocommerce' ) ); |
| 27 | + } |
| 28 | + return $store; |
| 29 | + } else { |
| 30 | + if ( ! class_exists( $store ) ) { |
| 31 | + throw new Exception( __( 'Invalid parent product data store.', 'woocommerce' ) ); |
| 32 | + } |
| 33 | + return new $store; |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + public function create( &$product ) { |
| 38 | + error_log( 'create' ); |
| 39 | + $this->parent_instance->create( $product ); |
| 40 | + } |
| 41 | + |
| 42 | + public function read( &$product ) { |
| 43 | + error_log( 'read' ); |
| 44 | + $this->parent_instance->read( $product ); |
| 45 | + |
| 46 | + //$product->set_stock_quantity( 20 ); |
| 47 | + |
| 48 | + $inventory_url = 'http://192.168.200.200:8080/api/inventory/' . $product->get_sku(); |
| 49 | + $request = wp_remote_get( $inventory_url ); |
| 50 | + $response = wp_remote_retrieve_body( $request ); |
| 51 | + $data = json_decode( $response ); |
| 52 | + $product->set_stock_quantity( $data ); |
| 53 | + } |
| 54 | + |
| 55 | + public function update( &$product ) { |
| 56 | + error_log( 'update' ); |
| 57 | + $this->parent_instance->update( $product ); |
| 58 | + } |
| 59 | + |
| 60 | + public function delete( &$product, $args = array() ) { |
| 61 | + error_log( 'delete' ); |
| 62 | + $this->parent_instance->delete( $product, $args ); |
| 63 | + } |
| 64 | + |
| 65 | + public function read_meta( &$product ) { |
| 66 | + error_log( 'read_meta' ); |
| 67 | + $this->parent_instance->read_meta( $product ); |
| 68 | + } |
| 69 | + |
| 70 | + public function delete_meta( &$product, $meta ) { |
| 71 | + error_log( 'delete_meta' ); |
| 72 | + $this->parent_instance->delete_meta( $product, $meta ); |
| 73 | + } |
| 74 | + |
| 75 | + public function add_meta( &$product, $meta ) { |
| 76 | + error_log( 'add_meta' ); |
| 77 | + $this->parent_instance->add_meta( $product, $meta ); |
| 78 | + } |
| 79 | + |
| 80 | + public function update_meta( &$product, $meta ) { |
| 81 | + error_log( 'update_meta' ); |
| 82 | + $this->parent_instance->update_meta( $product, $meta ); |
| 83 | + } |
| 84 | + |
| 85 | + public function get_on_sale_products() { |
| 86 | + error_log( 'get_on_sale_products' ); |
| 87 | + return $this->parent_instance->get_on_sale_products(); |
| 88 | + } |
| 89 | + |
| 90 | + public function get_featured_product_ids() { |
| 91 | + error_log( 'get_featured_product_ids' ); |
| 92 | + return $this->parent_instance->get_featured_product_ids(); |
| 93 | + } |
| 94 | + |
| 95 | + public function is_existing_sku( $product_id, $sku ) { |
| 96 | + error_log( 'is_existing_sku' ); |
| 97 | + return $this->parent_instance->is_existing_sku( $product_id, $sku ); |
| 98 | + } |
| 99 | + |
| 100 | + public function get_product_id_by_sku( $sku ) { |
| 101 | + error_log( 'get_product_id_by_sku' ); |
| 102 | + return $this->parent_instance->get_product_id_by_sku(); |
| 103 | + } |
| 104 | + |
| 105 | + public function get_starting_sales() { |
| 106 | + error_log( 'get_starting_sales' ); |
| 107 | + return $this->parent_instance->get_starting_sales(); |
| 108 | + } |
| 109 | + |
| 110 | + public function get_ending_sales() { |
| 111 | + error_log( 'get_ending_sales' ); |
| 112 | + return $this->parent_instance->get_ending_sales(); |
| 113 | + } |
| 114 | + |
| 115 | + public function find_matching_product_variation( $product, $match_attributes = array() ) { |
| 116 | + error_log( 'find_matching_product_variation' ); |
| 117 | + return $this->parent_instance->find_matching_product_variation( $product, $match_attributes ); |
| 118 | + } |
| 119 | + |
| 120 | + public function sort_all_product_variations( $parent_id ) { |
| 121 | + error_log( 'sort_all_product_variations' ); |
| 122 | + $this->parent_instance->sort_all_product_variations( $parent_id ); |
| 123 | + } |
| 124 | + |
| 125 | + public function get_related_products( $cats_array, $tags_array, $exclude_ids, $limit, $product_id ) { |
| 126 | + error_log( 'get_related_products' ); |
| 127 | + return $this->parent_instance->get_related_products( $cats_array, $tags_array, $exclude_ids, $limit, $product_id ); |
| 128 | + } |
| 129 | + |
| 130 | + public function update_product_stock( $product_id_with_stock, $stock_quantity = null, $operation = 'set' ) { |
| 131 | + error_log( 'update_product_stock' ); |
| 132 | + $this->parent_instance->update_product_stock( $product_id_with_stock, $stock_quantity, $operation ); |
| 133 | + } |
| 134 | + |
| 135 | + public function update_product_sales( $product_id, $quantity = null, $operation = 'set' ) { |
| 136 | + error_log( 'update_product_sales' ); |
| 137 | + $this->parent_instance->update_product_sales( $product_id, $quantity, $operation ); |
| 138 | + } |
| 139 | + |
| 140 | + public function get_shipping_class_id_by_slug( $slug ) { |
| 141 | + error_log( 'get_shipping_class_id_by_slug' ); |
| 142 | + return $this->parent_instance->get_shipping_class_id_by_slug( $slug ); |
| 143 | + } |
| 144 | + |
| 145 | + public function get_products( $args = array() ) { |
| 146 | + error_log( 'get_products' ); |
| 147 | + return $this->parent_instance->get_products( $args ); |
| 148 | + } |
| 149 | + |
| 150 | + public function get_product_type( $product_id ) { |
| 151 | + error_log( 'get_product_type' ); |
| 152 | + return $this->parent_instance->get_product_type( $product_id ); |
| 153 | + } |
| 154 | +} |
0 commit comments