| @@ -6,10 +6,11 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | declare( strict_types=1 ); |
| 9 | 9 | |
| 10 | +namespace Packetery\Module; | |
| 10 | 11 | |
| 11 | -namespace Packetery\Module; | |
| 12 | +use Packetery\Nette\Http\Request; | |
| 12 | 13 | |
| 13 | 14 | /** |
| 14 | 15 | * Class ContextResolver. |
| 15 | 16 | * |
| @@ -17,16 +18,38 @@ | ||
| 17 | 18 | */ |
| 18 | 19 | class ContextResolver { |
| 19 | 20 | |
| 20 | 21 | /** |
| 22 | + * Request. | |
| 23 | + * | |
| 24 | + * @var Request | |
| 25 | + */ | |
| 26 | + private $request; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * ContextResolver constructor. | |
| 30 | + * | |
| 31 | + * @param Request $request Packetery request. | |
| 32 | + */ | |
| 33 | + public function __construct( Request $request ) { | |
| 34 | + $this->request = $request; | |
| 35 | + } | |
| 36 | + | |
| 37 | + /** | |
| 21 | 38 | * Tells if requesting user is at order grid page. |
| 22 | 39 | * |
| 23 | 40 | * @return bool |
| 24 | 41 | */ |
| 25 | 42 | public function isOrderGridPage(): bool { |
| 26 | - global $pagenow, $typenow; | |
| 43 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 44 | + global $pagenow, $typenow, $plugin_page; | |
| 27 | 45 | |
| 28 | - return 'edit.php' === $pagenow && 'shop_order' === $typenow; | |
| 46 | + if ( ModuleHelper::isHposEnabled() ) { | |
| 47 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 48 | + return $pagenow === 'admin.php' && $plugin_page === 'wc-orders' && in_array( $this->request->getQuery( 'action' ), [ 'edit', 'new' ], true ) === false; | |
| 49 | + } | |
| 50 | + | |
| 51 | + return $pagenow === 'edit.php' && $typenow === 'shop_order'; | |
| 29 | 52 | } |
| 30 | 53 | |
| 31 | 54 | /** |
| 32 | 55 | * Tells if requesting user is at order detail page. |
| @@ -33,11 +56,17 @@ | ||
| 33 | 56 | * |
| 34 | 57 | * @return bool |
| 35 | 58 | */ |
| 36 | 59 | public function isOrderDetailPage(): bool { |
| 37 | - global $pagenow, $typenow; | |
| 60 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 61 | + global $pagenow, $typenow, $plugin_page; | |
| 38 | 62 | |
| 39 | - return 'post.php' === $pagenow && 'shop_order' === $typenow; | |
| 63 | + if ( ModuleHelper::isHposEnabled() ) { | |
| 64 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 65 | + return $pagenow === 'admin.php' && $plugin_page === 'wc-orders' && $this->request->getQuery( 'action' ) === 'edit'; | |
| 66 | + } | |
| 67 | + | |
| 68 | + return $pagenow === 'post.php' && $typenow === 'shop_order'; | |
| 40 | 69 | } |
| 41 | 70 | |
| 42 | 71 | /** |
| 43 | 72 | * Tells if requesting user is at product detail page. |
| @@ -46,9 +75,9 @@ | ||
| 46 | 75 | */ |
| 47 | 76 | private function isProductDetailPage(): bool { |
| 48 | 77 | global $pagenow, $typenow; |
| 49 | 78 | |
| 50 | - return 'post.php' === $pagenow && 'product' === $typenow; | |
| 79 | + return $pagenow === 'post.php' && $typenow === 'product'; | |
| 51 | 80 | } |
| 52 | 81 | |
| 53 | 82 | /** |
| 54 | 83 | * Tells if requesting user is at product create page. |
| @@ -57,9 +86,9 @@ | ||
| 57 | 86 | */ |
| 58 | 87 | private function isProductCreatePage(): bool { |
| 59 | 88 | global $pagenow, $typenow; |
| 60 | 89 | |
| 61 | - return 'post-new.php' === $pagenow && 'product' === $typenow; | |
| 90 | + return $pagenow === 'post-new.php' && $typenow === 'product'; | |
| 62 | 91 | } |
| 63 | 92 | |
| 64 | 93 | /** |
| 65 | 94 | * Tells if requesting user is at product page. |
| @@ -74,8 +103,68 @@ | ||
| 74 | 103 | * Tells if requesting user is at page using packetery confirm. |
| 75 | 104 | * |
| 76 | 105 | * @return bool |
| 77 | 106 | */ |
| 78 | - public function isPacketeryConfirmPage(): bool { | |
| 107 | + public function isConfirmModalPage(): bool { | |
| 79 | 108 | return $this->isOrderDetailPage() || $this->isOrderGridPage(); |
| 109 | + } | |
| 110 | + | |
| 111 | + /** | |
| 112 | + * Tells if requesting user is at product category grid page. | |
| 113 | + * | |
| 114 | + * @return bool | |
| 115 | + */ | |
| 116 | + public function isProductCategoryGridPage(): bool { | |
| 117 | + global $pagenow; | |
| 118 | + | |
| 119 | + return $pagenow === 'edit-tags.php' && $this->request->getQuery( 'taxonomy' ) === ProductCategory\Entity::TAXONOMY_NAME; | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Tells if requesting user is at product category grid page. | |
| 124 | + * | |
| 125 | + * @return bool | |
| 126 | + */ | |
| 127 | + public function isProductCategoryDetailPage(): bool { | |
| 128 | + global $pagenow; | |
| 129 | + | |
| 130 | + return $pagenow === 'term.php' && $this->request->getQuery( 'taxonomy' ) === ProductCategory\Entity::TAXONOMY_NAME; | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * Tells if user is at page detail. | |
| 135 | + * | |
| 136 | + * @return bool | |
| 137 | + */ | |
| 138 | + public function isPageDetail(): bool { | |
| 139 | + global $pagenow, $typenow; | |
| 140 | + | |
| 141 | + return $pagenow === 'post.php' && $typenow === 'page'; | |
| 142 | + } | |
| 143 | + | |
| 144 | + private function isShippingZoneDetailPage(): bool { | |
| 145 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 146 | + global $pagenow, $plugin_page; | |
| 147 | + | |
| 148 | + return ( | |
| 149 | + $pagenow === 'admin.php' && | |
| 150 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps | |
| 151 | + $plugin_page === 'wc-settings' && | |
| 152 | + $this->request->getQuery( 'tab' ) === 'shipping' && | |
| 153 | + $this->request->getQuery( 'zone_id' ) > 0 | |
| 154 | + ); | |
| 155 | + } | |
| 156 | + | |
| 157 | + public function getShippingZoneId(): ?int { | |
| 158 | + if ( $this->isShippingZoneDetailPage() ) { | |
| 159 | + return (int) $this->request->getQuery( 'zone_id' ); | |
| 160 | + } | |
| 161 | + | |
| 162 | + return null; | |
| 163 | + } | |
| 164 | + | |
| 165 | + public function isPluginsOverviewPage(): bool { | |
| 166 | + global $pagenow; | |
| 167 | + | |
| 168 | + return $pagenow === 'plugins.php'; | |
| 80 | 169 | } |
| 81 | 170 | } |