1<?php 2/** 3 * Copyright since 2007 PrestaShop SA and Contributors 4 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA 5 * 6 * NOTICE OF LICENSE 7 * 8 * This source file is subject to the Open Software License (OSL 3.0) 9 * that is bundled with this package in the file LICENSE.md. 10 * It is also available through the world-wide-web at this URL: 11 * https://opensource.org/licenses/OSL-3.0 12 * If you did not receive a copy of the license and are unable to 13 * obtain it through the world-wide-web, please send an email 14 * to license@prestashop.com so we can send you a copy immediately. 15 * 16 * DISCLAIMER 17 * 18 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer 19 * versions in the future. If you wish to customize PrestaShop for your 20 * needs please refer to https://devdocs.prestashop.com/ for more information. 21 * 22 * @author PrestaShop SA and Contributors <contact@prestashop.com> 23 * @copyright Since 2007 PrestaShop SA and Contributors 24 * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) 25 */ 26 27namespace PrestaShopBundle\Form\Admin\Configure\ShopParameters\CustomerPreferences; 28 29use PrestaShop\PrestaShop\Core\Form\Handler; 30use PrestaShopBundle\Entity\Repository\TabRepository; 31 32/** 33 * Class manages "Configure > Shop Parameters > Customer Settings" page 34 * form handling. 35 */ 36final class CustomerPreferencesFormHandler extends Handler 37{ 38 /** 39 * @var TabRepository 40 */ 41 private $tabRepository; 42 43 /** 44 * {@inheritdoc} 45 */ 46 public function save(array $data) 47 { 48 $errors = parent::save($data); 49 50 if (empty($errors)) { 51 $this->handleB2bUpdate($data['enable_b2b_mode']); 52 } 53 54 return $errors; 55 } 56 57 /** 58 * @param TabRepository $tabRepository 59 */ 60 public function setTabRepository(TabRepository $tabRepository) 61 { 62 $this->tabRepository = $tabRepository; 63 } 64 65 /** 66 * Based on B2b mode, we need to enable/disable some tabs. 67 * 68 * @param bool $b2bMode Current B2B mode status 69 * 70 * @throws \InvalidArgumentException 71 */ 72 private function handleB2bUpdate($b2bMode) 73 { 74 $b2bTabs = ['AdminOutstanding']; 75 foreach ($b2bTabs as $tabName) { 76 $this->tabRepository->changeStatusByClassName($tabName, (bool) $b2bMode); 77 } 78 } 79} 80