Beispiel #1
0
 /**
  * Prepare shopping cart data
  *
  * @param \XLite\Model\Order            $cart           X-Cart shopping cart
  * @param \XLite\Model\Payment\Method   $paymentMethod  Payment method
  * @param integer                       $refId          Transaction ID OPTIONAL
  * @param boolean                       $forceAuth      Force enable AUTH mode OPTIONAL
  *
  * @return array
  */
 public function prepareCart(\XLite\Model\Order $cart, \XLite\Model\Payment\Method $paymentMethod, $refId = null, $forceAuth = false)
 {
     $config = \XLite\Core\Config::getInstance()->CDev->XPaymentsConnector;
     $profile = $cart->getProfile();
     $result = array('login' => $profile->getLogin() . ' (User ID #' . $profile->getProfileId() . ')', 'items' => array(), 'currency' => $this->getCurrencyCode($paymentMethod), 'shippingCost' => 0.0, 'taxCost' => 0.0, 'discount' => 0.0, 'totalCost' => 0.0, 'description' => 'Order#' . $cart->getOrderNumber(), 'merchantEmail' => \XLite\Core\Config::getInstance()->Company->orders_department, 'forceTransactionType' => $forceAuth ? 'A' : '');
     $result['billingAddress'] = $this->prepareAddress($profile);
     if ($profile->getShippingAddress()) {
         $result['shippingAddress'] = $this->prepareAddress($profile, 'shipping');
     } else {
         $result['shippingAddress'] = $result['billingAddress'];
     }
     // Set items
     if ($cart->getItems()) {
         foreach ($cart->getItems() as $item) {
             $itemElement = array('sku' => strval($item->getSku() ? $item->getSku() : $item->getName()), 'name' => strval($item->getName() ? $item->getName() : $item->getSku()), 'price' => $this->roundCurrency($item->getPrice()), 'quantity' => $item->getAmount());
             if (!$itemElement['sku']) {
                 $itemElement['sku'] = 'N/A';
             }
             if (!$itemElement['name']) {
                 $itemElement['name'] = 'N/A';
             }
             $result['items'][] = $itemElement;
         }
     }
     // Set costs
     $result['shippingCost'] = $this->roundCurrency($cart->getSurchargesSubtotal(\XLite\Model\Base\Surcharge::TYPE_SHIPPING, false));
     $result['taxCost'] = $this->roundCurrency($cart->getSurchargesSubtotal(\XLite\Model\Base\Surcharge::TYPE_TAX, false));
     $result['totalCost'] = $this->roundCurrency($cart->getTotal());
     $result['discount'] = $this->roundCurrency(abs($cart->getSurchargesSubtotal(\XLite\Model\Base\Surcharge::TYPE_DISCOUNT, false)));
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function getSurchargesSubtotal($type = NULL, $include = NULL)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSurchargesSubtotal', array($type, $include));
     return parent::getSurchargesSubtotal($type, $include);
 }