protected function processProductSaleElementUpdate($changeForm)
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
            return $response;
        }

        try {
            // Check the form against constraints violations
            $form = $this->validateForm($changeForm, "POST");

            // Get the form field values
            $data = $form->getData();

            if (\is_array($data['product_sale_element_id'])) {
                // Common fields
                $tmp_data = array(
                    'tax_rule'          => $data['tax_rule'],
                    'currency'          => $data['currency'],
                    'use_exchange_rate' => $data['use_exchange_rate'],
                );

                $count = \count($data['product_sale_element_id']);

                for ($idx = 0; $idx < $count; $idx++) {
                    $tmp_data['product_sale_element_id'] = $pse_id = $data['product_sale_element_id'][$idx];
                    $tmp_data['reference']               = $data['reference'][$idx];
                    $tmp_data['price']                   = $data['price'][$idx];
                    $tmp_data['weight']                  = $data['weight'][$idx];
                    $tmp_data['quantity']                = $data['quantity'][$idx];
                    $tmp_data['sale_price']              = $data['sale_price'][$idx];
                    $tmp_data['onsale']                  = isset($data['onsale'][$idx]) ? 1 : 0;
                    $tmp_data['isnew']                   = isset($data['isnew'][$idx]) ? 1 : 0;
                    $tmp_data['isdefault']               = $data['default_pse'] == $pse_id;
                    $tmp_data['ean_code']                = $data['ean_code'][$idx];

                    $this->processSingleProductSaleElementUpdate($tmp_data);
                }
            } else {
                // No need to preprocess data
                $this->processSingleProductSaleElementUpdate($data);
            }

            // If we have to stay on the same page, do not redirect to the successUrl, just redirect to the edit page again.
            if ($this->getRequest()->get('save_mode') == 'stay') {
                return $this->redirectToEditionTemplate();
            }

           // Redirect to the success URL
            return $this->generateSuccessRedirect($changeForm);
        } catch (FormValidationException $ex) {
            // Form cannot be validated
            $error_msg = $this->createStandardFormValidationErrorMessage($ex);
        } catch (\Exception $ex) {
            // Any other error
            $error_msg = $ex->getMessage();
        }

        $this->setupFormErrorContext(
            $this->getTranslator()->trans("ProductSaleElement modification"),
            $error_msg,
            $changeForm,
            $ex
        );

        // At this point, the form has errors, and should be redisplayed.
        return $this->renderEditionTemplate();
    }
protected function processProductSaleElementUpdate($changeForm)
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
            return $response;
        }

        try {
            // Check the form against constraints violations
            $form = $this->validateForm($changeForm, "POST");

            // Get the form field values
            $data = $form->getData();

            if (\is_array($data['product_sale_element_id'])) {
                // Common fields
                $tmp_data = array(
                    'tax_rule'          => $data['tax_rule'],
                    'currency'          => $data['currency'],
                    'use_exchange_rate' => $data['use_exchange_rate'],
                );

                $count = \count($data['product_sale_element_id']);

                for ($idx = 0; $idx < $count; $idx++) {
                    $tmp_data['product_sale_element_id'] = $pse_id = $data['product_sale_element_id'][$idx];
                    $tmp_data['reference']               = $data['reference'][$idx];
                    $tmp_data['price']                   = $data['price'][$idx];
                    $tmp_data['weight']                  = $data['weight'][$idx];
                    $tmp_data['quantity']                = $data['quantity'][$idx];
                    $tmp_data['sale_price']              = $data['sale_price'][$idx];
                    $tmp_data['onsale']                  = isset($data['onsale'][$idx]) ? 1 : 0;
                    $tmp_data['isnew']                   = isset($data['isnew'][$idx]) ? 1 : 0;
                    $tmp_data['isdefault']               = $data['default_pse'] == $pse_id;
                    $tmp_data['ean_code']                = $data['ean_code'][$idx];

                    $this->processSingleProductSaleElementUpdate($tmp_data);
                }
            } else {
                // No need to preprocess data
                $this->processSingleProductSaleElementUpdate($data);
            }

            // If we have to stay on the same page, do not redirect to the successUrl, just redirect to the edit page again.
            if ($this->getRequest()->get('save_mode') == 'stay') {
                return $this->redirectToEditionTemplate();
            }

           // Redirect to the success URL
            return $this->generateSuccessRedirect($changeForm);
        } catch (FormValidationException $ex) {
            // Form cannot be validated
            $error_msg = $this->createStandardFormValidationErrorMessage($ex);
        } catch (\Exception $ex) {
            // Any other error
            $error_msg = $ex->getMessage();
        }

        $this->setupFormErrorContext(
            $this->getTranslator()->trans("ProductSaleElement modification"),
            $error_msg,
            $changeForm,
            $ex
        );

        // At this point, the form has errors, and should be redisplayed.
        return $this->renderEditionTemplate();
    }
protected function processProductSaleElementUpdate ( $ changeForm ) { // Check current user authorization if ( null !== $ response = $ this -> checkAuth ( $ this -> resourceCode , array ( ) , AccessManager :: UPDATE ) ) { return $ response ; } try { // Check the form against constraints violations $ form = $ this -> validateForm ( $ changeForm , "POST" ) ; // Get the form field values $ data = $ form -> getData ( ) ; if ( \ is_array ( $ data [ 'product_sale_element_id' ] ) ) { // Common fields $ tmp_data = array ( 'tax_rule' => $ data [ 'tax_rule' ] , 'currency' => $ data [ 'currency' ] , 'use_exchange_rate' => $ data [ 'use_exchange_rate' ] , ) ; $ count = \ count ( $ data [ 'product_sale_element_id' ] ) ; for ( $ idx = 0 ; $ idx < $ count ; $ idx ++ ) { $ tmp_data [ 'product_sale_element_id' ] = $ pse_id = $ data [ 'product_sale_element_id' ] [ $ idx ] ; $ tmp_data [ 'reference' ] = $ data [ 'reference' ] [ $ idx ] ; $ tmp_data [ 'price' ] = $ data [ 'price' ] [ $ idx ] ; $ tmp_data [ 'weight' ] = $ data [ 'weight' ] [ $ idx ] ; $ tmp_data [ 'quantity' ] = $ data [ 'quantity' ] [ $ idx ] ; $ tmp_data [ 'sale_price' ] = $ data [ 'sale_price' ] [ $ idx ] ; $ tmp_data [ 'onsale' ] = isset ( $ data [ 'onsale' ] [ $ idx ] ) ? 1 : 0 ; $ tmp_data [ 'isnew' ] = isset ( $ data [ 'isnew' ] [ $ idx ] ) ? 1 : 0 ; $ tmp_data [ 'isdefault' ] = $ data [ 'default_pse' ] == $ pse_id ; $ tmp_data [ 'ean_code' ] = $ data [ 'ean_code' ] [ $ idx ] ; $ this -> processSingleProductSaleElementUpdate ( $ tmp_data ) ; } } else { // No need to preprocess data $ this -> processSingleProductSaleElementUpdate ( $ data ) ; } // If we have to stay on the same page, do not redirect to the successUrl, just redirect to the edit page again. if ( $ this -> getRequest ( ) -> get ( 'save_mode' ) == 'stay' ) { return $ this -> redirectToEditionTemplate ( ) ; } // Redirect to the success URL return $ this -> generateSuccessRedirect ( $ changeForm ) ; } catch ( FormValidationException $ ex ) { // Form cannot be validated $ error_msg = $ this -> createStandardFormValidationErrorMessage ( $ ex ) ; } catch ( \ Exception $ ex ) { // Any other error $ error_msg = $ ex -> getMessage ( ) ; } $ this -> setupFormErrorContext ( $ this -> getTranslator ( ) -> trans ( "ProductSaleElement modification" ) , $ error_msg , $ changeForm , $ ex ) ; // At this point, the form has errors, and should be redisplayed. return $ this -> renderEditionTemplate ( ) ; }
Change a product sale element

@param BaseForm $changeForm

@return mixed|null|\Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response|Response
Change a product sale element