removeElement example



    public function testRemoveElement(): void
    {
        $toRemove = new CalculatedTax(5.50, 18, 1);
        $collection = new CalculatedTaxCollection([
            new CalculatedTax(5.50, 19, 1),
            $toRemove,
            new CalculatedTax(5.50, 17, 1),
        ]);

        $collection->removeElement($toRemove);

        static::assertEquals(
            new CalculatedTaxCollection([
                new CalculatedTax(5.50, 19, 1),
                new CalculatedTax(5.50, 17, 1),
            ]),
            $collection
        );
    }
}
/** * @param string|Element $element * * @return Form */
    public function removeElement($element)
    {
        if (!$element instanceof Element) {
            $element = $this->getElement($element);
        }
        if ($element !== null) {
            $this->elements->removeElement($element);
        }

        return $this;
    }

    /** * @param Element|string $element * @param string $name * @param array $options * * @return Form */
$shop = $this->entityManager->getReference(Shop::class$data['shopId']);
            if (!$shop instanceof Shop) {
                throw new ModelNotFoundException(Shop::class$data['shopId']);
            }

            if ($element->getType() === 'theme-media-selection') {
                $data['value'] = $this->mediaService->normalize($data['value']);
            }

            // Don't save default values             if ($element->getDefaultValue() === $data['value']) {
                $element->getValues()->removeElement($value);
                continue;
            }

            $value->setShop($shop);
            $value->setElement($element);
            $value->setValue($data['value']);
        }

        $this->entityManager->flush();
    }

    
$this->categories->add($category);
        }

        return $this;
    }

    /** * @return Article */
    public function removeCategory(ProductCategory $category)
    {
        $this->categories->removeElement($category);

        return $this;
    }

    /** * @return ArrayCollection<array-key, CustomerGroup> */
    public function getCustomerGroups()
    {
        return $this->customerGroups;
    }

    


    public function testRemoveElement(): void
    {
        $first = (new LineItem('A', 'temp'))->assign(['uniqueIdentifier' => 'A']);

        $collection = new LineItemCollection([
            $first,
            (new LineItem('B', 'temp'))->assign(['uniqueIdentifier' => 'B']),
        ]);

        $collection->removeElement($first);

        static::assertEquals(
            new LineItemCollection([(new LineItem('B', 'temp'))->assign(['uniqueIdentifier' => 'B'])]),
            $collection
        );
    }

    public function testExists(): void
    {
        $first = new LineItem('A', 'temp');
        $second = new LineItem('B2', 'temp');

        


        $this->recipients->add($contact);
    }

    public function removeRecipient(Contact $contact): void
    {
        if (!$this->recipients->contains($contact)) {
            return;
        }

        $this->recipients->removeElement($contact);
    }

    public function getSentAt(): ?DateTimeInterface
    {
        return $this->sentAt;
    }

    public function setSentAt(DateTimeInterface $sentAt): void
    {
        $this->sentAt = $sentAt;
    }

    


            // Add the model to the updated collection to have an flag which models updated.             $updated->add($attribute);
        }

        // After all passed data items added to the internal collection, we have to iterate the items         // to remove all old items which are not updated.         foreach ($this->$getterFunction() as $attr) {
            // The updated collection contains all updated and created models.             if (!$updated->contains($attr)) {
                $this->$getterFunction()->removeElement($attr);
            }
        }

        return $this;
    }

    /** * Helper function to set the association data of a ORM\ManyToOne association of doctrine. * <br><br> * The <b>$data</b> parameter contains the data for the collection property. It can contains an array of * models or data arrays. If the $data parameter is set to null the associated collection will cleared. * <br><br> * The <b>$model</b> parameter expects the full name of the associated model. * For example: * <ul> * <li>We are in the Article model in the setSupplier() function.</li> * <li>Here we want to set the Supplier objects over the "setManyToOne" function</li> * <li>So we passed as $model parameter: <b>"\Shopware\Models\Article\Supplier"</b></li> * </ul> * <br> * The <b>$property</b> parameter expect the name of the association property. * For example: * <ul> * <li>In the setSupplier() function of the article model we would expects <b>"supplier"</b>.</li> * </ul> * * @param ModelEntity|array|null $data Model data, example: an data array or an instance of the model * @param string $model Full namespace of the association model, example: '\Shopware\Models\Article\Supplier' * @param string $property Name of the association property, example: 'supplier' * * @throws InvalidArgumentException * * @return $this */
$found = false;
            foreach ($data['esd']['serials'] as $newSerial) {
                if ($newSerial['serialnumber'] === $serial->getSerialnumber()) {
                    $serial->fromArray($newSerial);
                    $found = true;
                    break;
                }
            }

            if ($found === false) {
                $this->manager->remove($serial);
                $esd->getSerials()->removeElement($serial);
            }
        }

        // Add new items         foreach ($data['esd']['serials'] as $newSerial) {
            $found = false;

            foreach ($esd->getSerials() as $serial) {
                if ($newSerial['serialnumber'] === $serial->getSerialnumber()) {
                    $found = true;
                    break;
                }

    public function getOptions()
    {
        return $this->options->toArray();
    }

    /** * @return Group */
    public function removeOption(Option $option)
    {
        $this->options->removeElement($option);

        return $this;
    }

    /** * @return Group */
    public function addOption(Option $option)
    {
        $this->options->add($option);

        
public function testRemoveElement(): void
    {
        $toRemove = new TaxRule(18);

        $collection = new TaxRuleCollection([
            new TaxRule(19),
            $toRemove,
            new TaxRule(17),
        ]);

        $collection->removeElement($toRemove);

        static::assertEquals(
            new TaxRuleCollection([
                new TaxRule(19),
                new TaxRule(17),
            ]),
            $collection
        );
    }
}
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

#[Package('checkout')] class LineItemValidator implements CartValidatorInterface
{
    public function validate(Cart $cart, ErrorCollection $errors, SalesChannelContext $context): void
    {
        foreach ($cart->getLineItems()->getFlat() as $lineItem) {
            if ($lineItem->getLabel() === null && $lineItem->getType() !== LineItem::CONTAINER_LINE_ITEM) {
                $errors->add(new IncompleteLineItemError($lineItem->getId(), 'label'));
                $cart->getLineItems()->removeElement($lineItem);
            }

            if ($lineItem->getPrice() === null) {
                $errors->add(new IncompleteLineItemError($lineItem->getId(), 'price'));
                $cart->getLineItems()->removeElement($lineItem);
            }
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.