Example #1
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)));
 }
Example #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();
 }
Example #3
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));
 }