uc_cart.admin.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <?php
  2. /**
  3. * @file
  4. * Cart administration menu items.
  5. */
  6. /**
  7. * General settings for the shopping cart.
  8. *
  9. * @see uc_cart_cart_settings_form_validate()
  10. *
  11. * @ingroup forms
  12. */
  13. function uc_cart_cart_settings_form($form, &$form_state) {
  14. // Put fieldsets into vertical tabs.
  15. $form['cart-settings'] = array(
  16. '#type' => 'vertical_tabs',
  17. '#attached' => array(
  18. 'js' => array(
  19. 'vertical-tabs' => drupal_get_path('module', 'uc_cart') . '/uc_cart.admin.js',
  20. ),
  21. ),
  22. );
  23. $form['general'] = array(
  24. '#type' => 'fieldset',
  25. '#title' => t('Basic settings'),
  26. '#group' => 'cart-settings',
  27. );
  28. $panes = uc_cart_cart_pane_list(NULL);
  29. $form['general']['panes'] = array(
  30. '#theme' => 'uc_pane_sort_table',
  31. '#pane_prefix' => 'uc_cap',
  32. '#draggable' => 'uc-cart-pane-weight',
  33. );
  34. foreach ($panes as $id => $pane) {
  35. $form['general']['panes'][$id]['uc_cap_' . $id . '_enabled'] = array(
  36. '#type' => 'checkbox',
  37. '#title' => check_plain($pane['title']),
  38. '#default_value' => variable_get('uc_cap_' . $pane['id'] . '_enabled', $pane['enabled']),
  39. );
  40. $form['general']['panes'][$id]['uc_cap_' . $id . '_weight'] = array(
  41. '#type' => 'weight',
  42. '#delta' => 10,
  43. '#default_value' => variable_get('uc_cap_' . $pane['id'] . '_weight', $pane['weight']),
  44. '#attributes' => array('class' => array('uc-cart-pane-weight')),
  45. );
  46. }
  47. $form['general']['uc_cart_add_item_msg'] = array(
  48. '#type' => 'checkbox',
  49. '#title' => t('Display a message when a customer adds an item to their cart.'),
  50. '#default_value' => variable_get('uc_cart_add_item_msg', TRUE),
  51. );
  52. $form['general']['uc_add_item_redirect'] = array(
  53. '#type' => 'textfield',
  54. '#title' => t('Add to cart redirect'),
  55. '#description' => t('Enter the page to redirect to when a customer adds an item to their cart, or &lt;none&gt; for no redirect.'),
  56. '#default_value' => variable_get('uc_add_item_redirect', 'cart'),
  57. '#size' => 32,
  58. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
  59. );
  60. $form['general']['uc_cart_empty_button'] = array(
  61. '#type' => 'checkbox',
  62. '#title' => t('Show an "Empty cart" button on the cart page.'),
  63. '#default_value' => variable_get('uc_cart_empty_button', FALSE),
  64. );
  65. $form['general']['uc_minimum_subtotal'] = array(
  66. '#type' => 'uc_price',
  67. '#title' => t('Minimum order subtotal'),
  68. '#description' => t('Customers will not be allowed to check out if the subtotal of items in their cart is less than this amount.'),
  69. '#default_value' => variable_get('uc_minimum_subtotal', 0),
  70. );
  71. $form['lifetime'] = array(
  72. '#type' => 'fieldset',
  73. '#title' => t('Cart lifetime'),
  74. '#description' => t('Set the length of time that products remain in the cart. Cron must be running for this feature to work.'),
  75. '#group' => 'cart-settings',
  76. );
  77. $durations = array(
  78. 'singular' => array(
  79. 'minutes' => t('minute'),
  80. 'hours' => t('hour'),
  81. 'days' => t('day'),
  82. 'weeks' => t('week'),
  83. 'years' => t('year'),
  84. ),
  85. 'plural' => array(
  86. 'minutes' => t('minutes'),
  87. 'hours' => t('hours'),
  88. 'days' => t('days'),
  89. 'weeks' => t('weeks'),
  90. 'years' => t('years'),
  91. ),
  92. );
  93. $form['lifetime']['anonymous'] = array(
  94. '#type' => 'fieldset',
  95. '#title' => t('Anonymous users'),
  96. '#attributes' => array('class' => array('uc-inline-form', 'clearfix')),
  97. );
  98. $form['lifetime']['anonymous']['uc_cart_anon_duration'] = array(
  99. '#type' => 'select',
  100. '#title' => t('Duration'),
  101. '#options' => drupal_map_assoc(range(1, 60)),
  102. '#default_value' => variable_get('uc_cart_anon_duration', '4'),
  103. );
  104. $form['lifetime']['anonymous']['uc_cart_anon_unit'] = array(
  105. '#type' => 'select',
  106. '#title' => t('Units'),
  107. '#options' => array(
  108. 'minutes' => t('Minute(s)'),
  109. 'hours' => t('Hour(s)'),
  110. 'days' => t('Day(s)'),
  111. 'weeks' => t('Week(s)'),
  112. 'years' => t('Year(s)'),
  113. ),
  114. '#default_value' => variable_get('uc_cart_anon_unit', 'hours'),
  115. );
  116. $form['lifetime']['authenticated'] = array(
  117. '#type' => 'fieldset',
  118. '#title' => t('Authenticated users'),
  119. '#attributes' => array('class' => array('uc-inline-form', 'clearfix')),
  120. );
  121. $form['lifetime']['authenticated']['uc_cart_auth_duration'] = array(
  122. '#type' => 'select',
  123. '#title' => t('Duration'),
  124. '#options' => drupal_map_assoc(range(1, 60)),
  125. '#default_value' => variable_get('uc_cart_auth_duration', '1'),
  126. );
  127. $form['lifetime']['authenticated']['uc_cart_auth_unit'] = array(
  128. '#type' => 'select',
  129. '#title' => t('Units'),
  130. '#options' => array(
  131. 'hours' => t('Hour(s)'),
  132. 'days' => t('Day(s)'),
  133. 'weeks' => t('Week(s)'),
  134. 'years' => t('Year(s)'),
  135. ),
  136. '#default_value' => variable_get('uc_cart_auth_unit', 'years'),
  137. );
  138. $form['continue_shopping'] = array(
  139. '#type' => 'fieldset',
  140. '#title' => t('Continue shopping element'),
  141. '#description' => t('These settings control the <em>continue shopping</em> option on the cart page.'),
  142. '#group' => 'cart-settings',
  143. );
  144. $form['continue_shopping']['uc_continue_shopping_type'] = array(
  145. '#type' => 'radios',
  146. '#title' => t('<em>Continue shopping</em> element'),
  147. '#options' => array(
  148. 'link' => t('Text link'),
  149. 'button' => t('Button'),
  150. 'none' => t('Do not display'),
  151. ),
  152. '#default_value' => variable_get('uc_continue_shopping_type', 'link'),
  153. );
  154. $form['continue_shopping']['uc_continue_shopping_use_last_url'] = array(
  155. '#type' => 'checkbox',
  156. '#title' => t('Make <em>continue shopping</em> go back to the last item that was added to the cart.'),
  157. '#description' => t('If this is disabled or the item is unavailable, the URL specified below will be used.'),
  158. '#default_value' => variable_get('uc_continue_shopping_use_last_url', TRUE),
  159. );
  160. $form['continue_shopping']['uc_continue_shopping_url'] = array(
  161. '#type' => 'textfield',
  162. '#title' => t('Default <em>continue shopping</em> destination'),
  163. '#default_value' => variable_get('uc_continue_shopping_url', ''),
  164. '#size' => 32,
  165. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
  166. );
  167. $form['breadcrumb'] = array(
  168. '#type' => 'fieldset',
  169. '#title' => t('Cart breadcrumb'),
  170. '#description' => t('Drupal automatically adds a <em>Home</em> breadcrumb to the cart page, or you can use these settings to specify a custom breadcrumb.'),
  171. '#group' => 'cart-settings',
  172. );
  173. $form['breadcrumb']['uc_cart_breadcrumb_text'] = array(
  174. '#type' => 'textfield',
  175. '#title' => t('Cart page breadcrumb text'),
  176. '#description' => t('Leave blank to use the default <em>Home</em> breadcrumb.'),
  177. '#default_value' => variable_get('uc_cart_breadcrumb_text', ''),
  178. );
  179. $form['breadcrumb']['uc_cart_breadcrumb_url'] = array(
  180. '#type' => 'textfield',
  181. '#title' => t('Cart page breadcrumb destination'),
  182. '#default_value' => variable_get('uc_cart_breadcrumb_url', ''),
  183. '#size' => 32,
  184. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
  185. );
  186. return system_settings_form($form);
  187. }
  188. /**
  189. * Form validation for uc_cart_cart_settings_form().
  190. *
  191. * @see uc_cart_cart_settings_form()
  192. */
  193. function uc_cart_cart_settings_form_validate($form, &$form_state) {
  194. if (!is_numeric($form_state['values']['uc_minimum_subtotal']) || $form_state['values']['uc_minimum_subtotal'] < 0 || $form_state['values']['uc_minimum_subtotal'] === '-0') {
  195. form_set_error('uc_minimum_subtotal', t('Minimum order subtotal should be a non-negative number.'));
  196. }
  197. }
  198. /**
  199. * General checkout settings.
  200. *
  201. * @ingroup forms
  202. */
  203. function uc_cart_checkout_settings_form($form, &$form_state) {
  204. // Put fieldsets into vertical tabs.
  205. $form['checkout-settings'] = array(
  206. '#type' => 'vertical_tabs',
  207. '#attached' => array(
  208. 'js' => array(
  209. 'vertical-tabs' => drupal_get_path('module', 'uc_cart') . '/uc_cart.admin.js',
  210. ),
  211. ),
  212. );
  213. $form['checkout'] = array(
  214. '#type' => 'fieldset',
  215. '#title' => t('Basic settings'),
  216. '#group' => 'checkout-settings',
  217. );
  218. $form['checkout']['uc_checkout_enabled'] = array(
  219. '#type' => 'checkbox',
  220. '#title' => t('Enable checkout.'),
  221. '#description' => t('Disable this to use only third party checkout services, such as PayPal Express Checkout.'),
  222. '#default_value' => variable_get('uc_checkout_enabled', TRUE),
  223. );
  224. $form['anonymous'] = array(
  225. '#type' => 'fieldset',
  226. '#title' => t('Anonymous checkout'),
  227. '#group' => 'checkout-settings',
  228. );
  229. $form['anonymous']['uc_checkout_anonymous'] = array(
  230. '#type' => 'checkbox',
  231. '#title' => t('Enable anonymous checkout.'),
  232. '#description' => t('Disable this to force users to log in before the checkout page.'),
  233. '#default_value' => variable_get('uc_checkout_anonymous', TRUE),
  234. );
  235. $anon_state = array('visible' => array('input[name="uc_checkout_anonymous"]' => array('checked' => TRUE)));
  236. $form['anonymous']['uc_cart_mail_existing'] = array(
  237. '#type' => 'checkbox',
  238. '#title' => t("Allow anonymous customers to use an existing account's email address."),
  239. '#default_value' => variable_get('uc_cart_mail_existing', TRUE),
  240. '#description' => t('If enabled, orders will be attached to the account matching the email address. If disabled, anonymous users using a registered email address must log in or use a different email address.'),
  241. '#states' => $anon_state,
  242. );
  243. $form['anonymous']['uc_cart_email_validation'] = array(
  244. '#type' => 'checkbox',
  245. '#title' => t('Require e-mail confirmation for anonymous customers.'),
  246. '#default_value' => variable_get('uc_cart_email_validation', FALSE),
  247. '#states' => $anon_state,
  248. );
  249. $form['anonymous']['uc_cart_new_account_name'] = array(
  250. '#type' => 'checkbox',
  251. '#title' => t('Allow new customers to specify a username.'),
  252. '#default_value' => variable_get('uc_cart_new_account_name', FALSE),
  253. '#states' => $anon_state,
  254. );
  255. $form['anonymous']['uc_cart_new_account_password'] = array(
  256. '#type' => 'checkbox',
  257. '#title' => t('Allow new customers to specify a password.'),
  258. '#default_value' => variable_get('uc_cart_new_account_password', FALSE),
  259. '#states' => $anon_state,
  260. );
  261. $form['anonymous']['uc_new_customer_email'] = array(
  262. '#type' => 'checkbox',
  263. '#title' => t('Send new customers a separate e-mail with their account details.'),
  264. '#default_value' => variable_get('uc_new_customer_email', TRUE),
  265. '#states' => $anon_state,
  266. );
  267. $form['anonymous']['uc_new_customer_login'] = array(
  268. '#type' => 'checkbox',
  269. '#title' => t('Log in new customers after checkout.'),
  270. '#default_value' => variable_get('uc_new_customer_login', FALSE),
  271. '#states' => $anon_state,
  272. );
  273. $form['anonymous']['uc_new_customer_status_active'] = array(
  274. '#type' => 'checkbox',
  275. '#title' => t('Set new customer accounts to active.'),
  276. '#description' => t('Uncheck to create new accounts but make them blocked.'),
  277. '#default_value' => variable_get('uc_new_customer_status_active', TRUE),
  278. '#states' => $anon_state,
  279. );
  280. $panes = _uc_checkout_pane_list();
  281. $form['checkout']['panes'] = array(
  282. '#theme' => 'uc_pane_sort_table',
  283. '#pane_prefix' => 'uc_pane',
  284. '#draggable' => 'uc-checkout-pane-weight',
  285. );
  286. foreach ($panes as $id => $pane) {
  287. $form['checkout']['panes'][$id]['uc_pane_' . $id . '_enabled'] = array(
  288. '#type' => 'checkbox',
  289. '#title' => check_plain($pane['title']),
  290. '#default_value' => variable_get('uc_pane_' . $id . '_enabled', $pane['enabled']),
  291. );
  292. $form['checkout']['panes'][$id]['uc_pane_' . $id . '_weight'] = array(
  293. '#type' => 'weight',
  294. '#default_value' => variable_get('uc_pane_' . $id . '_weight', $pane['weight']),
  295. '#attributes' => array('class' => array('uc-checkout-pane-weight')),
  296. );
  297. $form['checkout']['panes'][$id]['#weight'] = variable_get('uc_pane_' . $id . '_weight', $pane['weight']);
  298. $null = NULL;
  299. $pane_settings = $pane['callback']('settings', $null, array());
  300. if (is_array($pane_settings)) {
  301. $form['pane_' . $id] = $pane_settings + array(
  302. '#type' => 'fieldset',
  303. '#title' => t('@pane pane', array('@pane' => $pane['title'])),
  304. '#group' => 'checkout-settings',
  305. );
  306. }
  307. }
  308. $form['checkout']['uc_cart_default_same_address'] = array(
  309. '#type' => 'checkbox',
  310. '#title' => t('Use the same address for billing and delivery by default.'),
  311. '#default_value' => variable_get('uc_cart_default_same_address', FALSE),
  312. );
  313. $form['checkout']['uc_cart_delivery_not_shippable'] = array(
  314. '#type' => 'checkbox',
  315. '#title' => t('Hide delivery information when carts have no shippable items.'),
  316. '#default_value' => variable_get('uc_cart_delivery_not_shippable', TRUE),
  317. );
  318. $form['checkout']['uc_use_next_buttons'] = array(
  319. '#type' => 'checkbox',
  320. '#title' => t('Use collapsing checkout panes with <em>Next</em> buttons.'),
  321. '#default_value' => variable_get('uc_use_next_buttons', FALSE),
  322. );
  323. $form['checkout']['uc_collapse_current_pane'] = array(
  324. '#type' => 'checkbox',
  325. '#title' => t('Collapse pane after its <em>Next</em> button is clicked.'),
  326. '#default_value' => variable_get('uc_collapse_current_pane', TRUE),
  327. '#states' => array(
  328. 'visible' => array(
  329. 'input[name="uc_checkout_enabled"]' => array('checked' => TRUE),
  330. 'input[name="uc_use_next_buttons"]' => array('checked' => TRUE),
  331. ),
  332. ),
  333. );
  334. $form['instructions'] = array(
  335. '#type' => 'fieldset',
  336. '#title' => t('Instruction messages'),
  337. '#group' => 'checkout-settings',
  338. );
  339. $form['instructions']['uc_checkout_instructions'] = array(
  340. '#type' => 'textarea',
  341. '#title' => t('Checkout instructions'),
  342. '#description' => t('Provide instructions for customers at the top of the checkout screen.'),
  343. '#default_value' => variable_get('uc_checkout_instructions', ''),
  344. '#rows' => 3,
  345. );
  346. $form['instructions']['uc_checkout_review_instructions'] = array(
  347. '#type' => 'textarea',
  348. '#title' => t('Checkout review instructions'),
  349. '#description' => t('Provide instructions for customers at the top of the checkout review screen.'),
  350. '#default_value' => variable_get('uc_checkout_review_instructions', uc_get_message('review_instructions')),
  351. '#rows' => 3,
  352. );
  353. $form['completion_messages'] = array(
  354. '#type' => 'fieldset',
  355. '#title' => t('Completion messages'),
  356. '#group' => 'checkout-settings',
  357. );
  358. $form['completion_messages']['uc_cart_checkout_complete_page'] = array(
  359. '#type' => 'textfield',
  360. '#title' => t('Alternate checkout completion page'),
  361. '#description' => t('Leave blank to use the default completion page (recommended).'),
  362. '#default_value' => variable_get('uc_cart_checkout_complete_page', ''),
  363. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
  364. '#size' => 16,
  365. );
  366. $form['completion_messages']['uc_msg_order_submit'] = array(
  367. '#type' => 'textarea',
  368. '#title' => t('Message header'),
  369. '#description' => t('Header for message displayed after a user checks out.'),
  370. '#default_value' => variable_get('uc_msg_order_submit', uc_get_message('completion_message')),
  371. '#rows' => 3,
  372. );
  373. $form['completion_messages']['uc_msg_order_logged_in'] = array(
  374. '#type' => 'textarea',
  375. '#title' => t('Logged in users'),
  376. '#description' => t('Message displayed upon checkout for a user who is logged in.'),
  377. '#default_value' => variable_get('uc_msg_order_logged_in', uc_get_message('completion_logged_in')),
  378. '#rows' => 3,
  379. );
  380. $form['completion_messages']['uc_msg_order_existing_user'] = array(
  381. '#type' => 'textarea',
  382. '#title' => t('Existing users'),
  383. '#description' => t("Message displayed upon checkout for a user who has an account but wasn't logged in."),
  384. '#default_value' => variable_get('uc_msg_order_existing_user', uc_get_message('completion_existing_user')),
  385. '#rows' => 3,
  386. '#states' => $anon_state,
  387. );
  388. $form['completion_messages']['uc_msg_order_new_user'] = array(
  389. '#type' => 'textarea',
  390. '#title' => t('New users'),
  391. '#description' => t("Message displayed upon checkout for a new user whose account was just created. You may use the special tokens !new_username for the username of a newly created account and !new_password for that account's password."),
  392. '#default_value' => variable_get('uc_msg_order_new_user', uc_get_message('completion_new_user')),
  393. '#rows' => 3,
  394. '#states' => $anon_state,
  395. );
  396. $form['completion_messages']['uc_msg_order_new_user_logged_in'] = array(
  397. '#type' => 'textarea',
  398. '#title' => t('New logged in users'),
  399. '#description' => t('Message displayed upon checkout for a new user whose account was just created and also <em>"Login users when new customer accounts are created at checkout."</em> is set on the <a href="!user_login_setting_ur">checkout settings</a>.', array('!user_login_setting_ur' => 'admin/store/settings/checkout')),
  400. '#default_value' => variable_get('uc_msg_order_new_user_logged_in', uc_get_message('completion_new_user_logged_in')),
  401. '#rows' => 3,
  402. '#states' => $anon_state,
  403. );
  404. $form['completion_messages']['uc_msg_continue_shopping'] = array(
  405. '#type' => 'textarea',
  406. '#title' => t('Continue shopping message'),
  407. '#description' => t('Message displayed upon checkout to direct customers to another part of your site.'),
  408. '#default_value' => variable_get('uc_msg_continue_shopping', uc_get_message('continue_shopping')),
  409. '#rows' => 3,
  410. );
  411. if (module_exists('token')) {
  412. $form['completion_messages']['token_tree'] = array(
  413. '#markup' => theme('token_tree', array('token_types' => array('uc_order', 'site', 'store'))),
  414. );
  415. }
  416. return system_settings_form($form);
  417. }
  418. /**
  419. * Checkout rules configuration.
  420. */
  421. function uc_cart_checkout_rules() {
  422. $conditions = array(
  423. 'event' => 'uc_checkout_complete',
  424. 'plugin' => 'reaction rule',
  425. );
  426. $options = array(
  427. 'base path' => 'admin/store/settings/checkout/rules',
  428. 'show plugin' => FALSE,
  429. );
  430. $content['rules'] = rules_ui()->overviewTable($conditions, $options);
  431. return $content;
  432. }