Example #1
0
 /**
  * @return array List of available order statuses.
  */
 public static function getStatuses()
 {
     if (self::$statuses === null) {
         self::$statuses = self::$wp->applyFilters('jigoshop\\order\\statuses', array(Status::PENDING => __('Pending', 'jigoshop'), Status::ON_HOLD => __('On-Hold', 'jigoshop'), Status::PROCESSING => __('Processing', 'jigoshop'), Status::COMPLETED => __('Completed', 'jigoshop'), Status::CANCELLED => __('Cancelled', 'jigoshop'), Status::REFUNDED => __('Refunded', 'jigoshop')));
     }
     return self::$statuses;
 }
Example #2
0
 private function getCapabilities()
 {
     $capabilities = array('core' => array('manage_jigoshop', 'view_jigoshop_reports', 'manage_jigoshop_orders', 'manage_jigoshop_coupons', 'manage_jigoshop_products'));
     $types = $this->wp->applyFilters('jigoshop\\capability\\types', array(Types::PRODUCT, Types::ORDER, Types::EMAIL, Types::COUPON));
     foreach ($types as $type) {
         $capabilities[$type] = array("edit_{$type}", "read_{$type}", "delete_{$type}", "edit_{$type}s", "edit_others_{$type}s", "publish_{$type}s", "read_private_{$type}s", "delete_{$type}s", "delete_private_{$type}s", "delete_published_{$type}s", "delete_others_{$type}s", "edit_private_{$type}s", "edit_published_{$type}s", "manage_{$type}_terms", "edit_{$type}_terms", "delete_{$type}_terms", "assign_{$type}_terms");
     }
     return $capabilities;
 }
Example #3
0
 /**
  * Executes actions associated with selected page.
  */
 public function action()
 {
     if (isset($_POST['action']) && $_POST['action'] == 'add-to-cart') {
         /** @var \Jigoshop\Entity\Product $product */
         $product = $this->productService->find($_POST['item']);
         try {
             /** @var Item $item */
             $item = $this->wp->applyFilters('jigoshop\\cart\\add', null, $product);
             if ($item === null) {
                 throw new Exception(__('Unable to add product to the cart.', 'jigoshop'));
             }
             if (isset($_POST['quantity'])) {
                 $item->setQuantity($_POST['quantity']);
             }
             /** @var Cart $cart */
             $cart = $this->cartService->get($this->cartService->getCartIdForCurrentUser());
             $cart->addItem($item);
             $this->cartService->save($cart);
             $url = false;
             $button = '';
             switch ($this->options->get('shopping.redirect_add_to_cart')) {
                 case 'cart':
                     $url = $this->wp->getPermalink($this->options->getPageId(Pages::CART));
                     break;
                 case 'checkout':
                     $url = $this->wp->getPermalink($this->options->getPageId(Pages::CHECKOUT));
                     break;
                     /** @noinspection PhpMissingBreakStatementInspection */
                 /** @noinspection PhpMissingBreakStatementInspection */
                 case 'product_list':
                     $url = $this->wp->getPermalink($this->options->getPageId(Pages::SHOP));
                 case 'product':
                 case 'same_page':
                 default:
                     $button = sprintf('<a href="%s" class="btn btn-warning pull-right">%s</a>', $this->wp->getPermalink($this->options->getPageId(Pages::CART)), __('View cart', 'jigoshop'));
             }
             $this->messages->addNotice(sprintf(__('%s successfully added to your cart. %s', 'jigoshop'), $product->getName(), $button));
             if ($url !== false) {
                 $this->messages->preserveMessages();
                 $this->wp->wpRedirect($url);
             }
         } catch (NotEnoughStockException $e) {
             if ($e->getStock() == 0) {
                 $message = sprintf(__('Sorry, we do not have "%s" in stock.', 'jigoshop'), $product->getName());
             } else {
                 if ($this->options->get('products.show_stock')) {
                     $message = sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. We only have %d available at this time. Please edit your cart and try again. We apologize for any inconvenience caused.', 'jigoshop'), $product->getName(), $e->getStock());
                 } else {
                     $message = sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. Please edit your cart and try again. We apologize for any inconvenience caused.', 'jigoshop'), $product->getName());
                 }
             }
             $this->messages->addError($message);
         } catch (Exception $e) {
             $this->messages->addError(sprintf(__('A problem ocurred when adding to cart: %s', 'jigoshop'), $e->getMessage()));
         }
     }
 }
Example #4
0
 public function start_el(&$output, $category, $depth = 0, $args = array(), $current_object_id = 0)
 {
     $name = $this->wp->applyFilters('list_product_cats', $category->name, $category);
     if (!isset($args['value'])) {
         $args['value'] = $category->taxonomy == Types::PRODUCT_CATEGORY ? 'slug' : 'id';
     }
     $value = $args['value'] == 'slug' ? $category->slug : $category->term_id;
     $output .= Render::get($this->template, array('depth' => $depth, 'term' => $category, 'value' => $value, 'name' => $name, 'selected' => $args['selected'], 'show_count' => $args['show_count'], 'count' => $category->count));
 }
Example #5
0
 /**
  * @return Service Tax service.
  * @since 2.0
  */
 public function getService()
 {
     $service = new Service();
     switch ($this->options->get('advanced.cache')) {
         // TODO: Add caching mechanisms
         default:
             $service = $this->wp->applyFilters('jigoshop\\core\\get_payment_service', $service);
     }
     return $service;
 }
Example #6
0
 /**
  * @return ProductServiceInterface Products service.
  * @since 2.0
  */
 public function getService()
 {
     $service = new Service($this->wp, $this->factory, $this->productService);
     switch ($this->options->get('advanced.cache')) {
         case 'simple':
             $service = new SimpleCache($service);
             break;
         default:
             $service = $this->wp->applyFilters('jigoshop\\core\\get_product_variable_service', $service);
     }
     return $service;
 }
Example #7
0
 /**
  * @return Service Tax service.
  * @since 2.0
  */
 public function getService()
 {
     $service = new Service();
     switch ($this->options->get('advanced.cache')) {
         // TODO: Add caching mechanisms
         //			case 'simple':
         //				$service = new SimpleCache($service);
         //				break;
         default:
             $service = $this->wp->applyFilters('jigoshop\\core\\get_shipping_service', $service);
     }
     return $service;
 }
Example #8
0
 /**
  * @return SessionService
  */
 public function getService()
 {
     switch ($this->options->get('advanced.session', 'php')) {
         case 'php':
             $service = new Service\Session\Php($this->wp, $this->options, $this->factory);
             break;
         case 'transient':
             $service = new Service\Session\Transient($this->wp, $this->options, $this->factory);
             break;
         default:
             $service = $this->wp->applyFilters('jigoshop\\core\\get_session_service', '', $this->wp, $this->options, $this->factory);
             break;
     }
     return $service;
 }
Example #9
0
 public function __construct(Wordpress $wp, Options $options, Messages $messages)
 {
     $this->options = $options->get(self::SLUG);
     $this->messages = $messages;
     $this->addToCartRedirectionOptions = $wp->applyFilters('jigoshop\\admin\\settings\\shopping\\add_to_cart_redirect', array('same_page' => __('Stay on the same page', 'jigoshop'), 'product' => __('Redirect to product page', 'jigoshop'), 'cart' => __('Redirect to cart', 'jigoshop'), 'checkout' => __('Redirect to checkout', 'jigoshop'), 'product_list' => __('Redirect to product list', 'jigoshop')));
     $this->backToShopRedirectionOptions = $wp->applyFilters('jigoshop\\admin\\settings\\shopping\\continue_shopping_redirect', array('product_list' => __('Product list', 'jigoshop'), 'my_account' => __('My account', 'jigoshop')));
     $this->catalogOrderBy = $wp->applyFilters('jigoshop\\admin\\settings\\shopping\\catalog_order_by', array('post_date' => __('Date', 'jigoshop'), 'post_title' => __('Product name', 'jigoshop'), 'menu_order' => __('Product post order', 'jigoshop')));
     $this->catalogOrder = $wp->applyFilters('jigoshop\\admin\\settings\\shopping\\catalog_order', array('ASC' => __('Ascending', 'jigoshop'), 'DESC' => __('Descending', 'jigoshop')));
     $this->productButtonType = $wp->applyFilters('jigoshop\\admin\\settings\\shopping\\catalog_product_button_type', array('add_to_cart' => __('Add to cart', 'jigoshop'), 'view_product' => __('View Product', 'jigoshop'), 'no_button' => __('No button', 'jigoshop')));
     $wp->addAction('admin_enqueue_scripts', function () {
         if (isset($_GET['tab']) && $_GET['tab'] == ShoppingTab::SLUG) {
             Scripts::add('jigoshop.admin.settings.shopping', \JigoshopInit::getUrl() . '/assets/js/admin/settings/shopping.js', array('jquery'), array('page' => 'jigoshop_page_jigoshop_settings'));
         }
     });
 }
Example #10
0
 /**
  * @return array List of available coupon types.
  */
 public function getTypes()
 {
     if ($this->types === null) {
         $this->types = $this->wp->applyFilters('jigoshop\\service\\coupon\\types', array(Entity::FIXED_CART => __('Cart Discount', 'jigoshop'), Entity::PERCENT_CART => __('Cart % Discount', 'jigoshop'), Entity::FIXED_PRODUCT => __('Product Discount', 'jigoshop'), Entity::PERCENT_PRODUCT => __('Product % Discount', 'jigoshop')));
     }
     return $this->types;
 }
Example #11
0
 /**
  * @return Service Tax service.
  * @since 2.0
  */
 public function getService()
 {
     $classes = array_map(function ($item) {
         return $item['class'];
     }, $this->options->get('tax.classes'));
     $service = new Service($this->wp, $classes, $this->customerService, $this->options->get('tax.included'));
     switch ($this->options->get('advanced.cache')) {
         // TODO: Add caching mechanisms
         //			case 'simple':
         //				$service = new SimpleCache($service);
         //				break;
         default:
             $service = $this->wp->applyFilters('jigoshop\\core\\get_tax_service', $service);
     }
     return $service;
 }
Example #12
0
 /**
  * Fetches product from database.
  *
  * @param $post \WP_Post Post to fetch product for.
  *
  * @return \Jigoshop\Entity\Product
  */
 public function fetch($post)
 {
     $email = new Entity();
     $state = array();
     if ($post) {
         $state = array_map(function ($item) {
             return $item[0];
         }, $this->wp->getPostMeta($post->ID));
         $email->setId($post->ID);
         $email->setTitle($post->post_title);
         $email->setText($post->post_content);
         $state['actions'] = unserialize($state['actions']);
         $email->restoreState($state);
     }
     return $this->wp->applyFilters('jigoshop\\find\\email', $email, $state);
 }
Example #13
0
 /**
  * Validates whether
  *
  * @param OrderInterface $cart
  */
 public function validate(OrderInterface $cart)
 {
     $customer = $cart->getCustomer();
     $billingErrors = $this->validateAddress($customer->getBillingAddress());
     if ($customer->getBillingAddress()->getEmail() == null) {
         $billingErrors[] = __('Email address is empty.', 'jigoshop');
     }
     if ($customer->getBillingAddress()->getPhone() == null) {
         $billingErrors[] = __('Phone is empty.', 'jigoshop');
     }
     if (!Validation::isEmail($customer->getBillingAddress()->getEmail())) {
         $billingErrors[] = __('Email address is invalid.', 'jigoshop');
     }
     $shippingErrors = $this->validateAddress($customer->getShippingAddress());
     $billingErrors = $this->wp->applyFilters('jigoshop\\service\\cart\\billing_address_validation', $billingErrors, $customer->getBillingAddress());
     $shippingErrors = $this->wp->applyFilters('jigoshop\\service\\cart\\shipping_address_validation', $shippingErrors, $customer->getShippingAddress());
     $error = '';
     if (!empty($billingErrors)) {
         $error .= $this->prepareAddressError(__('Billing address is not valid.', 'jigoshop'), $billingErrors);
     }
     if (!empty($shippingErrors)) {
         $error .= $this->prepareAddressError(__('Shipping address is not valid.', 'jigoshop'), $shippingErrors);
     }
     if (!empty($error)) {
         throw new Exception($error);
     }
 }
Example #14
0
 /**
  * Registers setting item.
  */
 public function register()
 {
     // Weed out all admin pages except the Jigoshop Settings page hits
     if (!in_array($this->wp->getPageNow(), array('admin.php', 'options.php'))) {
         return;
     }
     $screen = $this->wp->getCurrentScreen();
     if (!in_array($screen->base, array('jigoshop_page_' . self::NAME, 'options'))) {
         return;
     }
     $this->wp->registerSetting(self::NAME, Options::NAME, array($this, 'validate'));
     $tab = $this->getCurrentTab();
     $tab = $this->tabs[$tab];
     // Workaround for PHP pre-5.4
     $that = $this;
     /** @var TabInterface $tab */
     $sections = $this->wp->applyFilters('jigoshop/admin/settings/tab/' . $tab->getSlug(), $tab->getSections(), $tab);
     foreach ($sections as $section) {
         $this->wp->addSettingsSection($section['id'], $section['title'], function () use($tab, $section, $that) {
             $that->displaySection($tab, $section);
         }, self::NAME);
         foreach ($section['fields'] as $field) {
             $field = $this->validateField($field);
             $this->wp->addSettingsField($field['id'], $field['title'], array($this, 'displayField'), self::NAME, $section['id'], $field);
         }
     }
 }
Example #15
0
 /**
  * Fetches product from database.
  *
  * @param $post \WP_Post Post to fetch product for.
  *
  * @return \Jigoshop\Entity\Product
  */
 public function fetch($post)
 {
     $coupon = new Entity();
     $state = array();
     if ($post) {
         $state = array_map(function ($item) {
             return $item[0];
         }, $this->wp->getPostMeta($post->ID));
         $coupon->setId($post->ID);
         $coupon->setTitle($post->post_title);
         $coupon->setCode($post->post_name);
         if (isset($state['products'])) {
             $state['products'] = unserialize($state['products']);
         }
         if (isset($state['excluded_products'])) {
             $state['excluded_products'] = unserialize($state['excluded_products']);
         }
         if (isset($state['categories'])) {
             $state['categories'] = unserialize($state['categories']);
         }
         if (isset($state['excluded_categories'])) {
             $state['excluded_categories'] = unserialize($state['excluded_categories']);
         }
         if (isset($state['payment_methods'])) {
             $state['payment_methods'] = unserialize($state['payment_methods']);
         }
         $coupon->restoreState($state);
     }
     return $this->wp->applyFilters('jigoshop\\find\\coupon', $coupon, $state);
 }
Example #16
0
 /**
  * @return OrderServiceInterface Orders service.
  * @since 2.0
  */
 public function getService()
 {
     /** @var \WPAL\Wordpress $wp */
     $service = new Service($this->wp, $this->options, $this->factory);
     switch ($this->options->get('advanced.cache')) {
         case 'simple':
             $service = new SimpleCache($service);
             break;
         case 'php_fast_cache':
             $service = new PhpFastCache($service);
             break;
         default:
             $service = $this->wp->applyFilters('jigoshop\\core\\get_order_service', $service);
     }
     return $service;
 }
Example #17
0
 /**
  * Return fields with all template overrides.
  *
  * @return array
  */
 private function getOverrides()
 {
     $templatePaths = $this->wp->applyFilters('jigoshop\\admin\\system_info\\system_status\\overrides_scan_paths', array('jigoshop' => \JigoshopInit::getDir() . '/templates/'));
     $scannedFiles = array();
     $foundFiles = array();
     foreach ($templatePaths as $pluginName => $templatePath) {
         $scannedFiles[$pluginName] = $this->scanTemplateFiles($templatePath);
     }
     foreach ($scannedFiles as $pluginName => $files) {
         foreach ($files as $file) {
             $themeFile = $this->getTemplateFile($file);
             if (!empty($themeFile)) {
                 $coreVersion = $this->getFileVersion(\JigoshopInit::getDir() . '/templates/' . $file);
                 $themeVersion = $this->getFileVersion($themeFile);
                 if ($coreVersion && (empty($themeVersion) || version_compare($themeVersion, $coreVersion, '<'))) {
                     $foundFiles[$pluginName][] = sprintf(__('<code>%s</code> version %s is out of date.', 'jigoshop'), str_replace(WP_CONTENT_DIR . '/themes/', '', $themeFile), $themeVersion ? $themeVersion : '-');
                 } else {
                     $foundFiles[$pluginName][] = sprintf('<code>%s</code>', str_replace(WP_CONTENT_DIR . '/themes/', '', $themeFile));
                 }
             }
         }
     }
     $fields = array();
     if ($foundFiles) {
         foreach ($foundFiles as $pluginName => $foundPluginFiles) {
             $fields[] = array('id' => strtolower($pluginName), 'name' => strtolower($pluginName), 'title' => sprintf(__('%s Overrides', 'jigoshop'), $pluginName), 'tip' => '', 'type' => 'constant', 'value' => implode(', <br/>', $foundPluginFiles));
         }
     } else {
         $fields[] = array('id' => 'no_overrides', 'name' => 'no_overrides', 'title' => __('No Overrides', 'jigoshop'), 'tip' => '', 'type' => 'constant', 'value' => '');
     }
     return $fields;
 }
Example #18
0
 private function getProductQuery($request)
 {
     $result = array('name' => isset($request['product']) ? $request['product'] : '', 'post_type' => Types::PRODUCT, 'post_status' => 'publish', 'posts_per_page' => 1);
     if (isset($request['p'], $request['preview']) && $request['preview'] == "true") {
         $result = array_merge($result, $request);
         unset($result['post_status']);
     }
     return $this->wp->applyFilters('jigoshop\\query\\product', $result, $request);
 }
Example #19
0
 public function init()
 {
     $wp = $this->wp;
     $di = $this->di;
     $widgets = $this->wp->applyFilters('jigoshop\\widget\\init', $this->getDefaultWidgets());
     $this->wp->addAction('widgets_init', function () use($wp, $di, $widgets) {
         foreach ($widgets as $widget) {
             $class = $widget['class'];
             $wp->registerWidget($class);
             if (isset($widget['calls'])) {
                 foreach ($widget['calls'] as $call) {
                     list($method, $argument) = $call;
                     $class::$method($di->get($argument));
                 }
             }
         }
     });
 }
Example #20
0
 public function render()
 {
     /** @var Order $order */
     $order = $this->orderService->find((int) $this->wp->getQueryParameter('pay'));
     $render = $this->wp->applyFilters('jigoshop\\pay\\render', '', $order);
     if (!empty($render)) {
         return Render::get('shop/checkout/payment', array('messages' => $this->messages, 'content' => $render, 'order' => $order));
     }
     $termsUrl = '';
     $termsPage = $this->options->get('advanced.pages.terms');
     if ($termsPage > 0) {
         $termsUrl = $this->wp->getPageLink($termsPage);
     }
     $accountUrl = $this->wp->getPermalink($this->options->getPageId(Pages::ACCOUNT));
     return Render::get('shop/checkout/pay', array('messages' => $this->messages, 'order' => $order, 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'termsUrl' => $termsUrl, 'myAccountUrl' => $accountUrl, 'myOrdersUrl' => Api::getEndpointUrl('orders', '', $accountUrl), 'paymentMethods' => $this->paymentService->getEnabled(), 'getTaxLabel' => function ($taxClass) use($order) {
         return Tax::getLabel($taxClass, $order);
     }));
 }
Example #21
0
 /**
  * Clears jigoshop.log and jigoshop.debug.log
  */
 private function clearLogs()
 {
     $logFiles = $this->wp->applyFilters('jigoshop/admin/system_info/tools/log_files', array('jigoshop', 'jigoshop.debug'));
     foreach ($logFiles as $logFile) {
         if (@fopen(JIGOSHOP_LOG_DIR . '/' . $logFile . '.log', 'a')) {
             file_put_contents(JIGOSHOP_LOG_DIR . '/' . $logFile . '.log', '');
         }
     }
 }
Example #22
0
 /**
  * Get report totals such as order totals and discount amounts.
  * Data example:
  * 'select' => array(
  *     'table' => array(
  *			array(
  * 				'field' => '*'
  * 			)
  * 		),
  * ),
  * 'from' => array(
  * 		'table' => 'table_name'
  * )
  * Return example:
  * "SELECT table.* FROM table_name AS table"
  *
  * @param  array $args
  * @return array|string depending on query_type
  */
 public function prepareQuery($args = array())
 {
     $defaultArgs = array('select' => array(), 'from' => array(), 'join' => array(), 'where' => array(), 'group_by' => '', 'order_by' => '', 'filter_range' => false);
     $args = $this->wp->applyFilters('jigoshop\\admin\\reports\\chart\\report_query_args', $args);
     $args = wp_parse_args($args, $defaultArgs);
     if (empty($args['select'])) {
         return '';
     }
     $query = implode(' ', array($this->prepareQuerySelect($args['select']), $this->prepareQueryFrom($args['from']), $this->prepareQueryJoin($args['join']), $this->prepareQueryWhere($args['where'], $args['filter_range']), $this->prepareQueryGroupBy($args['group_by']), $this->prepareQueryOrderBy($args['order_by'])));
     return $query;
 }
Example #23
0
 /**
  * Creates new attribute object based on type.
  *
  * @param      $type   int Attribute type.
  * @param bool $exists Is attribute loaded from DB.
  *
  * @return Attribute\Multiselect|Attribute\Select|Attribute\Text
  */
 public function createAttribute($type, $exists = false)
 {
     switch ($type) {
         case Attribute\Multiselect::TYPE:
             return new Attribute\Multiselect($exists);
         case Attribute\Select::TYPE:
             return new Attribute\Select($exists);
         case Attribute\Text::TYPE:
             return new Attribute\Text($exists);
         default:
             return $this->wp->applyFilters('jigoshop\\factory\\product\\create_attribute', null, $type, $exists);
     }
 }
Example #24
0
 public function dataBox()
 {
     $post = $this->wp->getGlobalPost();
     /** @var \Jigoshop\Entity\Order $order */
     $order = $this->orderService->findForPost($post);
     $billingOnly = $this->options->get('shipping.only_to_billing');
     $address = $order->getCustomer()->getBillingAddress();
     $billingFields = $this->wp->applyFilters('jigoshop\\admin\\order\\billing_fields', ProductHelper::getBasicBillingFields(array('first_name' => array('value' => $address->getFirstName()), 'last_name' => array('value' => $address->getLastName()), 'company' => array('value' => $address instanceof Customer\CompanyAddress ? $address->getCompany() : ''), 'euvatno' => array('value' => $address instanceof Customer\CompanyAddress ? $address->getVatNumber() : ''), 'address' => array('value' => $address->getAddress()), 'city' => array('value' => $address->getCity()), 'postcode' => array('value' => $address->getPostcode()), 'country' => array('value' => $address->getCountry(), 'options' => Country::getAllowed()), 'state' => array('type' => Country::hasStates($address->getCountry()) ? 'select' : 'text', 'value' => $address->getState(), 'options' => Country::getStates($address->getCountry())), 'phone' => array('value' => $address->getPhone()), 'email' => array('value' => $address->getEmail())), $order));
     $address = $order->getCustomer()->getShippingAddress();
     $shippingFields = $this->wp->applyFilters('jigoshop\\admin\\order\\shipping_fields', ProductHelper::getBasicShippingFields(array('first_name' => array('value' => $address->getFirstName()), 'last_name' => array('value' => $address->getLastName()), 'company' => array('value' => $address instanceof Customer\CompanyAddress ? $address->getCompany() : ''), 'address' => array('value' => $address->getAddress()), 'city' => array('value' => $address->getCity()), 'postcode' => array('value' => $address->getPostcode()), 'country' => array('value' => $address->getCountry(), 'options' => Country::getAllowed()), 'state' => array('type' => Country::hasStates($address->getCountry()) ? 'select' : 'text', 'value' => $address->getState(), 'options' => Country::getStates($address->getCountry()))), $order));
     $customers = $this->customerService->findAll();
     Render::output('admin/order/dataBox', array('order' => $order, 'billingFields' => $billingFields, 'shippingFields' => $shippingFields, 'customers' => $customers, 'billingOnly' => $billingOnly));
 }
Example #25
0
 /**
  * Displays the product data box, tabbed, with several panels covering price, stock etc
  *
  * @since        1.0
  */
 public function box()
 {
     $post = $this->wp->getGlobalPost();
     /** @var \Jigoshop\Entity\Product $product */
     $product = $this->productService->findForPost($post);
     $types = array();
     foreach ($this->type->getEnabledTypes() as $type) {
         /** @var $type Types\Product\Type */
         $types[$type->getId()] = $type->getName();
     }
     $taxClasses = array();
     foreach ($this->options->get('tax.classes') as $class) {
         $taxClasses[$class['class']] = $class['label'];
     }
     $attributes = array('' => array('label' => ''), '-1' => array('label' => __('Custom attribute', 'jigoshop')));
     foreach ($this->productService->findAllAttributes() as $attribute) {
         /** @var $attribute Attribute */
         $attributes[$attribute->getId()] = array('label' => $attribute->getLabel(), 'disabled' => $product->hasAttribute($attribute->getId()));
     }
     $tabs = $this->wp->applyFilters('jigoshop\\admin\\product\\tabs', array('general' => array('product' => $product), 'advanced' => array('product' => $product, 'taxClasses' => $taxClasses), 'attributes' => array('product' => $product, 'availableAttributes' => $attributes, 'attributes' => $product->getAttributes()), 'stock' => array('product' => $product), 'sales' => array('product' => $product)), $product);
     Render::output('admin/product/box', array('product' => $product, 'types' => $types, 'menu' => $this->menu, 'tabs' => $tabs, 'current_tab' => 'general'));
 }
Example #26
0
 private function getContent()
 {
     if (!in_array($this->wp->getPageNow(), array('admin.php', 'options.php'))) {
         return null;
     }
     if (!isset($_GET['page']) || $_GET['page'] != Reports::NAME) {
         return null;
     }
     if (!isset($_GET['tab']) || $_GET['tab'] != self::SLUG) {
         return null;
     }
     switch ($this->getCurrentType()) {
         case 'low_in_stock':
             return new Table\LowInStock($this->wp, $this->options);
         case 'out_of_stock':
             return new Table\OutOfStock($this->wp, $this->options);
         case 'most_stocked':
             return new Table\MostStocked($this->wp, $this->options);
         default:
             return $this->wp->applyFilters('jigoshop\\admin\\reports\\stock\\custom', null, $this->getCurrentType());
     }
 }
Example #27
0
 public function displayTitle($actions)
 {
     $post = $this->wp->getGlobalPost();
     // Remove "Quick edit" as we won't use it.
     unset($actions['inline hide-if-no-js']);
     if ($post->post_type == Types::ORDER) {
         $fullFormat = _x('Y/m/d g:i:s A', 'time', 'jigoshop');
         $format = _x('Y/m/d', 'time', 'jigoshop');
         $fullDate = $this->wp->getHelpers()->mysql2date($fullFormat, $post->post_date);
         $date = $this->wp->getHelpers()->mysql2date($format, $post->post_date);
         echo '<time title="' . $fullDate . '">' . $this->wp->applyFilters('post_date_column_time', $date, $post) . '</time>';
     }
     return $actions;
 }
Example #28
0
 /**
  * Fetches customer from database.
  *
  * @param $user \WP_User User object to fetch customer for.
  *
  * @return \Jigoshop\Entity\Customer
  */
 public function fetch($user)
 {
     $state = array();
     if ($user->ID == 0) {
         $customer = new Entity\Guest();
         if ($this->session->getField(self::CUSTOMER)) {
             $customer->restoreState($this->session->getField(self::CUSTOMER));
         }
     } else {
         $customer = new Entity();
         $meta = $this->wp->getUserMeta($user->ID);
         if (is_array($meta)) {
             $state = array_map(function ($item) {
                 return $item[0];
             }, $meta);
         }
         $state['id'] = $user->ID;
         $state['login'] = $user->get('login');
         $state['email'] = $user->get('user_email');
         $state['name'] = $user->get('display_name');
         $customer->restoreState($state);
     }
     return $this->wp->applyFilters('jigoshop\\find\\customer', $customer, $state);
 }
Example #29
0
 /**
  * @param $product \Jigoshop\Entity\Product Shown product.
  */
 public function productTabs($product)
 {
     $tabs = array();
     if ($product->getDescription()) {
         $tabs['description'] = __('Description', 'jigoshop');
     }
     if ($product->getVisibleAttributes()) {
         $tabs['attributes'] = __('Additional information', 'jigoshop');
     }
     if ($product->getAttachments()) {
         $tabs['downloads'] = __('Files to download', 'jigoshop');
     }
     $tabs = $this->wp->applyFilters('jigoshop\\product\\tabs', $tabs, $product);
     $availableTabs = array_keys($tabs);
     Render::output('shop/product/tabs', array('product' => $product, 'tabs' => $tabs, 'currentTab' => reset($availableTabs)));
 }
Example #30
0
 /**
  * @param $order Order The order.
  *
  * @return string Items formatted for email.
  */
 private function formatItems($order)
 {
     //		$inc_tax = $this->options->get('tax.included');
     $result = '';
     // validate if any item has cost less than 0. If that's the case, we can't use price including tax
     // TODO: Support for "price includes tax"
     //		$use_inc_tax = $inc_tax;
     //		if ($inc_tax) {
     //			foreach ($this->items as $item) {
     //				$use_inc_tax = ($item['cost_inc_tax'] >= 0);
     //				if (!$use_inc_tax) {
     //					break;
     //				}
     //			}
     //		}
     foreach ($order->getItems() as $item) {
         /** @var $item Order\Item */
         $itemResult = '';
         $product = $item->getProduct();
         $itemResult .= $item->getQuantity() . ' x ' . html_entity_decode($this->wp->applyFilters('jigoshop\\emails\\product_title', $item->getName(), $product, $item), ENT_QUOTES, 'UTF-8');
         if ($product->getSku()) {
             $itemResult .= ' (#' . $product->getSku() . ')';
         }
         // TODO: Support for "price includes tax"
         //			if ($use_inc_tax && $item['cost_inc_tax'] >= 0) {
         //				$return .= ' - '.html_entity_decode(strip_tags(jigoshop_price($item['cost_inc_tax'] * $item['qty'], array('ex_tax_label' => 0))), ENT_COMPAT, 'UTF-8');
         //			} else {
         $itemResult .= ' - ' . ProductHelper::formatPrice($item->getCost());
         //			}
         if ($product instanceof Product\Variable) {
             $variation = $product->getVariation($item->getMeta('variation_id')->getValue());
             $itemResult .= PHP_EOL;
             foreach ($variation->getAttributes() as $attribute) {
                 /** @var $attribute \Jigoshop\Entity\Product\Variable\Attribute */
                 $itemResult .= $attribute->getAttribute()->getLabel() . ': ' . $attribute->getItemValue($item) . ', ';
             }
             $itemResult = rtrim($itemResult, ',');
         }
         $itemResult = $this->wp->applyFilters('jigoshop\\emails\\order_item', $itemResult, $item, $order);
         $result .= $itemResult . PHP_EOL;
     }
     return $result;
 }