Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 public function __construct(Wordpress $wp, Options $options, CustomerServiceInterface $customerService, Messages $messages)
 {
     $this->wp = $wp;
     $this->options = $options;
     $this->customerService = $customerService;
     $this->messages = $messages;
     Styles::add('jigoshop.user.account', \JigoshopInit::getUrl() . '/assets/css/user/account.css');
     Styles::add('jigoshop.user.account.change_password', \JigoshopInit::getUrl() . '/assets/css/user/account/change_password.css', array('jigoshop.user.account'));
     $this->wp->doAction('jigoshop\\account\\assets', $wp);
 }
Ejemplo n.º 3
0
 public function __construct(Wordpress $wp, Options $options, CustomerServiceInterface $customerService, Messages $messages)
 {
     $this->wp = $wp;
     $this->options = $options;
     $this->customerService = $customerService;
     $this->messages = $messages;
     Styles::add('jigoshop.vendors.select2', \JigoshopInit::getUrl() . '/assets/css/vendors/select2.css');
     Styles::add('jigoshop.user.account', \JigoshopInit::getUrl() . '/assets/css/user/account.css', array('jigoshop.vendors.select2'));
     Styles::add('jigoshop.user.account.edit_address', \JigoshopInit::getUrl() . '/assets/css/user/account/edit_address.css', array('jigoshop.user.account'));
     Scripts::add('jigoshop.vendors.select2', \JigoshopInit::getUrl() . '/assets/js/vendors/select2.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'));
     $this->wp->doAction('jigoshop\\account\\assets', $wp);
 }
Ejemplo n.º 4
0
 /**
  * Saves entity to database.
  *
  * @param $object EntityInterface Entity to save.
  */
 public function save(EntityInterface $object)
 {
     if (!$object instanceof Entity) {
         throw new Exception('Trying to save not a coupon!');
     }
     // TODO: Support for transactions!
     $fields = $object->getStateToSave();
     if (isset($fields['id']) || isset($fields['title']) || isset($fields['code'])) {
         // We do not need to save ID, title and code (post name) as they are saved by WordPress itself.
         unset($fields['id'], $fields['title'], $fields['code']);
     }
     foreach ($fields as $field => $value) {
         $this->wp->updatePostMeta($object->getId(), $field, $value);
     }
     $this->wp->doAction('jigoshop\\service\\coupon\\save', $object);
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 public function ajaxSaveVariation()
 {
     try {
         if (!isset($_POST['product_id']) || empty($_POST['product_id'])) {
             throw new Exception(__('Product was not specified.', 'jigoshop'));
         }
         if (!is_numeric($_POST['product_id'])) {
             throw new Exception(__('Invalid product ID.', 'jigoshop'));
         }
         if (!isset($_POST['variation_id']) || empty($_POST['variation_id'])) {
             throw new Exception(__('Variation was not specified.', 'jigoshop'));
         }
         if (!is_numeric($_POST['variation_id'])) {
             throw new Exception(__('Invalid variation ID.', 'jigoshop'));
         }
         if (!isset($_POST['attributes']) || !is_array($_POST['attributes'])) {
             throw new Exception(__('Attribute values are not specified.', 'jigoshop'));
         }
         $product = $this->productService->find((int) $_POST['product_id']);
         if (!$product->getId()) {
             throw new Exception(__('Product does not exists.', 'jigoshop'));
         }
         if (!$product instanceof Product\Variable) {
             throw new Exception(__('Product is not variable - unable to add variation.', 'jigoshop'));
         }
         if (!$product->hasVariation((int) $_POST['variation_id'])) {
             throw new Exception(__('Variation does not exists.', 'jigoshop'));
         }
         $variation = $product->removeVariation((int) $_POST['variation_id']);
         foreach ($_POST['attributes'] as $attribute => $value) {
             if (!$variation->hasAttribute($attribute)) {
                 continue;
                 // TODO: Properly add attributes
                 //					$attr = $this->productService->getAttribute($attribute);
                 //					$variation->addAttribute();
             }
             $variation->getAttribute($attribute)->setValue(trim(htmlspecialchars(strip_tags($value))));
         }
         if (isset($_POST['product']) && is_array($_POST['product'])) {
             // For now - always manage variation product stock
             $_POST['product']['stock']['manage'] = 'on';
             $_POST['product']['sales_enabled'] = $product->getSales()->isEnabled();
             $variation->getProduct()->restoreState($_POST['product']);
             $variation->getProduct()->markAsDirty($_POST['product']);
         }
         $this->wp->doAction('jigoshop\\admin\\product_variation\\save', $variation);
         $product->addVariation($variation);
         $this->productService->save($product);
         $this->wp->updatePostMeta($variation->getProduct()->getId(), 'type', $_POST['product']['type']);
         $types = array();
         foreach ($this->allowedSubtypes as $type) {
             /** @var $type Type */
             $types[$type->getId()] = $type->getName();
         }
         echo json_encode(array('success' => true, 'html' => Render::get('admin/product/box/variations/variation', array('variation' => $variation, 'attributes' => $product->getVariableAttributes(), 'allowedSubtypes' => $types))));
     } catch (Exception $e) {
         echo json_encode(array('success' => false, 'error' => $e->getMessage()));
     }
     exit;
 }
Ejemplo n.º 7
0
 /**
  * Saves attribute to database.
  *
  * @param Attribute $attribute Attribute to save.
  *
  * @return \Jigoshop\Entity\Product\Attribute Saved attribute.
  */
 public function saveAttribute(Attribute $attribute)
 {
     $wpdb = $this->wp->getWPDB();
     $data = array('label' => $attribute->getLabel(), 'slug' => $attribute->getSlug(), 'type' => $attribute->getType(), 'is_local' => $attribute->isLocal());
     if ($attribute->getId()) {
         $wpdb->update($wpdb->prefix . 'jigoshop_attribute', $data, array('id' => $attribute->getId()));
     } else {
         $wpdb->insert($wpdb->prefix . 'jigoshop_attribute', $data);
         $attribute->setId($wpdb->insert_id);
     }
     $this->wp->doAction('jigoshop\\attribute\\save', $attribute);
     $this->removeAllAttributesExcept($attribute->getId(), array_map(function ($item) {
         /** @var $item Attribute\Option */
         return $item->getId();
     }, $attribute->getOptions()));
     foreach ($attribute->getOptions() as $option) {
         /** @var $option Attribute\Option */
         $data = array('attribute_id' => $option->getAttribute()->getId(), 'label' => $option->getLabel(), 'value' => $option->getValue());
         if ($option->getId()) {
             $wpdb->update($wpdb->prefix . 'jigoshop_attribute_option', $data, array('id' => $option->getId()));
         } else {
             $wpdb->insert($wpdb->prefix . 'jigoshop_attribute_option', $data);
             $option->setId($wpdb->insert_id);
         }
     }
     return $attribute;
 }
Ejemplo n.º 8
0
 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;
     });
 }
Ejemplo n.º 9
0
 /**
  * Displays field according to definition.
  *
  * @param array $field Field parameters.
  *
  * @return string Field output to display.
  */
 public function displayField(array $field)
 {
     switch ($field['type']) {
         case 'user_defined':
             // Workaround for PHP pre-5.4
             echo call_user_func($field['display'], $field);
             break;
         case 'text':
             Forms::text($field);
             break;
         case 'number':
             Forms::number($field);
             break;
         case 'select':
             Forms::select($field);
             break;
         case 'checkbox':
             Forms::checkbox($field);
             break;
         case 'constant':
             Forms::constant($field);
             break;
         case 'textarea':
             Forms::textarea($field);
             break;
         default:
             $this->wp->doAction('jigoshop\\admin\\settings\\form_field\\' . $field['type'], $field);
     }
 }
Ejemplo n.º 10
0
 /**
  * Adds Jigoshop settings and system information menus (at the end of Jigoshop sub-menu).
  */
 public function afterMenu()
 {
     //		$this->wp->addSubmenuPage(self::MENU, $this->settings->getTitle(), $this->settings->getTitle(), $this->settings->getCapability(),
     //			$this->settings->getMenuSlug(), array($this->settings, 'display'));
     //		$this->wp->addSubmenuPage(self::MENU, $this->systemInfo->getTitle(), $this->systemInfo->getTitle(), $this->systemInfo->getCapability(),
     //			$this->systemInfo->getMenuSlug(), array($this->systemInfo, 'display'));
     $this->wp->doAction('jigoshop\\admin\\after_menu');
 }
Ejemplo n.º 11
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');
     }
 }
Ejemplo n.º 12
0
 /**
  * @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;
     }
 }
Ejemplo n.º 13
0
 public function __construct(Wordpress $wp, Options $options, Messages $messages, OrderServiceInterface $orderService, PaymentServiceInterface $paymentService)
 {
     $this->wp = $wp;
     $this->options = $options;
     $this->messages = $messages;
     $this->orderService = $orderService;
     $this->paymentService = $paymentService;
     Styles::add('jigoshop.checkout.pay', \JigoshopInit::getUrl() . '/assets/css/shop/checkout/pay.css', array('jigoshop.shop'));
     Scripts::add('jigoshop.checkout.pay', \JigoshopInit::getUrl() . '/assets/js/shop/checkout/pay.js', array('jquery', 'jigoshop.helpers.payment'));
     $wp->doAction('jigoshop\\checkout\\pay\\assets', $wp);
 }
Ejemplo n.º 14
0
 public function __construct(Wordpress $wp, Options $options, CouponServiceInterface $couponService)
 {
     $this->wp = $wp;
     $this->options = $options;
     $this->couponService = $couponService;
     $wp->addFilter(sprintf('manage_edit-%s_columns', Types::COUPON), array($this, 'columns'));
     $wp->addAction(sprintf('manage_%s_posts_custom_column', Types::COUPON), array($this, 'displayColumn'), 2);
     $wp->addAction('admin_enqueue_scripts', function () use($wp) {
         if ($wp->getPostType() == Types::COUPON) {
             $wp->doAction('jigoshop\\admin\\coupons\\assets', $wp);
         }
     });
 }
Ejemplo n.º 15
0
 public function __construct(Wordpress $wp, Options $options, Messages $messages, OrderServiceInterface $orderService)
 {
     $this->wp = $wp;
     $this->options = $options;
     $this->messages = $messages;
     $this->orderService = $orderService;
     Styles::add('jigoshop.shop');
     Styles::add('jigoshop.user.account', \JigoshopInit::getUrl() . '/assets/css/user/account.css');
     Styles::add('jigoshop.user.account.orders', \JigoshopInit::getUrl() . '/assets/css/user/account/orders.css', array('jigoshop.user.account'));
     Styles::add('jigoshop.user.account.orders.single', \JigoshopInit::getUrl() . '/assets/css/user/account/orders/single.css', array('jigoshop.user.account.orders'));
     $wp->doAction('jigoshop\\checkout\\thank_you\\assets', $wp);
     $wp->addAction('wp_head', array($this, 'googleAnalyticsTracking'), 9999);
 }
Ejemplo n.º 16
0
 /**
  * @param EntityInterface $object
  */
 private function restoreItemsStock(EntityInterface $object)
 {
     foreach ($object->getItems() as $item) {
         /** @var \Jigoshop\Entity\Order\Item $item */
         $product = $item->getProduct();
         if ($product instanceof Variable) {
             $product = $product->getVariation($item->getMeta('variation_id')->getValue())->getProduct();
         }
         if ($product->getStock()->getManage()) {
             $this->wp->doAction('jigoshop\\product\\restore', $product, $item->getQuantity(), $item);
         }
     }
 }
Ejemplo n.º 17
0
 /**
  * Action method to run tools.
  */
 public function action()
 {
     if (!isset($_GET['tool'])) {
         return;
     }
     $id = trim(htmlspecialchars(strip_tags($_GET['tool'])));
     if (isset($this->tools[$id])) {
         /** @var Tool $tool */
         $tool = $this->tools[$id];
         $this->wp->doAction('jigoshop\\migration\\before', $tool);
         $tool->migrate(null);
         $this->messages->addNotice(__('Migration complete', 'jigoshop'));
         $this->wp->wpRedirect($this->wp->adminUrl('admin.php?page=' . self::NAME));
     }
 }
Ejemplo n.º 18
0
 public function __construct(Wordpress $wp)
 {
     $this->wp = $wp;
     $wp->addAction(sprintf('%s_add_form_fields', Types::PRODUCT_CATEGORY), array($this, 'showThumbnail'));
     $wp->addAction(sprintf('%s_edit_form_fields', Types::PRODUCT_CATEGORY), array($this, 'showThumbnail'));
     $wp->addAction('created_term', array($this, 'saveThumbnail'), 10, 3);
     $wp->addAction('edit_term', array($this, 'saveThumbnail'), 10, 3);
     $wp->addAction(sprintf('delete_%s', Types::PRODUCT_CATEGORY), array($this, 'delete'));
     $wp->addAction('admin_enqueue_scripts', function () use($wp) {
         $wp->wpEnqueueMedia();
         Scripts::add('jigoshop.admin.product_categories', \JigoshopInit::getUrl() . '/assets/js/admin/product_categories.js', array('jquery', 'jigoshop.media'));
         Scripts::localize('jigoshop.admin.product_categories', 'jigoshop_admin_product_categories', array('category_name' => Types::PRODUCT_CATEGORY, 'placeholder' => \JigoshopInit::getUrl() . '/assets/images/placeholder.png'));
         $wp->doAction('jigoshop\\admin\\product_categories\\assets', $wp);
     });
 }
Ejemplo n.º 19
0
 /**
  * Saves entity to database.
  *
  * @param $object EntityInterface Entity to save.
  */
 public function save(EntityInterface $object)
 {
     if (!$object instanceof \Jigoshop\Entity\Email) {
         throw new Exception('Trying to save not an email!');
     }
     // TODO: Support for transactions!
     $fields = $object->getStateToSave();
     if (isset($fields['id']) || isset($fields['title']) || isset($fields['text'])) {
         // We do not need to save ID, title and text (content) as they are saved by WordPress itself.
         unset($fields['id'], $fields['title'], $fields['text']);
     }
     foreach ($fields as $field => $value) {
         $this->wp->updatePostMeta($object->getId(), $field, $value);
     }
     //
     //$this->addTemplate($object->getId(), $object->getActions());
     $this->wp->doAction('jigoshop\\service\\email\\save', $object);
 }
Ejemplo n.º 20
0
 public function __construct(Wordpress $wp, Options $options, Service $emailService)
 {
     $this->wp = $wp;
     $this->options = $options;
     $this->emailService = $emailService;
     add_action('wp_ajax_jigoshop.admin.email.update_variable_list', array($this, 'ajaxVariables'));
     $that = $this;
     $wp->addAction('add_meta_boxes_' . Types::EMAIL, function () use($wp, $that) {
         $wp->addMetaBox('jigoshop-email-data', __('Email Data', 'jigoshop'), array($that, 'box'), Types::EMAIL, 'normal', 'default');
         $wp->addMetaBox('jigoshop-email-variable', __('Email Variables', 'jigoshop'), array($that, 'variablesBox'), Types::EMAIL, 'normal', 'default');
     });
     $wp->addAction('admin_enqueue_scripts', function () use($wp) {
         if ($wp->getPostType() == Types::EMAIL) {
             Scripts::add('jigoshop.admin.email', \JigoshopInit::getUrl() . '/assets/js/admin/email.js', array('jquery', 'jigoshop.helpers'));
             $wp->doAction('jigoshop\\admin\\email\\assets', $wp);
         }
     });
 }
Ejemplo n.º 21
0
 public function __construct(Wordpress $wp, Options $options, Types\Product $type, ProductServiceInterface $productService)
 {
     $this->wp = $wp;
     $this->options = $options;
     $this->productService = $productService;
     $this->type = $type;
     $wp->addFilter(sprintf('manage_edit-%s_columns', Types::PRODUCT), array($this, 'columns'));
     $wp->addAction(sprintf('manage_%s_posts_custom_column', Types::PRODUCT), array($this, 'displayColumn'), 2);
     $wp->addAction('restrict_manage_posts', array($this, 'categoryFilter'));
     $wp->addAction('restrict_manage_posts', array($this, 'typeFilter'));
     $wp->addAction('pre_get_posts', array($this, 'setTypeFilter'));
     $wp->addAction('wp_ajax_jigoshop.admin.products.feature_product', array($this, 'ajaxFeatureProduct'));
     $wp->addAction('admin_enqueue_scripts', function () use($wp) {
         if ($wp->getPostType() == Types::PRODUCT) {
             Scripts::add('jigoshop.admin.products', \JigoshopInit::getUrl() . '/assets/js/admin/products.js', array('jquery', 'jigoshop.helpers'));
             Styles::add('jigoshop.admin.products_list', \JigoshopInit::getUrl() . '/assets/css/admin/products_list.css', array('jigoshop.admin'));
             $wp->doAction('jigoshop\\admin\\products\\assets', $wp);
         }
     });
 }
Ejemplo n.º 22
0
 private function getStateFromCheckout($state)
 {
     $state['customer_note'] = $_POST['jigoshop_order']['customer_note'];
     $state['billing_address'] = $_POST['jigoshop_order']['billing_address'];
     if ($_POST['jigoshop_order']['different_shipping_address'] == 'on') {
         $state['shipping_address'] = $_POST['jigoshop_order']['shipping_address'];
     } else {
         $state['shipping_address'] = $state['billing_address'];
     }
     if (isset($_POST['jigoshop_order']['payment_method'])) {
         $payment = $this->paymentService->get($_POST['jigoshop_order']['payment_method']);
         $this->wp->doAction('jigoshop\\service\\cart\\payment', $payment);
         $state['payment'] = $payment;
     }
     if (isset($_POST['jigoshop_order']['shipping_method'])) {
         $shipping = $this->shippingService->get($_POST['jigoshop_order']['shipping_method']);
         $this->wp->doAction('jigoshop\\service\\cart\\shipping', $shipping);
         $state['shipping'] = array('method' => $shipping, 'rate' => isset($_POST['jigoshop_order']['shipping_method_rate']) ? $_POST['jigoshop_order']['shipping_method_rate'] : null, 'price' => -1);
     }
     return $state;
 }
Ejemplo n.º 23
0
 /**
  * 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);
 }
Ejemplo n.º 24
0
 private function createUserAccount()
 {
     // Check if user agreed to account creation
     if (isset($_POST['jigoshop_account']) && $_POST['jigoshop_account']['create'] != 'on') {
         return;
     }
     $email = $_POST['jigoshop_order']['billing_address']['email'];
     $errors = new \WP_Error();
     $this->wp->doAction('register_post', $email, $email, $errors);
     if ($errors->get_error_code()) {
         throw new Exception($errors->get_error_message());
     }
     $login = $_POST['jigoshop_account']['login'];
     $password = $_POST['jigoshop_account']['password'];
     if (empty($login) || empty($password)) {
         throw new Exception(__('You need to fill username and password fields.', 'jigoshop'));
     }
     if ($password != $_POST['jigoshop_account']['password2']) {
         throw new Exception(__('Passwords do not match.', 'jigoshop'));
     }
     $id = $this->wp->wpCreateUser($login, $password, $email);
     if (!$id) {
         throw new Exception(sprintf(__("<strong>Error</strong> Couldn't register an account for you. Please contact the <a href=\"mailto:%s\">administrator</a>.", 'jigoshop'), $this->options->get('general.email')));
     }
     if (is_wp_error($id)) {
         throw new Exception(sprintf(__("<strong>Error</strong> Account creation failed: %s", 'jigoshop'), $id->get_error_message($id->get_error_code())));
     }
     $this->wp->wpUpdateUser(array('ID' => $id, 'role' => 'customer', 'first_name' => $_POST['jigoshop_order']['billing_address']['first_name'], 'last_name' => $_POST['jigoshop_order']['billing_address']['last_name']));
     $this->wp->doAction('jigoshop\\checkout\\created_account', $id);
     // send the user a confirmation and their login details
     if ($this->wp->applyFilters('jigoshop\\checkout\\new_user_notification', true, $id)) {
         $this->wp->wpNewUserNotification($id);
     }
     $this->wp->wpSetAuthCookie($id, true, $this->wp->isSsl());
     $cart = $this->cartService->getCurrent();
     $customer = $this->customerService->find($id);
     $customer->restoreState($cart->getCustomer()->getStateToSave());
     $cart->setCustomer($customer);
 }
Ejemplo n.º 25
0
 public function __construct(Wordpress $wp, Options $options, Service $couponService, PaymentServiceInterface $paymentService)
 {
     $this->wp = $wp;
     $this->options = $options;
     $this->couponService = $couponService;
     $this->paymentService = $paymentService;
     $that = $this;
     $wp->addAction('wp_ajax_jigoshop.admin.coupon.find_category', array($this, 'ajaxFindCategory'), 10, 0);
     $wp->addAction('add_meta_boxes_' . Types::COUPON, function () use($wp, $that) {
         $wp->addMetaBox('jigoshop-coupon-data', __('Coupon Data', 'jigoshop'), array($that, 'box'), Types::COUPON, 'normal', 'default');
     });
     $wp->addAction('admin_enqueue_scripts', function () use($wp) {
         if ($wp->getPostType() == Types::COUPON) {
             Styles::add('jigoshop.admin.coupon', \JigoshopInit::getUrl() . '/assets/css/admin/coupon.css', array('jigoshop.admin'));
             Scripts::add('jigoshop.admin.coupon', \JigoshopInit::getUrl() . '/assets/js/admin/coupon.js', array('jquery', 'jigoshop.admin', 'jigoshop.helpers.ajax_search'));
             Styles::add('jigoshop.vendors.select2', \JigoshopInit::getUrl() . '/assets/css/vendors/select2.css', array('jigoshop.admin.coupon'));
             Scripts::add('jigoshop.vendors.select2', \JigoshopInit::getUrl() . '/assets/js/vendors/select2.js', array('jigoshop.admin.coupon'), array('in_footer' => true));
             Styles::add('jigoshop.vendors.datepicker', \JigoshopInit::getUrl() . '/assets/css/vendors/datepicker.css', array('jigoshop.admin.coupon'));
             Scripts::add('jigoshop.vendors.datepicker', \JigoshopInit::getUrl() . '/assets/js/vendors/datepicker.js', array('jquery', 'jigoshop.admin.coupon'));
             $wp->doAction('jigoshop\\admin\\coupon\\assets', $wp);
         }
     });
 }
Ejemplo n.º 26
0
 public function ajaxSaveAttribute()
 {
     try {
         if (!isset($_POST['product_id']) || empty($_POST['product_id'])) {
             throw new Exception(__('Product was not specified.', 'jigoshop'));
         }
         if (!is_numeric($_POST['product_id'])) {
             throw new Exception(__('Invalid product ID.', 'jigoshop'));
         }
         if (!isset($_POST['attribute_id']) || empty($_POST['attribute_id'])) {
             throw new Exception(__('Attribute was not specified.', 'jigoshop'));
         }
         if (!is_numeric($_POST['attribute_id'])) {
             throw new Exception(__('Invalid attribute ID.', 'jigoshop'));
         }
         /** @var \Jigoshop\Entity\Product $product */
         $product = $this->productService->find((int) $_POST['product_id']);
         if (!$product->getId()) {
             throw new Exception(__('Product does not exists.', 'jigoshop'));
         }
         $id = (int) $_POST['attribute_id'];
         if ($product->hasAttribute($id)) {
             $attribute = $product->removeAttribute($id);
             $attributeExists = true;
         } else {
             if ($id == -1) {
                 $attribute = new Attribute\Custom();
                 $label = trim(strip_tags($_POST['attribute_label']));
                 if (empty($label)) {
                     throw new Exception(__('Custom attribute requires label to be set.', 'jigoshop'));
                 }
                 $attribute->setLabel($label);
                 $attribute->setSlug($this->wp->getHelpers()->sanitizeTitle($label));
                 $this->productService->saveAttribute($attribute);
                 $attributeExists = false;
             } else {
                 $attribute = $this->productService->getAttribute($id);
                 $attributeExists = false;
             }
         }
         if ($attribute === null) {
             throw new Exception(__('Attribute does not exists.', 'jigoshop'));
         }
         if (isset($_POST['value'])) {
             $attribute->setValue(trim(htmlspecialchars(wp_kses_post($_POST['value']))));
         } else {
             if ($attributeExists) {
                 throw new Exception(sprintf(__('Attribute "%s" already exists.', 'jigoshop'), $attribute->getLabel()));
             } else {
                 $attribute->setValue('');
             }
         }
         if (isset($_POST['options']) && isset($_POST['options']['display'])) {
             $attribute->setVisible($_POST['options']['display'] === 'true');
         }
         $this->wp->doAction('jigoshop\\admin\\product_attribute\\add', $attribute, $product);
         $product->addAttribute($attribute);
         $this->productService->save($product);
         echo json_encode(array('success' => true, 'html' => Render::get('admin/product/box/attributes/attribute', array('attribute' => $attribute))));
     } catch (Exception $e) {
         echo json_encode(array('success' => false, 'error' => $e->getMessage()));
     }
     exit;
 }
Ejemplo n.º 27
0
 public function __construct(Wordpress $wp)
 {
     $this->wp = $wp;
     $wp->doAction('jigoshop\\email\\type\\init', $wp);
 }
Ejemplo n.º 28
0
 public function processResponse()
 {
     if (isset($_GET['file'])) {
         try {
             $data = explode('.', $_GET['file']);
             if (count($data) != 3) {
                 throw new Exception(__('Invalid download key. Unable to download file.', 'jigoshop'));
             }
             list($key, $id, $itemKey) = $data;
             $order = $this->orderService->find((int) $id);
             /** @var $order Order */
             if ($order->getKey() !== $key) {
                 throw new Exception(__('Invalid security key. Unable to download file.', 'jigoshop'));
             }
             if (!in_array($order->getStatus(), array(Order\Status::COMPLETED, Order\Status::PROCESSING))) {
                 throw new Exception(__('Invalid order.', 'jigoshop'));
             }
             $item = $order->getItem($itemKey);
             if ($item === null) {
                 throw new Exception(__('Product not found.', 'jigoshop'));
             }
             if ($item->getType() !== Downloadable::TYPE) {
                 throw new Exception(__('Invalid file to download.', 'jigoshop'));
             }
             $downloads = $item->getMeta('downloads')->getValue();
             if (!empty($downloads) && $downloads == 0) {
                 throw new Exception(__('Sorry, you have reached your download limit for this file.', 'jigoshop'));
             }
             if ($this->options->get('shopping.login_for_downloads')) {
                 if (!$this->wp->isUserLoggedIn()) {
                     throw new Exception(__('You have to log in before you can download a file.', 'jigoshop'));
                 } else {
                     if ($order->getCustomer()->getId() != $this->wp->getCurrentUserId()) {
                         throw new Exception(__('This is not your download link.', 'jigoshop'));
                     }
                 }
             }
             $file = $item->getMeta('file')->getValue();
             if (!$file) {
                 throw new Exception(__('File not found.', 'jigoshop'));
             }
             if (!empty($downloads)) {
                 $item->getMeta('downloads')->setValue($downloads - 1);
                 $this->orderService->saveItemMeta($item, $item->getMeta('downloads'));
             }
             if (!$this->wp->isMultisite()) {
                 $site_url = $this->wp->siteUrl();
                 $site_url = str_replace('https:', 'http:', $site_url);
                 $file = str_replace($this->wp->getHelpers()->trailingslashit($site_url), ABSPATH, $file);
             } else {
                 $network_url = $this->wp->networkAdminUrl();
                 $network_url = str_replace('https:', 'http:', $network_url);
                 $upload_dir = $this->wp->wpUploadDir();
                 // Try to replace network url
                 $file = str_replace($this->wp->getHelpers()->trailingslashit($network_url), ABSPATH, $file);
                 // Now try to replace upload URL
                 $file = str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $file);
             }
             $file = $this->wp->applyFilters('jigoshop\\downloadable\\file_path', $file, $itemKey, $order);
             // See if its local or remote
             if (strstr($file, 'http:') || strstr($file, 'https:') || strstr($file, 'ftp:')) {
                 $isRemote = true;
             } else {
                 $isRemote = false;
                 $file = realpath($file);
             }
             // Download the file
             $extension = strtolower(substr(strrchr($file, '.'), 1));
             switch ($extension) {
                 case 'pdf':
                     $type = 'application/pdf';
                     break;
                 case 'exe':
                     $type = 'application/octet-stream';
                     break;
                 case 'zip':
                     $type = 'application/zip';
                     break;
                 case 'doc':
                     $type = 'application/msword';
                     break;
                 case 'xls':
                     $type = 'application/vnd.ms-excel';
                     break;
                 case 'ppt':
                     $type = 'application/vnd.ms-powerpoint';
                     break;
                 case 'gif':
                     $type = 'image/gif';
                     break;
                 case 'png':
                     $type = 'image/png';
                     break;
                 case 'jpe':
                 case 'jpeg':
                 case 'jpg':
                     $type = 'image/jpg';
                     break;
                 default:
                     $type = 'application/force-download';
             }
             $this->wp->doAction('jigoshop\\downloadable\\before_download', $file, $order);
             @session_write_close();
             @set_time_limit(0);
             @ob_end_clean();
             // required for IE, otherwise Content-Disposition may be ignored
             if (ini_get('zlib.output_compression')) {
                 ini_set('zlib.output_compression', 'Off');
             }
             header('Pragma: no-cache');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Robots: none');
             header('Content-Type: ' . $type);
             header('Content-Description: File Transfer');
             header('Content-Transfer-Encoding: binary');
             if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
                 // workaround for IE filename bug with multiple periods / multiple dots in filename
                 header('Content-Disposition: attachment; filename="' . preg_replace('/\\./', '%2e', basename($file), substr_count(basename($file), '.') - 1) . '";');
             } else {
                 header('Content-Disposition: attachment; filename="' . basename($file) . '";');
             }
             if ($isRemote) {
                 header('Location: ' . $file);
             } else {
                 if (file_exists($file)) {
                     header('Content-Length: ' . filesize($file));
                     readfile($file);
                 } else {
                     throw new Exception(__('File not found.', 'jigoshop'));
                 }
             }
         } catch (Exception $e) {
             $this->messages->addError($e->getMessage());
             $this->wp->redirectTo($this->options->getPageId(Pages::SHOP));
         }
         exit;
     }
 }