Example #1
0
 /**
  * @return string
  */
 public function getName()
 {
     return sprintf(_x('%s - %s', 'shipping', 'jigoshop'), $this->method->getName(), $this->name);
 }
Example #2
0
 /**
  * Adds new method to service.
  *
  * @param Method $method Method to add.
  */
 public function addMethod(Method $method)
 {
     $this->methods[$method->getId()] = $method;
 }
Example #3
0
 /**
  * Checks whether current method is the one specified with selected rule.
  *
  * @param Method $method Method to check.
  * @param int    $rate   Rate to check.
  *
  * @return boolean Is this the method?
  */
 public function is(Method $method, $rate = null)
 {
     return $method->getId() == $this->getId();
 }
Example #4
0
 /**
  * @param Method         $method Method to calculate tax for.
  * @param OrderInterface $order  Order with the shipping method.
  * @param                $price  float Price calculated for current cart.
  *
  * @return array List of tax values per tax class.
  */
 public function getForShipping(Method $method, OrderInterface $order, $price)
 {
     return $this->get($price, $method->getTaxClasses(), $order->getTaxDefinitions());
 }
Example #5
0
 /**
  * @param array $state State to restore entity to.
  */
 public function restoreState(array $state)
 {
     if (isset($state['key'])) {
         $this->key = $state['key'];
     }
     if (isset($state['number'])) {
         $this->number = $state['number'];
     }
     if (isset($state['created_at'])) {
         $this->createdAt->setTimestamp($state['created_at']);
     }
     if (isset($state['updated_at'])) {
         $this->updatedAt->setTimestamp($state['updated_at']);
     }
     if (isset($state['completed_at'])) {
         $this->completedAt = new \DateTime();
         $this->completedAt->setTimestamp($state['completed_at']);
     }
     if (isset($state['status'])) {
         $this->status = $state['status'];
     }
     if (isset($state['items'])) {
         foreach ($state['items'] as $item) {
             $this->addItem($item);
         }
     }
     if (isset($state['customer']) && $state['customer'] !== false) {
         $this->customer = $state['customer'];
     }
     if (isset($state['shipping']) && is_array($state['shipping'])) {
         $this->shippingMethod = $state['shipping']['method'];
         $this->shippingMethodRate = $state['shipping']['rate'];
         if ($state['shipping']['price'] > -1) {
             $this->shippingPrice = $state['shipping']['price'];
         } else {
             $this->shippingPrice = $this->shippingMethod->calculate($this);
         }
         $this->subtotal += $this->shippingPrice;
     }
     if (isset($state['payment']) && !empty($state['payment'])) {
         $this->paymentMethod = $state['payment'];
     }
     if (isset($state['customer_note'])) {
         $this->customerNote = $state['customer_note'];
     }
     if (isset($state['shipping_tax'])) {
         $tax = maybe_unserialize($state['shipping_tax']);
         foreach ($tax as $class => $value) {
             if (!isset($this->shippingTax[$class])) {
                 $this->shippingTax[$class] = 0.0;
             }
             $this->shippingTax[$class] += $value;
         }
     }
     if (isset($state['product_subtotal'])) {
         $this->productSubtotal = (double) $state['product_subtotal'];
     }
     if (isset($state['discount'])) {
         $this->discount = (double) $state['discount'];
     }
     if (isset($state['coupons'])) {
         $this->coupons = maybe_unserialize($state['coupons']);
     }
     if (isset($state['tax_definitions'])) {
         $this->taxDefinitions = $state['tax_definitions'];
     }
     $this->total = $this->subtotal + array_reduce($this->tax, function ($value, $item) {
         return $value + $item;
     }, 0.0) + array_reduce($this->shippingTax, function ($value, $item) {
         return $value + $item;
     }, 0.0) - $this->discount;
 }