Example #1
0
 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)));
 }
Example #2
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));
 }
Example #3
0
 /**
  * Display the widget in the sidebar.
  *
  * @param array $args     Sidebar arguments.
  * @param array $instance The instance.
  *
  * @return bool|void
  */
 public function widget($args, $instance)
 {
     $accountUrl = get_permalink(self::$options->getPageId(Pages::ACCOUNT));
     if (is_user_logged_in()) {
         global $current_user;
         $title = !empty($instance['title_user']) ? $instance['title_user'] : __('Hey %s!', 'jigoshop');
         $links = apply_filters('jigoshop_widget_logout_user_links', array(__('My Account', 'jigoshop') => $accountUrl, __('My Orders', 'jigoshop') => Api::getEndpointUrl('orders', '', $accountUrl), __('Change Password', 'jigoshop') => Api::getEndpointUrl('change-password', '', $accountUrl), __('Logout', 'jigoshop') => wp_logout_url(home_url())));
         /** @noinspection PhpUndefinedFieldInspection */
         Render::output('widget/user_login/logged_in', array_merge($args, array('title' => sprintf($title, ucwords($current_user->display_name)), 'links' => $links)));
     } else {
         // Print title
         $title = $instance['title_guest'] ? $instance['title_guest'] : __('Login', 'jigoshop');
         $links = apply_filters('jigoshop_widget_login_user_links', array());
         $url = apply_filters('jigoshop_widget_login_redirect', $accountUrl);
         $loginUrl = wp_login_url($url);
         $passwordUrl = wp_lostpassword_url($url);
         // TODO: Support for other widgets
         //			$fields = array();
         //			// Support for other plugins which uses GET parameters
         //			$fields = apply_filters('jigoshop_get_hidden_fields', $fields);
         Render::output('widget/user_login/log_in', array_merge($args, array('title' => $title, 'links' => $links, 'loginUrl' => $loginUrl, 'passwordUrl' => $passwordUrl)));
     }
 }
Example #4
0
 /**
  * @param Order $order Order to process payment for.
  *
  * @return bool Is processing successful?
  */
 public function process($order)
 {
     if ($this->settings['test_mode']) {
         $url = self::TEST_URL . '&';
     } else {
         $url = self::LIVE_URL . '?';
     }
     $billingAddress = $order->getCustomer()->getBillingAddress();
     if (in_array($billingAddress->getCountry(), array('US', 'CA'))) {
         $phone = str_replace(array('(', '-', ' ', ')'), '', $billingAddress->getPhone());
         $phone = array('night_phone_a' => substr($phone, 0, 3), 'night_phone_b' => substr($phone, 3, 3), 'night_phone_c' => substr($phone, 6, 4), 'day_phone_a' => substr($phone, 0, 3), 'day_phone_b' => substr($phone, 3, 3), 'day_phone_c' => substr($phone, 6, 4));
     } else {
         $phone = array('night_phone_b' => $billingAddress->getPhone(), 'day_phone_b' => $billingAddress->getPhone());
     }
     $args = array_merge(array('cmd' => '_cart', 'business' => $this->settings['test_mode'] ? $this->settings['test_email'] : $this->settings['email'], 'no_note' => 1, 'currency_code' => Currency::code(), 'charset' => 'UTF-8', 'rm' => 2, 'upload' => 1, 'return' => OrderHelper::getThankYouLink($order), 'cancel_return' => OrderHelper::getCancelLink($order), 'custom' => $order->getId(), 'notify_url' => Api::getUrl(self::ID), 'first_name' => $billingAddress->getFirstName(), 'last_name' => $billingAddress->getLastName(), 'company' => $billingAddress instanceof CompanyAddress ? $billingAddress->getCompany() : '', 'address1' => $billingAddress->getAddress(), 'address2' => '', 'city' => $billingAddress->getCity(), 'state' => $billingAddress->getState(), 'zip' => $billingAddress->getPostcode(), 'country' => $billingAddress->getCountry(), 'email' => $billingAddress->getEmail(), 'invoice' => $order->getNumber(), 'amount' => number_format($order->getTotal(), $this->options->get('general.currency_decimals')), 'bn' => 'Jigoshop_SP'), $phone);
     if ($this->settings['send_shipping']) {
         $shippingAddress = $order->getCustomer()->getShippingAddress();
         $args['no_shipping'] = 1;
         $args['address_override'] = 1;
         $args['first_name'] = $shippingAddress->getFirstName();
         $args['last_name'] = $shippingAddress->getLastName();
         $args['address1'] = $shippingAddress->getAddress();
         $args['address2'] = '';
         $args['city'] = $shippingAddress->getCity();
         $args['state'] = $shippingAddress->getState();
         $args['zip'] = $shippingAddress->getPostcode();
         $args['country'] = $shippingAddress->getCountry();
         // PayPal counts Puerto Rico as a US Territory, won't allow payment without it
         if ($args['country'] == 'PR') {
             $args['country'] = 'US';
             $args['state'] = 'PR';
         }
     } else {
         $args['no_shipping'] = 1;
         $args['address_override'] = 0;
     }
     // If prices include tax, send the whole order as a single item
     // TODO: Price includes tax
     //		$priceIncludesTax = $this->options->get('tax.included');
     //		if($priceIncludesTax){
     //			// Discount
     //			//$args['discount_amount_cart'] = number_format($order->getDiscount(), $this->decimals);
     //
     //			// Don't pass items - PayPal breaks tax due to catalog prices include tax.
     //			// PayPal has no option for tax inclusive pricing.
     //			// Pass 1 item for the order items overall
     //			$item_names = array();
     //
     //			foreach($order->items as $item){
     //				$_product = $order->get_product_from_item($item);
     //				$title = $_product->get_title();
     //
     //				//if variation, insert variation details into product title
     //				if($_product instanceof jigoshop_product_variation){
     //					$title .= ' ('.jigoshop_get_formatted_variation($_product, $item['variation'], true).')';
     //				}
     //
     //				$item_names[] = $title.' x '.$item['qty'];
     //			}
     //
     //			$args['item_name_1'] = sprintf(__('Order %s', 'jigoshop'), $order->get_order_number()).' - '.implode(', ', $item_names);
     //			$args['quantity_1'] = 1;
     //			$args['amount_1'] = number_format($order->order_total - $order->order_shipping - $order->order_shipping_tax + $order->order_discount, $this->decimals, '.', '');
     //
     //			if(($order->order_shipping + $order->order_shipping_tax) > 0){
     //				$args['item_name_2'] = __('Shipping cost', 'jigoshop');
     //				$args['quantity_2'] = '1';
     //				$args['amount_2'] = number_format($order->order_shipping + $order->order_shipping_tax, $this->decimals, '.', '');
     //			}
     //		} else {
     // Cart Contents
     $item_loop = 0;
     foreach ($order->getItems() as $item) {
         /** @var $item Order\Item */
         $item_loop++;
         $product = $item->getProduct();
         $title = $product->getName();
         //if variation, insert variation details into product title
         if ($product instanceof Product\Variable) {
             $title .= '(' . join(', ', array_filter(array_map(function ($attribute) use($item) {
                 /** @var $attribute Product\Variable\Attribute */
                 if ($attribute->getValue() !== '') {
                     $value = $attribute->getValue();
                 } else {
                     $value = $item->getMeta($attribute->getAttribute()->getSlug())->getValue();
                 }
                 return sprintf(_x('%s: %s', 'product_variation', 'jigoshop'), $attribute->getAttribute()->getLabel(), $attribute->getAttribute()->getOption($value)->getLabel());
             }, $product->getVariation($item->getMeta('variation_id')->getValue())->getAttributes()))) . ')';
         }
         $args['item_name_' . $item_loop] = $title;
         $args['quantity_' . $item_loop] = $item->getQuantity();
         // Apparently, PayPal did not like "28.4525" as the amount. Changing that to "28.45" fixed the issue.
         $args['amount_' . $item_loop] = number_format($this->wp->applyFilters('jigoshop\\paypal\\item_price', $item->getPrice(), $item), $this->decimals);
     }
     // Shipping Cost
     if ($this->options->get('shipping.enabled') && $order->getShippingPrice() > 0) {
         $item_loop++;
         $args['item_name_' . $item_loop] = __('Shipping cost', 'jigoshop');
         $args['quantity_' . $item_loop] = '1';
         $args['amount_' . $item_loop] = number_format($order->getShippingPrice(), $this->decimals);
     }
     $args['tax'] = $args['tax_cart'] = number_format($order->getTotalCombinedTax(), $this->decimals);
     $args['discount_amount_cart'] = number_format($order->getDiscount(), $this->decimals);
     if ($this->settings['force_payment'] && $order->getTotal() == 0) {
         $item_loop++;
         $args['item_name_' . $item_loop] = __('Force payment on free orders', 'jigoshop');
         $args['quantity_' . $item_loop] = '1';
         $args['amount_' . $item_loop] = 0.01;
     }
     //		}
     $args = $this->wp->applyFilters('jigoshop\\paypal\\args', $args);
     $order->setStatus(Order\Status::PENDING, __('Waiting for PayPal payment.', 'jigoshop'));
     return $url . http_build_query($args);
 }
Example #5
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);
     }));
 }
Example #6
0
    ?>
					<?php 
    if ($unpaid) {
        ?>
						<a href="<?php 
        echo Order::getPayLink($order);
        ?>
" class="btn btn-success pull-right"><?php 
        _e('Pay', 'jigoshop');
        ?>
</a>
					<?php 
    }
    ?>
					<a href="<?php 
    echo Api::getEndpointUrl('orders', $order->getId());
    ?>
" class="btn btn-primary pull-right"><?php 
    _e('View', 'jigoshop');
    ?>
</span></a>
				</h4>
				<dl class="dl-horizontal list-group-item-text">
					<dt><?php 
    _e('Date', 'jigoshop');
    ?>
</dt>
					<dd><?php 
    echo $order->getCreatedAt()->format(_x('d.m.Y, H:i', 'account', 'jigoshop'));
    ?>
</dd>
Example #7
0
 /**
  * @param $result string Current email message.
  * @param $item   Order\Item Item to display.
  * @param $order  Order Order being displayed.
  *
  * @return string
  */
 public function emailLink($result, $item, $order)
 {
     $product = $item->getProduct();
     if ($product instanceof Product\Downloadable && in_array($order->getStatus(), array(Order\Status::COMPLETED, Order\Status::PROCESSING))) {
         $url = $this->wp->getHelpers()->addQueryArg(array('file' => $order->getKey() . '.' . $order->getId() . '.' . $item->getKey(), Api::getUrl(DownloadFile::NAME)));
         $result .= PHP_EOL . __('Your download link for this file is:', 'jigoshop');
         $result .= PHP_EOL . ' - ' . $url;
     }
     return $result;
 }
Example #8
0
 /**
  * @param $order \Jigoshop\Entity\Order Order to generate link for.
  *
  * @return string Payment link.
  */
 public static function getPayLink($order)
 {
     $args = array('key' => $order->getKey());
     $url = add_query_arg($args, Api::getEndpointUrl('pay', $order->getId(), get_permalink(self::$options->getPageId(Pages::CHECKOUT))));
     return apply_filters('jigoshop\\helper\\order\\pay_url', $url);
 }