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; }); }
/** * @return Routing\ControllerInterface[] */ private function getControllers() { /** @var Extensions $extensions */ $extensions = $this->di->get('jigoshop.extensions'); $controllers = array(new Routing\Controller()); foreach ($extensions->getExtensions() as $extension) { $controllers[] = $extension->getApiController(); } return array_filter($controllers); }
/** * @param \WP_Query $query */ public function parseRequest($query) { $endpoint = isset($query->query_vars[self::API_ENDPOINT]) ? $query->query_vars[self::API_ENDPOINT] : null; if (!empty($endpoint)) { if ($this->di->services->detailsExists('jigoshop.api.' . $endpoint)) { ob_start(); $api = $this->di->get('jigoshop.api.' . $endpoint); if (!$api instanceof Api\Processable) { if (WP_DEBUG) { throw new Exception(__('Provided API is not processable.', 'jigoshop')); } return; } $api->processResponse(); } else { $this->wp->doAction('jigoshop_api_' . $endpoint); } exit; } }
/** * Starts Jigoshop extensions and Jigoshop itself. * * @param Container $container */ public function run(Container $container) { $wp = $this->wp; // Add table to benefit from WordPress metadata API $wpdb = $wp->getWPDB(); /** @noinspection PhpUndefinedFieldInspection */ $wpdb->jigoshop_termmeta = "{$wpdb->prefix}jigoshop_term_meta"; $wp->addFilter('template_include', array($this->template, 'process')); $wp->addFilter('template_redirect', array($this->template, 'redirect')); $wp->addFilter('jigoshop\\get_fields', function ($fields) { // Post type if (isset($_GET['post_type'])) { $fields['post_type'] = $_GET['post_type']; } return $fields; }); $wp->addAction('jigoshop\\shop\\content\\before', array($this, 'displayCustomMessage')); $wp->addAction('wp_head', array($this, 'googleAnalyticsTracking'), 9990); // Action for limiting WordPress feed from using order notes. $wp->addAction('comment_feed_where', function ($where) { return $where . " AND comment_type <> 'order_note'"; }); $container->get('jigoshop.permalinks'); /** @var \Jigoshop\ApiDeprecated $api */ $api = $container->get('jigoshop.api_deprecated'); $api->run(); /** @var \Jigoshop\Api $api */ $api = $container->get('jigoshop.api'); $api->run(); /** @var \Jigoshop\Service\TaxServiceInterface $tax */ $tax = $container->get('jigoshop.service.tax'); $tax->register(); Tax::setService($tax); $container->get('jigoshop.emails'); $widget = $container->get('jigoshop.widget'); $widget->init($container, $wp); // TODO: Why this is required? :/ //$this->wp->flushRewriteRules(false); $this->wp->doAction('jigoshop\\run', $container); }
/** * Installs or updates Jigoshop. * * @param bool $network_wide */ public function update($network_wide = false) { // Require upgrade specific files require_once ABSPATH . '/wp-admin/includes/upgrade.php'; $this->initConfigurations(); $this->initCompilers(); /** @var $wp \WPAL\Wordpress */ $wp = $this->container->get('wpal'); /** @var $options \Jigoshop\Core\Installer */ $installer = $this->container->get('jigoshop.installer'); if (!$network_wide) { $installer->install(); return; } $blog = $wp->getWPDB()->blogid; $ids = $wp->getWPDB()->get_col("SELECT blog_id FROM {$wp->getWPDB()->blogs}"); foreach ($ids as $id) { switch_to_blog($id); $installer->install(); } switch_to_blog($blog); }
/** * @param Container $di * @param array $permissions */ public function init(Container $di, array $permissions) { $this->permissions = $permissions; $this->orderService = $di->get('jigoshop.service.order'); }
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 processResponse() { if ($this->isResponseValid()) { $posted = $this->wp->getHelpers()->stripSlashesDeep($_POST); // 'custom' holds post ID (Order ID) if (!empty($posted['custom']) && !empty($posted['txn_type']) && !empty($posted['invoice'])) { $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money', 'subscr_payment'); /** @var \Jigoshop\Service\OrderService $service */ $service = $this->di->get('jigoshop.service.order'); $order = $service->find((int) $posted['custom']); // Sandbox fix if (isset($posted['test_ipn']) && $posted['test_ipn'] == 1 && strtolower($posted['payment_status']) == 'pending') { $posted['payment_status'] = 'completed'; } $merchant = $this->settings['test_mode'] ? $this->settings['test_email'] : $this->settings['email']; if ($order->getStatus() !== Order\Status::COMPLETED) { // We are here so lets check status and do actions switch (strtolower($posted['payment_status'])) { case 'completed': if (!in_array(strtolower($posted['txn_type']), $accepted_types)) { // Put this order on-hold for manual checking $order->setStatus(Order\Status::ON_HOLD, sprintf(__('PayPal Validation Error: Unknown "txn_type" of "%s" for Order ID: %s.', 'jigoshop'), $posted['txn_type'], $posted['custom'])); break; } if ($order->getNumber() !== $posted['invoice']) { // Put this order on-hold for manual checking $order->setStatus(Order\Status::ON_HOLD, sprintf(__('PayPal Validation Error: Order Invoice Number does NOT match PayPal posted invoice (%s) for Order ID: .', 'jigoshop'), $posted['invoice'], $posted['custom'])); $service->save($order); exit; } // Validate Amount if (number_format($order->getTotal(), $this->decimals, '.', '') != $posted['mc_gross']) { // Put this order on-hold for manual checking $order->setStatus(Order\Status::ON_HOLD, sprintf(__('PayPal Validation Error: Payment amounts do not match initial order (gross %s).', 'jigoshop'), $posted['mc_gross'])); $service->save($order); exit; } if (strcasecmp(trim($posted['business']), trim($merchant)) != 0) { // Put this order on-hold for manual checking $order->setStatus(Order\Status::ON_HOLD, sprintf(__('PayPal Validation Error: Payment Merchant email received does not match PayPal Gateway settings. (%s)', 'jigoshop'), $posted['business'])); $service->save($order); exit; } if ($posted['mc_currency'] != $this->options->get('general.currency')) { // Put this order on-hold for manual checking $order->setStatus(Order\Status::ON_HOLD, sprintf(__('PayPal Validation Error: Payment currency received (%s) does not match Shop currency.', 'jigoshop'), $posted['mc_currency'])); $service->save($order); exit; } $order->setStatus(OrderHelper::getStatusAfterCompletePayment($order), __('PayPal payment completed', 'jigoshop')); break; case 'denied': case 'expired': case 'failed': case 'voided': // Failed order $order->setStatus(Order\Status::ON_HOLD, sprintf(__('Payment %s via PayPal.', 'jigoshop'), strtolower($posted['payment_status']))); break; case 'refunded': case 'reversed': case 'chargeback': // TODO: Implement refunds break; default: // No action break; } $service->save($order); } } } }
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'); } }
/** * @return \Jigoshop\Admin\Settings */ public static function getAdminSettings() { return self::$di->get('jigoshop.admin.settings'); }
/** * @param Container $di * @param array $permissions */ public function init(Container $di, array $permissions) { $this->productService = $di->get('jigoshop.service.product'); $this->permissions = $permissions; }
/** * Validate and sanitize input values. * * @param array $settings Input fields. * * @return array Sanitized and validated output. * @throws ValidationException When some items are not valid. */ public function validate($settings) { // This is required when installin emails this function is used twice, // once for advanced settings and once for all jigoshop settings. if (isset($settings['general']) && is_array($settings['general'])) { return $settings; } if (isset($settings['install_emails'])) { unset($settings['install_emails']); // TODO add this to WPAL remove_all_actions('save_post_' . Types\Email::NAME); $this->di->get('jigoshop.installer')->installEmails(); $this->messages->addNotice(__('Emails created.', 'jigoshop')); } $settings['automatic_complete'] = $settings['automatic_complete'] == 'on'; $settings['automatic_reset'] = $settings['automatic_reset'] == 'on'; $settings['products_list']['variations_sku_stock'] = $settings['products_list']['variations_sku_stock'] == 'on'; if (!in_array($settings['cache'], array_keys($this->caches))) { $this->messages->addWarning(sprintf(__('Invalid cache mechanism: "%s". Value set to %s.', 'jigoshop'), $settings['cache'], $this->caches['simple'])); $settings['cache'] = 'simple'; } $settings['ignore_meta_queries'] = $settings['ignore_meta_queries'] == 'on'; if (isset($settings['api'], $settings['api']['keys'])) { $settings['api']['keys'] = array_filter($settings['api']['keys'], function ($item) { return !empty($item['key']); }); $settings['api']['keys'] = array_map(function ($item) { return array_merge(array('key' => '', 'permissions' => array()), $item); }, $settings['api']['keys']); } $pages = $this->_getPages(); if (!in_array($settings['pages']['shop'], array_keys($pages))) { $this->messages->addError(__('Invalid shop page, please select again.', 'jigoshop')); } else { $this->options->setPageId(Pages::SHOP, $settings['pages']['shop']); } if (!in_array($settings['pages']['cart'], array_keys($pages))) { $this->messages->addError(__('Invalid cart page, please select again.', 'jigoshop')); } else { $this->options->setPageId(Pages::CART, $settings['pages']['cart']); } if (!in_array($settings['pages']['checkout'], array_keys($pages))) { $this->messages->addError(__('Invalid checkout page, please select again.', 'jigoshop')); } else { $this->options->setPageId(Pages::CHECKOUT, $settings['pages']['checkout']); } if (!in_array($settings['pages']['checkout_thank_you'], array_keys($pages))) { $this->messages->addError(__('Invalid thank you page, please select again.', 'jigoshop')); } else { $this->options->setPageId(Pages::THANK_YOU, $settings['pages']['checkout_thank_you']); } if (!in_array($settings['pages']['account'], array_keys($pages))) { $this->messages->addError(__('Invalid My account page, please select again.', 'jigoshop')); } else { $this->options->setPageId(Pages::ACCOUNT, $settings['pages']['account']); } if (!empty($settings['pages']['terms']) && $settings['pages']['terms'] != 0 && !in_array($settings['pages']['terms'], array_keys($pages))) { $this->messages->addError(__('Invalid terms page, please select again.', 'jigoshop')); } return $settings; }