PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/dev/tests/functional/tests/app/Mage/Catalog/Test/Fixture/CatalogProductSimple/CustomOptions.php

https://gitlab.com/blingbang2016/shop
PHP | 386 lines | 294 code | 11 blank | 81 comment | 3 complexity | c109b7eb5c77d5848cdf19224f345ad7 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Tests
  22. * @package Tests_Functional
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. namespace Mage\Catalog\Test\Fixture\CatalogProductSimple;
  27. use Magento\Mtf\Fixture\FixtureFactory;
  28. use Magento\Mtf\Fixture\FixtureInterface;
  29. /**
  30. * Preset for custom options.
  31. *
  32. * Data keys:
  33. * - preset (Custom options preset name)
  34. * - import_products (comma separated data set name)
  35. */
  36. class CustomOptions implements FixtureInterface
  37. {
  38. /**
  39. * Prepared dataSet data.
  40. *
  41. * @var array
  42. */
  43. protected $data;
  44. /**
  45. * Data set configuration settings.
  46. *
  47. * @var array
  48. */
  49. protected $params;
  50. /**
  51. * @constructor
  52. * @param array $params
  53. * @param array $data
  54. * @param FixtureFactory|null $fixtureFactory
  55. */
  56. public function __construct(array $params, array $data, FixtureFactory $fixtureFactory)
  57. {
  58. $this->params = $params;
  59. $preset = [];
  60. if (isset($data['preset'])) {
  61. $preset = $this->replaceData($this->getPreset($data['preset']), mt_rand());
  62. unset($data['preset']);
  63. }
  64. $this->data = array_merge_recursive($data, $preset);
  65. }
  66. /**
  67. * Replace custom options data.
  68. *
  69. * @param array $data
  70. * @param int $replace
  71. * @return array
  72. */
  73. protected function replaceData(array $data, $replace)
  74. {
  75. $result = [];
  76. foreach ($data as $key => $value) {
  77. if (is_array($value)) {
  78. $value = $this->replaceData($value, $replace);
  79. }
  80. $result[$key] = str_replace('%isolation%', $replace, $value);
  81. }
  82. return $result;
  83. }
  84. /**
  85. * Persist custom selections products.
  86. *
  87. * @return void
  88. */
  89. public function persist()
  90. {
  91. //
  92. }
  93. /**
  94. * Return prepared data set.
  95. *
  96. * @param string $key [optional]
  97. * @return mixed
  98. *
  99. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  100. */
  101. public function getData($key = null)
  102. {
  103. return $this->data;
  104. }
  105. /**
  106. * Return data set configuration settings.
  107. *
  108. * @return string
  109. */
  110. public function getDataConfig()
  111. {
  112. return $this->params;
  113. }
  114. /**
  115. * Get preset.
  116. *
  117. * @param string $name
  118. * @return array|null
  119. *
  120. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  121. */
  122. protected function getPreset($name)
  123. {
  124. $presets = [
  125. 'drop_down_with_two_options' => [
  126. [
  127. 'title' => 'custom option Drop-down %isolation%',
  128. 'is_require' => 'Yes',
  129. 'type' => 'Select/Drop-down',
  130. 'options' => [
  131. [
  132. 'title' => '30 bucks',
  133. 'price' => 30,
  134. 'price_type' => 'Fixed',
  135. 'sku' => 'sku_drop_down_row_1'
  136. ],
  137. [
  138. 'title' => '40 bucks',
  139. 'price' => 40,
  140. 'price_type' => 'Percent',
  141. 'sku' => 'sku_drop_down_row_2'
  142. ]
  143. ]
  144. ]
  145. ],
  146. 'drop_down_with_one_option_percent_price' => [
  147. [
  148. 'title' => 'custom option Drop-down %isolation%',
  149. 'is_require' => 'Yes',
  150. 'type' => 'Select/Drop-down',
  151. 'options' => [
  152. [
  153. 'title' => '40 bucks',
  154. 'price' => 40,
  155. 'price_type' => 'Percent',
  156. 'sku' => 'sku_drop_down_row_1'
  157. ]
  158. ]
  159. ]
  160. ],
  161. 'default' => [
  162. [
  163. 'title' => 'custom option Drop-down %isolation%',
  164. 'is_require' => 'Yes',
  165. 'type' => 'Select/Drop-down',
  166. 'options' => [
  167. [
  168. 'title' => '10 percent',
  169. 'price' => 10,
  170. 'price_type' => 'Percent',
  171. 'sku' => 'sku_drop_down_row_1',
  172. ],
  173. ],
  174. ],
  175. [
  176. 'title' => 'custom option Drop-down2 %isolation%',
  177. 'is_require' => 'Yes',
  178. 'type' => 'Select/Drop-down',
  179. 'options' => [
  180. [
  181. 'title' => '20 percent',
  182. 'price' => 20,
  183. 'price_type' => 'Percent',
  184. 'sku' => 'sku_drop_down_row_2',
  185. ],
  186. ]
  187. ],
  188. ],
  189. 'all_types' => [
  190. [
  191. 'title' => 'custom option Field %isolation%',
  192. 'type' => 'Text/Field',
  193. 'is_require' => 'Yes',
  194. 'options' => [
  195. 'price' => 10,
  196. 'price_type' => 'Fixed',
  197. 'sku' => 'sku_field_option_%isolation%',
  198. 'max_characters' => 1024,
  199. ],
  200. ],
  201. [
  202. 'title' => 'custom option Area %isolation%',
  203. 'is_require' => 'Yes',
  204. 'type' => 'Text/Area',
  205. 'options' => [
  206. 'price' => 10,
  207. 'price_type' => 'Fixed',
  208. 'sku' => 'sku_area_row_%isolation%',
  209. 'max_characters' => '10',
  210. ]
  211. ],
  212. [
  213. 'title' => 'custom option File %isolation%',
  214. 'is_require' => 'No',
  215. 'type' => 'File/File',
  216. 'options' => [
  217. 'price' => 10,
  218. 'price_type' => 'Fixed',
  219. 'sku' => 'sku_file_row_%isolation%',
  220. 'file_extension' => 'jpg',
  221. 'image_size_x' => '100',
  222. 'image_size_y' => '100',
  223. ]
  224. ],
  225. [
  226. 'title' => 'custom option Drop-down %isolation%',
  227. 'is_require' => 'Yes',
  228. 'type' => 'Select/Drop-down',
  229. 'options' => [
  230. [
  231. 'title' => '10 percent',
  232. 'price' => 10,
  233. 'price_type' => 'Percent',
  234. 'sku' => 'sku_drop_down_row_1_%isolation%',
  235. ],
  236. [
  237. 'title' => '20 percent',
  238. 'price' => 20,
  239. 'price_type' => 'Percent',
  240. 'sku' => 'sku_drop_down_row_2_%isolation%'
  241. ],
  242. [
  243. 'title' => '30 fixed',
  244. 'price' => 30,
  245. 'price_type' => 'Fixed',
  246. 'sku' => 'sku_drop_down_row_3_%isolation%'
  247. ],
  248. ]
  249. ],
  250. [
  251. 'title' => 'custom option Radio Buttons %isolation%',
  252. 'is_require' => 'Yes',
  253. 'type' => 'Select/Radio Buttons',
  254. 'options' => [
  255. [
  256. 'title' => '20 fixed',
  257. 'price' => 20,
  258. 'price_type' => 'Fixed',
  259. 'sku' => 'sku_radio_buttons_row%isolation%',
  260. ],
  261. ]
  262. ],
  263. [
  264. 'title' => 'custom option Checkbox %isolation%',
  265. 'is_require' => 'Yes',
  266. 'type' => 'Select/Checkbox',
  267. 'options' => [
  268. [
  269. 'title' => '20 fixed',
  270. 'price' => 20,
  271. 'price_type' => 'Fixed',
  272. 'sku' => 'sku_checkbox_row%isolation%',
  273. ],
  274. ]
  275. ],
  276. [
  277. 'title' => 'custom option Multiple Select %isolation%',
  278. 'is_require' => 'Yes',
  279. 'type' => 'Select/Multiple Select',
  280. 'options' => [
  281. [
  282. 'title' => '20 fixed',
  283. 'price' => 20,
  284. 'price_type' => 'Fixed',
  285. 'sku' => 'sku_multiple_select_row%isolation%',
  286. ],
  287. ]
  288. ],
  289. [
  290. 'title' => 'custom option Date %isolation%',
  291. 'is_require' => 'Yes',
  292. 'type' => 'Date/Date',
  293. 'options' => [
  294. 'price' => 20,
  295. 'price_type' => 'Fixed',
  296. 'sku' => 'sku_date_row%isolation%',
  297. ]
  298. ],
  299. [
  300. 'title' => 'custom option Date & Time %isolation%',
  301. 'is_require' => 'Yes',
  302. 'type' => 'Date/Date & Time',
  303. 'options' => [
  304. 'price' => 20,
  305. 'price_type' => 'Fixed',
  306. 'sku' => 'sku_date_and_time_row%isolation%',
  307. ]
  308. ],
  309. [
  310. 'title' => 'custom option Time %isolation%',
  311. 'is_require' => 'Yes',
  312. 'type' => 'Date/Time',
  313. 'options' => [
  314. 'price' => 20,
  315. 'price_type' => 'Fixed',
  316. 'sku' => 'sku_time_row%isolation%',
  317. ]
  318. ],
  319. ],
  320. 'two_options' => [
  321. [
  322. 'title' => 'custom option drop down %isolation%',
  323. 'is_require' => 'Yes',
  324. 'type' => 'Select/Drop-down',
  325. 'options' => [
  326. [
  327. 'title' => '10 percent',
  328. 'price' => 10,
  329. 'price_type' => 'Percent',
  330. 'sku' => 'sku_drop_down_row_1',
  331. ],
  332. [
  333. 'title' => '20 percent',
  334. 'price' => 20,
  335. 'price_type' => 'Percent',
  336. 'sku' => 'sku_drop_down_row_2'
  337. ],
  338. ],
  339. ],
  340. [
  341. 'title' => 'custom option field %isolation%',
  342. 'is_require' => 'Yes',
  343. 'type' => 'Text/Field',
  344. 'options' => [
  345. [
  346. 'price' => 10,
  347. 'price_type' => 'Fixed',
  348. 'sku' => 'sku_field_option_%isolation%',
  349. 'max_characters' => 1024,
  350. ],
  351. ]
  352. ],
  353. ],
  354. 'drop_down_with_one_option_fixed_price' => [
  355. [
  356. 'title' => 'custom option drop down %isolation%',
  357. 'is_require' => 'Yes',
  358. 'type' => 'Select/Drop-down',
  359. 'options' => [
  360. [
  361. 'title' => '30 bucks',
  362. 'price' => 30,
  363. 'price_type' => 'Fixed',
  364. 'sku' => 'sku_drop_down_row_1',
  365. ],
  366. ],
  367. ],
  368. ],
  369. ];
  370. if (!isset($presets[$name])) {
  371. return null;
  372. }
  373. return $presets[$name];
  374. }
  375. }