getPost example



    /** * this function enables the user to create groups * after taking a groupName and a templateVariable, it will check if either one already exists and if so, throw an exception * otherwise it will append the new group to cmsPositions in s_core_config */
    public function createGroupAction()
    {
        $manager = $this->getManager();
        $repository = $manager->getRepository(Group::class);
        $data = $this->Request()->getPost();
        $data = isset($data[0]) ? array_pop($data) : $data;

        $name = empty($data['groupName']) ? null : $data['groupName'];
        $key = empty($data['templateVar']) ? null : $data['templateVar'];

        if ($key === null) {
            $this->View()->assign([
                'success' => false,
                'message' => 'Template Variable may not be empty',
            ]);

            
'total' => \count($data),
        ]);
    }

    /** * Clear cache action * * @throws Zend_Cache_Exception */
    public function clearCacheAction()
    {
        $cache = $this->Request()->getPost('cache', []);

        $cacheInstance = $this->container->get('cache');

        $capabilities = $cacheInstance->getBackend()->getCapabilities();

        if (empty($capabilities['tags'])) {
            if ($cache['config'] === 'on' || $cache['template'] === 'on') {
                $cacheInstance->clean();
            }
        } else {
            $tags = [];
            
$view->assign('data', $category);
        $view->assign('success', true);
    }

    /** * Create new category * * POST /api/categories */
    public function postAction(): void
    {
        $category = $this->resource->create($this->Request()->getPost());

        $location = $this->apiBaseUrl . 'categories/' . $category->getId();
        $data = [
            'id' => $category->getId(),
            'location' => $location,
        ];

        $this->View()->assign(['success' => true, 'data' => $data]);
        $this->Response()->headers->set('location', $location);
    }

    
$request = $this->Request();

        if ($request->has('buildSearchIndex')) {
            $this->resource->buildSearchIndex(0, true);
            $this->resource->cleanupIndexSearchIndex();
            $this->View()->assign(['success' => true]);

            return;
        }

        $stream = $this->resource->create(
            $request->getPost(),
            $request->getParam('indexStream')
        );

        $location = $this->apiBaseUrl . 'customer_streams/' . $stream->getId();
        $data = [
            'id' => $stream->getId(),
            'location' => $location,
        ];

        $this->View()->assign(['success' => true, 'data' => $data]);
        $this->Response()->headers->set('location', $location);
    }
public function postAction(): void
    {
        if (!$this->Request()->getParam('password')) {
            $passwordPlain = Random::generatePassword();
            $this->Request()->setPost('password', $passwordPlain);
        }

        if ($this->Request()->getParam('apiKey') && \strlen($this->Request()->getParam('apiKey')) < 40) {
            throw new CustomValidationException('apiKey is too short. The minimal length is 40.');
        }

        $user = $this->resource->create($this->Request()->getPost());

        $location = $this->apiBaseUrl . 'users/' . $user->getId();
        $data = [
            'id' => $user->getId(),
            'location' => $location,
        ];
        if (isset($passwordPlain)) {
            $data['password'] = $passwordPlain;
        }

        $this->View()->assign(['success' => true, 'data' => $data]);
        
'LicenseHostException',
        'LicenseInvalidException',
        'LicenseProductKeyException',
    ];

    /** * Expects a request parameter 'licenseString' containing a shopware core license key string. * Will validate and, if successful, enter the license information into the database. */
    public function checkLicenseAction()
    {
        $licenseString = trim($this->Request()->getPost('licenseString'));

        if (empty($licenseString)) {
            $this->View()->assign([
                'success' => false,
                'message' => 'Empty license information cannot be validated.',
            ]);

            return;
        }

        try {
            
$this->View()->assign('data', $media);
        $this->View()->assign('success', true);
    }

    /** * Create new payment * * POST /api/payment */
    public function postAction(): void
    {
        $params = $this->Request()->getPost();

        $payment = $this->resource->create($params);

        $location = $this->apiBaseUrl . 'paymentMethods/' . $payment->getId();
        $data = [
            'id' => $payment->getId(),
            'location' => $location,
        ];

        $this->View()->assign(['success' => true, 'data' => $data]);
        $this->Response()->headers->set('location', $location);
    }
/** * Save the custom table values * * @return void */
    public function saveValuesAction()
    {
        $manager = $this->get('models');
        $name = $this->Request()->get('_repositoryClass');
        $repository = $this->getRepository($name);

        $data = $this->Request()->getPost();
        $data = isset($data[0]) ? array_pop($data) : $data;

        if (!empty($data['id'])) {
            $model = $repository->find($data['id']);
        } else {
            unset($data['id']);
            $model = $repository->getClassName();
            $model = new $model();
        }
        if (!$model instanceof ModelEntity) {
            throw new RuntimeException('Model object could not be created correctly');
        }
        $result = iterator_to_array($paginator);

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

    public function createEsdAction()
    {
        $variantId = $this->Request()->getPost('articleDetailId');

        $variant = $this->get('models')->getRepository(ProductVariant::class)->find($variantId);
        if (!$variant) {
            $this->View()->assign([
                'success' => false,
                'message' => sprintf('Product variant by id %s not found', $variantId),
            ]);

            return;
        }

        

    function set_value(string $field$default = '', bool $htmlEscape = true)
    {
        $request = Services::request();

        // Try any old input data we may have first         $value = $request->getOldInput($field);

        if ($value === null) {
            $value = $request->getPost($field) ?? $default;
        }

        return ($htmlEscape) ? esc($value) : $value;
    }
}

if (function_exists('set_select')) {
    /** * Set Select * * Let's you set the selected value of a <select> menu via data in the POST array. */
/** * Modifies the Request Object to use a different method if a POST * variable called _method is found. */
    public function spoofRequestMethod()
    {
        // Only works with POSTED forms         if (strtolower($this->request->getMethod()) !== 'post') {
            return;
        }

        $method = $this->request->getPost('_method');

        if (empty($method)) {
            return;
        }

        // Only allows PUT, PATCH, DELETE         if (in_array(strtoupper($method)['PUT', 'PATCH', 'DELETE'], true)) {
            $this->request = $this->request->setMethod($method);
        }
    }

    
/** * Validate input - check form field rules defined by merchant * Checks captcha and doing simple blacklist-/spam-check * * Populates $this->_errors * Modifies $this->_elements * * @throws Exception */
    private function checkFields(): void
    {
        $this->_errors = $this->_validateInput($this->Request()->getPost()$this->_elements);

        if (!empty(Shopware()->Config()->get('CaptchaColor'))) {
            $captchaValidator = $this->container->get('shopware.captcha.validator');

            if (!$captchaValidator->validate($this->Request())) {
                $this->_elements['sCaptcha']['class'] = ' instyle_error has--error';
                $this->_errors['e']['sCaptcha'] = true;
            }
        }

        if (!empty($this->_errors)) {
            

            }

            if (empty($sErrorFlag)) {
                if (!empty(Shopware()->Config()->sOPTINVOTE) && empty(Shopware()->Session()->get('sUserId'))) {
                    $hash = Random::getAlphanumericString(32);

                    // Save comment confirm for the optin                     $blogCommentModel = new CommentConfirm();
                    $blogCommentModel->setCreationDate(new DateTime('now'));
                    $blogCommentModel->setHash($hash);
                    $blogCommentModel->setData(serialize($this->Request()->getPost()));

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

                    $link = $this->Front()->ensureRouter()->assemble(['sViewport' => 'blog', 'action' => 'rating', 'blogArticle' => $blogArticleId, 'sConfirmation' => $hash]);

                    $context = ['sConfirmLink' => $link, 'sArticle' => ['title' => $blogArticleData['title']]];
                    $mail = Shopware()->TemplateMail()->createMail('sOPTINBLOGCOMMENT', $context);
                    $mail->addTo($this->Request()->getParam('eMail'));
                    $mail->send();
                } else {
                    

    protected function upgradeShop($request$response)
    {
        $shop = $this->get('shop');

        $cookieKey = null;
        $cookieValue = null;

        switch (true) {
            case $request->getPost('sLanguage') !== null:
                $cookieKey = 'shop';
                $cookieValue = $request->getPost('sLanguage');
                break;
            case $request->getPost('sCurrency') !== null:
                $cookieKey = 'currency';
                $cookieValue = $request->getPost('sCurrency');
                break;
            case $request->getPost('__shop') !== null:
                $cookieKey = 'shop';
                $cookieValue = $request->getPost('__shop');
                break;
            
$this->View()->assign('data', $order);
        $this->View()->assign('success', true);
    }

    /** * Create new order * * POST /api/orders */
    public function postAction(): void
    {
        $order = $this->resource->create($this->Request()->getPost());

        $location = $this->apiBaseUrl . 'orders/' . $order->getId();
        $data = [
            'id' => $order->getId(),
            'location' => $location,
        ];

        $this->View()->assign(['success' => true, 'data' => $data]);
        $this->Response()->headers->set('location', $location);
    }

    
Home | Imprint | This part of the site doesn't use cookies.