Exemple #1
0
 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));
 }
Exemple #2
0
 public function displayColumn($column)
 {
     $post = $this->wp->getGlobalPost();
     if ($post === null) {
         return;
     }
     /** @var Entity $order */
     $order = $this->orderService->findForPost($post);
     switch ($column) {
         case 'status':
             OrderHelper::renderStatus($order);
             break;
         case 'customer':
             echo OrderHelper::getUserLink($order->getCustomer());
             break;
         case 'billing_address':
             Render::output('admin/orders/billingAddress', array('order' => $order));
             break;
         case 'shipping_address':
             Render::output('admin/orders/shippingAddress', array('order' => $order));
             break;
         case 'shipping_payment':
             Render::output('admin/orders/shippingPayment', array('order' => $order));
             break;
         case 'total':
             Render::output('admin/orders/totals', array('order' => $order, 'getTaxLabel' => function ($taxClass) use($order) {
                 return Tax::getLabel($taxClass, $order);
             }));
             break;
         case 'products':
             $wpdb = $this->wp->getWPDB();
             $products = $wpdb->get_results("SELECT product_id, title FROM " . $wpdb->prefix . "jigoshop_order_item WHERE order_id = " . $order->getId());
             Render::output('admin/orders/products', array('products' => $products));
             break;
     }
 }
Exemple #3
0
 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);
     }));
 }
Exemple #4
0
 /**
  * Abstraction for cart update response.
  * Prepares and returns response array for cart update requests.
  *
  * @param \Jigoshop\Entity\Cart $cart Current cart.
  *
  * @return array
  */
 private function getAjaxCartResponse(\Jigoshop\Entity\Cart $cart)
 {
     $tax = array();
     foreach ($cart->getCombinedTax() as $class => $value) {
         $tax[$class] = array('label' => Tax::getLabel($class, $cart), 'value' => Product::formatPrice($value));
     }
     $shipping = array();
     $shippingHtml = array();
     foreach ($this->shippingService->getAvailable() as $method) {
         /** @var $method Method */
         if ($method instanceof MultipleMethod) {
             /** @var $method MultipleMethod */
             foreach ($method->getRates($cart) as $rate) {
                 /** @var $rate Rate */
                 $shipping[$method->getId() . '-' . $rate->getId()] = $method->isEnabled() ? $rate->calculate($cart) : -1;
                 if ($method->isEnabled()) {
                     $shippingHtml[$method->getId() . '-' . $rate->getId()] = array('price' => Product::formatPrice($rate->calculate($cart)), 'html' => Render::get('shop/cart/shipping/rate', array('method' => $method, 'rate' => $rate, 'cart' => $cart)));
                 }
             }
         } else {
             $shipping[$method->getId()] = $method->isEnabled() ? $method->calculate($cart) : -1;
             if ($method->isEnabled()) {
                 $shippingHtml[$method->getId()] = array('price' => Product::formatPrice($cart->getShippingPrice()), 'html' => Render::get('shop/cart/shipping/method', array('method' => $method, 'cart' => $cart)));
             }
         }
     }
     $shippingMethod = $cart->getShippingMethod();
     if ($shippingMethod) {
         try {
             $cart->setShippingMethod($shippingMethod);
         } catch (Exception $e) {
             $cart->removeShippingMethod();
         }
     }
     $productSubtotal = $this->options->get('tax.price_tax') == 'with_tax' ? $cart->getProductSubtotal() + $cart->getTotalTax() : $cart->getProductSubtotal();
     $coupons = join(',', array_map(function ($coupon) {
         /** @var $coupon Coupon */
         return $coupon->getCode();
     }, $cart->getCoupons()));
     $response = array('success' => true, 'shipping' => $shipping, 'subtotal' => $cart->getSubtotal(), 'product_subtotal' => $productSubtotal, 'discount' => $cart->getDiscount(), 'coupons' => $coupons, 'tax' => $cart->getCombinedTax(), 'total' => $cart->getTotal(), 'html' => array('shipping' => $shippingHtml, 'discount' => Product::formatPrice($cart->getDiscount()), 'subtotal' => Product::formatPrice($cart->getSubtotal()), 'product_subtotal' => Product::formatPrice($productSubtotal), 'tax' => $tax, 'total' => Product::formatPrice($cart->getTotal())));
     return $response;
 }
Exemple #5
0
 /**
  * Abstraction for cart update response.
  *
  * Prepares and returns response array for cart update requests.
  *
  * @param CartEntity $cart Current cart.
  *
  * @return array
  */
 private function getAjaxCartResponse(CartEntity $cart)
 {
     $tax = array();
     foreach ($cart->getCombinedTax() as $class => $value) {
         $tax[$class] = array('label' => Tax::getLabel($class, $cart), 'value' => ProductHelper::formatPrice($value));
     }
     $shipping = array();
     $shippingHtml = array();
     foreach ($this->shippingService->getAvailable() as $method) {
         /** @var $method Method */
         if ($method instanceof MultipleMethod) {
             /** @var $method MultipleMethod */
             foreach ($method->getRates($cart) as $rate) {
                 /** @var $rate Rate */
                 $shipping[$method->getId() . '-' . $rate->getId()] = $method->isEnabled() ? $rate->calculate($cart) : -1;
                 if ($method->isEnabled()) {
                     $shippingHtml[$method->getId() . '-' . $rate->getId()] = array('price' => ProductHelper::formatPrice($rate->calculate($cart)), 'html' => Render::get('shop/cart/shipping/rate', array('method' => $method, 'rate' => $rate, 'cart' => $cart)));
                 }
             }
         } else {
             $shipping[$method->getId()] = $method->isEnabled() ? $method->calculate($cart) : -1;
             if ($method->isEnabled()) {
                 $shippingHtml[$method->getId()] = array('price' => ProductHelper::formatPrice($method->calculate($cart)), 'html' => Render::get('shop/cart/shipping/method', array('method' => $method, 'cart' => $cart)));
             }
         }
     }
     $response = array('success' => true, 'shipping' => $shipping, 'subtotal' => $cart->getSubtotal(), 'product_subtotal' => $cart->getProductSubtotal(), 'tax' => $cart->getCombinedTax(), 'total' => $cart->getTotal(), 'html' => array('shipping' => $shippingHtml, 'subtotal' => ProductHelper::formatPrice($cart->getSubtotal()), 'product_subtotal' => ProductHelper::formatPrice($cart->getProductSubtotal()), 'tax' => $tax, 'total' => ProductHelper::formatPrice($cart->getTotal())));
     return $response;
 }
Exemple #6
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);
 }
Exemple #7
0
				</tr>
			<?php 
do_action('jigoshop\\template\\shop\\checkout\\before_tax');
?>
				<?php 
foreach ($cart->getCombinedTax() as $taxClass => $tax) {
    ?>
					<tr id="tax-<?php 
    echo $taxClass;
    ?>
"<?php 
    $tax == 0 and print ' style="display: none;"';
    ?>
>
						<th scope="row"><?php 
    echo Tax::getLabel($taxClass, $cart);
    ?>
</th>
						<td><?php 
    echo Product::formatPrice($tax);
    ?>
</td>
					</tr>
				<?php 
}
?>
				<tr id="cart-discount"<?php 
$cart->getDiscount() == 0 and print ' class="not-active"';
?>
>
					<th scope="row"><?php 
Exemple #8
0
 public function render()
 {
     /** @var Order $order */
     $order = $this->orderService->find((int) $this->wp->getQueryParameter('pay'));
     $render = $this->wp->applyFilters('jigoshop\\pay\\render', '', $order);
     if (!empty($render)) {
         return Render::get('shop/checkout/payment', array('messages' => $this->messages, 'content' => $render, 'order' => $order));
     }
     $termsUrl = '';
     $termsPage = $this->options->get('advanced.pages.terms');
     if ($termsPage > 0) {
         $termsUrl = $this->wp->getPageLink($termsPage);
     }
     $accountUrl = $this->wp->getPermalink($this->options->getPageId(Pages::ACCOUNT));
     return Render::get('shop/checkout/pay', array('messages' => $this->messages, 'order' => $order, 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'termsUrl' => $termsUrl, 'myAccountUrl' => $accountUrl, 'myOrdersUrl' => Api::getEndpointUrl('orders', '', $accountUrl), 'paymentMethods' => $this->paymentService->getEnabled(), 'getTaxLabel' => function ($taxClass) use($order) {
         return Tax::getLabel($taxClass, $order);
     }));
 }
Exemple #9
0
 /**
  * @param $order OrderInterface Order to get taxes for.
  *
  * @return array Taxes with labels array.
  */
 private function getTaxes($order)
 {
     $result = array();
     foreach ($order->getCombinedTax() as $class => $value) {
         $result[$class] = array('label' => Tax::getLabel($class, $order), 'value' => ProductHelper::formatPrice($value));
     }
     return $result;
 }