public function __construct(Container $di, Wordpress $wp, Options $options, ProductServiceInterface $productService) { $this->wp = $wp; $this->options = $options; $types = $options->getEnabledProductTypes(); foreach ($types as $typeClass) { /** @var Types\Product\Type $type */ $type = $di->get($typeClass); if (!$type instanceof Types\Product\Type) { if (WP_DEBUG) { throw new Exception(sprintf(__('Invalid type definition! Offending class: "%s".', 'jigoshop'), $typeClass)); } Registry::getInstance(JIGOSHOP_LOGGER)->addWarning(sprintf('Invalid type definition! Offending class: "%s".', $typeClass)); continue; } $this->enabledTypes[$type->getId()] = $type; $productService->addType($type->getId(), $type->getClass()); $wp->addAction('jigoshop\\product\\type\\init', array($type, 'initialize'), 10, 2); } $wp->doAction('jigoshop\\product\\type\\init', $wp, $this->enabledTypes); // Enable comments for all orders, disable pings $wp->addFilter('wp_insert_post_data', function ($data) { if ($data['post_type'] == Product::NAME) { $data['comment_status'] = 'open'; $data['ping_status'] = 'closed'; } return $data; }); }
/** * Initializes product type. * * @param Wordpress $wp WordPress Abstraction Layer * @param array $enabledTypes List of all available types. */ public function initialize(Wordpress $wp, array $enabledTypes) { $wp->addFilter('jigoshop\\cart\\add', array($this, 'addToCart'), 10, 2); $wp->addFilter('jigoshop\\core\\types\\variable\\subtypes', array($this, 'addVariableSubtype'), 10, 1); $wp->addFilter('jigoshop\\product\\get_stock', array($this, 'getStock'), 10, 2); $wp->addAction('jigoshop\\admin\\product\\assets', array($this, 'addAssets'), 10, 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; }
/** * 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); }
public function __construct(Wordpress $wp, Options $options, TaxServiceInterface $taxService, Messages $messages) { $this->options = $options->get(self::SLUG); $this->taxService = $taxService; $options = $this->options; $wp->addAction('admin_enqueue_scripts', function () use($options) { if (!isset($_GET['tab']) || $_GET['tab'] != TaxesTab::SLUG) { return; } $classes = array(); foreach ($options['classes'] as $class) { $classes[$class['class']] = $class['label']; } $states = array(); foreach (Country::getAllStates() as $country => $stateList) { $states[$country] = array(array('id' => '', 'text' => _x('All states', 'admin_taxing', 'jigoshop'))); foreach ($stateList as $code => $state) { $states[$country][] = array('id' => $code, 'text' => $state); } } $countries = array_merge(array('' => __('All countries', 'jigoshop')), Country::getAll()); Scripts::add('jigoshop.admin.settings.taxes', \JigoshopInit::getUrl() . '/assets/js/admin/settings/taxes.js', array('jquery'), array('page' => 'jigoshop_page_jigoshop_settings')); Scripts::localize('jigoshop.admin.settings.taxes', 'jigoshop_admin_taxes', array('new_class' => Render::get('admin/settings/tax/class', array('class' => array('label' => '', 'class' => ''))), 'new_rule' => Render::get('admin/settings/tax/rule', array('rule' => array('id' => '', 'label' => '', 'class' => '', 'is_compound' => false, 'rate' => '', 'country' => '', 'states' => array(), 'postcodes' => array()), 'classes' => $classes, 'countries' => $countries)), 'states' => $states)); }); }
public function getPage(Container $container) { $this->wp->doAction('jigoshop\\admin\\page_resolver\\before'); if ($this->pages->isProductCategories()) { return $container->get('jigoshop.admin.page.product_categories'); } if ($this->pages->isProductTags()) { return $container->get('jigoshop.admin.page.product_tags'); } if ($this->pages->isProductsList()) { return $container->get('jigoshop.admin.page.products'); } if ($this->pages->isProduct()) { return $container->get('jigoshop.admin.page.product'); } if ($this->pages->isOrdersList()) { return $container->get('jigoshop.admin.page.orders'); } if ($this->pages->isOrder()) { return $container->get('jigoshop.admin.page.order'); } if ($this->pages->isEmail()) { return $container->get('jigoshop.admin.page.email'); } if ($this->pages->isCouponList()) { return $container->get('jigoshop.admin.page.coupons'); } if ($this->pages->isCoupon()) { return $container->get('jigoshop.admin.page.coupon'); } if ($this->pages->isMigrationPage()) { return $container->get('jigoshop.admin.migration'); } return null; }
public function render() { if (!$this->wp->isUserLoggedIn()) { return Render::get('user/login', array()); } $customer = $this->customerService->getCurrent(); return Render::get('user/account/change_password', array('messages' => $this->messages, 'customer' => $customer, 'myAccountUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::ACCOUNT)))); }
/** * SessionService constructor. * @param Wordpress $wp * @param Factory $factory */ public function __construct(Wordpress $wp, Options $options, Factory $factory) { $this->wp = $wp; $this->options = $options; $this->factory = $factory; $this->sessionsToSave = array(); $this->wp->addAction('shutdown', array($this, 'saveAllSessions')); }
private function _getPages() { $pages = array(); foreach ($this->wp->getPages() as $page) { $pages[$page->ID] = $page->post_title; } return $pages; }
/** * 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())); } } }
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; }
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)); }
/** * @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; }
/** Schedules order processing events if not scheduled already. */ private function _scheduleEvents() { $time = time(); if (!$this->wp->nextScheduled('jigoshop\\cron\\pending_orders')) { $this->wp->scheduleEvent($time, 'daily', 'jigoshop\\cron\\pending_orders'); } if (!$this->wp->nextScheduled('jigoshop\\cron\\processing_orders')) { $this->wp->scheduleEvent($time, 'daily', 'jigoshop\\cron\\processing_orders'); } }
public function delete($termId) { $termId = (int) $termId; if (!$termId) { return; } $wpdb = $this->wp->getWPDB(); /** @noinspection PhpUndefinedFieldInspection */ $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->jigoshop_termmeta} WHERE `jigoshop_term_id` = %d", $termId)); }
public function updateMessages($messages) { if ($this->wp->getPostType() === self::NAME) { $messages['post'][1] = __('Order updated.', 'jigoshop'); $messages['post'][4] = __('Order updated.', 'jigoshop'); $messages['post'][6] = __('Order updated.', 'jigoshop'); $messages['post'][8] = __('Order submitted.', 'jigoshop'); $messages['post'][10] = __('Order draft updated.', 'jigoshop'); } return $messages; }
/** * Displays the product data box, tabbed, with several panels covering price, stock etc * * @since 1.0 */ public function box() { $post = $this->wp->getGlobalPost(); $coupon = $this->couponService->findForPost($post); $methods = array(); foreach ($this->paymentService->getAvailable() as $method) { /** @var $method Method */ $methods[$method->getId()] = $method->getName(); } Render::output('admin/coupon/box', array('coupon' => $coupon, 'types' => $this->couponService->getTypes(), 'paymentMethods' => $methods)); }
/** * @return bool Whether current method is enabled and able to work. */ public function isEnabled() { $cart = $this->cartService->getCurrent(); $post = $this->wp->getGlobalPost(); if ($post === null || $post->post_type != Types::ORDER) { $customer = $cart->getCustomer(); } else { // TODO: Get rid of this hack for customer fetching $customer = unserialize($this->wp->getPostMeta($post->ID, 'customer', true)); } return $this->options['enabled'] && ($this->options['available_for'] === 'all' || in_array($customer->getShippingAddress()->getCountry(), $this->options['countries'])); }
/** * @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; }
public function render() { if (!$this->wp->isUserLoggedIn()) { return Render::get('user/login', array()); } $content = $this->wp->getPostField('post_content', $this->options->getPageId(Pages::ACCOUNT)); $content = do_shortcode($content); $customer = $this->customerService->getCurrent(); $query = new \WP_Query(array('post_type' => Types::ORDER, 'post_status' => array(Status::PENDING, Status::ON_HOLD), 'posts_per_page' => $this->options->get('shopping.unpaid_orders_number'), 'meta_query' => array(array('key' => 'customer_id', 'value' => $this->wp->getCurrentUserId(), 'compare' => '=')))); $orders = $this->orderService->findByQuery($query); $permalink = get_permalink(); return Render::get('user/account', array('content' => $content, 'messages' => $this->messages, 'customer' => $customer, 'unpaidOrders' => $orders, 'editBillingAddressUrl' => Api::getEndpointUrl('edit-address', 'billing', $permalink), 'editShippingAddressUrl' => Api::getEndpointUrl('edit-address', 'shipping', $permalink), 'changePasswordUrl' => Api::getEndpointUrl('change-password', '', $permalink), 'myOrdersUrl' => Api::getEndpointUrl('orders', '', $permalink))); }
/** * @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; }
public function __construct(Wordpress $wp, SessionServiceInterface $sessionService) { $this->session = $sessionService->get($sessionService->getCurrentKey()); if ($this->session->getField(self::NOTICES)) { $this->notices = $this->session->getField(self::NOTICES); } if ($this->session->getField(self::WARNINGS)) { $this->warnings = $this->session->getField(self::WARNINGS); } if ($this->session->getField(self::ERRORS)) { $this->errors = $this->session->getField(self::ERRORS); } $wp->addAction('shutdown', array($this, 'preserveMessages'), 9); }
/** * @return bool Whether current method is enabled and able to work. */ public function isEnabled() { $cart = $this->cartService->getCurrent(); $post = $this->wp->getGlobalPost(); if ($post === null || $post->post_type != Types::ORDER) { $customer = $cart->getCustomer(); } else { // TODO: Get rid of this hack for customer fetching $customer = maybe_unserialize($this->wp->getPostMeta($post->ID, 'customer', true)); } if (empty($customer)) { return $this->options['enabled']; } return $this->options['enabled'] && $customer->getShippingAddress()->getCountry() == $this->baseCountry; }
/** * @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; }
/** * @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; }
/** * 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); } }
/** * 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); }
public function render() { $query = $this->wp->getQuery(); $products = $this->productService->findByQuery($query); $content = do_shortcode($this->getContent()); return Render::get('shop', array('content' => $content, 'products' => $products, 'product_count' => $query->max_num_pages, 'messages' => $this->messages, 'title' => $this->getTitle())); }
public function ajaxSaveAttributeOption() { $errors = array(); if (!isset($_POST['attribute_id']) || !is_numeric($_POST['attribute_id'])) { $errors[] = __('Respective attribute is not set.', 'jigoshop'); } if (!isset($_POST['label']) || empty($_POST['label'])) { $errors[] = __('Option label is not set.', 'jigoshop'); } if (!empty($errors)) { echo json_encode(array('success' => false, 'error' => join('<br/>', $errors))); exit; } $attribute = $this->productService->getAttribute((int) $_POST['attribute_id']); if (isset($_POST['id'])) { $option = $attribute->removeOption($_POST['id']); } else { $option = new Attribute\Option(); } $option->setLabel(trim(htmlspecialchars(strip_tags($_POST['label'])))); if (isset($_POST['slug']) && !empty($_POST['slug'])) { $option->setValue(trim(htmlspecialchars(strip_tags($_POST['value'])))); } else { $option->setValue($this->wp->getHelpers()->sanitizeTitle($option->getLabel())); } $attribute->addOption($option); $this->productService->saveAttribute($attribute); echo json_encode(array('success' => true, 'html' => Render::get('admin/product_attributes/option', array('id' => $attribute->getId(), 'option_id' => $option->getId(), 'option' => $option)))); exit; }
public function ajaxMigrationOptions() { try { // 1 - if first time ajax request if ($_POST['msgLog'] == 1) { Migration::saveLog(__('Migration options START.', 'jigoshop'), true); } $countAll = 93; $countRemain = 93; if (($itemsFromBase = $this->wp->getOption('jigoshop_options_migrate_id')) !== false) { if ($itemsFromBase === '1') { $countRemain = 0; } } $ajax_response = array('success' => true, 'percent' => floor(($countAll - $countRemain) / $countAll * 100), 'processed' => $countAll - $countRemain, 'remain' => $countRemain, 'total' => $countAll); if ($countRemain > 0) { if ($this->migrate()) { $this->wp->updateOption('jigoshop_options_migrate_id', '1'); } else { $ajax_response['success'] = false; Migration::saveLog(__('Migration coupons end with error.', 'jigoshop')); } } elseif ($countRemain == 0) { Migration::saveLog(__('Migration coupons END.', 'jigoshop')); } echo json_encode($ajax_response); } catch (Exception $e) { if (WP_DEBUG) { \Monolog\Registry::getInstance(JIGOSHOP_LOGGER)->addDebug($e); } echo json_encode(array('success' => false)); Migration::saveLog(__('Migration options end with error: ', 'jigoshop') . $e); } exit; }