Handles updating of the product.

@param ProductRepository $productRepository
@param Dispatcher $event
@return Product
490276
public function handle(ProductRepository $productRepository, Dispatcher $event)
    {
        $product = $productRepository->find($this->id)->fill(array_except(get_object_vars($this), ['attributes']));

        $productRepository->save($product, $this->attributes);

        $event->fire(new ProductWasUpdated($product));

        return $product;
    }
167809
public function update(ProductRequest $request, ProductModel $product)
    {
        //dd($request->all());
        try {
            //$product = ProductModel::findorfail($id);
            $product->saveProduct($request->all());
        } catch (\Exception $e) {
            throw new \Exception('Error in Saving Product: ' . $e->getMessage());
        }

        return redirect()->route('admin.product.index');
    }
1172075
public function handle(AttributeValueRepository $attributeValueRepository, Dispatcher $event)
    {
        $attributeValue = $attributeValueRepository->find($this->id)->fill(get_object_vars($this));

        $attributeValueRepository->save($attributeValue);

        $event->fire(new AttributeValueWasUpdated($attributeValue));

        return $attributeValue;
    }
824796
public function viewCheck(ViewCheckEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if ($event->getView() == 'product') {
            $product = ProductQuery::create()
                ->filterById($event->getViewId())
                ->filterByVisible(1)
                ->count();

            if ($product == 0) {
                $dispatcher->dispatch(TheliaEvents::VIEW_PRODUCT_ID_NOT_VISIBLE, $event);
            }
        }
    }
1250198
public function create(CouponCreateOrUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $coupon = new CouponModel();

        $this->createOrUpdate($coupon, $event, $dispatcher);
    }
853670
public function handle(ProductTypeRepository $productTypeRepository, Dispatcher $event)
    {
        $productType = $productTypeRepository->find($this->id);

        // TODO : Check if the product type is in use

        $productTypeRepository->destroy($productType);

        $event->fire(new ProductTypeWasDestroyed($productType));

        return $productType;
    }
579383
public function update(FeatureAvUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $feature = FeatureAvQuery::create()->findPk($event->getFeatureAvId())) {
            $feature
                ->setDispatcher($dispatcher)

                ->setLocale($event->getLocale())
                ->setTitle($event->getTitle())
                ->setDescription($event->getDescription())
                ->setChapo($event->getChapo())
                ->setPostscriptum($event->getPostscriptum())

                ->save();

            $event->setFeatureAv($feature);
        }
    }
78403
public function create(ProductOrder $productOrder)
    {
        $this->getEm()->persist($productOrder);
        $this->getEm()->flush();

        return $productOrder;
    }
676983
public function delete(TemplateDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== ($template = TemplateQuery::create()->findPk($event->getTemplateId()))) {
            // Check if template is used by a product
            $productCount = ProductQuery::create()->findByTemplateId($template->getId())->count();
            
            if ($productCount <= 0) {
                $con = Propel::getWriteConnection(TemplateTableMap::DATABASE_NAME);
                $con->beginTransaction();
                
                try {
                    $template
                        ->setDispatcher($dispatcher)
                        ->delete($con);
                    
                    // We have to also delete any reference of this template in category tables
                    // We can't use a FK here, as the DefaultTemplateId column may be NULL
                    // so let's take care of this.
                    CategoryQuery::create()
                        ->filterByDefaultTemplateId($event->getTemplateId())
                        ->update([ 'DefaultTemplateId' => null], $con);
                    
                    $con->commit();
                } catch (\Exception $ex) {
                    $con->rollback();
                    
                    throw $ex;
                }
            }
            
            $event->setTemplate($template);
            
            $event->setProductCount($productCount);
        }
    }
699645
protected function updateQuantity(ModelOrder $order, $newStatus, EventDispatcherInterface $dispatcher)
    {
        if ($newStatus !== $order->getStatusId()) {
            if (null !== $newStatusModel = OrderStatusQuery::create()->findPk($newStatus)) {
                $operationEvent = new GetStockUpdateOperationOnOrderStatusChangeEvent($order, $newStatusModel);

                $dispatcher->dispatch(
                    TheliaEvents::ORDER_GET_STOCK_UPDATE_OPERATION_ON_ORDER_STATUS_CHANGE,
                    $operationEvent
                );

                if ($operationEvent->getOperation() !== $operationEvent::DO_NOTHING) {
                    $orderProductList = $order->getOrderProducts();

                    /** @var OrderProduct $orderProduct */
                    foreach ($orderProductList as $orderProduct) {
                        $productSaleElementsId = $orderProduct->getProductSaleElementsId();

                        /** @var ProductSaleElements $productSaleElements */
                        if (null !== $productSaleElements = ProductSaleElementsQuery::create()->findPk($productSaleElementsId)) {
                            $offset = 0;

                            if ($operationEvent->getOperation() == $operationEvent::INCREASE_STOCK) {
                                $offset = $orderProduct->getQuantity();
                            } elseif ($operationEvent->getOperation() == $operationEvent::DECREASE_STOCK) {
                                /* Check if we have enough stock */
                                if ($orderProduct->getQuantity() > $productSaleElements->getQuantity() && true === ConfigQuery::checkAvailableStock()) {
                                    throw new TheliaProcessException($productSaleElements->getRef() . " : Not enough stock 2");
                                }

                                $offset = -$orderProduct->getQuantity();
                            }

                            Tlog::getInstance()->addError("Product stock: " . $productSaleElements->getQuantity() . " -> " . ($productSaleElements->getQuantity() + $offset));

                            $productSaleElements
                                ->setQuantity($productSaleElements->getQuantity() + $offset)
                                ->save();
                        }
                    }
                }
            }
        }
    }
1077717
public function handle(AttributeRepository $attributeRepository, Dispatcher $event)
    {
        $attribute = Attribute::instantiate($this->description, $this->type);

        $attributeRepository->save($attribute);

        $event->fire(new AttributeWasStored($attribute));

        return $attribute;
    }
322325
public function update(CurrencyUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) {
            $currency
                ->setDispatcher($dispatcher)

                ->setLocale($event->getLocale())
                ->setName($event->getCurrencyName())
                ->setSymbol($event->getSymbol())
                ->setFormat($event->getFormat())
                ->setRate($event->getRate())
                ->setCode(strtoupper($event->getCode()))

                ->save();

            $event->setCurrency($currency);
        }
    }
486155
protected function setProductProductBundle($product_id)
    {
        $this->data_product = $this->product->get($product_id);

        if (empty($this->data_product)) {
            $this->outputHttpStatus(404);
        }

        $this->prepareProductBundle($this->data_product);
    }
742858
public function setProductOrder(\Amulen\ShopBundle\Entity\ProductOrder $productOrder = null)
    {
        $this->productOrder = $productOrder;

        return $this;
    }
412126
public function update(SaleUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $sale = SaleQuery::create()->findPk($event->getSaleId())) {
            $sale->setDispatcher($dispatcher);

            $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME);

            $con->beginTransaction();

            try {
                // Disable all promo flag on sale's currently selected products,
                // to reset promo status of the products that may have been removed from the selection.
                $sale->setActive(false);

                $dispatcher->dispatch(
                    TheliaEvents::UPDATE_PRODUCT_SALE_STATUS,
                    new ProductSaleStatusUpdateEvent($sale)
                );

                $sale
                    ->setActive($event->getActive())
                    ->setStartDate($event->getStartDate())
                    ->setEndDate($event->getEndDate())
                    ->setPriceOffsetType($event->getPriceOffsetType())
                    ->setDisplayInitialPrice($event->getDisplayInitialPrice())
                    ->setLocale($event->getLocale())
                    ->setSaleLabel($event->getSaleLabel())
                    ->setTitle($event->getTitle())
                    ->setDescription($event->getDescription())
                    ->setChapo($event->getChapo())
                    ->setPostscriptum($event->getPostscriptum())
                    ->save($con)
                ;

                $event->setSale($sale);

                // Update price offsets
                SaleOffsetCurrencyQuery::create()->filterBySaleId($sale->getId())->delete($con);

                foreach ($event->getPriceOffsets() as $currencyId => $priceOffset) {
                    $saleOffset = new SaleOffsetCurrency();

                    $saleOffset
                        ->setCurrencyId($currencyId)
                        ->setSaleId($sale->getId())
                        ->setPriceOffsetValue($priceOffset)
                        ->save($con)
                    ;
                }

                // Update products
                SaleProductQuery::create()->filterBySaleId($sale->getId())->delete($con);

                $productAttributesArray = $event->getProductAttributes();

                foreach ($event->getProducts() as $productId) {
                    if (isset($productAttributesArray[$productId])) {
                        foreach ($productAttributesArray[$productId] as $attributeId) {
                            $saleProduct = new SaleProduct();

                            $saleProduct
                                ->setSaleId($sale->getId())
                                ->setProductId($productId)
                                ->setAttributeAvId($attributeId)
                                ->save($con)
                            ;
                        }
                    } else {
                        $saleProduct = new SaleProduct();

                        $saleProduct
                            ->setSaleId($sale->getId())
                            ->setProductId($productId)
                            ->setAttributeAvId(null)
                            ->save($con)
                        ;
                    }
                }

                // Update related products sale status if the Sale is active. This is not required if the sale is
                // not active, as we de-activated promotion for this sale at the beginning ofd this method
                if ($sale->getActive()) {
                    $dispatcher->dispatch(
                        TheliaEvents::UPDATE_PRODUCT_SALE_STATUS,
                        new ProductSaleStatusUpdateEvent($sale)
                    );
                }

                $con->commit();
            } catch (PropelException $e) {
                $con->rollback();
                throw $e;
            }
        }
    }
322921
public function onSaveJobResultQuery(
        QueueSaveJobResultEvent $event,
        $eventName,
        EventDispatcherInterface $dispatcher
    ) {
        $table          = $event->getQueueTable();
        $field          = $event->getField();
        $data           = urlencode(serialize($event->getData()));
        $id             = $event->getId();
        $query          = "UPDATE $table SET $field = '$data' WHERE id = $id";
        $event->setQuery($query);
    }
210805
public function onSubscriptionCreate(StripeSubscriptionCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $localSubscription = $event->getLocalSubscription();

        $result = $this->getStripeManager()->createSubscription($localSubscription);

        // Check if something went wrong
        if (false === $result) {
            // Stop progation
            $event->setStopReason($this->getStripeManager()->getError())->stopPropagation();

            // Dispatch a failed event
            $dispatcher->dispatch(StripeSubscriptionCreateEvent::FAILED, $event);

            // exit
            return;
        }

        $dispatcher->dispatch(StripeSubscriptionCreateEvent::CREATED, $event);
    }