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 27declare(strict_types=1); 28 29namespace PrestaShop\PrestaShop\Core\Domain\Product\QueryResult; 30 31use PrestaShop\PrestaShop\Core\Domain\Product\ProductCustomizabilitySettings; 32 33/** 34 * Transfers data of product customization options 35 */ 36class ProductCustomizationOptions 37{ 38 /** 39 * @var int value representing if product requires, allows, disallows customizations 40 * see @var ProductCustomizabilitySettings for more info 41 */ 42 private $customizabilityValue; 43 44 /** 45 * @var int 46 */ 47 private $availableTextCustomizationsCount; 48 49 /** 50 * @var int 51 */ 52 private $availableFileCustomizationsCount; 53 54 /** 55 * @return ProductCustomizationOptions 56 */ 57 public static function createNotCustomizable(): ProductCustomizationOptions 58 { 59 return new self(ProductCustomizabilitySettings::NOT_CUSTOMIZABLE, 0, 0); 60 } 61 62 /** 63 * @param int $availableTextCustomizationsCount 64 * @param int $availableFileCustomizationsCount 65 * 66 * @return ProductCustomizationOptions 67 */ 68 public static function createAllowsCustomization( 69 int $availableTextCustomizationsCount, 70 int $availableFileCustomizationsCount 71 ): ProductCustomizationOptions { 72 return new self( 73 ProductCustomizabilitySettings::ALLOWS_CUSTOMIZATION, 74 $availableTextCustomizationsCount, 75 $availableFileCustomizationsCount 76 ); 77 } 78 79 /** 80 * @param int $availableTextCustomizationsCount 81 * @param int $availableFileCustomizationsCount 82 * 83 * @return ProductCustomizationOptions 84 */ 85 public static function createRequiresCustomization( 86 int $availableTextCustomizationsCount, 87 int $availableFileCustomizationsCount 88 ): ProductCustomizationOptions { 89 return new self( 90 ProductCustomizabilitySettings::REQUIRES_CUSTOMIZATION, 91 $availableTextCustomizationsCount, 92 $availableFileCustomizationsCount 93 ); 94 } 95 96 /** 97 * @return int 98 */ 99 public function getCustomizabilityValue(): int 100 { 101 return $this->customizabilityValue; 102 } 103 104 /** 105 * @return int 106 */ 107 public function getAvailableTextCustomizationsCount(): int 108 { 109 return $this->availableTextCustomizationsCount; 110 } 111 112 /** 113 * @return int 114 */ 115 public function getAvailableFileCustomizationsCount(): int 116 { 117 return $this->availableFileCustomizationsCount; 118 } 119 120 /** 121 * @return bool true if product does not have any customizations 122 */ 123 public function isNotCustomizable(): bool 124 { 125 return $this->customizabilityValue === ProductCustomizabilitySettings::NOT_CUSTOMIZABLE; 126 } 127 128 /** 129 * @return bool true if product has customizations, but none of them are required 130 */ 131 public function allowsCustomization(): bool 132 { 133 return $this->customizabilityValue === ProductCustomizabilitySettings::ALLOWS_CUSTOMIZATION; 134 } 135 136 /** 137 * @return bool true if product has at least one required customization 138 */ 139 public function requiresCustomization(): bool 140 { 141 return $this->customizabilityValue === ProductCustomizabilitySettings::REQUIRES_CUSTOMIZATION; 142 } 143 144 /** 145 * Use static factories to instantiate this class 146 * 147 * @param int $value 148 * @param int $availableTextCustomizations 149 * @param int $availableFileCustomizations 150 */ 151 private function __construct(int $value, int $availableTextCustomizations, int $availableFileCustomizations) 152 { 153 $this->customizabilityValue = $value; 154 $this->availableTextCustomizationsCount = $availableTextCustomizations; 155 $this->availableFileCustomizationsCount = $availableFileCustomizations; 156 } 157} 158