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 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)))); }
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)); }
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))); }
public function render() { if (!$this->wp->isUserLoggedIn()) { return Render::get('user/login', array()); } $order = $this->wp->getQueryParameter('orders'); $accountUrl = $this->wp->getPermalink($this->options->getPageId(Pages::ACCOUNT)); if (!empty($order) && is_numeric($order)) { $order = $this->orderService->find($order); /** @var Entity $order */ return Render::get('user/account/orders/single', array('messages' => $this->messages, 'order' => $order, 'myAccountUrl' => $accountUrl, 'listUrl' => Api::getEndpointUrl('orders', '', $accountUrl), 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'getTaxLabel' => function ($taxClass) use($order) { return Tax::getLabel($taxClass, $order); })); } $customer = $this->customerService->getCurrent(); $orders = $this->orderService->findForUser($customer->getId()); return Render::get('user/account/orders', array('messages' => $this->messages, 'customer' => $customer, 'orders' => $orders, 'myAccountUrl' => $accountUrl)); }
/** * Displays the product data box, tabbed, with several panels covering price, stock etc * * @since 1.0 */ public function ajaxVariables() { try { /** @var \Jigoshop\Entity\Email $email */ $email = $this->emailService->find((int) $_POST['email']); if ($email->getId() === null) { throw new Exception(__('Email not found.', 'jigoshop')); } $availableActions = $this->emailService->getAvailableActions(); $actions = array_intersect($_POST['actions'], $availableActions); $email->setActions($actions); $result = array('success' => true, 'html' => Render::get('admin/email/variables', array('email' => $email, 'emails' => $this->emailService->getMails()))); } catch (Exception $e) { $result = array('success' => false, 'error' => $e->getMessage()); } echo json_encode($result); exit; }
public function render() { $cart = $this->cartService->getCurrent(); $content = $this->wp->getPostField('post_content', $this->options->getPageId(Pages::CART)); $content = do_shortcode($content); $termsUrl = ''; $termsPage = $this->options->get('advanced.pages.terms'); if ($termsPage > 0) { $termsUrl = $this->wp->getPermalink($termsPage); } return Render::get('shop/cart', array('content' => $content, 'cart' => $cart, 'messages' => $this->messages, 'productService' => $this->productService, 'customer' => $this->customerService->getCurrent(), 'shippingMethods' => $this->shippingService->getEnabled(), 'shopUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::SHOP)), 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'showShippingCalculator' => $this->options->get('shipping.calculator'), 'termsUrl' => $termsUrl)); }
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())); }
/** * Renders page template. * * @return string Page template. */ public function render() { $content = $this->wp->getPostField('post_content', $this->options->getPageId(Pages::CHECKOUT)); $content = do_shortcode($content); $cart = $this->cartService->getCurrent(); $billingFields = $this->getBillingFields($cart->getCustomer()->getBillingAddress()); $shippingFields = $this->getShippingFields($cart->getCustomer()->getShippingAddress()); $termsUrl = ''; $termsPage = $this->options->get('advanced.pages.terms'); if ($termsPage > 0) { $termsUrl = $this->wp->getPageLink($termsPage); } $verificationMessage = $this->options->get('shopping.enable_verification_message') ? $this->options->get('shopping.verification_message') : ''; return Render::get('shop/checkout', array('cartUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::CART)), 'content' => $content, 'cart' => $cart, 'messages' => $this->messages, 'shippingMethods' => $this->shippingService->getEnabled(), 'paymentMethods' => $this->paymentService->getEnabled(), 'billingFields' => $billingFields, 'shippingFields' => $shippingFields, 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'showLoginForm' => $this->options->get('shopping.show_login_form') && !$this->wp->isUserLoggedIn(), 'allowRegistration' => $this->options->get('shopping.allow_registration') && !$this->wp->isUserLoggedIn(), 'showRegistrationForm' => $this->options->get('shopping.allow_registration') && !$this->options->get('shopping.guest_purchases') && !$this->wp->isUserLoggedIn(), 'alwaysShowShipping' => $this->options->get('shipping.always_show_shipping'), 'verificationMessage' => $verificationMessage, 'differentShipping' => isset($_POST['jigoshop_order']) ? $_POST['jigoshop_order']['different_shipping_address'] == 'on' : false, 'termsUrl' => $termsUrl, 'defaultGateway' => $this->options->get('payment.default_gateway'))); }
?> <?php foreach ($values as $i => $keyData) { ?> <?php \Jigoshop\Helper\Render::output('admin/settings/api_keys/key', array('index' => $i, 'name' => $name, 'userId' => $keyData['user_id'], 'key' => $keyData['key'], 'permissions' => $keyData['permissions'], 'availablePermissions' => $availablePermissions, 'active' => false)); ?> <?php } ?> <?php } else { ?> <?php \Jigoshop\Helper\Render::output('admin/settings/api_keys/key', array('index' => 0, 'name' => $name, 'userId' => '', 'key' => '', 'permissions' => array(), 'availablePermissions' => $availablePermissions, 'active' => true)); ?> <?php } ?> </ul> <a href="#" class="add-key btn btn-default pull-right"><?php _e('Add key', 'jigoshop'); ?> </a> </div> </div> <script type="text/template" id="tmpl-api-key"> <?php echo preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', '', \Jigoshop\Helper\Render::get('admin/settings/api_keys/key', array('index' => '{{{ data.id }}}', 'name' => $name, 'userId' => '', 'key' => '', 'permissions' => array(), 'availablePermissions' => $availablePermissions, 'active' => true))); ?> </script>
public function render() { if (!$this->wp->isUserLoggedIn()) { return Render::get('user/login', array()); } $customer = $this->customerService->getCurrent(); switch ($this->wp->getQueryParameter('edit-address')) { case 'shipping': $address = $customer->getShippingAddress(); break; case 'billing': default: $address = $customer->getBillingAddress(); break; } return Render::get('user/account/edit_address', array('messages' => $this->messages, 'customer' => $customer, 'address' => $address, 'myAccountUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::ACCOUNT)))); }
public function render() { $post = $this->wp->getGlobalPost(); $product = $this->productService->findForPost($post); return Render::get('shop/product', array('product' => $product, 'messages' => $this->messages)); }
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; }
/** * @param Entity\Product\Variable\Variation $variation Variation to format. * @param Entity\Order\Item $item Order item. * * @return string Formatted variation data in HTML. */ public static function getVariation(Entity\Product\Variable\Variation $variation, Entity\Order\Item $item) { return Render::get('helper/product/variation', array('variation' => $variation, 'item' => $item)); }
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 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); })); }
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; }
public function render() { $content = $this->wp->getPostField('post_content', $this->options->getPageId(Pages::THANK_YOU)); /** @var Order $order */ $order = $this->orderService->find((int) $_REQUEST['order']); if ($order->getKey() != $_REQUEST['key']) { $this->messages->addError(__('Invalid security key. The order was processed.', 'jigoshop')); $this->wp->redirectTo($this->options->getPageId(Pages::SHOP)); } return Render::get('shop/checkout/thanks', array('content' => $content, 'messages' => $this->messages, 'order' => $order, 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'shopUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::SHOP)), 'cancelUrl' => \Jigoshop\Helper\Order::getCancelLink($order), 'getTaxLabel' => function ($taxClass) use($order) { return Tax::getLabel($taxClass, $order); })); }
/** * @param $order OrderInterface Order to get values from. * * @return array Ajax response array. */ private function getAjaxResponse($order) { $tax = $order->getTax(); $shippingTax = $order->getShippingTax(); foreach ($order->getTax() as $class => $value) { if (isset($shippingTax[$class])) { $tax[$class] = $value + $shippingTax[$class]; } } $shipping = array(); $shippingHtml = array(); foreach ($this->shippingService->getAvailable() as $method) { /** @var $method Shipping\Method */ if ($method instanceof Shipping\MultipleMethod) { /** @var $method Shipping\MultipleMethod */ foreach ($method->getRates($order) as $rate) { /** @var $rate Shipping\Rate */ $shipping[$method->getId() . '-' . $rate->getId()] = $method->isEnabled() ? $rate->calculate($order) : -1; if ($method->isEnabled()) { $shippingHtml[$method->getId() . '-' . $rate->getId()] = array('price' => ProductHelper::formatPrice($rate->calculate($order)), 'html' => Render::get('admin/order/totals/shipping/rate', array('method' => $method, 'rate' => $rate, 'order' => $order))); } } } else { $shipping[$method->getId()] = $method->isEnabled() ? $method->calculate($order) : -1; if ($method->isEnabled()) { $shippingHtml[$method->getId()] = array('price' => ProductHelper::formatPrice($method->calculate($order)), 'html' => Render::get('admin/order/totals/shipping/method', array('method' => $method, 'order' => $order))); } } } return array('success' => true, 'shipping' => $shipping, 'product_subtotal' => $order->getProductSubtotal(), 'subtotal' => $order->getSubtotal(), 'total' => $order->getTotal(), 'tax' => $tax, 'html' => array('shipping' => $shippingHtml, 'product_subtotal' => ProductHelper::formatPrice($order->getProductSubtotal()), 'subtotal' => ProductHelper::formatPrice($order->getSubtotal()), 'total' => ProductHelper::formatPrice($order->getTotal()), 'tax' => $this->getTaxes($order))); }