Programming Language PHP

Namespace Bavix\Wallet\Internal\Dto

Class BasketDtoInterface

Method/Function items

Total Examples 2

2 code examples of PHP Bavix\Wallet\Internal\Dto\BasketDtoInterface::items extracted from open source projects

Was this example useful?
0
                                                    public function already(Customer $customer, BasketDtoInterface $basketDto, bool $gifts = false): array
    {
        $status = $gifts
            ? [Transfer::STATUS_PAID, Transfer::STATUS_GIFT]
            : [Transfer::STATUS_PAID];

        $arrays = [];
        $wallets = [];
        $productCounts = [];
        $query = $customer->transfers();
        foreach ($basketDto->items() as $itemDto) {
            $wallet = $this->castService->getWallet($itemDto->getProduct());
            $wallets[$wallet->uuid] = $wallet;

            $productCounts[$wallet->uuid] = ($productCounts[$wallet->uuid] ?? 0) + count($itemDto);
        }

        foreach ($wallets as $wallet) {
            /**
             * As part of my work, "with" was added, it gives a 50x boost for a huge number of returns. In this case,
             * it's a crutch. It is necessary to come up with a more correct implementation of the internal and external
             * interface for "purchases".
             */
            $arrays[] = (clone $query)
                ->with(['deposit', 'withdraw.wallet'])
                ->where('to_type', $wallet->getMorphClass())
                ->where('to_id', $wallet->getKey())
                ->whereIn('status', $status)
                ->orderBy('id', 'desc')
                ->limit($productCounts[$wallet->uuid])
                ->get()
                ->all();
        }

        return array_merge(...$arrays);
    }
                                            
Was this example useful?
0
                                                    public function loadWalletsByBasket(BasketDtoInterface $basketDto): void
    {
        $products = [];
        /** @var array<array-key, array<array-key, int|string>> $productGroupIds */
        $productGroupIds = [];
        foreach ($basketDto->items() as $index => $item) {
            $model = $this->castService->getModel($item->getProduct());
            if (!$model->relationLoaded('wallet')) {
                $products[$index] = $item->getProduct();
                $productGroupIds[$model->getMorphClass()][$index] = $model->getKey();
            }
        }

        foreach ($productGroupIds as $holderType => $holderIds) {
            $allWallets = $this->walletRepository->findDefaultAll($holderType, array_unique($holderIds));
            $wallets = [];
            foreach ($allWallets as $wallet) {
                $wallets[$wallet->holder_id] = $wallet;
            }

            foreach ($holderIds as $index => $holderId) {
                $wallet = $wallets[$holderId] ?? null;
                if ($wallet !== null) {
                    $model = $this->castService->getModel($products[$index]);
                    $model->setRelation('wallet', $wallet);
                }
            }
        }
    }
                                            
BasketDtoInterface's Other Methods