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
 private function generateCartId()
 {
     if ($this->wp->getCurrentUserId() > 0) {
         $id = $this->wp->getCurrentUserId();
     } elseif ($this->session->getField(self::CART_ID)) {
         $id = $this->session->getField(self::CART_ID);
     } elseif (isset($_COOKIE[self::CART_ID])) {
         $id = $_COOKIE[self::CART_ID];
     } else {
         $id = md5((isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '') . time() . $_SERVER['REMOTE_ADDR'] . rand(1, 10000000));
     }
     if ($this->session->getField(self::CART_ID) == '') {
         $this->session->setField(self::CART_ID, $id);
     }
     if (!isset($_COOKIE[self::CART_ID])) {
         setcookie(self::CART_ID, $id, null, '/', null, null, true);
     }
     return $id;
 }
Example #3
0
 private function _createPages()
 {
     // start out with basic page parameters, modify as we go
     $data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => $this->wp->getCurrentUserId(), 'post_name' => '', 'post_content' => '', 'comment_status' => 'closed', 'ping_status' => false);
     $this->_createPage(Pages::SHOP, array_merge($data, array('post_title' => __('Shop', 'jigoshop'))));
     $this->_createPage(Pages::CART, array_merge($data, array('post_title' => __('Cart', 'jigoshop'))));
     $this->_createPage(Pages::CHECKOUT, array_merge($data, array('post_title' => __('Checkout', 'jigoshop'))));
     $this->_createPage(Pages::THANK_YOU, array_merge($data, array('post_title' => __('Checkout - thank you', 'jigoshop'))));
     $this->_createPage(Pages::ACCOUNT, array_merge($data, array('post_title' => __('My account', 'jigoshop'))));
     $this->options->saveOptions();
 }
Example #4
0
 /**
  * @param $object Order
  *
  * @return string Random order key.
  */
 private function generateOrderKey($object)
 {
     $fields = $object->getStateToSave();
     $keys = array_keys($fields);
     $min = 0;
     $max = count($keys) - 1;
     $source = time() . $this->wp->getCurrentUserId();
     $fields = array_map(function ($item) {
         return is_array($item) ? serialize($item) : $item;
     }, $fields);
     for ($i = 0; $i < 5; $i++) {
         $source .= $fields[$keys[rand($min, $max)]];
     }
     return hash('md5', str_repeat($source, 5));
 }
Example #5
0
    /**
     * Displays Google Analytics tracking code in the header as the LAST item before closing </head> tag
     */
    public function googleAnalyticsTracking()
    {
        // Do not track admin pages
        if ($this->wp->isAdmin()) {
            return;
        }
        // Do not track shop owners
        if ($this->wp->currentUserCan('manage_jigoshop')) {
            return;
        }
        $trackingId = $this->options->get('advanced.integration.google_analytics');
        if (empty($trackingId)) {
            return;
        }
        $userId = '';
        if ($this->wp->isUserLoggedIn()) {
            $userId = $this->wp->getCurrentUserId();
        }
        ?>
		<script type="text/javascript">
			(function(i, s, o, g, r, a, m) {
				i['GoogleAnalyticsObject'] = r;
				i[r] = i[r] || function() {
						(i[r].q = i[r].q || []).push(arguments)
					}, i[r].l = 1 * new Date();
				a = s.createElement(o),
					m = s.getElementsByTagName(o)[0];
				a.async = 1;
				a.src = g;
				m.parentNode.insertBefore(a, m)
			})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'jigoshopGoogleAnalytics');
			jigoshopGoogleAnalytics('create', '<?php 
        echo $trackingId;
        ?>
', {'userId': '<?php 
        echo $userId;
        ?>
'});
			jigoshopGoogleAnalytics('send', 'pageview');
		</script>
		<?php 
    }
Example #6
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;
     }
 }