Issues (3641)

Replacer/DeliveryItemProductOfferReplacer.php (1 issue)

1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace Spryker\Zed\ClickAndCollectExample\Business\Replacer;
9
10
use Generated\Shared\Transfer\ItemTransfer;
11
use Generated\Shared\Transfer\ProductOfferServicePointCriteriaTransfer;
12
use Generated\Shared\Transfer\QuoteReplacementResponseTransfer;
13
use Generated\Shared\Transfer\QuoteTransfer;
14
15
class DeliveryItemProductOfferReplacer extends AbstractItemProductOfferReplacer
16
{
17
    /**
18
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
19
     * @param array<string, \Generated\Shared\Transfer\ItemTransfer> $itemTransfersForReplacement
20
     *
21
     * @return array<int, \Generated\Shared\Transfer\ProductOfferServicePointTransfer>
22
     */
23
    protected function getProductOfferServicePointTransfers(QuoteTransfer $quoteTransfer, array $itemTransfersForReplacement): array
24
    {
25
        $productOfferServicePointCriteriaTransfer = $this
26
            ->createProductOfferServicePointCriteriaTransfer($quoteTransfer, $itemTransfersForReplacement);
27
28
        return $this->productOfferServicePointReader
29
            ->getDeliveryProductOfferServicePoints($productOfferServicePointCriteriaTransfer);
30
    }
31
32
    /**
33
     * @param \Generated\Shared\Transfer\QuoteReplacementResponseTransfer $quoteReplacementResponseTransfer
34
     *
35
     * @return list<\Generated\Shared\Transfer\ItemTransfer>
36
     */
37
    protected function getQuoteItemsAvailableForReplacement(QuoteReplacementResponseTransfer $quoteReplacementResponseTransfer): array
38
    {
39
        $quoteItemTransfersForReplacement = [];
40
        foreach ($quoteReplacementResponseTransfer->getQuoteOrFail()->getItems() as $itemTransfer) {
41
            if (!$this->isQuoteItemApplicable($itemTransfer)) {
42
                continue;
43
            }
44
45
            $quoteItemTransfersForReplacement[] = $itemTransfer;
46
        }
47
48
        return $quoteItemTransfersForReplacement;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $quoteItemTransfersForReplacement returns the type array which is incompatible with the documented return type Spryker\Zed\ClickAndColl...\Business\Replacer\list.
Loading history...
49
    }
50
51
    /**
52
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
53
     *
54
     * @return bool
55
     */
56
    protected function isQuoteItemApplicable(ItemTransfer $itemTransfer): bool
57
    {
58
        return $itemTransfer->getShipmentType()
59
            && !$this->isItemProductBundle($itemTransfer)
60
            && $itemTransfer->getProductOfferReference()
61
            && $itemTransfer->getShipmentTypeOrFail()->getKey() === $this->clickAndCollectExampleConfig->getDeliveryShipmentTypeKey();
62
    }
63
64
    /**
65
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
66
     *
67
     * @return bool
68
     */
69
    protected function isItemProductBundle(ItemTransfer $itemTransfer): bool
70
    {
71
        return $itemTransfer->getRelatedBundleItemIdentifier() || $itemTransfer->getBundleItemIdentifier();
72
    }
73
74
    /**
75
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
76
     * @param array<string, \Generated\Shared\Transfer\ItemTransfer> $quoteItemTransfersForReplacement
77
     *
78
     * @return \Generated\Shared\Transfer\ProductOfferServicePointCriteriaTransfer
79
     */
80
    protected function createProductOfferServicePointCriteriaTransfer(
81
        QuoteTransfer $quoteTransfer,
82
        array $quoteItemTransfersForReplacement
83
    ): ProductOfferServicePointCriteriaTransfer {
84
        $productOfferServicePointCriteriaTransfer = (new ProductOfferServicePointCriteriaTransfer())
85
            ->setStoreName($quoteTransfer->getStoreOrFail()->getNameOrFail())
86
            ->setShipmentTypeKey($this->clickAndCollectExampleConfig->getDeliveryShipmentTypeKey())
87
            ->setCurrencyCode($quoteTransfer->getCurrencyOrFail()->getCodeOrFail())
88
            ->setPriceMode($quoteTransfer->getPriceModeOrFail());
89
90
        foreach ($quoteItemTransfersForReplacement as $itemTransfer) {
91
            $productOfferServicePointCriteriaTransfer
92
                ->addConcreteSku($itemTransfer->getSkuOrFail());
93
        }
94
95
        return $productOfferServicePointCriteriaTransfer;
96
    }
97
}
98