public static function getModelSettings()
 {
     include WCAPIDIR . "/_globals.php";
     $table = array_merge(Base::getDefaultModelSettings(), array('model_conditions' => "WHERE post_type IN ('shop_order') AND post_status != 'trash'", 'has_many' => array('order_items' => array('class_name' => 'OrderItem', 'foreign_key' => 'order_id', 'conditions' => "order_item_type = 'line_item'"), 'tax_items' => array('class_name' => 'OrderTaxItem', 'foreign_key' => 'order_id', 'conditions' => "order_item_type = 'tax'"), 'coupon_items' => array('class_name' => 'OrderCouponItem', 'foreign_key' => 'order_id', 'conditions' => "order_item_type = 'coupon'"), 'notes' => array('class_name' => 'Comment', 'foreign_key' => 'comment_post_ID', 'conditions' => array("comment_type IN ('order_note')", "comment_approved != 'trash'")))));
     $table = apply_filters("WCAPI_order_model_settings", $table);
     return $table;
 }
 public static function getModelSettings()
 {
     include WCAPIDIR . "/_globals.php";
     $table = array_merge(Base::getDefaultModelSettings(), array('model_table' => $wpdb->prefix . 'woocommerce_order_items', 'meta_table' => $wpdb->prefix . 'woocommerce_order_itemmeta', 'model_table_id' => 'order_item_id', 'meta_table_foreign_key' => 'order_item_id', 'meta_function' => 'woocommerce_get_order_item_meta', 'belongs_to' => array('order' => array('class_name' => 'Order', 'foreign_key' => 'order_id'), 'product' => array('class_name' => 'Product', 'meta_attribute' => 'product_id'))));
     $table = apply_filters('WCAPI_order_item_model_settings', $table);
     return $table;
 }
 public static function getModelSettings()
 {
     include WCAPIDIR . "/_globals.php";
     $table = array_merge(Base::getDefaultModelSettings(), array('model_table' => $wpdb->comments, 'meta_table' => $wpdb->commentmeta, 'model_table_id' => 'comment_ID', 'meta_table_foreign_key' => 'comment_id', 'meta_function' => 'get_comment_meta', 'update_meta_function' => 'update_comment_meta', 'belongs_to' => array('order' => array('class_name' => 'Order', 'foreign_key' => 'comment_post_ID'))));
     $table = apply_filters('WCAPI_comment_model_settings', $table);
     return $table;
 }
 public static function getModelSettings()
 {
     include WCAPIDIR . "/_globals.php";
     $table = array_merge(Base::getDefaultModelSettings(), array('model_table' => $wpdb->posts, 'meta_table' => $wpdb->postmeta, 'model_table_id' => 'id', 'meta_table_foreign_key' => 'post_id', 'model_conditions' => "WHERE post_type IN ('attachment') AND post_status NOT IN ('trash','auto-draft')"));
     $table = apply_filters('WCAPI_image_model_settings', $table);
     return $table;
 }
 public static function getModelSettings()
 {
     include WCAPIDIR . "/_globals.php";
     $table = array_merge(Base::getDefaultModelSettings(), array('model_table' => $wpdb->posts, 'meta_table' => $wpdb->postmeta, 'model_table_id' => 'id', 'meta_table_foreign_key' => 'post_id', 'model_conditions' => "WHERE post_type IN ('shop_coupon') AND post_status NOT IN ('trash','auto-draft')", 'has_many' => array('order_items' => array('class_name' => 'OrderItem', 'foreign_key' => 'order_id'), 'categories' => array('class_name' => 'Category', 'foreign_key' => '', 'sql' => "SELECT t.term_id FROM \n                {$wpdb->terms} AS t, \n                {$wpdb->term_taxonomy} AS tt, \n                {$wpdb->term_relationships} AS tr \n              WHERE\n                tr.object_id = %s AND\n                tt.term_taxonomy_id = tr.term_taxonomy_id AND\n                tt.taxonomy = 'product_cat' AND\n                t.term_id = tt.term_id\n              ", 'connect' => function ($product, $category) {
         include WCAPIDIR . "/_globals.php";
         $product->insert($wpdb->term_relationships, array('object_id' => $product->_actual_model_id, 'term_taxonomy_id' => $category->taxonomy_id));
     }), 'tags' => array('class_name' => 'Category', 'foreign_key' => '', 'sql' => "SELECT t.term_id FROM \n                {$wpdb->terms} AS t, \n                {$wpdb->term_taxonomy} AS tt, \n                {$wpdb->term_relationships} AS tr \n              WHERE\n                tr.object_id = %s AND\n                tt.term_taxonomy_id = tr.term_taxonomy_id AND\n                tt.taxonomy = 'product_tag' AND\n                t.term_id = tt.term_id\n              ", 'connect' => function ($product, $tag) {
         include WCAPIDIR . "/_globals.php";
         $product->insert($wpdb->term_relationships, array('object_id' => $product->_actual_model_id, 'term_taxonomy_id' => $tag->taxonomy_id));
     }))));
     $table = apply_filters('WCAPI_coupon_model_settings', $table);
     return $table;
 }
 public static function getModelSettings()
 {
     include WCAPIDIR . "/_globals.php";
     $table = array_merge(Base::getDefaultModelSettings(), array('model_table' => $wpdb->posts, 'meta_table' => $wpdb->postmeta, 'model_table_id' => 'id', 'meta_table_foreign_key' => 'post_id', 'model_conditions' => "WHERE post_type IN ('product','product_variation') AND post_status NOT IN ('trash','auto-draft')", 'has_many' => array('order_items' => array('class_name' => 'OrderItem', 'foreign_key' => 'order_id'), 'categories' => array('class_name' => 'Category', 'foreign_key' => '', 'sql' => "SELECT t.term_id FROM \n                {$wpdb->terms} AS t, \n                {$wpdb->term_taxonomy} AS tt, \n                {$wpdb->term_relationships} AS tr \n              WHERE\n                tr.object_id = %s AND\n                tt.term_taxonomy_id = tr.term_taxonomy_id AND\n                tt.taxonomy = 'product_cat' AND\n                t.term_id = tt.term_id\n              ", 'connect' => function ($product, $category) {
         $product->connectToCategory($category);
     }, 'disconnect' => function ($product, $category) {
         $product->disconnectFromCategory($category);
     }), 'tags' => array('class_name' => 'Category', 'foreign_key' => '', 'sql' => "SELECT t.term_id FROM \n                {$wpdb->terms} AS t, \n                {$wpdb->term_taxonomy} AS tt, \n                {$wpdb->term_relationships} AS tr \n              WHERE\n                tr.object_id = %s AND\n                tt.term_taxonomy_id = tr.term_taxonomy_id AND\n                tt.taxonomy = 'product_tag' AND\n                t.term_id = tt.term_id\n              ", 'connect' => function ($product, $tag) {
         $product->connectToCategory($tag);
     }, 'disconnect' => function ($product, $tag) {
         $product->disconnectFromCategory($tag);
     }), 'reviews' => array('class_name' => 'Review', 'foreign_key' => 'comment_post_ID', 'conditions' => array("comment_approved != 'trash'")), 'images' => array('class_name' => 'Image', 'sql' => function ($product) {
         $product_gallery = get_post_meta($product->_actual_model_id, "_product_image_gallery", true);
         if (empty($product_gallery)) {
             return null;
         }
         $img = new Image();
         $s = $img->getModelSettings();
         $sql = "SELECT {$s['model_table_id']} FROM {$s['model_table']} WHERE  {$s['model_table_id']} IN ({$product_gallery})";
         return $sql;
     }, 'connect' => function ($product, $image) {
         $product->connectToImage($image);
     }, 'disconnect' => function ($product, $image) {
         $product->disconnectFromImage($image);
     }), 'featured_image' => array('class_name' => 'Image', 'foreign_key' => 'post_parent', 'sql' => function ($model) {
         $s = $model->getModelSettings();
         $tid = get_post_thumbnail_id($model->_actual_model_id);
         if (empty($tid)) {
             return false;
         }
         $parts = array("post_type = 'attachment'", "post_mime_type IN ('image/jpeg','image/png','image/gif')", "ID = {$tid}");
         return "SELECT {$s['model_table_id']} FROM {$s['model_table']} WHERE " . join(' AND ', $parts);
     }, 'connect' => function ($product, $image) {
         update_post_meta($product->_actual_model_id, '_thumbnail_id', $image->_actual_model_id);
         // Don't need to do this...hrmm
     }), 'variations' => array('class_name' => 'Product', 'foreign_key' => 'post_parent', 'conditions' => array("post_type = 'product_variation'")))));
     $table = apply_filters('WCAPI_product_model_settings', $table);
     return $table;
 }