Example #1
0
/**
 * shopp_product_variant_set_type - set the type of a product/variant/addon
 *
 * @api
 * @since 1.2
 *
 * @param int/Price $variant (required) The priceline id to set the type on, or the Price object to change.  If Price object is specified, the object will be returned, but not saved to the database.
 * @param string $type (optional default:N/A) The product price type, ex Shipped, Download, Virtual, Subscription.  N/A is a disabled priceline.
 * @param string $context (optional default:variant) enforces the priceline is a 'product','variant', or 'addon'
 * @return bool/Price false on failure, true if Price saved, else the modified Price object.
 **/
function shopp_product_variant_set_type($variant = false, $type = 'N/A', $context = 'variant')
{
    $context = 'variant' == $context ? 'variation' : $context;
    $save = true;
    if (is_object($variant) && is_a($variant, 'ShoppPrice')) {
        $Price = $variant;
        $save = false;
    } else {
        if (false == $variant) {
            shopp_debug(__FUNCTION__ . " failed: Variant id required.");
            return false;
        }
        $Price = new ShoppPrice($variant);
        if (empty($Price->id) || $Price->context != $context) {
            shopp_debug(__FUNCTION__ . " failed: No such {$context} with id {$variant}.");
        }
    }
    $types = array();
    foreach (ShoppPrice::types() as $t) {
        $types[] = $t['value'];
    }
    if (!in_array($type, $types)) {
        shopp_debug(__FUNCTION__ . " failed: Invalid type {$type}.");
        return false;
    }
    $Price->type = $type;
    if ($save) {
        return $Price->save();
    }
    return $Price;
}
Example #2
0
 /**
  * Interface processor for the product editor
  *
  * @author Jonathan Davis
  * @return void
  **/
 public function editor()
 {
     $Shopp = Shopp::object();
     if (!current_user_can('shopp_products')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     if (empty($Shopp->Product)) {
         $Product = new ShoppProduct();
         $Product->status = "publish";
     } else {
         $Product = $Shopp->Product;
     }
     $Product->slug = apply_filters('editable_slug', $Product->slug);
     $permalink = trailingslashit(Shopp::url());
     $Price = new ShoppPrice();
     $priceTypes = ShoppPrice::types();
     $billPeriods = ShoppPrice::periods();
     $workflows = array('continue' => Shopp::__('Continue Editing'), 'close' => Shopp::__('Products Manager'), 'new' => Shopp::__('New Product'), 'next' => Shopp::__('Edit Next'), 'previous' => Shopp::__('Edit Previous'));
     $taglist = array();
     foreach ($Product->tags as $tag) {
         $taglist[] = $tag->name;
     }
     if ($Product->id && !empty($Product->images)) {
         $ids = join(',', array_keys($Product->images));
         $CoverImage = reset($Product->images);
         $image_table = $CoverImage->_table;
         $Product->cropped = sDB::query("SELECT * FROM {$image_table} WHERE context='image' AND type='image' AND '2'=SUBSTRING_INDEX(SUBSTRING_INDEX(name,'_',4),'_',-1) AND parent IN ({$ids})", 'array', 'index', 'parent');
     }
     $shiprates = shopp_setting('shipping_rates');
     if (!empty($shiprates)) {
         ksort($shiprates);
     }
     $uploader = shopp_setting('uploader_pref');
     if (!$uploader) {
         $uploader = 'flash';
     }
     $process = empty($Product->id) ? 'new' : $Product->id;
     $_POST['action'] = add_query_arg(array_merge($_GET, array('page' => $this->Admin->pagename('products'))), admin_url('admin.php'));
     $post_type = ShoppProduct::posttype();
     // Re-index menu options to maintain order in JS #2930
     if (isset($Product->options['v']) || isset($Product->options['a'])) {
         $options = array_keys($Product->options);
         foreach ($options as $type) {
             foreach ($Product->options[$type] as $id => $menu) {
                 $Product->options[$type][$type . $id] = $menu;
                 $Product->options[$type][$type . $id]['options'] = array_values($menu['options']);
                 unset($Product->options[$type][$id]);
             }
         }
     } else {
         foreach ($Product->options as &$menu) {
             $menu['options'] = array_values($menu['options']);
         }
     }
     do_action('add_meta_boxes', ShoppProduct::$posttype, $Product);
     do_action('add_meta_boxes_' . ShoppProduct::$posttype, $Product);
     do_action('do_meta_boxes', ShoppProduct::$posttype, 'normal', $Product);
     do_action('do_meta_boxes', ShoppProduct::$posttype, 'advanced', $Product);
     do_action('do_meta_boxes', ShoppProduct::$posttype, 'side', $Product);
     include $this->ui('editor.php');
 }
Example #3
0
 /**
  * Interface processor for the category editor
  *
  * @author Jonathan Davis
  * @since 1.0
  * @return void
  **/
 public function screen()
 {
     global $CategoryImages;
     $Shopp = Shopp::object();
     if (!current_user_can('shopp_categories')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $Category = $this->Model;
     $Price = new ShoppPrice();
     $priceTypes = ShoppPrice::types();
     $billPeriods = ShoppPrice::periods();
     // Build permalink for slug editor
     $permalink = trailingslashit(Shopp::url()) . "category/";
     $Category->slug = apply_filters('editable_slug', $Category->slug);
     $pricerange_menu = array("disabled" => __('Price ranges disabled', 'Shopp'), "auto" => __('Build price ranges automatically', 'Shopp'), "custom" => __('Use custom price ranges', 'Shopp'));
     $uploader = shopp_setting('uploader_pref');
     if (!$uploader) {
         $uploader = 'flash';
     }
     $workflows = array("continue" => __('Continue Editing', 'Shopp'), "close" => __('Categories Manager', 'Shopp'), "new" => __('New Category', 'Shopp'), "next" => __('Edit Next', 'Shopp'), "previous" => __('Edit Previous', 'Shopp'));
     do_action('add_meta_boxes', ProductCategory::$taxon, $Category);
     do_action('add_meta_boxes_' . ProductCategory::$taxon, $Category);
     do_action('do_meta_boxes', ProductCategory::$taxon, 'normal', $Category);
     do_action('do_meta_boxes', ProductCategory::$taxon, 'advanced', $Category);
     do_action('do_meta_boxes', ProductCategory::$taxon, 'side', $Category);
     include $this->ui('category.php');
 }