Returns basket item information array from session or order.

@param \OxidEsales\Eshop\Application\Model\Discount $oDiscount discount object

@return array
344706
protected function _getBasketItems($oDiscount = null)
    {
        if ($this->oxvouchers__oxorderid->value) {
            return $this->_getOrderBasketItems($oDiscount);
        } elseif ($this->getSession()->getBasket()) {
            return $this->_getSessionBasketItems($oDiscount);
        } else {
            return [];
        }
    }
36758
protected function getCountCommon(array $aData = [])
    {
        //  Define the selects
        $oDb = Factory::service('Database');
        $oDb->select($this->tableAlias . '.*');
        $oDb->select([
            $this->tableEmailAlias . '.email',
            $this->tableEmailAlias . '.code email_verification_code',
            $this->tableEmailAlias . '.is_verified email_is_verified',
            $this->tableEmailAlias . '.date_verified email_is_verified_on',
        ]);
        $oDb->select($this->getMetaColumns($this->tableMetaAlias));
        $oDb->select([
            $this->tableGroupAlias . '.slug group_slug',
            $this->tableGroupAlias . '.label group_name',
            $this->tableGroupAlias . '.default_homepage group_homepage',
            $this->tableGroupAlias . '.acl group_acl',
        ]);

        // --------------------------------------------------------------------------

        //  Define the joins
        $oDb->join(
            $this->tableEmail . ' ' . $this->tableEmailAlias,
            $this->tableAlias . '.id = ' . $this->tableEmailAlias . '.user_id AND ' . $this->tableEmailAlias . '.is_primary = 1',
            'LEFT'
        );

        $oDb->join(
            $this->tableMeta . ' ' . $this->tableMetaAlias,
            $this->tableAlias . '.id = ' . $this->tableMetaAlias . '.user_id',
            'LEFT'
        );

        $oDb->join(
            $this->tableGroup . ' ' . $this->tableGroupAlias,
            $this->tableAlias . '.group_id = ' . $this->tableGroupAlias . '.id',
            'LEFT'
        );

        //  Let the parent method handle sorting, etc
        parent::getCountCommon($aData);
    }
240816
function itemList( $asObject = true )
    {
        return eZPersistentObject::fetchObjectList( eZProductCollectionItem::definition(),
                                                    null, array( "productcollection_id" => $this->ID ),
                                                    null,
                                                    null,
                                                    $asObject );
    }
120940
protected function _mergeDiscounts($aDiscounts, $aItemDiscounts)
    {
        foreach ($aItemDiscounts as $sKey => $oDiscount) {
            // add prices of the same discounts
            if (array_key_exists($sKey, $aDiscounts)) {
                $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
            } else {
                $aDiscounts[$sKey] = $oDiscount;
            }
        }

        return $aDiscounts;
    }
956815
protected function getDiscountLinesCreditNote()
    {
        $result = array();

        // Get total amount credited.
        /** @noinspection PhpUndefinedFieldInspection */
        $creditSlipAmountInc = $this->creditSlip->total_products_tax_incl;

        // Get sum of product lines.
        $lines = $this->creditSlip->getOrdersSlipProducts($this->invoiceSource->getId(), $this->order);
        $detailsAmountInc = array_reduce($lines, function ($sum, $item) {
            $sum += $item['total_price_tax_incl'];
            return $sum;
        }, 0.0);

        // We assume that if total < sum(details), a discount given on the
        // original order has now been subtracted from the amount credited.
        if (!Number::floatsAreEqual($creditSlipAmountInc, $detailsAmountInc, 0.05)
            && $creditSlipAmountInc < $detailsAmountInc
        ) {
            // PS Error: total_products_tax_excl is not adjusted (whereas
            // total_products_tax_incl is) when a discount is subtracted from
            // the amount to be credited.
            // So we cannot calculate the discount ex VAT ourselves.
            // What we can try is the following: Get the order cart rules to see
            // if 1 or all of those match the discount amount here.
            $discountAmountInc = $detailsAmountInc - $creditSlipAmountInc;
            $totalOrderDiscountInc = 0.0;
            // Note: The sign of the entries in $orderDiscounts will be correct.
            $orderDiscounts = $this->getDiscountLinesOrder();

            foreach ($orderDiscounts as $key => $orderDiscount) {
                if (Number::floatsAreEqual($orderDiscount[Meta::UnitPriceInc], $discountAmountInc)) {
                    // Return this single line.
                    $from = $to = $key;
                    break;
                }
                $totalOrderDiscountInc += $orderDiscount[Meta::UnitPriceInc];
                if (Number::floatsAreEqual($totalOrderDiscountInc, $discountAmountInc)) {
                    // Return all lines up to here.
                    $from = 0;
                    $to = $key;
                    break;
                }
            }

            if (isset($from) && isset($to)) {
                $result = array_slice($orderDiscounts, $from, $to - $from + 1);
                // Correct meta-invoice-amount.
                $totalOrderDiscountEx = array_reduce($result, function ($sum, $item) {
                    $sum += $item[Tag::Quantity] * $item[Tag::UnitPrice];
                    return $sum;
                }, 0.0);
                $this->invoice[Tag::Customer][Tag::Invoice][Meta::InvoiceAmount] += $totalOrderDiscountEx;
            } //else {
                // We could not match a discount with the difference between the
                // total amount credited and the sum of the products returned. A
                // manual line will correct the invoice.
            //}
        }
        return $result;
    }
219897
public function getDiscount()
    {
        $amount = 0;
        $cart = ShoppingCart::get();
        $items = $cart->TotalItems;
        $discount = $cart->getDiscount();
        
        if ($this->BasePrice && $discount && $discount->Amount) {
            if ($discount->Type == "Fixed") {
                $amount = ($discount->Amount / $items) * $this->Quantity;
            } elseif ($discount->Type == "Percentage") {
                $amount = (($this->Price / 100) * $discount->Amount) * $this->Quantity;
            }
        }
        
        return $amount;
    }
277910
public function _getDiscountedProductsSum()
    {
        if ($oProductsPrice = $this->getDiscountProductsPrice()) {
            $dPrice = $oProductsPrice->getSum($this->isCalculationModeNetto());
        }

        // subtracting total discount
        if ($oPrice = $this->getTotalDiscount()) {
            $dPrice -= $oPrice->getPrice();
        }

        if ($oVoucherPrice = $this->getVoucherDiscount()) {
            $dPrice -= $oVoucherPrice->getPrice();
        }

        return $dPrice;
    }
900404
protected function getItems($recordName, $idSite, $period, $date, $abandonedCarts, $segment)
    {
        Piwik::checkUserHasViewAccess($idSite);

        $recordNameFinal = $recordName;
        if ($abandonedCarts) {
            $recordNameFinal = Archiver::getItemRecordNameAbandonedCart($recordName);
        }

        $archive   = Archive::build($idSite, $period, $date, $segment);
        $dataTable = $archive->getDataTable($recordNameFinal);

        $this->enrichItemsTableWithViewMetrics($dataTable, $recordName, $idSite, $period, $date, $segment);

        // First rename the avg_price_viewed column
        $renameColumn = array(self::AVG_PRICE_VIEWED => 'avg_price');
        $dataTable->filter('ReplaceColumnNames', array($renameColumn));

        $dataTable->queueFilter('ReplaceColumnNames');
        $dataTable->queueFilter('ReplaceSummaryRowLabel');

        if ($abandonedCarts) {
            $ordersColumn = 'abandoned_carts';
            $dataTable->renameColumn(Metrics::INDEX_ECOMMERCE_ORDERS, $ordersColumn);
        }

        $dataTable->queueFilter('ColumnDelete', array('price'));

        return $dataTable;
    }
15182
protected function toArray( \Aimeos\MShop\Coupon\Item\Iface $item, $copy = false )
	{
		$config = $item->getConfig();
		$data = $item->toArray( true );
		$data['config'] = [];

		if( $copy === true )
		{
			$data['coupon.siteid'] = $this->getContext()->getLocale()->getSiteId();
			$data['coupon.id'] = '';
		}

		ksort( $config );

		foreach( $config as $key => $value )
		{
			$data['config']['key'][] = $key;
			$data['config']['val'][] = $value;
		}

		return $data;
	}
157728
protected function _getSerieDiscount()
    {
        $oSeries = $this->getSerie();
        $oDiscount = oxNew(\OxidEsales\Eshop\Application\Model\Discount::class);

        $oDiscount->setId($oSeries->getId());
        $oDiscount->oxdiscount__oxshopid = new \OxidEsales\Eshop\Core\Field($oSeries->oxvoucherseries__oxshopid->value);
        $oDiscount->oxdiscount__oxactive = new \OxidEsales\Eshop\Core\Field(true);
        $oDiscount->oxdiscount__oxactivefrom = new \OxidEsales\Eshop\Core\Field($oSeries->oxvoucherseries__oxbegindate->value);
        $oDiscount->oxdiscount__oxactiveto = new \OxidEsales\Eshop\Core\Field($oSeries->oxvoucherseries__oxenddate->value);
        $oDiscount->oxdiscount__oxtitle = new \OxidEsales\Eshop\Core\Field($oSeries->oxvoucherseries__oxserienr->value);
        $oDiscount->oxdiscount__oxamount = new \OxidEsales\Eshop\Core\Field(1);
        $oDiscount->oxdiscount__oxamountto = new \OxidEsales\Eshop\Core\Field(MAX_64BIT_INTEGER);
        $oDiscount->oxdiscount__oxprice = new \OxidEsales\Eshop\Core\Field(0);
        $oDiscount->oxdiscount__oxpriceto = new \OxidEsales\Eshop\Core\Field(MAX_64BIT_INTEGER);
        $oDiscount->oxdiscount__oxaddsumtype = new \OxidEsales\Eshop\Core\Field($oSeries->oxvoucherseries__oxdiscounttype->value == 'percent' ? '%' : 'abs');
        $oDiscount->oxdiscount__oxaddsum = new \OxidEsales\Eshop\Core\Field($oSeries->oxvoucherseries__oxdiscount->value);
        $oDiscount->oxdiscount__oxitmartid = new \OxidEsales\Eshop\Core\Field();
        $oDiscount->oxdiscount__oxitmamount = new \OxidEsales\Eshop\Core\Field();
        $oDiscount->oxdiscount__oxitmmultiple = new \OxidEsales\Eshop\Core\Field();

        return $oDiscount;
    }
1324699
protected function GetTopsellers()
    {
        $oLocal = &TCMSLocal::GetActive();
        $query = 'SELECT SUM(`shop_order_item`.`order_amount`) AS totalordered,
                       SUM(`shop_order_item`.`order_price_after_discounts`) AS totalorderedvalue,
                       `shop_category`.`url_path` AS categorypath, `shop_order_item`.*
                  FROM `shop_order_item`
             LEFT JOIN `shop_order` ON `shop_order_item`.`shop_order_id` = `shop_order`.`id`
             LEFT JOIN `shop_article_shop_category_mlt` ON `shop_order_item`.`shop_article_id` = `shop_article_shop_category_mlt`.`source_id`
             LEFT JOIN `shop_category` ON `shop_article_shop_category_mlt`.`target_id` = `shop_category`.`id`

               ';
        $aBaseCondition = array();
        if (!is_null($this->sStartDate)) {
            $aBaseCondition[] = "`shop_order`.`datecreated` >= '".\MySqlLegacySupport::getInstance()->real_escape_string($oLocal->StringToDate($this->sStartDate))."'";
        }
        if (!is_null($this->sEndDate)) {
            $aBaseCondition[] = "`shop_order`.`datecreated` <= '".\MySqlLegacySupport::getInstance()->real_escape_string($oLocal->StringToDate($this->sEndDate))." 23:59:59'";
        }
        if ('' != $this->selectedPortalId) {
            $aBaseCondition[] = "`shop_order`.`cms_portal_id` = '".\MySqlLegacySupport::getInstance()->real_escape_string($this->selectedPortalId)."'";
        }

        $query .= ' WHERE ('.implode(') AND (', $aBaseCondition).')';

        $query .= ' GROUP BY `shop_category`.`id`, `shop_order_item`.`shop_article_id`';
        $query .= ' ORDER BY totalordered DESC ';
        $query .= ' LIMIT 0,50';

        $oOrderItems = TdbShopOrderItemList::GetList($query);

        return $oOrderItems;
    }
506591
public function coupons()
    {
        $coupons = [];

        foreach ($this->transaction->discounts as $discount) {
            $coupons[] = $discount->id;
        }

        return $coupons;
    }
554676
public function getVoucherNrList()
    {
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
        $aVouchers = [];
        $sSelect = "select oxvouchernr from oxvouchers where oxorderid = " . $oDb->quote($this->oxorder__oxid->value);
        $rs = $oDb->select($sSelect);
        if ($rs != false && $rs->count() > 0) {
            while (!$rs->EOF) {
                $aVouchers[] = $rs->fields['oxvouchernr'];
                $rs->fetchRow();
            }
        }

        return $aVouchers;
    }
360392
protected function _getBasketBundles($aBundles = [])
    {
        $aDiscounts = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Application\Model\DiscountList::class)->getBasketBundleDiscounts($this, $this->getBasketUser());

        // calculating amount of non bundled/discount items
        $dAmount = 0;
        foreach ($this->_aBasketContents as $oBasketItem) {
            if (!($oBasketItem->isBundle() || $oBasketItem->isDiscountArticle())) {
                $dAmount += $oBasketItem->getAmount();
            }
        }

        foreach ($aDiscounts as $oDiscount) {
            if ($oDiscount->oxdiscount__oxitmartid->value) {
                if (!isset($aBundles[$oDiscount->oxdiscount__oxitmartid->value])) {
                    $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
                }

                $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount($dAmount);
            }
        }

        return $aBundles;
    }
128730
public function calculateTotalDiscount(Basket $basket, Discount $discount, Money $total)
    {
        // Handle a ValueDiscount
        if ($discount instanceof ValueDiscount) {
            $total = $this->subtractValueDiscount($total, $discount);
        }

        // Handle a PercentageDiscount
        if ($discount instanceof PercentageDiscount) {
            $total = $this->subtractPercentageDiscount($total, $discount);
        }

        // Handle a QuantityDiscount
        if ($discount instanceof QuantityDiscount) {
            // Calculate the total quantity of items ordered
            $totalQuantity = 0;

            foreach ($basket->products() as $product) {
                $totalQuantity = $totalQuantity + $product->quantity;
            }

            $quantityDiscount = $discount->rate();

            // Handle a ValueDiscount within a QuantityDiscount
            if ($quantityDiscount instanceof ValueDiscount) {
                $total = $this->subtractValueDiscount($total, $quantityDiscount);
            }

            // Handle a PercentageDiscount within a QuantityDiscount
            if ($quantityDiscount instanceof PercentageDiscount) {
                $total = $this->subtractPercentageDiscount($total, $quantityDiscount);
            }
        }

        return $total;
    }
824390
private function toPayPalItems($order)
    {
        $items = [];

        foreach ($order->items as $shopItem) {

            if ($shopItem->price > 0) {

                $item = new Item();

                $item->setName(substr($shopItem->displayName, 0, 127))
                    ->setDescription($shopItem->sku)
                    ->setCurrency($shopItem->currency)
                    ->setQuantity($shopItem->quantity)
                    ->setTax($shopItem->tax)
                    ->setPrice($shopItem->price);

                $items[] = $item;
            }
        }
        if ($discount = $order->totalDiscount) {
            $item = new Item();

            $item->setName('Discount')
                ->setDescription('discount')
                ->setCurrency($shopItem->currency)
                ->setQuantity(1)
                ->setTax(0)
                ->setPrice(-$discount);

            $items[] = $item;
        }

        return $items;
    }
1248719
public function getPaymorrowTotalAmount()
    {
        /** @var OxpsPaymorrowOxBasket|oxBasket $this */

        $dTotalPrice = (double) $this->getPrice()->getPrice();

        // Add surcharge price in case it is not yet included in basket
        $oSurchargePrice = $this->_getPaymentMethodSurcharge();

        if ( !empty( $oSurchargePrice ) and is_object( $oSurchargePrice ) ) {
            $dTotalPrice += (double) $oSurchargePrice->getPrice();
        }

        return $dTotalPrice;
    }