Beispiel #1
0
 /**
  * Remove temporary order
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return void
  */
 protected function removeTemporaryOrder(\XLite\Model\Order $order)
 {
     foreach ($order->getItems() as $item) {
         foreach ($item->getPinCodes() as $pin) {
             \XLite\Core\Database::getEM()->remove($pin);
         }
     }
     parent::removeTemporaryOrder($order);
 }
Beispiel #2
0
 /**
  * Returns order items
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return array
  * @see    https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables
  */
 protected function getItems($order)
 {
     $result = array();
     $itemsSubtotal = 0;
     if ($order->countItems()) {
         $index = 1;
         /** @var \XLite\Model\Currency $currency */
         $currency = $order->getCurrency();
         foreach ($order->getItems() as $item) {
             $amt = $currency->roundValue($item->getItemNetPrice());
             $result['amount_' . $index] = $amt;
             /** @var \XLite\Model\Product $product */
             $product = $item->getProduct();
             $result['item_name_' . $index] = $product->getName();
             $qty = $item->getAmount();
             $result['quantity_' . $index] = $qty;
             $itemsSubtotal += $amt * $qty;
             ++$index;
         }
         // Prepare data about discount
         $discount = $currency->roundValue($order->getSurchargeSumByType(\XLite\Model\Base\Surcharge::TYPE_DISCOUNT));
         if (0 != $discount) {
             $result['discount_amount_cart'] = $discount;
         }
         $result = array_merge($result, array('items_amount' => $itemsSubtotal));
         // Prepare data about summary tax cost
         $taxCost = $currency->roundValue($order->getSurchargeSumByType(\XLite\Model\Base\Surcharge::TYPE_TAX));
         if (0 < $taxCost) {
             $result['tax_cart'] = $taxCost;
         }
     }
     return $result;
 }
Beispiel #3
0
 /**
  * Get the errors related to categories of products in order
  *
  * @param \XLite\Model\Order $order
  *
  * @return array
  */
 protected function getCategoryErrors(\XLite\Model\Order $order)
 {
     $found = true;
     // Categories
     if (0 < count($this->getCategories())) {
         $found = false;
         foreach ($order->getItems() as $item) {
             foreach ($item->getProduct()->getCategories() as $cat) {
                 if ($this->getCategories()->contains($cat)) {
                     $found = true;
                     break;
                 }
             }
             if ($found) {
                 break;
             }
         }
     }
     return $found ? array() : array(static::ERROR_CATEGORY);
 }
Beispiel #4
0
 /**
  * Get cart items
  *
  * @return array
  */
 public function getItems()
 {
     $items = parent::getItems();
     if (!\XLite::isAdminZone()) {
         foreach ($items as $item) {
             if ($item->isDeleted()) {
                 $items->removeElement($item);
                 \XLite\Core\Database::getRepo('XLite\\Model\\OrderItem')->delete($item);
             }
         }
     }
     return $items;
 }
Beispiel #5
0
 /**
  * Check if the re-order button is shown
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return boolean
  */
 protected function showReorder(\XLite\Model\Order $order)
 {
     $items = $order->getItems();
     return (bool) \Includes\Utils\ArrayManager::findValue($items, array($this, 'checkIsAvailableToOrder'), false);
 }
Beispiel #6
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;
 }
Beispiel #7
0
 /**
  * Check coupon product class
  *
  * @param \XLite\Model\Order $order Order
  *
  * @throws \XLite\Module\CDev\Coupons\Core\CompatibilityException
  *
  * @return void
  */
 protected function checkProductClass(\XLite\Model\Order $order)
 {
     if ($this->getProductClasses()->count()) {
         $found = false;
         foreach ($order->getItems() as $item) {
             if ($item->getProduct()->getProductClass() && $this->getProductClasses()->contains($item->getProduct()->getProductClass())) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $this->throwCompatibilityException('', 'There is no such a coupon, please check the spelling: X', array('code' => $this->getCode()));
         }
     }
 }
Beispiel #8
0
 /**
  * Get items for card setup there should be only one item
  *
  * @return Doctrine\Common\Collections\Collection
  */
 public function getItems()
 {
     $items = parent::getItems();
     foreach ($items as $key => $item) {
         if ($item->isXpcFakeItem()) {
             $items->clear();
             $items[] = $item;
             break;
         }
     }
     return $items;
 }
Beispiel #9
0
 /**
  * Returns order items
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return array
  */
 protected function getItems($order)
 {
     $result = array();
     $itemsSubtotal = 0;
     if ($order->countItems()) {
         $index = 0;
         /** @var \XLite\Model\Currency $currency */
         $currency = $order->getCurrency();
         foreach ($order->getItems() as $item) {
             $amt = $currency->roundValue($item->getItemNetPrice());
             $result['L_PAYMENTREQUEST_0_AMT' . $index] = $amt;
             /** @var \XLite\Model\Product $product */
             $product = $item->getProduct();
             $result['L_PAYMENTREQUEST_0_NAME' . $index] = $product->getName();
             if ($product->getSku()) {
                 $result['L_PAYMENTREQUEST_0_NUMBER' . $index] = $product->getSku();
             }
             $qty = $item->getAmount();
             $result['L_PAYMENTREQUEST_0_QTY' . $index] = $qty;
             $itemsSubtotal += $amt * $qty;
             $index += 1;
         }
         // Prepare data about discount
         $discount = $currency->roundValue($order->getSurchargeSumByType(\XLite\Model\Base\Surcharge::TYPE_DISCOUNT));
         if (0 != $discount) {
             $result['L_PAYMENTREQUEST_0_AMT' . $index] = $discount;
             $result['L_PAYMENTREQUEST_0_NAME' . $index] = 'Discount';
             $result['L_PAYMENTREQUEST_0_QTI' . $index] = 1;
             $itemsSubtotal += $discount;
         }
         $result += array('PAYMENTREQUEST_0_ITEMAMT' => $itemsSubtotal);
         // Prepare data about summary tax cost
         $taxCost = $currency->roundValue($order->getSurchargeSumByType(\XLite\Model\Base\Surcharge::TYPE_TAX));
         if (0 < $taxCost) {
             $result['L_PAYMENTREQUEST_0_TAXAMT' . $index] = $taxCost;
             $result['PAYMENTREQUEST_0_TAXAMT'] = $taxCost;
         }
     }
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function getItems()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getItems', array());
     return parent::getItems();
 }