uc_cart.admin.inc 18 KB

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