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 PrestaShop\PrestaShop\Adapter\Order;
28
29use PrestaShop\PrestaShop\Adapter\Configuration;
30use PrestaShop\PrestaShop\Core\Configuration\DataConfigurationInterface;
31
32/**
33 * Gift Settings configuration available in ShopParameters > Order Preferences.
34 */
35class GiftOptionsConfiguration implements DataConfigurationInterface
36{
37    /**
38     * @var Configuration
39     */
40    private $configuration;
41
42    public function __construct(Configuration $configuration)
43    {
44        $this->configuration = $configuration;
45    }
46
47    /**
48     * {@inheritdoc}
49     */
50    public function getConfiguration()
51    {
52        return [
53            'enable_gift_wrapping' => $this->configuration->getBoolean('PS_GIFT_WRAPPING'),
54            'gift_wrapping_price' => $this->configuration->get('PS_GIFT_WRAPPING_PRICE'),
55            'gift_wrapping_tax_rules_group' => $this->configuration->get('PS_GIFT_WRAPPING_TAX_RULES_GROUP'),
56            'offer_recyclable_pack' => $this->configuration->getBoolean('PS_RECYCLABLE_PACK'),
57        ];
58    }
59
60    /**
61     * {@inheritdoc}
62     */
63    public function updateConfiguration(array $configuration)
64    {
65        if ($this->validateConfiguration($configuration)) {
66            $this->configuration->set('PS_GIFT_WRAPPING', $configuration['enable_gift_wrapping']);
67            $this->configuration->set('PS_GIFT_WRAPPING_PRICE', $configuration['gift_wrapping_price']);
68            $this->configuration->set('PS_GIFT_WRAPPING_TAX_RULES_GROUP', $configuration['gift_wrapping_tax_rules_group']);
69            $this->configuration->set('PS_RECYCLABLE_PACK', $configuration['offer_recyclable_pack']);
70        }
71
72        return [];
73    }
74
75    /**
76     * {@inheritdoc}
77     */
78    public function validateConfiguration(array $configuration)
79    {
80        return isset(
81            $configuration['enable_gift_wrapping'],
82            $configuration['gift_wrapping_price'],
83            $configuration['gift_wrapping_tax_rules_group'],
84            $configuration['offer_recyclable_pack']
85        );
86    }
87}
88