Example #1
0
 /**
  * @param $id int Order ID.
  *
  * @return array List of items assigned to the order.
  */
 private function getItems($id)
 {
     $wpdb = $this->wp->getWPDB();
     $query = $wpdb->prepare("\n\t\t\tSELECT * FROM {$wpdb->prefix}jigoshop_order_item joi\n\t\t\tLEFT JOIN {$wpdb->prefix}jigoshop_order_item_meta joim ON joim.item_id = joi.id\n\t\t\tWHERE joi.order_id = %d\n\t\t\tORDER BY joi.id", array($id));
     $results = $wpdb->get_results($query, ARRAY_A);
     $items = array();
     for ($i = 0, $endI = count($results); $i < $endI;) {
         $id = $results[$i]['id'];
         $product = $this->productService->find($results[$i]['product_id']);
         $item = new Entity\Item();
         $item->setId($results[$i]['item_id']);
         $item->setName($results[$i]['title']);
         $item->setQuantity($results[$i]['quantity']);
         $item->setPrice($results[$i]['price']);
         $item->setTax($results[$i]['tax']);
         while ($i < $endI && $results[$i]['id'] == $id) {
             //				Securing against empty meta's, but still no piece of code does not add the meta.
             if ($results[$i]['meta_key']) {
                 $meta = new Entity\Item\Meta();
                 $meta->setKey($results[$i]['meta_key']);
                 $meta->setValue($results[$i]['meta_value']);
                 $item->addMeta($meta);
             }
             $i++;
         }
         $product = $this->wp->applyFilters('jigoshop\\factory\\order\\find_product', $product, $item);
         $item->setProduct($product);
         $item->setKey($this->productService->generateItemKey($item));
         $items[] = $item;
     }
     return $items;
 }
Example #2
0
 public function addToCart($value, $product)
 {
     if ($product instanceof Product\Variable) {
         $item = new Item();
         $item->setProduct($product);
         $variation = $this->factory->getVariation($product, $_POST['variation_id']);
         foreach ($variation->getAttributes() as $attribute) {
             /** @var $attribute \Jigoshop\Entity\Product\Variable\Attribute */
             if ($attribute->getValue() === '') {
                 $meta = new Item\Meta();
                 $metaValue = isset($_POST['attributes']) ? $_POST['attributes'][$attribute->getAttribute()->getId()] : 'any';
                 $meta->setKey($attribute->getAttribute()->getSlug());
                 $meta->setValue($metaValue);
                 $item->addMeta($meta);
                 $attribute->setValue($metaValue);
             }
         }
         $item->setName($variation->getTitle());
         $item->setPrice($variation->getProduct()->getPrice());
         $item->setQuantity($_POST['quantity']);
         $item->setTaxClasses($variation->getProduct()->getTaxClasses());
         $meta = new Item\Meta();
         $meta->setKey('variation_id');
         $meta->setValue($variation->getId());
         $item->addMeta($meta);
         return $item;
     }
     return $value;
 }