Example #1
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);
 }
Example #2
0
 /**
  * Returns list of default fields for billing section.
  *
  * @param Address $address Address to fill values.
  *
  * @return array Default fields.
  */
 public function getDefaultBillingFields(Address $address)
 {
     return ProductHelper::getBasicBillingFields(array('first_name' => array('value' => $address->getFirstName(), 'columnSize' => 6), 'last_name' => array('value' => $address->getLastName(), 'columnSize' => 6), 'company' => array('value' => $address instanceof CompanyAddress ? $address->getCompany() : '', 'columnSize' => 6), 'euvatno' => array('value' => $address instanceof CompanyAddress ? $address->getVatNumber() : '', 'columnSize' => 6), 'address' => array('value' => $address->getAddress(), 'columnSize' => 12), 'country' => array('options' => Country::getAllowed(), 'value' => $address->getCountry(), 'columnSize' => 6), 'state' => array('type' => Country::hasStates($address->getCountry()) ? 'select' : 'text', 'options' => Country::getStates($address->getCountry()), 'value' => $address->getState(), 'columnSize' => 6), 'city' => array('value' => $address->getCity(), 'columnSize' => 6), 'postcode' => array('value' => $address->getPostcode(), 'columnSize' => 6), 'phone' => array('value' => $address->getPhone(), 'columnSize' => 6), 'email' => array('value' => $address->getEmail(), 'columnSize' => 6)));
 }
Example #3
0
 public function dataBox()
 {
     $post = $this->wp->getGlobalPost();
     /** @var \Jigoshop\Entity\Order $order */
     $order = $this->orderService->findForPost($post);
     $billingOnly = $this->options->get('shipping.only_to_billing');
     $address = $order->getCustomer()->getBillingAddress();
     $billingFields = $this->wp->applyFilters('jigoshop\\admin\\order\\billing_fields', ProductHelper::getBasicBillingFields(array('first_name' => array('value' => $address->getFirstName()), 'last_name' => array('value' => $address->getLastName()), 'company' => array('value' => $address instanceof Customer\CompanyAddress ? $address->getCompany() : ''), 'euvatno' => array('value' => $address instanceof Customer\CompanyAddress ? $address->getVatNumber() : ''), 'address' => array('value' => $address->getAddress()), 'city' => array('value' => $address->getCity()), 'postcode' => array('value' => $address->getPostcode()), 'country' => array('value' => $address->getCountry(), 'options' => Country::getAllowed()), 'state' => array('type' => Country::hasStates($address->getCountry()) ? 'select' : 'text', 'value' => $address->getState(), 'options' => Country::getStates($address->getCountry())), 'phone' => array('value' => $address->getPhone()), 'email' => array('value' => $address->getEmail())), $order));
     $address = $order->getCustomer()->getShippingAddress();
     $shippingFields = $this->wp->applyFilters('jigoshop\\admin\\order\\shipping_fields', ProductHelper::getBasicShippingFields(array('first_name' => array('value' => $address->getFirstName()), 'last_name' => array('value' => $address->getLastName()), 'company' => array('value' => $address instanceof Customer\CompanyAddress ? $address->getCompany() : ''), 'address' => array('value' => $address->getAddress()), 'city' => array('value' => $address->getCity()), 'postcode' => array('value' => $address->getPostcode()), 'country' => array('value' => $address->getCountry(), 'options' => Country::getAllowed()), 'state' => array('type' => Country::hasStates($address->getCountry()) ? 'select' : 'text', 'value' => $address->getState(), 'options' => Country::getStates($address->getCountry()))), $order));
     $customers = $this->customerService->findAll();
     Render::output('admin/order/dataBox', array('order' => $order, 'billingFields' => $billingFields, 'shippingFields' => $shippingFields, 'customers' => $customers, 'billingOnly' => $billingOnly));
 }