예제 #1
0
 /**
  * Finds single user with specified ID.
  *
  * @param $id int Customer ID.
  * @return \Jigoshop\Entity\Customer Customer for selected ID.
  */
 public function find($id)
 {
     if (!isset($this->customers[$id])) {
         $this->customers[$id] = $this->service->find($id);
     }
     return $this->customers[$id];
 }
예제 #2
0
 /**
  * Finds single user with specified ID.
  *
  * @param $id int Customer ID.
  * @return \Jigoshop\Entity\Customer Customer for selected ID.
  */
 public function find($id)
 {
     if (!isset($this->customers[$id])) {
         $cachedCustomer = $this->instanceCache->getItem('customer_' . $id);
         if ($cachedCustomer->get() instanceof Order) {
             $this->customers[$id] = $this->service->find($id);
         } else {
             $this->customers[$id] = $this->service->find($id);
             $cachedCustomer->set($this->objects[$id->ID]);
             $this->instanceCache->save($cachedCustomer);
         }
     }
     return $this->customers[$id];
 }
예제 #3
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);
 }
예제 #4
0
 public function fill(OrderInterface $order, array $data)
 {
     if (!empty($data['customer']) && is_numeric($data['customer'])) {
         $data['customer'] = $this->customerService->find($data['customer']);
     }
     if (isset($data['customer'])) {
         if (!empty($data['customer'])) {
             $data['customer'] = $this->wp->getHelpers()->maybeUnserialize($data['customer']);
         } else {
             $data['customer'] = new CustomerEntity\Guest();
         }
         if (isset($data['billing_address'])) {
             $data['billing_address'] = array_merge(array_flip(array_keys(ProductHelper::getBasicBillingFields())), $data['billing_address']);
             /** @var CustomerEntity $customer */
             $customer = $data['customer'];
             $customer->setBillingAddress($this->createAddress($data['billing_address']));
         }
         if (isset($data['shipping_address'])) {
             $data['shipping_address'] = array_merge(array_flip(array_keys(ProductHelper::getBasicShippingFields())), $data['shipping_address']);
             /** @var CustomerEntity $customer */
             $customer = $data['customer'];
             $customer->setShippingAddress($this->createAddress($data['shipping_address']));
         }
         $order->setCustomer($data['customer']);
         unset($data['customer']);
     }
     /** @var OrderInterface $order */
     $order = $this->wp->applyFilters('jigoshop\\factory\\order\\fetch\\after_customer', $order);
     if (isset($data['items'])) {
         $order->removeItems();
     }
     //We do not want to add coupons and from directly, without validation.
     $coupons = null;
     if (isset($data['coupons'])) {
         $coupons = $data['coupons'];
         unset($data['coupons']);
     }
     if (isset($data['discount'])) {
         unset($data['discount']);
     }
     $order->restoreState($data);
     if ($coupons) {
         $coupons = $this->wp->getHelpers()->maybeUnserialize($coupons);
         if (isset($coupons[0]) && is_array($coupons[0])) {
             $codes = array_map(function ($coupon) {
                 return $coupon['code'];
             }, $coupons);
         } else {
             $codes = $coupons;
         }
         $coupons = $this->couponService->getByCodes($codes);
         foreach ($coupons as $coupon) {
             /** @var Coupon $coupon */
             try {
                 $order->addCoupon($coupon);
             } catch (Exception $e) {
                 $this->messages->addWarning($e->getMessage(), false);
             }
         }
     }
     return $this->wp->applyFilters('jigoshop\\factory\\order\\fill', $order);
 }