public function toWPBool($b)
 {
     if ($b == 1 || $b === 'yes') {
         $ret = 'yes';
     } else {
         $ret = 'no';
     }
     Helpers::debug("toWpBool b:{$b} ret:{$ret}");
     return $ret;
 }
 public function updateStatus($to, $desc)
 {
     // $order = new \WC_Order( $this->_actual_model_id );
     // $order->update_status( $to );
     // Right now, we don't want the overhead of the WooCom
     // events that are triggered with a status update.
     Helpers::debug("Order::updateStatus to " . var_export($to, true));
     $order = new \WC_Order($this->_actual_model_id);
     Helpers::debug("Using WOOCOM to update status");
     $order->update_status($to);
     //$this->updateTerm('status','shop_order_status',$to);
 }
 public function create($attrs = NULL)
 {
     Helpers::debug("Image::create() was called");
     include WCAPIDIR . "/_globals.php";
     include WCAPIDIR . "/_model_static_attributes.php";
     $name = $attrs['name'];
     if (isset($_FILES['images'])) {
         foreach ($_FILES["images"]["error"] as $key => $error) {
             if ($error == UPLOAD_ERR_OK) {
                 $fname = basename($_FILES["images"]["name"][$key]);
                 if ($fname == $name) {
                     $upload = new Upload($_FILES["images"]["tmp_name"][$key], $_FILES["images"]["name"][$key], $_FILES["images"]["error"][$key], $_FILES["images"]["size"][$key]);
                     $id = $upload->saveMediaAttachment();
                     $record = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$self->settings['model_table']} WHERE {$self->settings['model_table_id']} = %d", (int) $id), 'ARRAY_A');
                     if ($record) {
                         $this->fromDatabaseResult($record);
                         $this->setNewRecord(true);
                         // i.e. we want to know if models were created in this request.
                         Helpers::debug("Set attrs from record: " . var_export($record, true));
                     } else {
                         Helpers::debug("Did not get record! setting valid to false");
                         $this->setValid(false);
                     }
                     return $this;
                 }
             }
         }
         // end foreach
         // We shouldn't get this far if we did it right...
         Helpers::debug("Image::create: throwing exception No entry for %s found in uploaded files!");
         throw new \Exception(sprintf(__('No entry for %s found in uploaded files!', $this->td), $name));
     } else {
         Helpers::debug("Image::create: throwing exception You cannot create a new image unless you upload an image with the same name as %s");
         Helpers::debug(var_export($_FILES, true));
         throw new \Exception(sprintf(__('You cannot create a new image unless you upload an image with the same name as %s', $this->td), $name));
     }
 }
示例#4
0
 public function updateTerm($name, $type, $value = null)
 {
     Helpers::debug("Base::updateTerm {$name} {$type} {$value}");
     if ($value == null) {
         $value = $this->{"_{$name}"};
     }
     Helpers::debug("Calling wp_set_object_terms( {$this->_actual_model_id}, array('{$value}'), {$type}, false );");
     $ret = wp_set_object_terms($this->_actual_model_id, array($value), $type, false);
     Helpers::debug("Call to wp_set_object_terms returned " . var_export($ret, true));
     $tmp_term = $this->getTerm($name, $type, 'no, it wasnt set');
     Helpers::debug("Did we really set it? " . var_export($tmp_term, true));
     if (is_wp_error($ret)) {
         throw new \Exception($ret->get_messages());
     } else {
         if (is_string($ret)) {
             throw new \Exception("Wrong term name {$ret}");
         }
     }
 }
 public function disconnectFromImage($image)
 {
     $product = $this;
     include WCAPIDIR . "/_globals.php";
     Helpers::debug("Product::image::connect");
     $ms = $image->getModelSettings();
     $product_gallery = get_post_meta($product->_actual_model_id, "_product_image_gallery", true);
     Helpers::debug("product_gallery as fetched from meta: {$product_gallery}");
     if (empty($product_gallery)) {
         Helpers::debug("product_gallery is empty!");
         $product_gallery = array();
     } else {
         if (!strpos(',', $product_gallery) == false) {
             Helpers::debug("product_gallery contains  a comma!");
             $product_gallery = explode(',', $product_gallery);
         } else {
             Helpers::debug("product_gallery is empty!");
             $product_gallery = array($product_gallery);
         }
     }
     Helpers::debug("Product Gallery is: " . var_export($product_gallery, true));
     if (!in_array($image->_actual_model_id, $product_gallery)) {
         Helpers::debug("id {$image->_actual_model_id} is not in " . join(",", $product_gallery));
     } else {
         Helpers::debug("id {$image->_actual_model_id} is not in " . join(",", $product_gallery));
         $new_gallery = array();
         foreach ($product_gallery as $g) {
             if ($g == $image->_actual_model_id) {
                 continue;
             }
             $new_gallery[] = $g;
         }
         $product_gallery = $new_gallery;
         Helpers::debug("Updating {$product->_actual_model_id}'s' _product_image_gallery to {$product_gallery}");
         update_post_meta($product->_actual_model_id, '_product_image_gallery', $product_gallery);
     }
 }
 public function getProperName()
 {
     $wp_filetype = wp_check_filetype_and_ext($this->tmp_name, $this->name, $this->allowed_mimes);
     extract($wp_filetype);
     // Check to see if wp_check_filetype_and_ext() determined the filename was incorrect
     if ($proper_filename) {
         Helpers::debug(" Returning proper name: {$proper_filename}");
         return $proper_fillename;
     }
     Helpers::debug(" Returning name {$this->name} ");
     return $this->name;
 }