public function new_product()
 {
     if (!isset($_POST['title'])) {
         die;
     }
     check_ajax_referer('fpd_ajax_nonce', '_ajax_nonce');
     if (class_exists('Fancy_Product')) {
         $id = Fancy_Product::create($_POST['title']);
         header('Content-Type: application/json');
         echo json_encode(array('id' => $id, 'message' => $id ? __('Product successfully created!', 'radykal') : __('Product could not be created. Please try again!', 'radykal'), 'html' => FPD_Admin_Manage_Fancy_Products::get_product_item_html($id, $_POST['title'], '', '')));
     }
     die;
 }
Exemplo n.º 2
0
 public static function do_upgrade($to_version)
 {
     global $wpdb;
     if ($to_version === '1.1.3') {
         $wpdb->query("ALTER TABLE " . FPD_VIEWS_TABLE . " ADD view_order INT COLLATE utf8_general_ci NULL DEFAULT 0;");
     } else {
         if ($to_version === '2.0.0') {
             $views = $wpdb->get_results("SELECT * FROM " . FPD_VIEWS_TABLE . " GROUP BY product_id");
             foreach ($views as $view) {
                 //check if product exists, otherwise delete it from views table
                 if (get_post_status($view->product_id) === false) {
                     $wpdb->query($wpdb->prepare("DELETE FROM " . FPD_VIEWS_TABLE . " WHERE product_id=%d", $view->product_id));
                 } else {
                     $check_title = get_the_title($view->product_id);
                     if (!empty($check_title)) {
                         $product_id = Fancy_Product::create($check_title);
                         //create product
                         $fancy_product_settings = new FPD_Product_Settings($view->product_id);
                         //get stage dimensions and add them in the product options
                         $product_options = array();
                         if ($fancy_product_settings->get_individual_option('stage_width')) {
                             $product_options['stage_width'] = $fancy_product_settings->get_individual_option('stage_width');
                         }
                         if ($fancy_product_settings->get_individual_option('stage_height')) {
                             $product_options['stage_height'] = $fancy_product_settings->get_individual_option('stage_height');
                         }
                         $fancy_product = new Fancy_Product($product_id);
                         if (sizeof($product_options) !== 0) {
                             $fancy_product->update(null, json_encode($product_options));
                         }
                         //assign product to wc product
                         update_post_meta($view->product_id, 'fpd_source_type', 'product');
                         $product_array = array($product_id);
                         update_post_meta($view->product_id, 'fpd_products', $product_array);
                         //update product id of views
                         $wpdb->update(FPD_VIEWS_TABLE, array('product_id' => $product_id), array('product_id' => $view->product_id), array('%d'), array('%d'));
                     }
                 }
             }
             //add options to views table
             $wpdb->query("ALTER TABLE " . FPD_VIEWS_TABLE . " ADD options TEXT COLLATE utf8_general_ci NULL DEFAULT '';");
         }
     }
 }