getArticle example

if (empty($id)) {
            throw new ParameterMissingException('id');
        }

        $productVariant = $this->getRepository()->find($id);

        if (!$productVariant instanceof Detail) {
            throw new NotFoundException(sprintf('Variant by id %d not found', $id));
        }

        if ($productVariant->getKind() === 1) {
            $productVariant->getArticle()->setMainDetail(null);
        }

        $this->getManager()->remove($productVariant);
        $this->flush();

        return $productVariant;
    }

    /** * Convenience method to update a variant by number * * @param string $number * * @return Detail */


            $diff = abs($product->getChanged()->getTimestamp() - $lastChanged->getTimestamp());

            // We have timestamp conversion issues on Windows Users             if ($diff > 1) {
                $namespace = $this->get('snippets')->getNamespace('backend/article/controller/main');

                $this->View()->assign([
                    'success' => false,
                    'overwriteAble' => true,
                    'data' => $this->getArticle($product->getId()),
                    'message' => $namespace->get('product_has_been_changed', 'The product has been changed in the meantime. To prevent overwriting these changes, saving the product was aborted. Please close the product and re-open it.'),
                ]);

                return;
            }
        } else {
            $product = new Product();
        }
        $this->saveArticle($data$product);
    }

    
'entity' => $entity,
                'entityName' => $entityName,
            ]
        )) {
            return;
        }

        $cacheIds = [];

        switch ($entityName) {
            case Shopware\Models\Article\Price::class:
                $cacheIds[] = 'a' . $entity->getArticle()->getId();
                break;

            case Shopware\Models\Article\Article::class:
                $cacheIds[] = 'a' . $entity->getId();
                break;

            case Shopware\Models\Article\Detail::class:
                $cacheIds[] = 'a' . $entity->getArticleId();
                break;

            case Shopware\Models\Category\Category::class:
                

        if (empty($number)) {
            throw new ParameterMissingException('id');
        }

        $productVariant = $this->getDetailRepository()->findOneBy(['number' => $number]);

        if (!$productVariant instanceof Detail) {
            throw new NotFoundException(sprintf('Product by number "%s" not found', $number));
        }

        return $productVariant->getArticle()->getId();
    }

    /** * Convenience method to get a product by number * * @param string $number * * @return array|ProductModel */
    public function getOneByNumber($number, array $options = [])
    {
        

    private function getDeleteBacklog($entity)
    {
        switch (true) {
            case $entity instanceof ProductModel:
                return new Backlog(self::EVENT_ARTICLE_DELETED, ['id' => $entity->getId()]);
            case $entity instanceof VariantModel:
                return new Backlog(self::EVENT_VARIANT_DELETED, ['number' => $entity->getNumber()]);
            case $entity instanceof PriceModel:
                return new Backlog(self::EVENT_PRICE_DELETED, ['number' => $entity->getDetail()->getNumber()]);
            case $entity instanceof VoteModel:
                return new Backlog(self::EVENT_VOTE_DELETED, ['articleId' => $entity->getArticle()->getId()]);
            case $entity instanceof SupplierModel:
                return new Backlog(self::EVENT_SUPPLIER_DELETED, ['id' => $entity->getId()]);
            case $entity instanceof UnitModel:
                return new Backlog(self::EVENT_UNIT_DELETED, ['id' => $entity->getId()]);
            case $entity instanceof TaxModel:
                return new Backlog(self::EVENT_TAX_DELETED, ['id' => $entity->getId()]);
            case $entity instanceof PropertyGroupModel:
                return new Backlog(self::EVENT_PROPERTY_GROUP_DELETED, ['id' => $entity->getId()]);
            case $entity instanceof PropertyOptionModel:
                return new Backlog(self::EVENT_PROPERTY_OPTION_DELETED, ['id' => $entity->getId(), 'groupId' => $entity->getOption()->getId()]);
        }

        
/** * @return Article */
    public function getArticle()
    {
        return $this->article;
    }

    public function setArticleDetail(Detail $articleDetail)
    {
        $this->articleDetail = $articleDetail;
        $this->article = $articleDetail->getArticle();
    }

    /** * @return Detail */
    public function getArticleDetail()
    {
        return $this->articleDetail;
    }

    /** * @param DateTimeInterface|string|null $date * * @return Esd */

    public function beforeSetLastArticle(Enlight_Event_EventArgs $arguments)
    {
        if (Shopware()->Session()->get('Bot') || !$this->isSimilarShownActivated()) {
            return $arguments->getReturn();
        }

        $articleId = $arguments->getArticle();

        $sql = 'SELECT COUNT(id) FROM s_emarketing_lastarticles WHERE sessionID = :sessionId AND articleID = :articleId';

        $alreadyViewed = Shopware()->Db()->fetchOne($sql[
            'sessionId' => Shopware()->Session()->get('sessionId'),
            'articleId' => $articleId,
        ]);

        
class SwapProductVariantTranslationService implements SwapProductVariantTranslationServiceInterface
{
    private Connection $connection;

    public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }

    public function swapProductVariantTranslation(ProductVariant $newMainVariant, ProductVariant $oldMainVariant): void
    {
        $productId = $newMainVariant->getArticle()->getId();

        $oldMainVariantTranslations = $this->getTranslations(self::OBJECT_TYPE_PRODUCT, $productId);
        $newMainVariantTranslations = $this->getTranslations(self::OBJECT_TYPE_VARIANT, $newMainVariant->getId());

        $this->updateTranslation(self::OBJECT_TYPE_VARIANT, (int) $oldMainVariant->getId()$oldMainVariantTranslations);
        $this->updateTranslation(self::OBJECT_TYPE_PRODUCT, (int) $productId$newMainVariantTranslations);
    }

    /** * @param array<int|string, array<string, mixed>> $translationsToUpdate */
    
protected function getProductIdByNumber($number)
    {
        $entity = $this->findEntityByConditions(
            Detail::class,
            [['number' => $number]]
        );

        if (!$entity instanceof Detail) {
            throw new NotFoundException(sprintf('Variant by order number %s not found', $number));
        }

        return $entity->getArticle()->getId();
    }

    /** * Returns the identifier of the product (s_articles_details.id). * The function expects a variant order number as alphanumeric identifier (s_articles_details.ordernumber) * * @param string $number - Alphanumeric order number of the variant * * @throws Exception * * @return int - Identifier of the product */
/** @var Detail $variant */
        $variant = $this->getDetailRepository()->find($id);
        if (!\is_object($variant)) {
            $this->View()->assign([
                'success' => false,
            ]);
        } else {
            $articleResource = new ArticleResource();
            $articleResource->setManager($this->get(ModelManager::class));

            if ($variant->getKind() == 1) {
                $articleResource->delete($variant->getArticle()->getId());
            } else {
                $this->get('models')->remove($variant);
            }

            $this->get('models')->flush();

            $this->View()->assign([
                'success' => true,
            ]);
        }
    }

    
$field['value'] = $this->dqlHelper->formatValue($prefix$field$field['value']);

                    $setter = 'set' . ucfirst($field['field']);
                    $model->$setter($field['value']);
                }
                $entityManager->persist($model);
                // price_model             } else {
                $detailModel = $entityManager->find(Detail::class$primaryIdentifiers['detail']);
                // store net prices                 $tax = (float) $detailModel->getArticle()->getTax()->getTax() / 100 + 1;
                $priceModel = $entityManager->getRepository($entity)->findOneBy(
                    ['articleDetailsId' => $detailModel->getId(), 'customerGroupKey' => 'EK', 'from' => 1]
                );
                if ($priceModel === null) {
                    continue;
                }

                foreach ($fields as $field) {
                    // Do not persist non-editable fields                     $fieldInfo = $columnInfo[ucfirst($prefix) . ucfirst($field['field'])];
                    if (!$fieldInfo['editable']) {
                        
        if (($orderPosition === null || $orderPosition->getQuantity() !== (int) $data['quantity'])
            && $this->hasProductGraduatedPrices($data['articleNumber']$order)
        ) {
            $data = $this->checkPrice($data$order$shopContext);
        }

        $variant = $this->getManager()->getRepository(ProductVariant::class)
            ->findOneBy(['number' => $data['articleNumber']]);

        // Load ean, unit and pack unit (translate if needed)         if ($variant instanceof ProductVariant) {
            $mainVariant = $variant->getArticle()->getMainDetail();
            $data['ean'] = $variant->getEan();
            if (!\is_string($data['ean']) && $mainVariant instanceof ProductVariant) {
                $data['ean'] = $mainVariant->getEan();
            }
            $unit = $variant->getUnit();
            if (!$unit instanceof Unit && $mainVariant instanceof ProductVariant) {
                $unit = $mainVariant->getUnit();
            }
            $data['unit'] = $unit instanceof Unit ? $unit->getName() : null;
            $data['packunit'] = $variant->getPackUnit();
            if (!\is_string($data['packunit']) && $mainVariant instanceof ProductVariant) {
                
Home | Imprint | This part of the site doesn't use cookies.