Esempio n. 1
0
 /**
  * Shipping rates sorting callback
  *
  * @param \XLite\Model\Shipping\Rate $a First shipping rate
  * @param \XLite\Model\Shipping\Rate $b Second shipping rate
  *
  * @return integer
  */
 protected function compareRates(\XLite\Model\Shipping\Rate $a, \XLite\Model\Shipping\Rate $b)
 {
     $aMethod = $a->getMethod();
     $bMethod = $b->getMethod();
     $aRate = $a->getTotalRate();
     $bRate = $b->getTotalRate();
     return 'auctionInc' === $aMethod->getProcessor() && 'auctionInc' === $bMethod->getProcessor() ? $aRate === $bRate ? 0 : ($aRate < $bRate ? -1 : 1) : parent::compareRates($a, $b);
 }
Esempio n. 2
0
 /**
  * Restore rates
  *
  * @return array(\XLite\Model\Shipping\Rate)
  */
 protected function restoreRates()
 {
     $rates = parent::restoreRates();
     if ($rates && $this->order->getAuctionIncPackage()) {
         $extraData = new \XLite\Core\CommonCell(array('auctionIncPackage' => $this->order->getAuctionIncPackage()));
         $rates[0]->setExtraData($extraData);
     }
     return $rates;
 }
Esempio n. 3
0
 /**
  * Get shipped items
  *
  * @return array
  */
 public function getItems()
 {
     $items = parent::getItems();
     if ($this->order->getUsedCoupons()) {
         foreach ($this->order->getUsedCoupons() as $coupon) {
             if ($coupon->getCoupon() && $coupon->getCoupon()->isFreeShipping()) {
                 foreach ($items as $k => $item) {
                     if ($coupon->getCoupon()->isValidItem($item)) {
                         unset($items[$k]);
                     }
                 }
             }
         }
     }
     return $items;
 }
Esempio n. 4
0
 /**
  * Returns true if any of order items are shipped
  *
  * @return boolean
  */
 protected function isShippable()
 {
     $result = parent::isShippable();
     foreach (parent::getItems() as $item) {
         if ($item->isShippable()) {
             $result = true;
             break;
         }
     }
     return $result;
 }
Esempio n. 5
0
 /**
  * Collect items data from modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier
  *
  * @return array
  */
 protected function getItems($modifier)
 {
     $result = array();
     /** @var \XLite\Model\OrderItem $item */
     foreach ($modifier->getItems() as $item) {
         $product = $item->getProduct();
         /** @var \XLite\Module\XC\AuctionInc\Model\ProductAuctionInc $auctionIncData */
         $auctionIncData = $product->getAuctionIncData() ?: new \XLite\Module\XC\AuctionInc\Model\ProductAuctionInc();
         $onDemand = array_map(function ($a) {
             list(, $serviceCode) = explode('_', $a);
             return $serviceCode;
         }, $auctionIncData->getOnDemand());
         $resultItem = array('calculationMethod' => $auctionIncData->getCalculationMethod(), 'sku' => $product->getSku(), 'name' => $product->getName(), 'qty' => (int) $item->getAmount(), 'weight' => $product->getWeight(), 'weightUOM' => $auctionIncData->getWeightUOM(), 'dimensions' => $auctionIncData->getDimensions(), 'dimensionsUOM' => $auctionIncData->getDimensionsUOM(), 'package' => $auctionIncData->getPackage(), 'originCode' => $auctionIncData->getOriginCode(), 'onDemand' => implode(', ', $onDemand), 'carrierAccessorialFees' => implode(', ', $auctionIncData->getCarrierAccessorialFees()));
         $resultItem['price'] = 'Y' == $auctionIncData->getInsurable() ? $item->getTotal() / $item->getAmount() : 0;
         if ('F' == $auctionIncData->getSupplementalItemHandlingMode()) {
             $resultItem['supplementalItemHandlingFee'] = $auctionIncData->getSupplementalItemHandlingFee();
         } elseif ('C' == $auctionIncData->getSupplementalItemHandlingMode()) {
             $resultItem['supplementalItemHandlingCode'] = $auctionIncData->getSupplementalItemHandlingCode();
         }
         if ('F' == $auctionIncData->getFixedFeeMode()) {
             $resultItem['fixedFee1'] = $auctionIncData->getFixedFee1();
             $resultItem['fixedFee2'] = $auctionIncData->getFixedFee2();
         } elseif ('C' == $auctionIncData->getFixedFeeMode()) {
             $resultItem['fixedFeeCode'] = $auctionIncData->getFixedFeeCode();
         }
         $result[] = $resultItem;
     }
     return $result;
 }
Esempio n. 6
0
 /**
  * Register "Place order" event to the order history
  *
  * @param integer                              $orderId  Order ID
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Order's shipping modifier
  *
  * @return void
  */
 public function registerOrderPackaging($orderId, $modifier)
 {
     $packages = $modifier && $modifier->getMethod() && $modifier->getMethod()->getProcessorObject() ? $modifier->getMethod()->getProcessorObject()->getPackages($modifier) : array();
     if (is_array($packages) && 1 < count($packages)) {
         $result = array();
         // Correct package keys to improve appearance
         foreach ($packages as $packId => $pack) {
             $result[$packId + 1] = $pack;
         }
         // Register event
         $this->registerEvent($orderId, static::CODE_ORDER_PACKAGING, $this->getOrderPackagingDescription($orderId), array(), $this->getOrderPackagingComment($result));
     }
 }
Esempio n. 7
0
 /**
  * Prepare input data from order modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier
  *
  * @return array
  */
 protected function prepareDataFromModifier(\XLite\Logic\Order\Modifier\Shipping $inputData)
 {
     $data = array();
     $sourceAddress = $inputData->getOrder()->getSourceAddress();
     if ('AU' === $sourceAddress->getCountryCode()) {
         $addrInfo = array();
         $addrInfo['from_postcode'] = $sourceAddress->getZipcode();
         $dstAddress = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
         if (null !== $dstAddress) {
             $addrInfo['to_postcode'] = $dstAddress['zipcode'];
             $addrInfo['country_code'] = $dstAddress['country'];
             $data['packages'] = $this->getPackages($inputData);
             foreach ($data['packages'] as $key => $package) {
                 $data['packages'][$key] = array_merge($package, $addrInfo);
             }
         }
     }
     return $data;
 }
Esempio n. 8
0
 /**
  * Adds markup condition to the query builder object
  *
  * @param \Doctrine\ORM\QueryBuilder           $qb       Query builder object
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier
  * @param integer                              $zoneId   Zone Id
  *
  * @return \Doctrine\ORM\QueryBuilder
  */
 protected function addMarkupCondition(\Doctrine\ORM\QueryBuilder $qb, \XLite\Logic\Order\Modifier\Shipping $modifier, $zoneId)
 {
     $prepareSum = array('m.markup_flat', '(m.markup_percent * :value / 100)', '(m.markup_per_item * :items)', '(m.markup_per_weight * :weight)');
     return $qb->addSelect(implode(' + ', $prepareSum) . ' as markup_value')->innerJoin('m.zone', 'zone')->andWhere('m.min_weight <= :weight')->andWhere('zone.zone_id = :zoneId')->andWhere('m.max_weight >= :weight')->andWhere('m.min_total <= :total')->andWhere('m.max_total >= :total')->andWhere('m.min_items <= :items')->andWhere('m.max_items >= :items')->setParameters(array_merge($qb->getParameters(), array('zoneId' => $zoneId, 'weight' => $modifier->getWeight(), 'total' => $modifier->getSubtotal(), 'items' => $modifier->countItems(), 'value' => $modifier->getSubtotal())));
 }
Esempio n. 9
0
 /**
  * Adds markup condition to the query builder object
  *
  * @param \Doctrine\ORM\QueryBuilder           $qb       Query builder object
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier
  * @param integer                              $zoneId   Zone Id
  *
  * @return \Doctrine\ORM\QueryBuilder
  */
 protected function addMarkupCondition(\Doctrine\ORM\QueryBuilder $qb, \XLite\Logic\Order\Modifier\Shipping $modifier, $zoneId)
 {
     $prepareSum = array('m.markup_flat', '(m.markup_percent * :value / 100)', '(m.markup_per_item * :items)', '(m.markup_per_weight * :weight)');
     $qb->addSelect(implode(' + ', $prepareSum) . ' as markup_value')->linkInner('m.zone')->andWhere('zone.zone_id = :zoneId')->setParameter('zoneId', $zoneId)->setParameter('weight', $modifier->getWeight())->setParameter('items', $modifier->countItems())->setParameter('value', $modifier->getSubtotal());
     $qb->linkInner('m.shipping_method');
     $qb->andWhere($qb->expr()->orX($qb->expr()->andX('shipping_method.tableType = :WSIType', 'm.min_weight <= :weightCondition', 'm.max_weight >= :weightCondition', 'm.min_total <= :totalCondition', 'm.max_total >= :totalCondition', 'm.min_items <= :itemsCondition', 'm.max_items >= :itemsCondition'), $qb->expr()->andX('shipping_method.tableType = :WType', 'm.min_weight <= :weightCondition', 'm.max_weight >= :weightCondition'), $qb->expr()->andX('shipping_method.tableType = :SType', 'm.min_total <= :totalCondition', 'm.max_total >= :totalCondition'), $qb->expr()->andX('shipping_method.tableType = :IType', 'm.min_items <= :itemsCondition', 'm.max_items >= :itemsCondition')));
     $qb->setParameter('totalCondition', $modifier->getSubtotalCondition())->setParameter('weightCondition', $modifier->getWeightCondition())->setParameter('itemsCondition', $modifier->countItemsCondition())->setParameter('WSIType', 'WSI')->setParameter('WType', 'W')->setParameter('SType', 'S')->setParameter('IType', 'I');
     return $qb;
 }
Esempio n. 10
0
 /**
  * Get destination address
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier
  *
  * @return array
  */
 public function getDestinationAddress(\XLite\Logic\Order\Modifier\Shipping $modifier)
 {
     $address = null;
     $profile = $modifier->getOrder()->getProfile();
     if ($profile && $profile->getShippingAddress()) {
         // Profile is exists
         $address = static::prepareAddressData($profile->getShippingAddress());
     }
     return null === $address ? static::getDefaultAddress() : $address;
 }
Esempio n. 11
0
 /**
  * Get packages for shipment
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping modifier
  *
  * @return array
  */
 public function getPackages($modifier)
 {
     return \XLite\Core\Package::getInstance()->getPackages($modifier->getItems(), $this->getPackageLimits());
 }
Esempio n. 12
0
 /**
  * Prepare input data from order modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier
  *
  * @return array
  */
 protected function prepareDataFromModifier(\XLite\Logic\Order\Modifier\Shipping $inputData)
 {
     $result = array();
     $sourceAddress = $inputData->getOrder()->getSourceAddress();
     $result['srcAddress'] = array('zipcode' => $sourceAddress->getZipcode(), 'country' => $sourceAddress->getCountryCode());
     if ($sourceAddress->getStatе()) {
         $result['srcAddress']['state'] = $sourceAddress->getStatе()->getCode();
     }
     $result['dstAddress'] = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
     if (empty($result['dstAddress']['country'])) {
         $result['dstAddress'] = null;
     } elseif (isset($result['dstAddress']['state'])) {
         /** @var \XLite\Model\Repo\State $repo */
         $repo = \XLite\Core\Database::getRepo('XLite\\Model\\State');
         $result['dstAddress']['state'] = $repo->getCodeById($result['dstAddress']['state']);
     }
     $result['packages'] = $this->getPackages($inputData);
     // Detect if COD payment method has been selected by customer on checkout
     if ($inputData->getOrder()->getFirstOpenPaymentTransaction()) {
         $paymentMethod = $inputData->getOrder()->getPaymentMethod();
         if ($paymentMethod && 'COD_FEDEX' === $paymentMethod->getServiceName()) {
             $result['cod_enabled'] = true;
         }
     }
     return $result;
 }
Esempio n. 13
0
 /**
  * Get destination address
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier
  *
  * @return array
  */
 public function getDestinationAddress(\XLite\Logic\Order\Modifier\Shipping $modifier)
 {
     $address = null;
     if ($modifier->getOrder()->getProfile() && $modifier->getOrder()->getProfile()->getShippingAddress()) {
         // Profile is exists
         $address = static::prepareAddressData($modifier->getOrder()->getProfile()->getShippingAddress());
     }
     if (!isset($address)) {
         $address = static::getDefaultAddress();
     }
     return $address;
 }
Esempio n. 14
0
 /**
  * Prepare input data from order modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier
  *
  * @return array
  */
 protected function prepareDataFromModifier(\XLite\Logic\Order\Modifier\Shipping $inputData)
 {
     $data = array();
     $sourceAddress = $inputData->getOrder()->getSourceAddress();
     $data['srcAddress'] = array('city' => $sourceAddress->getCity(), 'zipcode' => $sourceAddress->getZipcode(), 'country' => $sourceAddress->getCountryCode());
     if ($sourceAddress->getState()) {
         $data['srcAddress']['state'] = $sourceAddress->getStateCode();
     }
     $data['dstAddress'] = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
     if (isset($data['dstAddress']['state'])) {
         $data['dstAddress']['state'] = \XLite\Core\Database::getRepo('XLite\\Model\\State')->getCodeById($data['dstAddress']['state']);
     }
     $data['packages'] = $this->getPackages($inputData);
     $data['cod_enabled'] = false;
     // Detect if COD payment method has been selected by customer on checkout
     if ($inputData->getOrder()->getFirstOpenPaymentTransaction()) {
         $paymentMethod = $inputData->getOrder()->getPaymentMethod();
         if ($paymentMethod && 'COD_UPS' === $paymentMethod->getServiceName()) {
             $data['cod_enabled'] = true;
         }
     }
     return $data;
 }
Esempio n. 15
0
 /**
  * Prepare input data from order modifier
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $inputData Shipping order modifier
  *
  * @return array
  */
 protected function prepareDataFromModifier(\XLite\Logic\Order\Modifier\Shipping $inputData)
 {
     $data = array();
     $commonData = array();
     $sourceAddress = $inputData->getOrder()->getSourceAddress();
     if ('CA' === $sourceAddress->getCountryCode()) {
         $commonData['srcAddress'] = array('zipcode' => $sourceAddress->getZipcode());
     }
     $commonData['dstAddress'] = \XLite\Model\Shipping::getInstance()->getDestinationAddress($inputData);
     if (!empty($commonData['srcAddress']) && !empty($commonData['dstAddress'])) {
         $data['packages'] = $this->getPackages($inputData);
         $data['commonData'] = $commonData;
     }
     return $data;
 }
Esempio n. 16
0
 /**
  * Get destination address
  *
  * @param \XLite\Logic\Order\Modifier\Shipping $modifier Shipping order modifier
  *
  * @return array
  */
 public function getDestinationAddress(\XLite\Logic\Order\Modifier\Shipping $modifier)
 {
     $address = null;
     if ($modifier->getOrder()->getProfile() && $modifier->getOrder()->getProfile()->getShippingAddress()) {
         // Profile is exists
         $addressObj = $modifier->getOrder()->getProfile()->getShippingAddress();
         $address = array('address' => $addressObj->getStreet(), 'city' => $addressObj->getCity(), 'state' => $addressObj->getState()->getStateId(), 'zipcode' => $addressObj->getZipcode(), 'country' => $addressObj->getCountry() ? $addressObj->getCountry()->getCode() : '');
     }
     if (!isset($address)) {
         // Anonymous address
         $config = \XLite\Core\Config::getInstance()->Shipping;
         $address = array('address' => $config->anonymous_address, 'city' => $config->anonymous_city, 'state' => $config->anonymous_state, 'zipcode' => $config->anonymous_zipcode, 'country' => $config->anonymous_country);
     }
     return $address;
 }