Example #1
0
 /**
  * Filter products by category, uses slugs for option values.
  * Props to: Andrew Benbow - chromeorange.co.uk
  */
 public function categoryFilter()
 {
     $type = $this->wp->getTypeNow();
     if ($type != Types::PRODUCT) {
         return;
     }
     $query = array('pad_counts' => 1, 'hierarchical' => true, 'hide_empty' => true, 'show_count' => true, 'selected' => $this->wp->getQueryParameter(Types::PRODUCT_CATEGORY));
     $terms = $this->wp->getTerms(Types::PRODUCT_CATEGORY, $query);
     if (!$terms) {
         return;
     }
     $current = isset($_GET[Types::PRODUCT_CATEGORY]) ? $_GET[Types::PRODUCT_CATEGORY] : '';
     $walker = new \Jigoshop\Web\CategoryWalker($this->wp, 'admin/products/categoryFilter/item');
     Render::output('admin/products/categoryFilter', array('terms' => $terms, 'current' => $current, 'walker' => $walker, 'query' => $query));
 }
Example #2
0
 /**
  * Creates new product properly based on POST variable data.
  *
  * @param $id int Post ID to create object for.
  *
  * @return \Jigoshop\Entity\Product
  */
 public function create($id)
 {
     $type = isset($_POST['product']['type']) ? $_POST['product']['type'] : Simple::TYPE;
     $product = $this->get($type);
     $product->setId($id);
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $product;
     }
     if (!empty($_POST)) {
         $helpers = $this->wp->getHelpers();
         $product->setName($helpers->sanitizeTitle($_POST['post_title']));
         $product->setDescription($helpers->parsePostBody($_POST['post_excerpt']));
         $_POST['product']['categories'] = $this->getTerms($id, Types::PRODUCT_CATEGORY, $this->wp->getTerms(Types::PRODUCT_CATEGORY, array('posts__in' => $_POST['tax_input']['product_category'])));
         $_POST['product']['tags'] = $this->getTerms($id, Types::PRODUCT_TAG, $this->wp->getTerms(Types::PRODUCT_TAG, array('posts__in' => $_POST['tax_input']['product_tag'])));
         if (!isset($_POST['product']['tax_classes'])) {
             $_POST['product']['tax_classes'] = array();
         }
         if (isset($_POST['product']['attributes'])) {
             $_POST['product']['attribute_order'] = array_keys($_POST['product']['attributes']);
             unset($_POST['product']['attributes']);
         }
         if (isset($_POST['product']['stock_manage'])) {
             $_POST['product']['stock_manage'] = $_POST['product']['stock_manage'] == 'on';
         }
         if (isset($_POST['product']['sales_enabled'])) {
             $_POST['product']['sales_enabled'] = $_POST['product']['sales_enabled'] == 'on';
         }
         if (isset($_POST['product']['attachments'])) {
             $temp = $_POST['product']['attachments'];
             $_POST['product']['attachments'] = array();
             foreach ($temp as $type => $ids) {
                 for ($i = 0; $i < sizeof($ids); $i++) {
                     $_POST['product']['attachments'][] = array('id' => $ids[$i], 'type' => $type);
                 }
             }
         }
         $product->restoreState($_POST['product']);
         $product->markAsDirty($_POST['product']);
     }
     return $product;
 }