Exemplo n.º 1
0
 public function __construct(Wordpress $wp, \Jigoshop\Core\Options $options, ProductServiceInterface $productService, TaxServiceInterface $taxService)
 {
     $this->wp = $wp;
     $this->options = $options;
     $this->productService = $productService;
     if ($this->options->get('tax.included')) {
         $address = new Customer\Address();
         $address->setCountry($this->options->get('general.country'));
         $address->setState($this->options->get('general.state'));
         $this->taxes = $taxService->getDefinitions($address);
     }
     $wp->addAction('wp_ajax_jigoshop.admin.migration.products', array($this, 'ajaxMigrationProducts'), 10, 0);
 }
Exemplo n.º 2
0
 /**
  * Checks whether billing and shipping addresses have the same country, state and postcode
  * .
  *
  * @return bool Shipping and billing address matches?
  */
 public function hasMatchingAddresses()
 {
     return $this->billingAddress->getCountry() == $this->shippingAddress->getCountry() && $this->billingAddress->getState() == $this->shippingAddress->getState() && $this->billingAddress->getPostcode() == $this->shippingAddress->getPostcode();
 }
Exemplo n.º 3
0
 /**
  * Returns list of default fields for shipping section.
  *
  * @param Address $address Address to fill values for.
  *
  * @return array Default fields.
  */
 public function getDefaultShippingFields(Address $address)
 {
     return ProductHelper::getBasicShippingFields(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' => 12), '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)));
 }
Exemplo n.º 4
0
 /**
  * Finds and returns available tax definitions for selected parameters.
  *
  * @param $taxClass string Tax class.
  * @param $address  Customer\Address Address to fetch data for.
  *
  * @return array Tax definition.
  */
 public function getDefinition($taxClass, Customer\Address $address)
 {
     $taxClass = str_replace('__compound__', '', $taxClass);
     // TODO: Remember downloaded data for each address separately
     // TODO: Probably it will be good idea to update getRules() call to fetch and format only proper rules for the customer
     $rules = array_filter($this->getRules(), function ($item) use($taxClass, $address) {
         return $item['class'] == $taxClass && (empty($item['country']) || $item['country'] == $address->getCountry()) && (empty($item['states']) || in_array($address->getState(), $item['states'])) && (empty($item['postcodes']) || in_array($address->getPostcode(), $item['postcodes']));
     });
     $standard = array_filter($rules, function ($rule) {
         return !$rule['is_compound'];
     });
     $compound = array_filter($rules, function ($rule) {
         return $rule['is_compound'];
     });
     $comparator = function ($a, $b) {
         $aRate = 0;
         $bRate = 0;
         if (!empty($a['country'])) {
             $aRate += 1;
         }
         if (!empty($a['states'])) {
             $aRate += 1;
         }
         if (!empty($a['postcodes'])) {
             $aRate += 1;
         }
         if (!empty($b['country'])) {
             $bRate += 1;
         }
         if (!empty($b['states'])) {
             $bRate += 1;
         }
         if (!empty($b['postcodes'])) {
             $bRate += 1;
         }
         return $aRate - $bRate;
     };
     usort($standard, $comparator);
     usort($compound, $comparator);
     return array('standard' => array_pop($standard), 'compound' => array_pop($compound));
 }
Exemplo n.º 5
0
 private function createAddress($data)
 {
     if (!empty($data['company'])) {
         $address = new CustomerEntity\CompanyAddress();
         $address->setCompany($data['company']);
         if (isset($data['euvatno'])) {
             $address->setVatNumber($data['euvatno']);
         }
     } else {
         $address = new CustomerEntity\Address();
     }
     $address->setFirstName($data['first_name']);
     $address->setLastName($data['last_name']);
     $address->setAddress($data['address']);
     $address->setCountry($data['country']);
     $address->setState($data['state']);
     $address->setCity($data['city']);
     $address->setPostcode($data['postcode']);
     if (isset($data['phone'])) {
         $address->setPhone($data['phone']);
     }
     if (isset($data['email'])) {
         $address->setEmail($data['email']);
     }
     return $address;
 }
Exemplo n.º 6
0
 private function _migrateCustomer($customer, $data)
 {
     $data = $this->_fetchCustomerData($data);
     if (!$customer) {
         $customer = new Customer();
     } else {
         $customer = maybe_unserialize(maybe_unserialize($customer));
     }
     if (!$customer instanceof Customer) {
         $customer = new Customer();
     }
     if (!empty($data['billing_company']) && !empty($data['billing_euvatno'])) {
         $address = new Customer\CompanyAddress();
         $address->setCompany($data['billing_company']);
         $address->setVatNumber($data['billing_euvatno']);
     } else {
         $address = new Customer\Address();
     }
     $address->setFirstName($data['billing_first_name']);
     $address->setLastName($data['billing_last_name']);
     $address->setAddress($data['billing_address_1'] . ' ' . $data['billing_address_2']);
     $address->setCountry($data['billing_country']);
     $address->setState($data['billing_state']);
     $address->setPostcode($data['billing_postcode']);
     $address->setPhone($data['billing_phone']);
     $address->setEmail($data['billing_email']);
     $customer->setBillingAddress($address);
     if (!empty($data['shipping_company'])) {
         $address = new Customer\CompanyAddress();
         $address->setCompany($data['shipping_company']);
     } else {
         $address = new Customer\Address();
     }
     $address->setFirstName($data['shipping_first_name']);
     $address->setLastName($data['shipping_last_name']);
     $address->setAddress($data['shipping_address_1'] . ' ' . $data['shipping_address_2']);
     $address->setCountry($data['shipping_country']);
     $address->setState($data['shipping_state']);
     $address->setPostcode($data['shipping_postcode']);
     $customer->setShippingAddress($address);
     return $customer;
 }