Exemple #1
0
 /**
  * Displays the widget in the sidebar.
  *
  * @param array $args     Sidebar arguments.
  * @param array $instance The instance.
  *
  * @return bool|void
  */
 public function widget($args, $instance)
 {
     if (!Pages::isProductList()) {
         return;
     }
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Filter by Price', 'jigoshop'), $instance, $this->id_base);
     $fields = apply_filters('jigoshop\\get_fields', array());
     Render::output('widget/price_filter/widget', array_merge($args, array('title' => $title, 'max' => $this->max, 'fields' => $fields)));
 }
Exemple #2
0
 /**
  * Display the widget in the sidebar.
  *
  * @param array $args     Sidebar arguments.
  * @param array $instance Instance.
  */
 public function widget($args, $instance)
 {
     // Hide widget if page is the cart or checkout
     if (Pages::isCart() || Pages::isCheckout()) {
         return;
     }
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Cart', 'jigoshop'), $instance, $this->id_base);
     Render::output('widget/cart/widget', array_merge($args, array('title' => $title, 'cart' => self::$cart->getCurrent(), 'cart_url' => get_permalink(self::$options->getPageId(\Jigoshop\Frontend\Pages::CART)), 'checkout_url' => get_permalink(self::$options->getPageId(\Jigoshop\Frontend\Pages::CHECKOUT)))));
 }
Exemple #3
0
 /**
  * Removes style from enqueued list.
  * Calls filter `jigoshop_remove_style`. If the filter returns empty value the style is omitted.
  * Available options:
  *   * page - list of pages to use the style
  * Options could be extended by plugins.
  *
  * @param string $handle  Handle name.
  * @param array  $options List of options.
  */
 public static function remove($handle, $options)
 {
     $page = isset($options['page']) ? (array) $options['page'] : array('all');
     if (Pages::isOneOf($page)) {
         $handle = apply_filters('jigoshop\\style\\remove', $handle, $options);
         if (!empty($handle)) {
             wp_deregister_style($handle);
         }
     }
 }
Exemple #4
0
 public function getPage(Container $container)
 {
     if (!Pages::isJigoshop() && !Pages::isAjax()) {
         return $container->get('jigoshop.page.dummy');
     }
     $this->wp->doAction('jigoshop\\page_resolver\\before');
     if (Pages::isCheckoutThankYou()) {
         return $container->get('jigoshop.page.checkout.thank_you');
     }
     if (Pages::isCheckoutPay()) {
         return $container->get('jigoshop.page.checkout.pay');
     }
     if (Pages::isCheckout()) {
         return $container->get('jigoshop.page.checkout');
     }
     if (Pages::isCart()) {
         return $container->get('jigoshop.page.cart');
     }
     if (Pages::isProductCategory()) {
         return $container->get('jigoshop.page.product_category_list');
     }
     if (Pages::isProductTag()) {
         return $container->get('jigoshop.page.product_tag_list');
     }
     if (Pages::isProductList()) {
         return $container->get('jigoshop.page.product_list');
     }
     if (Pages::isProduct()) {
         return $container->get('jigoshop.page.product');
     }
     if (Pages::isAccountOrders()) {
         return $container->get('jigoshop.page.account.orders');
     }
     if (Pages::isAccountEditAddress()) {
         return $container->get('jigoshop.page.account.edit_address');
     }
     if (Pages::isAccountChangePassword()) {
         return $container->get('jigoshop.page.account.change_password');
     }
     if (Pages::isAccount()) {
         return $container->get('jigoshop.page.account');
     }
 }
 /**
  * Displays the widget in the sidebar.
  *
  * @param array $args     Sidebar arguments.
  * @param array $instance The instance.
  *
  * @return bool|void
  */
 public function widget($args, $instance)
 {
     // Get the best selling products from the transient
     $cache = get_transient(Core::WIDGET_CACHE);
     // If cached get from the cache
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return;
     }
     // Otherwise Start buffering and output the Widget
     ob_start();
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Product Categories', 'jigoshop'), $instance, $this->id_base);
     // Get options
     $count = isset($instance['count']) ? $instance['count'] : false;
     $is_hierarchical = isset($instance['hierarchical']) ? $instance['hierarchical'] : false;
     $is_dropdown = isset($instance['dropdown']) ? $instance['dropdown'] : false;
     $query = array('orderby' => 'name', 'show_count' => $count, 'hierarchical' => $is_hierarchical, 'taxonomy' => Core\Types::PRODUCT_CATEGORY, 'title_li' => null);
     if (Pages::isProduct()) {
         global $post;
         $categories = get_the_terms($post->ID, Core\Types::PRODUCT_CATEGORY);
         if (!empty($categories)) {
             $category = reset($categories);
             $query['current_category'] = apply_filters('jigoshop_product_cat_widget_terms', $category->term_id, $categories);
         }
     }
     if ($is_dropdown) {
         global $wp_query;
         $query = array('pad_counts' => 1, 'hierarchical' => $is_hierarchical, 'hide_empty' => true, 'show_count' => $count, 'selected' => isset($wp_query->query[Core\Types::PRODUCT_CATEGORY]) ? $wp_query->query[Core\Types::PRODUCT_CATEGORY] : '');
         $terms = get_terms(Core\Types::PRODUCT_CATEGORY, $query);
         if (!$terms) {
             return;
         }
         $walker = new CategoryWalker(self::$wp, 'widget/product_categories/item');
         Render::output('widget/product_categories/dropdown', array_merge($args, array('title' => $title, 'query' => $query, 'walker' => $walker, 'terms' => $terms, 'value' => $query['selected'], 'shopUrl' => get_permalink(self::$options->getPageId(Pages::SHOP)))));
     } else {
         Render::output('widget/product_categories/list', array_merge($args, array('title' => $title, 'args' => $query)));
     }
     // Flush output buffer and save to transient cache
     $cache[$args['widget_id']] = ob_get_flush();
     set_transient(Core::WIDGET_CACHE, $cache, 3600 * 3);
     // 3 hours ahead
 }
Exemple #6
0
 /**
  * Loads proper template based on current page.
  *
  * @param $template string Template chain.
  *
  * @return string Template to load.
  */
 public function process($template)
 {
     if (!Pages::isJigoshop()) {
         return $template;
     }
     if ($this->page === null) {
         if (WP_DEBUG) {
             throw new Exception('Page object should already be set for Jigoshop pages, but none found.');
         }
         Registry::getInstance(JIGOSHOP_LOGGER)->addCritical('Page object should already be set for Jigoshop pages, but none found.');
         return false;
     }
     $content = $this->page->render();
     $template = $this->wp->getOption('template');
     $theme = $this->wp->wpGetTheme();
     if ($theme->get('Author') === 'WooThemes') {
         $template = 'woothemes';
     }
     if (!file_exists(\JigoshopInit::getDir() . '/templates/layout/' . $template . '.php')) {
         $template = 'default';
     }
     Render::output('layout/' . $template, array('content' => $content));
     return false;
 }
Exemple #7
0
 /**
  * Find and fetches saved cart.
  * If cart is not found - returns new empty one.
  *
  * @param $id string Id of cart to fetch.
  *
  * @return \Jigoshop\Entity\Cart Prepared cart instance.
  */
 public function get($id)
 {
     if (!isset($this->carts[$id])) {
         $cart = new Cart($this->options->get('tax.classes'));
         $cart->setCustomer($this->customerService->getCurrent());
         $cart->getCustomer()->selectTaxAddress($this->options->get('taxes.shipping') ? 'shipping' : 'billing');
         // Fetch data from session if available
         $cart->setId($id);
         $state = $this->getStateFromSession($id);
         if (isset($_POST['jigoshop_order']) && Pages::isCheckout()) {
             $state = $this->getStateFromCheckout($state);
         }
         // TODO: Support for transients?
         $cart = $this->orderFactory->fill($cart, $state);
         $this->carts[$id] = $this->wp->applyFilters('jigoshop\\service\\cart\\get', $cart, $state);
     }
     return $this->carts[$id];
 }
Exemple #8
0
 /**
  * Displays the widget in the sidebar.
  *
  * @param array $args     Sidebar arguments.
  * @param array $instance The instance.
  */
 public function widget($args, $instance)
 {
     // Hide widget if not product related
     if (!Pages::isProductList()) {
         return;
     }
     // Set the widget title
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Filter by Attributes', 'jigoshop'), $instance, $this->id_base);
     $attribute = self::$productService->getAttribute($instance['attribute']);
     if ($attribute && $attribute->hasOptions()) {
         $selected = self::$parameters[$attribute->getId()];
         $productsPerOption = array();
         $products = array_filter($this->products, function ($product) use($attribute, $selected, &$productsPerOption) {
             /** @var $product Product */
             if (!$product->hasAttribute($attribute->getId())) {
                 return false;
             }
             $value = $product->getAttribute($attribute->getId())->getValue();
             if (is_array($value)) {
                 foreach ($value as $subValue) {
                     if (!isset($productsPerOption[$subValue])) {
                         $productsPerOption[$subValue] = 0;
                     }
                     $productsPerOption[$subValue]++;
                 }
                 return (bool) array_intersect($value, $selected);
             } else {
                 if (!isset($productsPerOption[$value])) {
                     $productsPerOption[$value] = 0;
                 }
                 $productsPerOption[$value]++;
                 return in_array($value, $selected);
             }
         });
         if (empty($selected) || !empty($products)) {
             $fields = apply_filters('jigoshop_get_hidden_fields', array());
             Render::output('widget/layered_nav/widget', array('title' => $title, 'attribute' => $attribute, 'selected' => $selected, 'productsPerOption' => $productsPerOption, 'baseUrl' => remove_query_arg('filter_' . $attribute->getSlug()), 'fields' => $fields));
         }
     }
 }
Exemple #9
0
 /**
  * Adds a custom store banner to the site.
  */
 public function displayCustomMessage()
 {
     if ($this->options->get('general.show_message') && Frontend\Pages::isJigoshop()) {
         Render::output('shop/custom_message', array('message' => $this->options->get('general.message')));
     }
     if ($this->options->get('general.demo_store') && Frontend\Pages::isJigoshop()) {
         Render::output('shop/custom_message', array('message' => __('This is a demo store for testing purposes — no orders shall be fulfilled.', 'jigoshop')));
     }
 }
Exemple #10
0
 /**
  *
  */
 private function disableRelationLinks()
 {
     $disable = function ($value) {
         if (\Jigoshop\Frontend\Pages::isProduct()) {
             return false;
         }
         return $value;
     };
     add_filter('index_rel_link', $disable);
     add_filter('parent_post_rel_link', $disable);
     add_filter('start_post_rel_link', $disable);
     add_filter('previous_post_rel_link', $disable);
     add_filter('next_post_rel_link', $disable);
 }