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