Exemplo n.º 1
0
 /**
  * Validates whether
  *
  * @param OrderInterface $cart
  */
 public function validate(OrderInterface $cart)
 {
     $customer = $cart->getCustomer();
     $billingErrors = $this->validateAddress($customer->getBillingAddress());
     if ($customer->getBillingAddress()->getEmail() == null) {
         $billingErrors[] = __('Email address is empty.', 'jigoshop');
     }
     if ($customer->getBillingAddress()->getPhone() == null) {
         $billingErrors[] = __('Phone is empty.', 'jigoshop');
     }
     if (!Validation::isEmail($customer->getBillingAddress()->getEmail())) {
         $billingErrors[] = __('Email address is invalid.', 'jigoshop');
     }
     $shippingErrors = $this->validateAddress($customer->getShippingAddress());
     $billingErrors = $this->wp->applyFilters('jigoshop\\service\\cart\\billing_address_validation', $billingErrors, $customer->getBillingAddress());
     $shippingErrors = $this->wp->applyFilters('jigoshop\\service\\cart\\shipping_address_validation', $shippingErrors, $customer->getShippingAddress());
     $error = '';
     if (!empty($billingErrors)) {
         $error .= $this->prepareAddressError(__('Billing address is not valid.', 'jigoshop'), $billingErrors);
     }
     if (!empty($shippingErrors)) {
         $error .= $this->prepareAddressError(__('Shipping address is not valid.', 'jigoshop'), $shippingErrors);
     }
     if (!empty($error)) {
         throw new Exception($error);
     }
 }
Exemplo n.º 2
0
 /**
  * @param                $taxClass string Tax class to get label for.
  * @param OrderInterface $order    Order to calculate taxes for.
  *
  * @return string Tax class rate
  * @throws Exception When tax class is not found.
  */
 public function getRate($taxClass, $order)
 {
     if (!in_array($taxClass, $this->taxClasses)) {
         if (WP_DEBUG) {
             throw new Exception(sprintf(__('No tax class: %s', 'jigoshop'), $taxClass));
         }
         return $taxClass;
     }
     $definitions = $order->getTaxDefinitions();
     if (!isset($definitions[$taxClass])) {
         $definitions[$taxClass] = $this->getDefinition($taxClass, $order->getCustomer()->getTaxAddress());
     }
     return $definitions[$taxClass]['rate'];
 }