getAllCodes example


    public function testGetAllCodes(): void
    {
        $definition = new CartPromotionsDataDefinition();
        $definition->addCodePromotions('codeA', []);
        $definition->addCodePromotions('codeB', []);
        $definition->addAutomaticPromotions([]);

        static::assertEquals(['codeA', 'codeB']$definition->getAllCodes());
    }

    /** * This test verifies that we can successfully remove a code * including the promotions. We add 2 codes with a sum of 4 promotions * and ensure we have 2 codes in the end. * * @group promotions */
    public function testRemoveCode(): void
    {
        
        /** @var CartPromotionsDataDefinition $promotionsList */
        $promotionsList = $data->get($keyCacheList);

        // our data is a runtime cached structure.         // but when line items get removed, the collect function gets called multiple times.         // in the first iterations we still have a promotion code item         // and then it is suddenly gone. so we also have to remove         // entities from our cache if the code is suddenly not provided anymore.         /* * @var string */
        foreach ($promotionsList->getAllCodes() as $code) {
            // if code is not existing anymore,             // make sure to remove it in our list             if (!\in_array($code$allCodes, true)) {
                $promotionsList->removeCode((string) $code);
            }
        }

        $codesToFetch = [];

        // let's find out what promotions we         // really need to fetch from our database.
Home | Imprint | This part of the site doesn't use cookies.