| Total Complexity | 68 |
| Total Lines | 696 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like OrderAddTestData 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 OrderAddTestData, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class OrderAddTestData extends Base |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Returns the list of task names which this task depends on. |
||
| 20 | * |
||
| 21 | * @return string[] List of task names |
||
| 22 | */ |
||
| 23 | public function after() : array |
||
| 26 | } |
||
| 27 | |||
| 28 | |||
| 29 | /** |
||
| 30 | * Adds order test data. |
||
| 31 | */ |
||
| 32 | public function up() |
||
| 33 | { |
||
| 34 | $this->info( 'Adding order test data', 'v' ); |
||
| 35 | |||
| 36 | $context = $this->context(); |
||
|
|
|||
| 37 | $context->setEditor( 'core:lib/mshoplib' ); |
||
| 38 | $context->getLocale()->setCurrencyId( 'EUR' ); |
||
| 39 | |||
| 40 | $attributeManager = \Aimeos\MShop\Attribute\Manager\Factory::create( $context, 'Standard' ); |
||
| 41 | $customerManager = \Aimeos\MShop\Customer\Manager\Factory::create( $context, 'Standard' ); |
||
| 42 | $productManager = \Aimeos\MShop\Product\Manager\Factory::create( $context, 'Standard' ); |
||
| 43 | $serviceManager = \Aimeos\MShop\Service\Manager\Factory::create( $context, 'Standard' ); |
||
| 44 | $localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $context, 'Standard' ); |
||
| 45 | $orderManager = \Aimeos\MShop\Order\Manager\Factory::create( $context, 'Standard' ); |
||
| 46 | $priceManager = \Aimeos\MShop\Price\Manager\Factory::create( $context, 'Standard' ); |
||
| 47 | |||
| 48 | $orderBaseManager = $orderManager->getSubManager( 'base' ); |
||
| 49 | $orderStatusManager = $orderManager->getSubManager( 'status' ); |
||
| 50 | $orderCouponManager = $orderBaseManager->getSubManager( 'coupon' ); |
||
| 51 | $orderAddressManager = $orderBaseManager->getSubManager( 'address' ); |
||
| 52 | $orderProductManager = $orderBaseManager->getSubManager( 'product' ); |
||
| 53 | $orderServiceManager = $orderBaseManager->getSubManager( 'service' ); |
||
| 54 | $orderProductAttrManager = $orderProductManager->getSubManager( 'attribute' ); |
||
| 55 | $orderServiceAttrManager = $orderServiceManager->getSubManager( 'attribute' ); |
||
| 56 | |||
| 57 | $filter = $orderBaseManager->filter()->add( ['order.base.sitecode' => ['unittest', 'unit']] ); |
||
| 58 | $orderBaseManager->delete( $orderBaseManager->search( $filter ) ); |
||
| 59 | |||
| 60 | $ds = DIRECTORY_SEPARATOR; |
||
| 61 | $path = __DIR__ . $ds . 'data' . $ds . 'order.php'; |
||
| 62 | |||
| 63 | if( ( $testdata = include( $path ) ) == false ) { |
||
| 64 | throw new \RuntimeException( sprintf( 'No file "%1$s" found for order domain', $path ) ); |
||
| 65 | } |
||
| 66 | |||
| 67 | $customerId = $customerManager->find( '[email protected]' )->getId(); |
||
| 68 | $products = $productManager->search( $productManager->filter() )->col( 'product.id', 'product.code' ); |
||
| 69 | $services = $serviceManager->search( $serviceManager->filter() )->col( 'service.id', 'service.code' ); |
||
| 70 | $attributes = $attributeManager->search( $attributeManager->filter() ) |
||
| 71 | ->groupBy( 'attribute.type' )->map( function( $list ) { |
||
| 72 | return map( $list )->col( 'attribute.id', 'attribute.code' ); |
||
| 73 | } ); |
||
| 74 | |||
| 75 | foreach( $testdata as $data ) |
||
| 76 | { |
||
| 77 | if( !isset( $data['base'] ) ) { |
||
| 78 | throw new \RuntimeException( 'No base data found for ' . print_r( $data, true ) ); |
||
| 79 | } |
||
| 80 | |||
| 81 | $basket = $orderBaseManager->create()->off() |
||
| 82 | ->fromArray( $data['base'], true )->setCustomerId( $customerId ); |
||
| 83 | |||
| 84 | |||
| 85 | foreach( $data['base']['address'] ?? [] as $entry ) |
||
| 86 | { |
||
| 87 | $type = $entry['order.base.address.type'] ?? 'payment'; |
||
| 88 | $basket->addAddress( $orderAddressManager->create()->fromArray( $entry, true ), $type ); |
||
| 89 | } |
||
| 90 | |||
| 91 | |||
| 92 | foreach( $data['base']['product'] ?? [] as $entry ) |
||
| 93 | { |
||
| 94 | $list = []; |
||
| 95 | foreach( $entry['product'] ?? [] as $subentry ) |
||
| 96 | { |
||
| 97 | $attrs = []; |
||
| 98 | foreach( $subentry['attribute'] ?? [] as $attr ) |
||
| 99 | { |
||
| 100 | $key = $attr['order.base.product.attribute.code'] . '/' . $attr['order.base.product.attribute.value']; |
||
| 101 | $attrs[] = $orderProductAttrManager->create()->fromArray( $attr, true ) |
||
| 102 | ->setAttributeId( $attributes->get( $key ) ); |
||
| 103 | } |
||
| 104 | |||
| 105 | $code = $subentry['order.base.product.prodcode'] ?? null; |
||
| 106 | $price = $priceManager->create()->fromArray( $subentry, true ); |
||
| 107 | |||
| 108 | $list[] = $orderProductManager->create()->fromArray( $subentry, true ) |
||
| 109 | ->setAttributeItems( $attrs )->setPrice( $price ) |
||
| 110 | ->setProductId( $products->get( $code ) ); |
||
| 111 | } |
||
| 112 | |||
| 113 | $attrs = []; |
||
| 114 | foreach( $entry['attribute'] ?? [] as $attr ) |
||
| 115 | { |
||
| 116 | $key = $attr['order.base.product.attribute.code'] . '/' . $attr['order.base.product.attribute.value']; |
||
| 117 | $attrs[] = $orderProductAttrManager->create()->fromArray( $attr, true ) |
||
| 118 | ->setAttributeId( $attributes->get( $key ) ); |
||
| 119 | } |
||
| 120 | |||
| 121 | $code = $entry['order.base.product.prodcode'] ?? null; |
||
| 122 | $price = $priceManager->create()->fromArray( $entry, true ); |
||
| 123 | |||
| 124 | $product = $orderProductManager->create()->fromArray( $entry, true ) |
||
| 125 | ->setProducts( $list )->setAttributeItems( $attrs )->setPrice( $price ) |
||
| 126 | ->setProductId( $products->get( $code ) ); |
||
| 127 | |||
| 128 | $basket->addProduct( $product ); |
||
| 129 | } |
||
| 130 | |||
| 131 | |||
| 132 | foreach( $data['base']['coupon'] ?? [] as $entry ) |
||
| 133 | { |
||
| 134 | $list = []; |
||
| 135 | |||
| 136 | if( ( $pos = $entry['ordprodpos'] ?? null ) !== null ) |
||
| 137 | { |
||
| 138 | $list = [$basket->getProduct( $pos )]; |
||
| 139 | $basket->deleteProduct( $pos ); |
||
| 140 | } |
||
| 141 | |||
| 142 | $basket->setCoupon( $entry['code'], $list ); |
||
| 143 | } |
||
| 144 | |||
| 145 | |||
| 146 | foreach( $data['base']['service'] ?? [] as $entry ) |
||
| 147 | { |
||
| 148 | $attrs = []; |
||
| 149 | foreach( $entry['attribute'] ?? [] as $attr ) { |
||
| 150 | $attrs[] = $orderServiceAttrManager->create()->fromArray( $attr, true ); |
||
| 151 | } |
||
| 152 | |||
| 153 | $code = $entry['order.base.service.code'] ?? null; |
||
| 154 | $type = $entry['order.base.service.type'] ?? 'payment'; |
||
| 155 | $price = $priceManager->create()->fromArray( $entry, true ); |
||
| 156 | |||
| 157 | $service = $orderServiceManager->create()->fromArray( $entry, true ) |
||
| 158 | ->setAttributeItems( $attrs )->setPrice( $price ) |
||
| 159 | ->setServiceId( $services->get( $code ) ?: '' ); |
||
| 160 | |||
| 161 | $basket->addService( $service, $type ); |
||
| 162 | } |
||
| 163 | |||
| 164 | $item = $orderManager->create()->fromArray( $data, true ); |
||
| 165 | |||
| 166 | $orderBaseManager->store( $basket ); |
||
| 167 | $orderManager->save( $item->setBaseId( $basket->getId() ) ); |
||
| 168 | |||
| 169 | foreach( $data['status'] ?? [] as $entry ) { |
||
| 170 | $orderStatusManager->save( $orderStatusManager->create()->fromArray( $entry )->setParentId( $item->getId() ) ); |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | $context->getLocale()->setCurrencyId( null ); |
||
| 175 | } |
||
| 176 | |||
| 177 | |||
| 178 | /** |
||
| 179 | * Adds the required order base data. |
||
| 180 | * |
||
| 181 | * @param \Aimeos\MShop\Common\Manager\Iface $localeManager Locale manager |
||
| 182 | * @param \Aimeos\MShop\Common\Manager\Iface $orderBaseManager Order base manager |
||
| 183 | * @param array $testdata Associative list of key/list pairs |
||
| 184 | */ |
||
| 185 | protected function addOrderBaseData( \Aimeos\MShop\Common\Manager\Iface $localeManager, |
||
| 186 | \Aimeos\MShop\Common\Manager\Iface $orderBaseManager, array $testdata ) |
||
| 187 | { |
||
| 188 | $bases = []; |
||
| 189 | $locale = $localeManager->create(); |
||
| 190 | $customerIds = $this->getCustomerIds( $testdata ); |
||
| 191 | $orderBaseAddressManager = $orderBaseManager->getSubManager( 'address', 'Standard' ); |
||
| 192 | |||
| 193 | $orderBaseManager->begin(); |
||
| 194 | |||
| 195 | foreach( $testdata['order/base'] as $key => $dataset ) |
||
| 196 | { |
||
| 197 | $bases['items'][$key] = $orderBaseManager->create(); |
||
| 198 | $bases['items'][$key]->setId( null ); |
||
| 199 | $bases['items'][$key]->setComment( $dataset['comment'] ); |
||
| 200 | $bases['items'][$key]->setCustomerReference( $dataset['customerref'] ); |
||
| 201 | $bases['items'][$key]->setCustomerId( $customerIds[$dataset['customerid']] ); |
||
| 202 | |||
| 203 | $locale->setId( null ); |
||
| 204 | $locale->setSiteId( $this->context()->getLocale()->getSiteId() ); |
||
| 205 | $locale->setLanguageId( $dataset['langid'] ); |
||
| 206 | $locale->setCurrencyId( $dataset['currencyid'] ); |
||
| 207 | $bases['items'][$key]->setLocale( $locale ); |
||
| 208 | |||
| 209 | $orderBaseManager->save( $bases['items'][$key] ); |
||
| 210 | $bases['ids'][$key] = $bases['items'][$key]->getId(); |
||
| 211 | } |
||
| 212 | |||
| 213 | $this->addOrderBaseAddressData( $orderBaseAddressManager, $bases, $testdata ); |
||
| 214 | |||
| 215 | $orderBaseManager->commit(); |
||
| 216 | |||
| 217 | return $bases; |
||
| 218 | } |
||
| 219 | |||
| 220 | |||
| 221 | /** |
||
| 222 | * Adds the order address data. |
||
| 223 | * |
||
| 224 | * @param \Aimeos\MShop\Common\Manager\Iface $manager |
||
| 225 | * @param array $testdata |
||
| 226 | */ |
||
| 227 | protected function addOrderBaseAddressData( \Aimeos\MShop\Common\Manager\Iface $manager, |
||
| 228 | array $bases, array $testdata ) |
||
| 229 | { |
||
| 230 | $orderAddr = $manager->create(); |
||
| 231 | |||
| 232 | foreach( $testdata['order/base/address'] as $dataset ) |
||
| 233 | { |
||
| 234 | if( !isset( $bases['ids'][$dataset['baseid']] ) ) { |
||
| 235 | throw new \RuntimeException( sprintf( 'No base ID found for "%1$s"', $dataset['baseid'] ) ); |
||
| 236 | } |
||
| 237 | |||
| 238 | $orderAddr->setId( null ); |
||
| 239 | $orderAddr->setBaseId( $bases['ids'][$dataset['baseid']] ); |
||
| 240 | $orderAddr->setAddressId( ( $dataset['addrid'] ?? '' ) ); |
||
| 241 | $orderAddr->setType( $dataset['type'] ); |
||
| 242 | $orderAddr->setCompany( $dataset['company'] ?? '' ); |
||
| 243 | $orderAddr->setVatID( ( $dataset['vatid'] ?? '' ) ); |
||
| 244 | $orderAddr->setSalutation( $dataset['salutation'] ); |
||
| 245 | $orderAddr->setTitle( $dataset['title'] ); |
||
| 246 | $orderAddr->setFirstname( $dataset['firstname'] ); |
||
| 247 | $orderAddr->setLastname( $dataset['lastname'] ); |
||
| 248 | $orderAddr->setAddress1( $dataset['address1'] ); |
||
| 249 | $orderAddr->setAddress2( $dataset['address2'] ); |
||
| 250 | $orderAddr->setAddress3( $dataset['address3'] ); |
||
| 251 | $orderAddr->setPostal( $dataset['postal'] ); |
||
| 252 | $orderAddr->setCity( $dataset['city'] ); |
||
| 253 | $orderAddr->setState( $dataset['state'] ); |
||
| 254 | $orderAddr->setCountryId( $dataset['countryid'] ); |
||
| 255 | $orderAddr->setTelephone( $dataset['telephone'] ); |
||
| 256 | $orderAddr->setEmail( $dataset['email'] ); |
||
| 257 | $orderAddr->setTelefax( $dataset['telefax'] ); |
||
| 258 | $orderAddr->setWebsite( $dataset['website'] ); |
||
| 259 | $orderAddr->setLanguageId( $dataset['langid'] ); |
||
| 260 | $orderAddr->setLatitude( $dataset['latitude'] ); |
||
| 261 | $orderAddr->setLongitude( $dataset['longitude'] ); |
||
| 262 | $orderAddr->setBirthday( $dataset['birthday'] ?? null ); |
||
| 263 | |||
| 264 | $manager->save( $orderAddr, false ); |
||
| 265 | } |
||
| 266 | } |
||
| 267 | |||
| 268 | |||
| 269 | /** |
||
| 270 | * Adds the order coupon test data. |
||
| 271 | * |
||
| 272 | * @param array $testdata Associative list of key/list pairs |
||
| 273 | * @throws \RuntimeException If a required ID is not available |
||
| 274 | */ |
||
| 275 | private function addOrderBaseCouponData( array $testdata ) |
||
| 276 | { |
||
| 277 | $order = \Aimeos\MShop\Order\Manager\Factory::create( $this->context(), 'Standard' ); |
||
| 278 | $orderBase = $order->getSubManager( 'base', 'Standard' ); |
||
| 279 | $orderBaseProd = $orderBase->getSubManager( 'product', 'Standard' ); |
||
| 280 | $orderBaseCoupon = $orderBase->getSubManager( 'coupon', 'Standard' ); |
||
| 281 | |||
| 282 | $orderBaseIds = []; |
||
| 283 | $orderBasePrices = []; |
||
| 284 | $ordProdIds = []; |
||
| 285 | $prodcode = $quantity = $pos = []; |
||
| 286 | foreach( $testdata['order/base/coupon'] as $key => $dataset ) { |
||
| 287 | $exp = explode( '/', $dataset['ordprodid'] ); |
||
| 288 | |||
| 289 | if( count( $exp ) != 3 ) { |
||
| 290 | throw new \RuntimeException( sprintf( 'Some keys for ordprod are set wrong "%1$s"', $dataset ) ); |
||
| 291 | } |
||
| 292 | |||
| 293 | $prodcode[$exp[0]] = $exp[0]; |
||
| 294 | $quantity[$exp[1]] = $exp[1]; |
||
| 295 | $pos[$exp[2]] = $exp[2]; |
||
| 296 | |||
| 297 | $orderBasePrices[$dataset['baseid']] = $dataset['baseid']; |
||
| 298 | } |
||
| 299 | |||
| 300 | $search = $orderBase->filter(); |
||
| 301 | $search->setConditions( $search->compare( '==', 'order.base.price', $orderBasePrices ) ); |
||
| 302 | |||
| 303 | foreach( $orderBase->search( $search ) as $orderBaseItem ) { |
||
| 304 | $orderBaseIds[$orderBaseItem->getPrice()->getValue()] = $orderBaseItem->getId(); |
||
| 305 | } |
||
| 306 | |||
| 307 | |||
| 308 | $search = $orderBaseProd->filter(); |
||
| 309 | $expr = array( |
||
| 310 | $search->compare( '==', 'order.base.product.prodcode', $prodcode ), |
||
| 311 | $search->compare( '==', 'order.base.product.quantity', $quantity ), |
||
| 312 | $search->compare( '==', 'order.base.product.position', $pos ), |
||
| 313 | ); |
||
| 314 | $search->setConditions( $search->and( $expr ) ); |
||
| 315 | |||
| 316 | foreach( $orderBaseProd->search( $search ) as $ordProd ) { |
||
| 317 | $ordProdIds[$ordProd->getProductCode() . '/' . $ordProd->getQuantity() . '/' . $ordProd->getPosition()] = $ordProd->getId(); |
||
| 318 | } |
||
| 319 | |||
| 320 | $orderCoupon = $orderBaseCoupon->create(); |
||
| 321 | foreach( $testdata['order/base/coupon'] as $key => $dataset ) |
||
| 322 | { |
||
| 323 | if( !isset( $orderBaseIds[$dataset['baseid']] ) ) { |
||
| 324 | throw new \RuntimeException( sprintf( 'No oder base ID found for "%1$s"', $dataset['baseid'] ) ); |
||
| 325 | } |
||
| 326 | |||
| 327 | if( !isset( $ordProdIds[$dataset['ordprodid']] ) ) { |
||
| 328 | throw new \RuntimeException( sprintf( 'No order base product ID found for "%1$s"', $dataset['ordprodid'] ) ); |
||
| 329 | } |
||
| 330 | |||
| 331 | $orderCoupon->setId( null ); |
||
| 332 | $orderCoupon->setBaseId( $orderBaseIds[$dataset['baseid']] ); |
||
| 333 | $orderCoupon->setProductId( $ordProdIds[$dataset['ordprodid']] ); |
||
| 334 | $orderCoupon->setCode( $dataset['code'] ); |
||
| 335 | |||
| 336 | $orderBaseCoupon->save( $orderCoupon, false ); |
||
| 337 | } |
||
| 338 | } |
||
| 339 | |||
| 340 | |||
| 341 | /** |
||
| 342 | * Adds the required order base service data. |
||
| 343 | * |
||
| 344 | * @param \Aimeos\MShop\Common\Manager\Iface $orderBaseManager Order base manager |
||
| 345 | * @param array $bases Associative list of key/list pairs |
||
| 346 | * @param array $testdata Associative list of key/list pairs |
||
| 347 | * @return array Associative list of enhanced order base items |
||
| 348 | * @throws \RuntimeException If no type ID is found |
||
| 349 | */ |
||
| 350 | protected function addOrderBaseServiceData( \Aimeos\MShop\Common\Manager\Iface $orderBaseManager, |
||
| 351 | array $bases, array $testdata ) |
||
| 352 | { |
||
| 353 | $ordServices = []; |
||
| 354 | $servIds = $this->getServiceIds( $testdata ); |
||
| 355 | $orderBaseServiceManager = $orderBaseManager->getSubManager( 'service', 'Standard' ); |
||
| 356 | $orderBaseServiceAttrManager = $orderBaseServiceManager->getSubManager( 'attribute', 'Standard' ); |
||
| 357 | $priceManager = \Aimeos\MShop::create( $this->context(), 'price' ); |
||
| 358 | $ordServ = $orderBaseServiceManager->create(); |
||
| 359 | |||
| 360 | $orderBaseManager->begin(); |
||
| 361 | |||
| 362 | foreach( $testdata['order/base/service'] as $key => $dataset ) |
||
| 363 | { |
||
| 364 | if( !isset( $bases['ids'][$dataset['baseid']] ) ) { |
||
| 365 | throw new \RuntimeException( sprintf( 'No base ID found for "%1$s" in order base serive data', $dataset['baseid'] ) ); |
||
| 366 | } |
||
| 367 | |||
| 368 | if( !isset( $bases['items'][$dataset['baseid']] ) ) { |
||
| 369 | throw new \RuntimeException( sprintf( 'No base Item found for "%1$s" in order base service data', $dataset['baseid'] ) ); |
||
| 370 | } |
||
| 371 | |||
| 372 | $ordServ->setId( null ); |
||
| 373 | $ordServ->setBaseId( $bases['ids'][$dataset['baseid']] ); |
||
| 374 | $ordServ->setType( $dataset['type'] ); |
||
| 375 | $ordServ->setCode( $dataset['code'] ); |
||
| 376 | $ordServ->setName( $dataset['name'] ); |
||
| 377 | $ordServ->setMediaUrl( $dataset['mediaurl'] ); |
||
| 378 | |||
| 379 | if( isset( $dataset['servid'] ) ) { |
||
| 380 | $ordServ->setServiceId( $servIds[$dataset['servid']] ); |
||
| 381 | } |
||
| 382 | |||
| 383 | $priceItem = $priceManager->create(); |
||
| 384 | $priceItem->setCurrencyId( $dataset['currencyid'] ); |
||
| 385 | $priceItem->setValue( $dataset['price'] ); |
||
| 386 | $priceItem->setCosts( $dataset['shipping'] ); |
||
| 387 | $priceItem->setRebate( $dataset['rebate'] ); |
||
| 388 | $priceItem->setTaxRates( $dataset['taxrates'] ); |
||
| 389 | $ordServ->setPrice( $priceItem ); |
||
| 390 | |||
| 391 | $orderBaseServiceManager->save( $ordServ ); |
||
| 392 | |||
| 393 | $ordServices[$key] = $ordServ->getId(); |
||
| 394 | $bases['items'][$dataset['baseid']]->addService( $ordServ, $dataset['type'] ); //adds Services to orderbase |
||
| 395 | } |
||
| 396 | |||
| 397 | $this->addOrderBaseServiceAttributeData( $orderBaseServiceAttrManager, $testdata, $ordServices ); |
||
| 398 | |||
| 399 | $orderBaseManager->commit(); |
||
| 400 | |||
| 401 | return $bases['items']; |
||
| 402 | } |
||
| 403 | |||
| 404 | |||
| 405 | /** |
||
| 406 | * Adds the required order base product data. |
||
| 407 | * |
||
| 408 | * @param \Aimeos\MShop\Common\Manager\Iface $orderBaseManager Order Base Manager |
||
| 409 | * @param array $bases Associative list of key/list pairs |
||
| 410 | * @param array $testdata Associative list of key/list pairs |
||
| 411 | * @return array Enhanced list of order base items |
||
| 412 | * @throws \RuntimeException If no type ID is found |
||
| 413 | */ |
||
| 414 | protected function addOrderBaseProductData( \Aimeos\MShop\Common\Manager\Iface $orderBaseManager, |
||
| 481 | } |
||
| 482 | |||
| 483 | |||
| 484 | /** |
||
| 485 | * Adds the order product attribute test data. |
||
| 486 | * |
||
| 487 | * @param \Aimeos\MShop\Common\Manager\Iface $manager |
||
| 488 | * @param array $testdata |
||
| 489 | * @param array $ordProds |
||
| 490 | * @param \Aimeos\MShop\Product\Item\Iface[] $products |
||
| 491 | * @throws \RuntimeException |
||
| 492 | */ |
||
| 493 | protected function addOrderBaseProductAttributeData( \Aimeos\MShop\Common\Manager\Iface $manager, |
||
| 494 | array $testdata, array $ordProds, array $products ) |
||
| 495 | { |
||
| 496 | $attrCodes = []; |
||
| 497 | $attributeManager = \Aimeos\MShop::create( $this->context(), 'attribute' ); |
||
| 498 | $attributes = $attributeManager->search( $attributeManager->filter() ); |
||
| 499 | |||
| 500 | foreach( $attributes as $attrItem ) { |
||
| 501 | $attrCodes[$attrItem->getType()][] = $attrItem; |
||
| 502 | } |
||
| 503 | |||
| 504 | $ordProdAttr = $manager->create(); |
||
| 505 | |||
| 506 | foreach( $testdata['order/base/product/attr'] as $dataset ) |
||
| 507 | { |
||
| 508 | if( !isset( $ordProds[$dataset['ordprodid']] ) ) { |
||
| 509 | throw new \RuntimeException( sprintf( 'No order product ID found for "%1$s"', $dataset['ordprodid'] ) ); |
||
| 510 | } |
||
| 511 | |||
| 512 | $ordProdAttr->setId( null ); |
||
| 513 | $ordProdAttr->setParentId( $ordProds[$dataset['ordprodid']] ); |
||
| 514 | $ordProdAttr->setCode( $dataset['code'] ); |
||
| 515 | $ordProdAttr->setValue( $dataset['value'] ); |
||
| 516 | $ordProdAttr->setName( $dataset['name'] ); |
||
| 517 | $ordProdAttr->setQuantity( $dataset['quantity'] ); |
||
| 518 | |||
| 519 | if( isset( $attrCodes[$dataset['code']] ) ) |
||
| 520 | { |
||
| 521 | foreach( (array) $attrCodes[$dataset['code']] as $attrItem ) |
||
| 522 | { |
||
| 523 | if( $attrItem->getCode() == $dataset['value'] ) { |
||
| 524 | $ordProdAttr->setAttributeId( $attrItem->getId() ); |
||
| 525 | } |
||
| 526 | } |
||
| 527 | } |
||
| 528 | |||
| 529 | if( isset( $dataset['type'] ) ) { |
||
| 530 | $ordProdAttr->setType( $dataset['type'] ); |
||
| 531 | } |
||
| 532 | |||
| 533 | $manager->save( $ordProdAttr, false ); |
||
| 534 | } |
||
| 535 | } |
||
| 536 | |||
| 537 | |||
| 538 | /** |
||
| 539 | * Adds the order service attributes. |
||
| 540 | * |
||
| 541 | * @param \Aimeos\MShop\Common\Manager\Iface $manager |
||
| 542 | * @param array $testdata |
||
| 543 | * @param array $ordServices |
||
| 544 | * @throws \RuntimeException |
||
| 545 | */ |
||
| 546 | protected function addOrderBaseServiceAttributeData( \Aimeos\MShop\Common\Manager\Iface $manager, |
||
| 547 | array $testdata, array $ordServices ) |
||
| 548 | { |
||
| 549 | $ordServAttr = $manager->create(); |
||
| 550 | |||
| 551 | foreach( $testdata['order/base/service/attr'] as $dataset ) |
||
| 552 | { |
||
| 553 | if( !isset( $ordServices[$dataset['ordservid']] ) ) { |
||
| 554 | throw new \RuntimeException( sprintf( 'No order service ID found for "%1$s"', $dataset['ordservid'] ) ); |
||
| 555 | } |
||
| 556 | |||
| 557 | $ordServAttr->setId( null ); |
||
| 558 | $ordServAttr->setParentId( $ordServices[$dataset['ordservid']] ); |
||
| 559 | $ordServAttr->setCode( $dataset['code'] ); |
||
| 560 | $ordServAttr->setValue( $dataset['value'] ); |
||
| 561 | $ordServAttr->setName( $dataset['name'] ); |
||
| 562 | $ordServAttr->setType( $dataset['type'] ); |
||
| 563 | $ordServAttr->setQuantity( $dataset['quantity'] ); |
||
| 564 | |||
| 565 | if( isset( $dataset['attrid'] ) ) { |
||
| 566 | $ordServAttr->setAttributeId( $dataset['attrid'] ); |
||
| 567 | } |
||
| 568 | |||
| 569 | $manager->save( $ordServAttr, false ); |
||
| 570 | } |
||
| 571 | } |
||
| 572 | |||
| 573 | |||
| 574 | /** |
||
| 575 | * Adds the order test data. |
||
| 576 | * |
||
| 577 | * @param \Aimeos\MShop\Common\Manager\Iface $orderManager Order manager |
||
| 578 | * @param array $baseIds List of ids |
||
| 579 | * @param array $testdata Associative list of key/list pairs |
||
| 580 | * @throws \RuntimeException If no type ID is found |
||
| 581 | */ |
||
| 582 | protected function addOrderData( \Aimeos\MShop\Common\Manager\Iface $orderManager, array $baseIds, array $testdata ) |
||
| 626 | } |
||
| 627 | |||
| 628 | |||
| 629 | /** |
||
| 630 | * Returns the customer IDs for the given test data. |
||
| 631 | * |
||
| 632 | * @param array $testdata Test data |
||
| 633 | * @return array Customer Ids |
||
| 634 | */ |
||
| 635 | protected function getCustomerIds( array $testdata ) |
||
| 652 | } |
||
| 653 | |||
| 654 | |||
| 655 | /** |
||
| 656 | * Returns the product items for the given test data. |
||
| 657 | * |
||
| 658 | * @param array $testdata Test data |
||
| 659 | * @return \Aimeos\MShop\Product\Item\Iface[] Product Items |
||
| 660 | */ |
||
| 661 | protected function getProductItems( array $testdata ) |
||
| 682 | } |
||
| 683 | |||
| 684 | |||
| 685 | /** |
||
| 686 | * Returns the service item IDs for the given test data. |
||
| 687 | * |
||
| 688 | * @param array $testdata Test data |
||
| 689 | * @return array List of service IDs |
||
| 690 | */ |
||
| 691 | protected function getServiceIds( array $testdata ) |
||
| 714 |