public function __construct(Wordpress $wp, Options $options, ProductServiceInterface $productService, CartServiceInterface $cartService, Messages $messages) { $this->wp = $wp; $this->options = $options; $this->productService = $productService; $this->cartService = $cartService; $this->messages = $messages; Styles::add('jigoshop.vendors.colorbox', \JigoshopInit::getUrl() . '/assets/css/vendors/colorbox.css'); Styles::add('jigoshop.vendors.select2', \JigoshopInit::getUrl() . '/assets/css/vendors/select2.css'); Styles::add('jigoshop.shop.product', \JigoshopInit::getUrl() . '/assets/css/shop/product.css', array('jigoshop.shop', 'jigoshop.vendors.select2', 'jigoshop.vendors.colorbox')); if ($this->options->get('products.related')) { Styles::add('jigoshop.shop.related_products', \JigoshopInit::getUrl() . '/assets/css/shop/related_products.css', array('jigoshop.shop')); } Scripts::add('jigoshop.vendors.select2', \JigoshopInit::getUrl() . '/assets/js/vendors/select2.js', array('jquery')); Scripts::add('jigoshop.vendors.colorbox', \JigoshopInit::getUrl() . '/assets/js/vendors/colorbox.js', array('jquery')); Scripts::add('jigoshop.vendors.bs_tab_trans_tooltip_collapse', \JigoshopInit::getUrl() . '/assets/js/vendors/bs_tab_trans_tooltip_collapse.js', array('jquery')); Scripts::add('jigoshop.shop.product', \JigoshopInit::getUrl() . '/assets/js/shop/product.js', array('jquery', 'jigoshop.shop', 'jigoshop.vendors.select2', 'jigoshop.vendors.colorbox', 'jigoshop.vendors.bs_tab_trans_tooltip_collapse')); $wp->addFilter('jigoshop\\cart\\add', function ($item) use($productService) { /** @var $item Item */ if ($item instanceof Item) { $item->setKey($productService->generateItemKey($item)); } return $item; }); $wp->addAction('jigoshop\\template\\product\\before_summary', array($this, 'productImages'), 10, 1); $wp->addAction('jigoshop\\template\\product\\after_summary', array($this, 'productTabs'), 10, 1); if ($this->options->get('products.related')) { $wp->addAction('jigoshop\\template\\product\\after_summary', array($this, 'relatedProducts'), 20, 1); } $wp->addAction('jigoshop\\template\\product\\tab_panels', array($this, 'productDescription'), 10, 2); $wp->addAction('jigoshop\\template\\product\\tab_panels', array($this, 'productAttributes'), 15, 2); $wp->addAction('jigoshop\\template\\product\\tab_panels', array($this, 'productDownloads'), 20, 2); $wp->doAction('jigoshop\\product\\assets', $wp); }
/** * @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; }
/** * Dummy constructor. * @param Wordpress $wp * @param Options $options * @param ProductServiceInterface $productService * @param CartServiceInterface $cartService * @param Messages $messages */ public function __construct(Wordpress $wp, Options $options, ProductServiceInterface $productService, CartServiceInterface $cartService, Messages $messages) { $this->wp = $wp; $this->options = $options; $this->productService = $productService; $this->cartService = $cartService; $this->messages = $messages; $wp->addFilter('jigoshop\\cart\\add', function ($item) use($productService) { /** @var $item Item */ $item->setKey($productService->generateItemKey($item)); return $item; }); }
public function __construct(Wordpress $wp, Options $options, ProductServiceInterface $productService, CartServiceInterface $cartService, Messages $messages) { $this->wp = $wp; $this->options = $options; $this->productService = $productService; $this->cartService = $cartService; $this->messages = $messages; $wp->addFilter('jigoshop\\cart\\add', function ($item) use($productService) { /** @var $item Item */ $item->setKey($productService->generateItemKey($item)); return $item; }); Styles::add('jigoshop.shop.list', \JigoshopInit::getUrl() . '/assets/css/shop/list.css', array('jigoshop.shop')); Styles::add('jigoshop.vendors.select2', \JigoshopInit::getUrl() . '/assets/css/vendors/select2.css', array('jigoshop.shop')); Scripts::add('jigoshop.shop'); }
public function ajaxAddProduct() { try { /** @var \Jigoshop\Entity\Order $order */ $order = $this->orderService->find((int) $_POST['order']); if ($order->getId() === null) { throw new Exception(__('Order not found.', 'jigoshop')); } /** @var ProductEntity|ProductEntity\Purchasable $product */ $post = $this->wp->getPost((int) $_POST['product']); if ($post->post_type == 'product_variation' && $post->post_parent > 0) { $post = $this->wp->getPost($post->post_parent); //TODO: change this!!! $_POST['variation_id'] = (int) $_POST['product']; $_POST['quantity'] = 1; } /** @var Product\* $product */ $product = $this->productService->findforPost($post); if ($product->getId() === null) { throw new Exception(__('Product not found.', 'jigoshop')); } /** @var Item $item */ $item = $this->wp->applyFilters('jigoshop\\cart\\add', null, $product); if ($item === null) { throw new Exception(__('Product cannot be added to the order.', 'jigoshop')); } $key = $this->productService->generateItemKey($item); $item->setKey($key); $order->addItem($item); $this->orderService->save($order); $row = Render::get('admin/order/item/' . $item->getType(), array('item' => $item)); $result = $this->getAjaxResponse($order); $result['html']['row'] = $row; } catch (Exception $e) { $result = array('success' => false, 'error' => $e->getMessage()); } echo json_encode($result); exit; }
/** * Returns unique key for product in the cart. * * @param $item Item Item to get key for. * @return string */ public function generateItemKey(Item $item) { return $this->service->generateItemKey($item); }