BundleScriptsController.php
6 days ago
BundlesController.php
6 days ago
BundlesListTable.php
6 days ago
BundlesController.php
126 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Controllers\Admin\Bundles; |
| 4 | |
| 5 | use SureCart\Controllers\Admin\Products\ProductsController; |
| 6 | use SureCart\Sync\ImportState; |
| 7 | |
| 8 | /** |
| 9 | * Bundle admin controller. Bundles are Products with `bundle: true`, so most |
| 10 | * of the flow is inherited from ProductsController — this subclass only |
| 11 | * overrides what differs (slugs, view paths, list-table refs, copy). |
| 12 | */ |
| 13 | class BundlesController extends ProductsController { |
| 14 | /** |
| 15 | * Re-declared so the DI factory resolves `ImportState` for the subclass — |
| 16 | * auto-resolution skips inherited constructors. |
| 17 | * |
| 18 | * @param ImportState $woo_import_state Import state for WooCommerce runs. |
| 19 | */ |
| 20 | public function __construct( ImportState $woo_import_state ) { |
| 21 | parent::__construct( $woo_import_state ); |
| 22 | } |
| 23 | |
| 24 | /** @var string */ |
| 25 | protected $page_slug = 'sc-bundles'; |
| 26 | |
| 27 | /** |
| 28 | * Key passed to \SureCart::getUrl()->index(). |
| 29 | * Plural — mirrors ProductsController's `$url_key = 'products'`. |
| 30 | * |
| 31 | * @var string |
| 32 | */ |
| 33 | protected $url_key = 'bundles'; |
| 34 | |
| 35 | /** |
| 36 | * View path prefix (no trailing slash). |
| 37 | * |
| 38 | * @var string |
| 39 | */ |
| 40 | protected $view_prefix = 'admin/bundles'; |
| 41 | |
| 42 | /** @var string */ |
| 43 | protected $scripts_controller_class = BundleScriptsController::class; |
| 44 | |
| 45 | /** @var string */ |
| 46 | protected $list_table_class = BundlesListTable::class; |
| 47 | |
| 48 | /** @var string */ |
| 49 | protected $bulk_delete_view_key = 'bundles'; |
| 50 | |
| 51 | /** |
| 52 | * Index breadcrumb shape used by withHeader(). |
| 53 | * |
| 54 | * @return array |
| 55 | */ |
| 56 | protected function indexBreadcrumb() { |
| 57 | return array( |
| 58 | 'bundles' => array( |
| 59 | 'title' => __( 'Bundles', 'surecart' ), |
| 60 | ), |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Status-query → notice message map for the index page. |
| 66 | * |
| 67 | * @return array |
| 68 | */ |
| 69 | protected function indexNotices() { |
| 70 | return array( |
| 71 | 'sync_success' => __( 'Bundle synced successfully.', 'surecart' ), |
| 72 | 'archived' => __( 'Bundle archived.', 'surecart' ), |
| 73 | 'unarchived' => __( 'Bundle unarchived.', 'surecart' ), |
| 74 | 'duplicated' => __( 'Bundle duplicated successfully.', 'surecart' ), |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Admin-bar "View Bundle" link on the edit screen. |
| 80 | * |
| 81 | * @return array |
| 82 | */ |
| 83 | protected function adminBarViewEntry() { |
| 84 | return array( |
| 85 | 'id' => 'view-bundle-page', |
| 86 | 'title' => __( 'View Bundle', 'surecart' ), |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Message when bulk-delete is opened with no IDs selected. |
| 92 | * |
| 93 | * @return string |
| 94 | */ |
| 95 | protected function bulkDeleteEmptyMessage() { |
| 96 | return __( 'No bundles selected. Please choose at least one bundle to delete.', 'surecart' ); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Message when bulk-delete targets ids that no longer exist. |
| 101 | * |
| 102 | * @param int $count Number of ids requested for deletion. |
| 103 | * |
| 104 | * @return string |
| 105 | */ |
| 106 | protected function bulkDeleteAlreadyDeletedMessage( $count ) { |
| 107 | return _n( |
| 108 | 'This bundle has already been deleted.', |
| 109 | 'These bundles have already been deleted.', |
| 110 | $count, |
| 111 | 'surecart' |
| 112 | ); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Header title on the confirm-bulk-delete screen. |
| 117 | * |
| 118 | * @param int $count Number of items being deleted. |
| 119 | * |
| 120 | * @return string |
| 121 | */ |
| 122 | protected function bulkDeleteHeaderTitle( $count ) { |
| 123 | return _n( 'Delete Bundle', 'Delete Bundles', $count, 'surecart' ); |
| 124 | } |
| 125 | } |
| 126 |