| Total Complexity | 40 |
| Total Lines | 603 |
| Duplicated Lines | 0 % |
| Changes | 5 | ||
| Bugs | 1 | Features | 0 |
Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class Standard extends Base |
||
| 21 | implements \Aimeos\MShop\Order\Manager\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface |
||
| 22 | { |
||
| 23 | use Session; |
||
| 24 | use Update; |
||
| 25 | |||
| 26 | |||
| 27 | /** |
||
| 28 | * Counts the number items that are available for the values of the given key. |
||
| 29 | * |
||
| 30 | * @param \Aimeos\Base\Criteria\Iface $search Search criteria |
||
| 31 | * @param array|string $key Search key or list of key to aggregate items for |
||
| 32 | * @param string|null $value Search key for aggregating the value column |
||
| 33 | * @param string|null $type Type of the aggregation, empty string for count or "sum" or "avg" (average) |
||
| 34 | * @return \Aimeos\Map List of the search keys as key and the number of counted items as value |
||
| 35 | */ |
||
| 36 | public function aggregate( \Aimeos\Base\Criteria\Iface $search, $key, string $value = null, string $type = null ) : \Aimeos\Map |
||
| 37 | { |
||
| 38 | /** mshop/order/manager/aggregate/mysql |
||
| 39 | * Counts the number of records grouped by the values in the key column and matched by the given criteria |
||
| 40 | * |
||
| 41 | * @see mshop/order/manager/aggregate/ansi |
||
| 42 | */ |
||
| 43 | |||
| 44 | /** mshop/order/manager/aggregate/ansi |
||
| 45 | * Counts the number of records grouped by the values in the key column and matched by the given criteria |
||
| 46 | * |
||
| 47 | * Groups all records by the values in the key column and counts their |
||
| 48 | * occurence. The matched records can be limited by the given criteria |
||
| 49 | * from the order database. The records must be from one of the sites |
||
| 50 | * that are configured via the context item. If the current site is part |
||
| 51 | * of a tree of sites, the statement can count all records from the |
||
| 52 | * current site and the complete sub-tree of sites. |
||
| 53 | * |
||
| 54 | * As the records can normally be limited by criteria from sub-managers, |
||
| 55 | * their tables must be joined in the SQL context. This is done by |
||
| 56 | * using the "internaldeps" property from the definition of the ID |
||
| 57 | * column of the sub-managers. These internal dependencies specify |
||
| 58 | * the JOIN between the tables and the used columns for joining. The |
||
| 59 | * ":joins" placeholder is then replaced by the JOIN strings from |
||
| 60 | * the sub-managers. |
||
| 61 | * |
||
| 62 | * To limit the records matched, conditions can be added to the given |
||
| 63 | * criteria object. It can contain comparisons like column names that |
||
| 64 | * must match specific values which can be combined by AND, OR or NOT |
||
| 65 | * operators. The resulting string of SQL conditions replaces the |
||
| 66 | * ":cond" placeholder before the statement is sent to the database |
||
| 67 | * server. |
||
| 68 | * |
||
| 69 | * This statement doesn't return any records. Instead, it returns pairs |
||
| 70 | * of the different values found in the key column together with the |
||
| 71 | * number of records that have been found for that key values. |
||
| 72 | * |
||
| 73 | * The SQL statement should conform to the ANSI standard to be |
||
| 74 | * compatible with most relational database systems. This also |
||
| 75 | * includes using double quotes for table and column names. |
||
| 76 | * |
||
| 77 | * @param string SQL statement for aggregating order items |
||
| 78 | * @since 2014.09 |
||
| 79 | * @see mshop/order/manager/insert/ansi |
||
| 80 | * @see mshop/order/manager/update/ansi |
||
| 81 | * @see mshop/order/manager/newid/ansi |
||
| 82 | * @see mshop/order/manager/delete/ansi |
||
| 83 | * @see mshop/order/manager/search/ansi |
||
| 84 | * @see mshop/order/manager/count/ansi |
||
| 85 | */ |
||
| 86 | |||
| 87 | /** mshop/order/manager/aggregateavg/mysql |
||
| 88 | * Computes the average of all values grouped by the key column and matched by the given criteria |
||
| 89 | * |
||
| 90 | * @param string SQL statement for aggregating the order items and computing the average value |
||
| 91 | * @since 2017.10 |
||
| 92 | * @see mshop/order/manager/aggregateavg/ansi |
||
| 93 | * @see mshop/order/manager/aggregate/mysql |
||
| 94 | */ |
||
| 95 | |||
| 96 | /** mshop/order/manager/aggregateavg/ansi |
||
| 97 | * Computes the average of all values grouped by the key column and matched by the given criteria |
||
| 98 | * |
||
| 99 | * @param string SQL statement for aggregating the order items and computing the average value |
||
| 100 | * @since 2017.10 |
||
| 101 | * @see mshop/order/manager/aggregate/ansi |
||
| 102 | */ |
||
| 103 | |||
| 104 | /** mshop/order/manager/aggregatesum/mysql |
||
| 105 | * Computes the sum of all values grouped by the key column and matched by the given criteria |
||
| 106 | * |
||
| 107 | * @param string SQL statement for aggregating the order items and computing the sum |
||
| 108 | * @since 2017.10 |
||
| 109 | * @see mshop/order/manager/aggregatesum/ansi |
||
| 110 | * @see mshop/order/manager/aggregate/mysql |
||
| 111 | */ |
||
| 112 | |||
| 113 | /** mshop/order/manager/aggregatesum/ansi |
||
| 114 | * Computes the sum of all values grouped by the key column and matched by the given criteria |
||
| 115 | * |
||
| 116 | * @param string SQL statement for aggregating the order items and computing the sum |
||
| 117 | * @since 2017.10 |
||
| 118 | * @see mshop/order/manager/aggregate/ansi |
||
| 119 | */ |
||
| 120 | |||
| 121 | $cfgkey = 'mshop/order/manager/aggregate'; |
||
| 122 | return $this->aggregateBase( $search, $key, $cfgkey, ['order'], $value, $type ); |
||
| 123 | } |
||
| 124 | |||
| 125 | |||
| 126 | /** |
||
| 127 | * Creates a new empty item instance |
||
| 128 | * |
||
| 129 | * @param array $values Values the item should be initialized with |
||
| 130 | * @return \Aimeos\MShop\Order\Item\Iface New order item object |
||
| 131 | */ |
||
| 132 | public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface |
||
| 133 | { |
||
| 134 | $context = $this->context(); |
||
| 135 | $locale = $context->locale(); |
||
| 136 | |||
| 137 | $values['.locale'] = $values['.locale'] ?? $locale; |
||
| 138 | $values['.price'] = $values['.price'] ?? \Aimeos\MShop::create( $context, 'price' )->create(); |
||
| 139 | $values['order.siteid'] = $values['order.siteid'] ?? $locale->getSiteId(); |
||
| 140 | |||
| 141 | $item = new \Aimeos\MShop\Order\Item\Standard( 'order.', $values ); |
||
| 142 | \Aimeos\MShop::create( $context, 'plugin' )->register( $item, 'order' ); |
||
| 143 | |||
| 144 | return $item; |
||
| 145 | } |
||
| 146 | |||
| 147 | |||
| 148 | /** |
||
| 149 | * Creates a new address item instance |
||
| 150 | * |
||
| 151 | * @param array $values Values the item should be initialized with |
||
| 152 | * @return \Aimeos\MShop\Order\Item\Address\Iface New order address item object |
||
| 153 | */ |
||
| 154 | public function createAddress( array $values = [] ) : \Aimeos\MShop\Order\Item\Address\Iface |
||
| 155 | { |
||
| 156 | return $this->object()->getSubManager( 'address' )->create( $values ); |
||
| 157 | } |
||
| 158 | |||
| 159 | |||
| 160 | /** |
||
| 161 | * Creates a new coupon item instance |
||
| 162 | * |
||
| 163 | * @param array $values Values the item should be initialized with |
||
| 164 | * @return \Aimeos\MShop\Order\Item\Coupon\Iface New order coupon item object |
||
| 165 | */ |
||
| 166 | public function createCoupon( array $values = [] ) : \Aimeos\MShop\Order\Item\Coupon\Iface |
||
| 167 | { |
||
| 168 | return $this->object()->getSubManager( 'coupon' )->create( $values ); |
||
| 169 | } |
||
| 170 | |||
| 171 | |||
| 172 | /** |
||
| 173 | * Creates a new product item instance |
||
| 174 | * |
||
| 175 | * @param array $values Values the item should be initialized with |
||
| 176 | * @return \Aimeos\MShop\Order\Item\Product\Iface New order product item object |
||
| 177 | */ |
||
| 178 | public function createProduct( array $values = [] ) : \Aimeos\MShop\Order\Item\Product\Iface |
||
| 179 | { |
||
| 180 | return $this->object()->getSubManager( 'product' )->create( $values ); |
||
| 181 | } |
||
| 182 | |||
| 183 | |||
| 184 | /** |
||
| 185 | * Creates a new product attribute item instance |
||
| 186 | * |
||
| 187 | * @param array $values Values the item should be initialized with |
||
| 188 | * @return \Aimeos\MShop\Order\Item\Product\Attribute\Iface New order product attribute item object |
||
| 189 | */ |
||
| 190 | public function createProductAttribute( array $values = [] ) : \Aimeos\MShop\Order\Item\Product\Attribute\Iface |
||
| 191 | { |
||
| 192 | return $this->object()->getSubManager( 'product' )->getSubManager( 'attribute' )->create( $values ); |
||
| 193 | } |
||
| 194 | |||
| 195 | |||
| 196 | /** |
||
| 197 | * Creates a new service item instance |
||
| 198 | * |
||
| 199 | * @param array $values Values the item should be initialized with |
||
| 200 | * @return \Aimeos\MShop\Order\Item\Service\Iface New order service item object |
||
| 201 | */ |
||
| 202 | public function createService( array $values = [] ) : \Aimeos\MShop\Order\Item\Service\Iface |
||
| 203 | { |
||
| 204 | return $this->object()->getSubManager( 'service' )->create( $values ); |
||
| 205 | } |
||
| 206 | |||
| 207 | |||
| 208 | /** |
||
| 209 | * Creates a new service attribute item instance |
||
| 210 | * |
||
| 211 | * @param array $values Values the item should be initialized with |
||
| 212 | * @return \Aimeos\MShop\Order\Item\Service\Attribute\Iface New order service attribute item object |
||
| 213 | */ |
||
| 214 | public function createServiceAttribute( array $values = [] ) : \Aimeos\MShop\Order\Item\Service\Attribute\Iface |
||
| 215 | { |
||
| 216 | return $this->object()->getSubManager( 'service' )->getSubManager( 'attribute' )->create( $values ); |
||
| 217 | } |
||
| 218 | |||
| 219 | |||
| 220 | /** |
||
| 221 | * Creates a new service transaction item instance |
||
| 222 | * |
||
| 223 | * @param array $values Values the item should be initialized with |
||
| 224 | * @return \Aimeos\MShop\Order\Item\Service\Transaction\Iface New order service transaction item object |
||
| 225 | */ |
||
| 226 | public function createServiceTransaction( array $values = [] ) : \Aimeos\MShop\Order\Item\Service\Transaction\Iface |
||
| 229 | } |
||
| 230 | |||
| 231 | |||
| 232 | /** |
||
| 233 | * Creates a new status item instance |
||
| 234 | * |
||
| 235 | * @param array $values Values the item should be initialized with |
||
| 236 | * @return \Aimeos\MShop\Order\Item\Status\Iface New order item object |
||
| 237 | */ |
||
| 238 | public function createStatus( array $values = [] ) : \Aimeos\MShop\Order\Item\Status\Iface |
||
| 239 | { |
||
| 240 | return $this->object()->getSubManager( 'status' )->create( $values ); |
||
| 241 | } |
||
| 242 | |||
| 243 | |||
| 244 | /** |
||
| 245 | * Creates a search critera object |
||
| 246 | * |
||
| 247 | * @param bool|null $default Add default criteria or NULL for relaxed default criteria |
||
| 248 | * @param bool $site TRUE to add site criteria to show orders with available products only |
||
| 249 | * @return \Aimeos\Base\Criteria\Iface New search criteria object |
||
| 250 | */ |
||
| 251 | public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface |
||
| 252 | { |
||
| 253 | $search = parent::filter( $default ); |
||
| 254 | |||
| 255 | if( $default !== false ) { |
||
| 256 | $search->add( ['order.customerid' => $this->context()->user()] ); |
||
| 257 | } |
||
| 258 | |||
| 259 | if( $site === true ) |
||
| 260 | { |
||
| 261 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE; |
||
| 262 | $search->add( $this->siteCondition( 'order.product.siteid', $level ) ); |
||
| 263 | } |
||
| 264 | |||
| 265 | return $search; |
||
| 266 | } |
||
| 267 | |||
| 268 | |||
| 269 | /** |
||
| 270 | * Returns the additional column/search definitions |
||
| 271 | * |
||
| 272 | * @return array Associative list of column names as keys and items implementing \Aimeos\Base\Criteria\Attribute\Iface |
||
| 273 | */ |
||
| 274 | public function getSaveAttributes() : array |
||
| 275 | { |
||
| 276 | return $this->createAttributes( [ |
||
| 277 | 'order.invoiceno' => [ |
||
| 278 | 'label' => 'Invoice number', |
||
| 279 | 'internalcode' => 'invoiceno', |
||
| 280 | ], |
||
| 281 | 'order.relatedid' => [ |
||
| 282 | 'label' => 'Related invoice ID', |
||
| 283 | 'internalcode' => 'relatedid', |
||
| 284 | ], |
||
| 285 | 'order.channel' => [ |
||
| 286 | 'label' => 'Order channel', |
||
| 287 | 'internalcode' => 'channel', |
||
| 288 | ], |
||
| 289 | 'order.datepayment' => [ |
||
| 290 | 'label' => 'Purchase date', |
||
| 291 | 'internalcode' => 'datepayment', |
||
| 292 | 'type' => 'datetime', |
||
| 293 | ], |
||
| 294 | 'order.datedelivery' => [ |
||
| 295 | 'label' => 'Delivery date', |
||
| 296 | 'internalcode' => 'datedelivery', |
||
| 297 | 'type' => 'datetime', |
||
| 298 | ], |
||
| 299 | 'order.statusdelivery' => [ |
||
| 300 | 'label' => 'Delivery status', |
||
| 301 | 'internalcode' => 'statusdelivery', |
||
| 302 | 'type' => 'int', |
||
| 303 | ], |
||
| 304 | 'order.statuspayment' => [ |
||
| 305 | 'label' => 'Payment status', |
||
| 306 | 'internalcode' => 'statuspayment', |
||
| 307 | 'type' => 'int', |
||
| 308 | ], |
||
| 309 | 'order.customerid' => [ |
||
| 310 | 'label' => 'Order customer ID', |
||
| 311 | 'internalcode' => 'customerid', |
||
| 312 | ], |
||
| 313 | 'order.customerref' => [ |
||
| 314 | 'label' => 'Order customer reference', |
||
| 315 | 'internalcode' => 'customerref', |
||
| 316 | ], |
||
| 317 | 'order.comment' => [ |
||
| 318 | 'label' => 'Order comment', |
||
| 319 | 'internalcode' => 'comment', |
||
| 320 | ], |
||
| 321 | ] ); |
||
| 322 | } |
||
| 323 | |||
| 324 | |||
| 325 | /** |
||
| 326 | * Returns the attributes that can be used for searching. |
||
| 327 | * |
||
| 328 | * @param bool $withsub Return also attributes of sub-managers if true |
||
| 329 | * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attribute items |
||
| 330 | */ |
||
| 331 | public function getSearchAttributes( bool $withsub = true ) : array |
||
| 332 | { |
||
| 333 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
||
| 334 | $level = $this->context()->config()->get( 'mshop/order/manager/sitemode', $level ); |
||
| 335 | $expr = $this->siteString( 'mordst_cs."siteid"', $level ); |
||
| 336 | |||
| 337 | return array_replace( parent::getSearchAttributes( $withsub ), $this->createAttributes( [ |
||
| 338 | 'order.sitecode' => [ |
||
| 339 | 'label' => 'Order site code', |
||
| 340 | 'internalcode' => 'sitecode', |
||
| 341 | 'public' => false, |
||
| 342 | ], |
||
| 343 | 'order.languageid' => [ |
||
| 344 | 'label' => 'Order language code', |
||
| 345 | 'internalcode' => 'langid', |
||
| 346 | ], |
||
| 347 | 'order.currencyid' => [ |
||
| 348 | 'label' => 'Order currencyid code', |
||
| 349 | 'internalcode' => 'currencyid', |
||
| 350 | ], |
||
| 351 | 'order.price' => [ |
||
| 352 | 'label' => 'Order price amount', |
||
| 353 | 'internalcode' => 'price', |
||
| 354 | ], |
||
| 355 | 'order.costs' => [ |
||
| 356 | 'label' => 'Order shipping amount', |
||
| 357 | 'internalcode' => 'costs', |
||
| 358 | ], |
||
| 359 | 'order.rebate' => [ |
||
| 360 | 'label' => 'Order rebate amount', |
||
| 361 | 'internalcode' => 'rebate', |
||
| 362 | ], |
||
| 363 | 'order.taxvalue' => [ |
||
| 364 | 'label' => 'Order tax amount', |
||
| 365 | 'internalcode' => 'tax', |
||
| 366 | ], |
||
| 367 | 'order.taxflag' => [ |
||
| 368 | 'label' => 'Order tax flag (0=net, 1=gross)', |
||
| 369 | 'internalcode' => 'taxflag', |
||
| 370 | ], |
||
| 371 | 'order.cdate' => [ |
||
| 372 | 'label' => 'Create date', |
||
| 373 | 'internalcode' => 'cdate', |
||
| 374 | ], |
||
| 375 | 'order.cmonth' => [ |
||
| 376 | 'label' => 'Create month', |
||
| 377 | 'internalcode' => 'cmonth', |
||
| 378 | ], |
||
| 379 | 'order.cweek' => [ |
||
| 380 | 'label' => 'Create week', |
||
| 381 | 'internalcode' => 'cweek', |
||
| 382 | ], |
||
| 383 | 'order.cwday' => [ |
||
| 384 | 'label' => 'Create weekday', |
||
| 385 | 'internalcode' => 'cwday', |
||
| 386 | ], |
||
| 387 | 'order.chour' => [ |
||
| 388 | 'label' => 'Create hour', |
||
| 389 | 'internalcode' => 'chour', |
||
| 390 | ], |
||
| 391 | 'order:status' => [ |
||
| 392 | 'code' => 'order:status()', |
||
| 393 | 'internalcode' => '( SELECT COUNT(mordst_cs."parentid") |
||
| 394 | FROM "mshop_order_status" AS mordst_cs |
||
| 395 | WHERE mord."id" = mordst_cs."parentid" AND ' . $expr . ' |
||
| 396 | AND mordst_cs."type" = $1 AND mordst_cs."value" IN ( $2 ) )', |
||
| 397 | 'label' => 'Number of order status items, parameter(<type>,<value>)', |
||
| 398 | 'type' => 'int', |
||
| 399 | 'public' => false, |
||
| 400 | ], |
||
| 401 | ] ) ); |
||
| 402 | } |
||
| 403 | |||
| 404 | |||
| 405 | /** |
||
| 406 | * Saves the dependent items of the item |
||
| 407 | * |
||
| 408 | * @param \Aimeos\MShop\Common\Item\Iface $item Item object |
||
| 409 | * @param bool $fetch True if the new ID should be returned in the item |
||
| 410 | * @return \Aimeos\MShop\Common\Item\Iface Updated item |
||
| 411 | */ |
||
| 412 | public function saveRefs( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Common\Item\Iface |
||
| 413 | { |
||
| 414 | $this->addStatus( $item ); |
||
| 415 | $this->saveAddresses( $item ); |
||
| 416 | $this->saveServices( $item ); |
||
| 417 | $this->saveProducts( $item ); |
||
| 418 | $this->saveCoupons( $item ); |
||
| 419 | $this->saveStatuses( $item ); |
||
| 420 | |||
| 421 | return $item; |
||
| 422 | } |
||
| 423 | |||
| 424 | |||
| 425 | /** |
||
| 426 | * Merges the data from the given map and the referenced items |
||
| 427 | * |
||
| 428 | * @param array $entries Associative list of ID as key and the associative list of property key/value pairs as values |
||
| 429 | * @param array $ref List of referenced items to fetch and add to the entries |
||
| 430 | * @return array Associative list of ID as key and the updated entries as value |
||
| 431 | */ |
||
| 432 | public function searchRefs( array $entries, array $ref ) : array |
||
| 496 | } |
||
| 497 | |||
| 498 | |||
| 499 | /** |
||
| 500 | * Adds the new payment and delivery values to the order status log. |
||
| 501 | * |
||
| 502 | * @param \Aimeos\MShop\Order\Item\Iface $item Order item object |
||
| 503 | * @return \Aimeos\MShop\Order\Manager\Iface Manager object for chaining method calls |
||
| 504 | */ |
||
| 505 | protected function addStatus( \Aimeos\MShop\Order\Item\Iface $item ) : \Aimeos\MShop\Order\Manager\Iface |
||
| 506 | { |
||
| 507 | $object = $this->object(); |
||
| 508 | |||
| 509 | if( ( $status = $item->get( '.statuspayment' ) ) !== null && $status != $item->getStatusPayment() ) { |
||
| 510 | $item->addStatus( $object->createStatus()->setType( 'status-payment' )->setValue( $item->getStatusPayment() ) ); |
||
| 511 | } |
||
| 512 | |||
| 513 | if( ( $status = $item->get( '.statusdelivery' ) ) !== null && $status != $item->getStatusDelivery() ) { |
||
| 514 | $item->addStatus( $object->createStatus()->setType( 'status-delivery' )->setValue( $item->getStatusDelivery() ) ); |
||
| 515 | } |
||
| 516 | |||
| 517 | return $this; |
||
| 518 | } |
||
| 519 | |||
| 520 | |||
| 521 | /** |
||
| 522 | * Binds additional values to the statement before execution. |
||
| 523 | * |
||
| 524 | * @param \Aimeos\MShop\Common\Item\Iface $item Item object |
||
| 525 | * @param \Aimeos\Base\DB\Statement\Iface $stmt Database statement object |
||
| 526 | * @param int $idx Current bind index |
||
| 527 | * @return \Aimeos\Base\DB\Statement\Iface Database statement object with bound values |
||
| 528 | */ |
||
| 529 | protected function bind( \Aimeos\MShop\Common\Item\Iface $item, \Aimeos\Base\DB\Statement\Iface $stmt, int &$idx ) : \Aimeos\Base\DB\Statement\Iface |
||
| 530 | { |
||
| 531 | $price = $item->getPrice(); |
||
| 532 | $context = $this->context(); |
||
| 533 | |||
| 534 | $stmt->bind( $idx++, $context->locale()->getSiteItem()->getCode() ); |
||
| 535 | $stmt->bind( $idx++, $item->locale()->getLanguageId() ); |
||
| 536 | $stmt->bind( $idx++, $price->getCurrencyId() ); |
||
| 537 | $stmt->bind( $idx++, $price->getValue() ); |
||
| 538 | $stmt->bind( $idx++, $price->getCosts() ); |
||
| 539 | $stmt->bind( $idx++, $price->getRebate() ); |
||
| 540 | $stmt->bind( $idx++, $price->getTaxValue() ); |
||
| 541 | $stmt->bind( $idx++, $price->getTaxFlag(), \Aimeos\Base\DB\Statement\Base::PARAM_INT ); |
||
| 542 | |||
| 543 | if( $item->getId() === null ) |
||
| 544 | { |
||
| 545 | $date = date_create_from_format( 'Y-m-d H:i:s', $context->datetime() ); |
||
| 546 | $stmt->bind( $idx++, $date->format( 'Y-m-d' ) ); // cdate |
||
| 547 | $stmt->bind( $idx++, $date->format( 'Y-m' ) ); // cmonth |
||
| 548 | $stmt->bind( $idx++, $date->format( 'Y-W' ) ); // cweek |
||
| 549 | $stmt->bind( $idx++, $date->format( 'w' ) ); // cwday |
||
| 550 | $stmt->bind( $idx++, $date->format( 'G' ) ); // chour |
||
| 551 | } |
||
| 552 | |||
| 553 | return $stmt; |
||
| 554 | } |
||
| 555 | |||
| 556 | |||
| 557 | /** |
||
| 558 | * Creates a new invoice number for the passed order and site. |
||
| 559 | * |
||
| 560 | * @param \Aimeos\MShop\Order\Item\Iface $item Order item with necessary values |
||
| 561 | * @return string Unique invoice number for the current site |
||
| 562 | */ |
||
| 563 | protected function createInvoiceNumber( \Aimeos\MShop\Order\Item\Iface $item ) : string |
||
| 564 | { |
||
| 565 | $context = $this->context(); |
||
| 566 | $siteId = $context->locale()->getSiteId(); |
||
| 567 | $conn = $context->db( 'db-locale', true ); |
||
| 568 | |||
| 569 | try |
||
| 570 | { |
||
| 571 | $conn->query( 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE' )->finish(); |
||
| 572 | $conn->query( 'START TRANSACTION' )->finish(); |
||
| 573 | |||
| 574 | $result = $conn->query( 'SELECT "invoiceno" FROM "mshop_locale_site" where "siteid" = ?', [$siteId] ); |
||
| 575 | $row = $result->fetch(); |
||
| 576 | $result->finish(); |
||
| 577 | |||
| 578 | $conn->create( 'UPDATE "mshop_locale_site" SET "invoiceno" = "invoiceno" + 1 WHERE "siteid" = ?' ) |
||
| 579 | ->bind( 1, $siteId )->execute()->finish(); |
||
| 580 | |||
| 581 | $conn->query( 'COMMIT' )->finish(); |
||
| 582 | } |
||
| 583 | catch( \Exception $e ) |
||
| 584 | { |
||
| 585 | $conn->close(); |
||
| 586 | throw $e; |
||
| 587 | } |
||
| 588 | |||
| 589 | return $row['invoiceno'] ?? ''; |
||
| 590 | } |
||
| 591 | |||
| 592 | |||
| 593 | /** |
||
| 594 | * Returns the prefix for the item properties and search keys. |
||
| 595 | * |
||
| 596 | * @return string Prefix for the item properties and search keys |
||
| 597 | */ |
||
| 598 | protected function prefix() : string |
||
| 599 | { |
||
| 600 | return 'order.'; |
||
| 601 | } |
||
| 602 | |||
| 603 | |||
| 604 | /** |
||
| 605 | * Creates a one-time order in the storage from the given invoice object. |
||
| 606 | * |
||
| 607 | * @param \Aimeos\MShop\Common\Item\Iface $item Order item with necessary values |
||
| 608 | * @param bool $fetch True if the new ID should be returned in the item |
||
| 609 | * @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID |
||
| 610 | */ |
||
| 611 | protected function saveBase( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Common\Item\Iface |
||
| 623 | } |
||
| 624 | |||
| 625 | |||
| 626 | /** mshop/order/manager/name |
||
| 627 | * Class name of the used order manager implementation |
||
| 628 | * |
||
| 629 | * Each default manager can be replace by an alternative imlementation. |
||
| 630 | * To use this implementation, you have to set the last part of the class |
||
| 631 | * name as configuration value so the manager factory knows which class it |
||
| 632 | * has to instantiate. |
||
| 633 | * |
||
| 634 | * For example, if the name of the default class is |
||
| 635 | * |
||
| 636 | * \Aimeos\MShop\Order\Manager\Standard |
||
| 1032 |