/** * After generate Xml * * @param \Magento\Framework\View\LayoutInterface $subject * @param \Magento\Framework\View\LayoutInterface $result * @return \Magento\Framework\View\LayoutInterface */ public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result) { if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) { $this->checkoutSession->clearStorage(); } return $result; }
/** * After generate Xml * * @param \Magento\Framework\View\LayoutInterface $subject * @param \Magento\Framework\View\LayoutInterface $result * @return \Magento\Framework\View\LayoutInterface */ public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result) { if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) { $this->eventManager->dispatch('depersonalize_clear_session'); session_write_close(); $this->messageSession->clearStorage(); } return $result; }
/** * Returns current customer according to session and context * * @return \Magento\Customer\Service\V1\Data\Customer */ public function getCustomer() { if ($this->moduleManager->isEnabled('Magento_PageCache') && !$this->request->isAjax() && $this->view->isLayoutLoaded() && $this->layout->isCacheable()) { return $this->getDepersonalizedCustomer(); } else { return $this->getCustomerFromService(); } }
/** * Save checkout shipping address * * @param array $data * @param int $customerAddressId * @return array * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function saveShipping($data, $customerAddressId) { if (empty($data)) { return ['error' => -1, 'message' => __('Invalid data')]; } $address = $this->getQuote()->getShippingAddress(); $addressForm = $this->_formFactory->create('customer_address', 'customer_address_edit', [], $this->_request->isAjax(), Form::IGNORE_INVISIBLE, []); if (!empty($customerAddressId)) { $addressData = null; try { $addressData = $this->addressRepository->getById($customerAddressId); } catch (NoSuchEntityException $e) { // do nothing if customer is not found by id } if ($addressData->getCustomerId() != $this->getQuote()->getCustomerId()) { return ['error' => 1, 'message' => __('The customer address is not valid.')]; } $address->importCustomerAddressData($addressData)->setSaveInAddressBook(0); $addressErrors = $addressForm->validateData($address->getData()); if ($addressErrors !== true) { return ['error' => 1, 'message' => $addressErrors]; } } else { // emulate request object $addressData = $addressForm->extractData($addressForm->prepareRequest($data)); $addressErrors = $addressForm->validateData($addressData); if ($addressErrors !== true) { return ['error' => 1, 'message' => $addressErrors]; } $compactedData = $addressForm->compactData($addressData); // unset shipping address attributes which were not shown in form foreach ($addressForm->getAttributes() as $attribute) { $attributeCode = $attribute->getAttributeCode(); if (!isset($data[$attributeCode])) { $address->setData($attributeCode, null); } else { if (isset($compactedData[$attributeCode])) { $address->setDataUsingMethod($attributeCode, $compactedData[$attributeCode]); } } } $address->setCustomerAddressId(null); // Additional form data, not fetched by extractData (as it fetches only attributes) $address->setSaveInAddressBook(empty($data['save_in_address_book']) ? 0 : 1); $address->setSameAsBilling(empty($data['same_as_billing']) ? 0 : 1); } $address->setCollectShippingRates(true); if (($validateRes = $address->validate()) !== true) { return ['error' => 1, 'message' => $validateRes]; } $this->totalsCollector->collectAddressTotals($this->getQuote(), $address); $address->save(); $this->getCheckout()->setStepData('shipping', 'complete', true)->setStepData('shipping_method', 'allow', true); return []; }
/** * After generate Xml * * @param \Magento\Framework\View\LayoutInterface $subject * @param \Magento\Framework\View\LayoutInterface $result * @return \Magento\Framework\View\LayoutInterface */ public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result) { if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) { $this->visitor->setSkipRequestLogging(true); $this->visitor->unsetData(); $this->session->clearStorage(); $this->customerSession->clearStorage(); $this->session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->formKey); $this->customerSession->setCustomerGroupId($this->customerGroupId); $this->customer->setGroupId($this->customerGroupId); $this->customerSession->setCustomer($this->customer); } return $result; }
/** * Check if depersonalize or not * * @param \Magento\Framework\View\LayoutInterface $subject * @return bool * @api */ public function checkIfDepersonalize(\Magento\Framework\View\LayoutInterface $subject) { return $this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && ($this->request->isGet() || $this->request->isHead()) && $subject->isCacheable(); }
/** * Update system data for current VDE environment * * @param string $areaCode * @param \Magento\Framework\App\RequestInterface $request * @return void */ public function update($areaCode, \Magento\Framework\App\RequestInterface $request) { $mode = $request->getAlias('editorMode') ?: self::MODE_NAVIGATION; $this->_themeContext->setEditableThemeById($request->getAlias('themeId')); if (!$request->isAjax()) { $this->_backendSession->setData(self::CURRENT_URL_SESSION_KEY, $request->getPathInfo()); $this->_backendSession->setData(self::CURRENT_MODE_SESSION_KEY, $mode); } $this->_injectUrlModel($mode); $this->_emulateArea($mode, $areaCode); $this->_setTheme(); $this->_disableCache(); }