| Total Complexity | 23 |
| Total Lines | 302 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | class Standard |
||
| 26 | extends \Aimeos\Client\Html\Common\Client\Factory\Base |
||
| 27 | implements \Aimeos\Client\Html\Common\Client\Factory\Iface |
||
| 28 | { |
||
| 29 | /** client/html/checkout/standard/delivery/standard/subparts |
||
| 30 | * List of HTML sub-clients rendered within the checkout standard delivery section |
||
| 31 | * |
||
| 32 | * The output of the frontend is composed of the code generated by the HTML |
||
| 33 | * clients. Each HTML client can consist of serveral (or none) sub-clients |
||
| 34 | * that are responsible for rendering certain sub-parts of the output. The |
||
| 35 | * sub-clients can contain HTML clients themselves and therefore a |
||
| 36 | * hierarchical tree of HTML clients is composed. Each HTML client creates |
||
| 37 | * the output that is placed inside the container of its parent. |
||
| 38 | * |
||
| 39 | * At first, always the HTML code generated by the parent is printed, then |
||
| 40 | * the HTML code of its sub-clients. The order of the HTML sub-clients |
||
| 41 | * determines the order of the output of these sub-clients inside the parent |
||
| 42 | * container. If the configured list of clients is |
||
| 43 | * |
||
| 44 | * array( "subclient1", "subclient2" ) |
||
| 45 | * |
||
| 46 | * you can easily change the order of the output by reordering the subparts: |
||
| 47 | * |
||
| 48 | * client/html/<clients>/subparts = array( "subclient1", "subclient2" ) |
||
| 49 | * |
||
| 50 | * You can also remove one or more parts if they shouldn't be rendered: |
||
| 51 | * |
||
| 52 | * client/html/<clients>/subparts = array( "subclient1" ) |
||
| 53 | * |
||
| 54 | * As the clients only generates structural HTML, the layout defined via CSS |
||
| 55 | * should support adding, removing or reordering content by a fluid like |
||
| 56 | * design. |
||
| 57 | * |
||
| 58 | * @param array List of sub-client names |
||
| 59 | * @since 2014.03 |
||
| 60 | * @category Developer |
||
| 61 | */ |
||
| 62 | private $subPartPath = 'client/html/checkout/standard/delivery/standard/subparts'; |
||
| 63 | private $subPartNames = []; |
||
| 64 | |||
| 65 | |||
| 66 | /** |
||
| 67 | * Returns the HTML code for insertion into the body. |
||
| 68 | * |
||
| 69 | * @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
||
| 70 | * @return string HTML code |
||
| 71 | */ |
||
| 72 | public function getBody( $uid = '' ) |
||
| 73 | { |
||
| 74 | $view = $this->getView(); |
||
| 75 | $step = $view->get( 'standardStepActive' ); |
||
| 76 | $onepage = $view->config( 'client/html/checkout/standard/onepage', [] ); |
||
| 77 | |||
| 78 | if( $step != 'delivery' && !( in_array( 'delivery', $onepage ) && in_array( $step, $onepage ) ) ) { |
||
| 79 | return ''; |
||
| 80 | } |
||
| 81 | |||
| 82 | $html = ''; |
||
| 83 | foreach( $this->getSubClients() as $subclient ) { |
||
| 84 | $html .= $subclient->setView( $view )->getBody( $uid ); |
||
| 85 | } |
||
| 86 | $view->deliveryBody = $html; |
||
| 87 | |||
| 88 | /** client/html/checkout/standard/delivery/standard/template-body |
||
| 89 | * Relative path to the HTML body template of the checkout standard delivery client. |
||
| 90 | * |
||
| 91 | * The template file contains the HTML code and processing instructions |
||
| 92 | * to generate the result shown in the body of the frontend. The |
||
| 93 | * configuration string is the path to the template file relative |
||
| 94 | * to the templates directory (usually in client/html/templates). |
||
| 95 | * |
||
| 96 | * You can overwrite the template file configuration in extensions and |
||
| 97 | * provide alternative templates. These alternative templates should be |
||
| 98 | * named like the default one but with the string "standard" replaced by |
||
| 99 | * an unique name. You may use the name of your project for this. If |
||
| 100 | * you've implemented an alternative client class as well, "standard" |
||
| 101 | * should be replaced by the name of the new class. |
||
| 102 | * |
||
| 103 | * @param string Relative path to the template creating code for the HTML page body |
||
| 104 | * @since 2014.03 |
||
| 105 | * @category Developer |
||
| 106 | * @see client/html/checkout/standard/delivery/standard/template-header |
||
| 107 | */ |
||
| 108 | $tplconf = 'client/html/checkout/standard/delivery/standard/template-body'; |
||
| 109 | $default = 'checkout/standard/delivery-body-standard'; |
||
| 110 | |||
| 111 | return $view->render( $view->config( $tplconf, $default ) ); |
||
| 112 | } |
||
| 113 | |||
| 114 | |||
| 115 | /** |
||
| 116 | * Returns the HTML string for insertion into the header. |
||
| 117 | * |
||
| 118 | * @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
||
| 119 | * @return string|null String including HTML tags for the header on error |
||
| 120 | */ |
||
| 121 | public function getHeader( $uid = '' ) |
||
| 122 | { |
||
| 123 | $view = $this->getView(); |
||
| 124 | $step = $view->get( 'standardStepActive' ); |
||
| 125 | $onepage = $view->config( 'client/html/checkout/standard/onepage', [] ); |
||
| 126 | |||
| 127 | if( $step != 'delivery' && !( in_array( 'delivery', $onepage ) && in_array( $step, $onepage ) ) ) { |
||
| 128 | return ''; |
||
| 129 | } |
||
| 130 | |||
| 131 | return parent::getHeader( $uid ); |
||
| 132 | } |
||
| 133 | |||
| 134 | |||
| 135 | /** |
||
| 136 | * Returns the sub-client given by its name. |
||
| 137 | * |
||
| 138 | * @param string $type Name of the client type |
||
| 139 | * @param string|null $name Name of the sub-client (Default if null) |
||
| 140 | * @return \Aimeos\Client\Html\Iface Sub-client object |
||
| 141 | */ |
||
| 142 | public function getSubClient( $type, $name = null ) |
||
| 143 | { |
||
| 144 | /** client/html/checkout/standard/delivery/decorators/excludes |
||
| 145 | * Excludes decorators added by the "common" option from the checkout standard delivery html client |
||
| 146 | * |
||
| 147 | * Decorators extend the functionality of a class by adding new aspects |
||
| 148 | * (e.g. log what is currently done), executing the methods of the underlying |
||
| 149 | * class only in certain conditions (e.g. only for logged in users) or |
||
| 150 | * modify what is returned to the caller. |
||
| 151 | * |
||
| 152 | * This option allows you to remove a decorator added via |
||
| 153 | * "client/html/common/decorators/default" before they are wrapped |
||
| 154 | * around the html client. |
||
| 155 | * |
||
| 156 | * client/html/checkout/standard/delivery/decorators/excludes = array( 'decorator1' ) |
||
| 157 | * |
||
| 158 | * This would remove the decorator named "decorator1" from the list of |
||
| 159 | * common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
||
| 160 | * "client/html/common/decorators/default" to the html client. |
||
| 161 | * |
||
| 162 | * @param array List of decorator names |
||
| 163 | * @since 2015.08 |
||
| 164 | * @category Developer |
||
| 165 | * @see client/html/common/decorators/default |
||
| 166 | * @see client/html/checkout/standard/delivery/decorators/global |
||
| 167 | * @see client/html/checkout/standard/delivery/decorators/local |
||
| 168 | */ |
||
| 169 | |||
| 170 | /** client/html/checkout/standard/delivery/decorators/global |
||
| 171 | * Adds a list of globally available decorators only to the checkout standard delivery html client |
||
| 172 | * |
||
| 173 | * Decorators extend the functionality of a class by adding new aspects |
||
| 174 | * (e.g. log what is currently done), executing the methods of the underlying |
||
| 175 | * class only in certain conditions (e.g. only for logged in users) or |
||
| 176 | * modify what is returned to the caller. |
||
| 177 | * |
||
| 178 | * This option allows you to wrap global decorators |
||
| 179 | * ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
||
| 180 | * |
||
| 181 | * client/html/checkout/standard/delivery/decorators/global = array( 'decorator1' ) |
||
| 182 | * |
||
| 183 | * This would add the decorator named "decorator1" defined by |
||
| 184 | * "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
||
| 185 | * |
||
| 186 | * @param array List of decorator names |
||
| 187 | * @since 2015.08 |
||
| 188 | * @category Developer |
||
| 189 | * @see client/html/common/decorators/default |
||
| 190 | * @see client/html/checkout/standard/delivery/decorators/excludes |
||
| 191 | * @see client/html/checkout/standard/delivery/decorators/local |
||
| 192 | */ |
||
| 193 | |||
| 194 | /** client/html/checkout/standard/delivery/decorators/local |
||
| 195 | * Adds a list of local decorators only to the checkout standard delivery html client |
||
| 196 | * |
||
| 197 | * Decorators extend the functionality of a class by adding new aspects |
||
| 198 | * (e.g. log what is currently done), executing the methods of the underlying |
||
| 199 | * class only in certain conditions (e.g. only for logged in users) or |
||
| 200 | * modify what is returned to the caller. |
||
| 201 | * |
||
| 202 | * This option allows you to wrap local decorators |
||
| 203 | * ("\Aimeos\Client\Html\Checkout\Decorator\*") around the html client. |
||
| 204 | * |
||
| 205 | * client/html/checkout/standard/delivery/decorators/local = array( 'decorator2' ) |
||
| 206 | * |
||
| 207 | * This would add the decorator named "decorator2" defined by |
||
| 208 | * "\Aimeos\Client\Html\Checkout\Decorator\Decorator2" only to the html client. |
||
| 209 | * |
||
| 210 | * @param array List of decorator names |
||
| 211 | * @since 2015.08 |
||
| 212 | * @category Developer |
||
| 213 | * @see client/html/common/decorators/default |
||
| 214 | * @see client/html/checkout/standard/delivery/decorators/excludes |
||
| 215 | * @see client/html/checkout/standard/delivery/decorators/global |
||
| 216 | */ |
||
| 217 | |||
| 218 | return $this->createSubClient( 'checkout/standard/delivery/' . $type, $name ); |
||
| 219 | } |
||
| 220 | |||
| 221 | |||
| 222 | /** |
||
| 223 | * Processes the input, e.g. store given values. |
||
| 224 | * A view must be available and this method doesn't generate any output |
||
| 225 | * besides setting view variables. |
||
| 226 | */ |
||
| 227 | public function process() |
||
| 228 | { |
||
| 229 | $view = $this->getView(); |
||
| 230 | |||
| 231 | try |
||
| 232 | { |
||
| 233 | $context = $this->getContext(); |
||
| 234 | $basketCtrl = \Aimeos\Controller\Frontend::create( $context, 'basket' ); |
||
| 235 | $serviceCtrl = \Aimeos\Controller\Frontend::create( $context, 'service' ); |
||
| 236 | |||
| 237 | // only start if there's something to do |
||
| 238 | if( ( $serviceIds = $view->param( 'c_deliveryoption', null ) ) !== null ) |
||
| 239 | { |
||
| 240 | $basketCtrl->deleteService( 'delivery' ); |
||
|
1 ignored issue
–
show
|
|||
| 241 | |||
| 242 | foreach( (array) $serviceIds as $serviceId ) |
||
| 243 | { |
||
| 244 | $attributes = $view->param( 'c_delivery/' . $serviceId, [] ); |
||
| 245 | $errors = $serviceCtrl->checkAttributes( $serviceId, $attributes ); |
||
|
1 ignored issue
–
show
|
|||
| 246 | $view->deliveryError = $errors; |
||
| 247 | |||
| 248 | if( count( $errors ) > 0 ) |
||
| 249 | { |
||
| 250 | $view->standardErrorList = $view->get( 'standardErrorList', [] ) + $errors; |
||
| 251 | throw new \Aimeos\Client\Html\Exception( sprintf( 'Please recheck your delivery choice' ) ); |
||
| 252 | } |
||
| 253 | else |
||
| 254 | { |
||
| 255 | $basketCtrl->addService( 'delivery', $serviceId, $attributes ); |
||
|
1 ignored issue
–
show
|
|||
| 256 | } |
||
| 257 | } |
||
| 258 | } |
||
| 259 | |||
| 260 | |||
| 261 | parent::process(); |
||
| 262 | |||
| 263 | |||
| 264 | // Test if delivery service is available |
||
| 265 | $services = $basketCtrl->get()->getServices(); |
||
|
1 ignored issue
–
show
|
|||
| 266 | |||
| 267 | if( !isset( $view->standardStepActive ) && ( !isset( $services['delivery'] ) || empty( $services['delivery'] ) ) |
||
| 268 | && count( $serviceCtrl->getProviders( 'delivery' ) ) > 0 |
||
|
1 ignored issue
–
show
|
|||
| 269 | ) { |
||
| 270 | $view->standardStepActive = 'delivery'; |
||
| 271 | return false; |
||
| 272 | } |
||
| 273 | } |
||
| 274 | catch( \Exception $e ) |
||
| 275 | { |
||
| 276 | $view->standardStepActive = 'delivery'; |
||
| 277 | throw $e; |
||
| 278 | } |
||
| 279 | } |
||
| 280 | |||
| 281 | |||
| 282 | /** |
||
| 283 | * Returns the list of sub-client names configured for the client. |
||
| 284 | * |
||
| 285 | * @return array List of HTML client names |
||
| 286 | */ |
||
| 287 | protected function getSubClientNames() |
||
| 288 | { |
||
| 289 | return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames ); |
||
| 290 | } |
||
| 291 | |||
| 292 | |||
| 293 | /** |
||
| 294 | * Sets the necessary parameter values in the view. |
||
| 295 | * |
||
| 296 | * @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
||
| 297 | * @param array &$tags Result array for the list of tags that are associated to the output |
||
| 298 | * @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
||
| 299 | * @return \Aimeos\MW\View\Iface Modified view object |
||
| 300 | */ |
||
| 301 | public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], &$expire = null ) |
||
| 327 | } |
||
| 328 | } |