|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2013 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 | 6 | namespace Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Variations\Config;
|
7 | 7 |
|
@@ -355,46 +355,6 @@ public function getProductAttributes()
|
355 | 355 | return $this->productAttributes;
|
356 | 356 | }
|
357 | 357 |
|
358 |
| - /** |
359 |
| - * Get configurable product existing setup |
360 |
| - * |
361 |
| - * @return array |
362 |
| - */ |
363 |
| - public function getExistingVariantConfiguration(): array |
364 |
| - { |
365 |
| - $productMatrix = $attributes = []; |
366 |
| - $variants = $this->getVariantAttributeComposition(); |
367 |
| - foreach ($this->getAssociatedProducts() as $product) { |
368 |
| - $childProductOptions = []; |
369 |
| - foreach ($variants[$product->getId()] as $attributeComposition) { |
370 |
| - $childProductOptions[] = $this->buildChildProductOption($attributeComposition); |
371 |
| - |
372 |
| - /** @var AbstractAttribute $attribute */ |
373 |
| - $attribute = $attributeComposition['attribute']; |
374 |
| - if (!isset($attributes[$attribute->getAttributeId()])) { |
375 |
| - $attributes[$attribute->getAttributeId()] = $this->buildAttributeDetails($attribute); |
376 |
| - } |
377 |
| - $variationOption = [ |
378 |
| - 'attribute_code' => $attribute->getAttributeCode(), |
379 |
| - 'attribute_label' => $attribute->getStoreLabel(0), |
380 |
| - 'id' => $attributeComposition['value_id'], |
381 |
| - 'label' => $this->extractAttributeValueLabel( |
382 |
| - $attribute, |
383 |
| - $attributeComposition['value_id'] |
384 |
| - ), |
385 |
| - 'value' => $attributeComposition['value_id'], |
386 |
| - '__disableTmpl' => true, |
387 |
| - ]; |
388 |
| - $attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption; |
389 |
| - } |
390 |
| - $productMatrix[] = $this->buildChildProductDetails($product, $childProductOptions); |
391 |
| - } |
392 |
| - return [ |
393 |
| - 'product_matrix' => $productMatrix, |
394 |
| - 'attributes' => array_values($attributes) |
395 |
| - ]; |
396 |
| - } |
397 |
| - |
398 | 358 | /**
|
399 | 359 | * Prepare attribute details for child product configuration
|
400 | 360 | *
|
@@ -479,109 +439,38 @@ private function extractAttributeValueLabel($attribute, int $valueId): string
|
479 | 439 | */
|
480 | 440 | protected function prepareVariations()
|
481 | 441 | {
|
482 |
| - $variations = $this->getVariations(); |
483 |
| - $productMatrix = []; |
484 |
| - $attributes = []; |
485 |
| - if ($variations) { |
486 |
| - $usedProductAttributes = $this->getUsedAttributes(); |
487 |
| - $productByUsedAttributes = $this->getAssociatedProducts(); |
488 |
| - $configurableAttributes = $this->getAttributes(); |
489 |
| - foreach ($variations as $variation) { |
490 |
| - $attributeValues = []; |
491 |
| - foreach ($usedProductAttributes as $attribute) { |
492 |
| - $attributeValues[$attribute->getAttributeCode()] = $variation[$attribute->getId()]['value']; |
493 |
| - } |
494 |
| - $key = implode('-', $attributeValues); |
495 |
| - if (isset($productByUsedAttributes[$key])) { |
496 |
| - $product = $productByUsedAttributes[$key]; |
497 |
| - $price = $product->getPrice(); |
498 |
| - $variationOptions = []; |
499 |
| - foreach ($usedProductAttributes as $attribute) { |
500 |
| - list($attributes, $variationOptions) = $this->prepareAttributes( |
501 |
| - $attributes, |
502 |
| - $attribute, |
503 |
| - $configurableAttributes, |
504 |
| - $variation, |
505 |
| - $variationOptions |
506 |
| - ); |
507 |
| - } |
| 442 | + $productMatrix = $attributes = []; |
| 443 | + $variants = $this->getVariantAttributeComposition(); |
| 444 | + foreach ($this->getAssociatedProducts() as $product) { |
| 445 | + $childProductOptions = []; |
| 446 | + foreach ($variants[$product->getId()] as $attributeComposition) { |
| 447 | + $childProductOptions[] = $this->buildChildProductOption($attributeComposition); |
508 | 448 |
|
509 |
| - $productMatrix[] = [ |
510 |
| - 'productId' => $product->getId(), |
511 |
| - 'images' => [ |
512 |
| - 'preview' => $this->image->init($product, 'product_thumbnail_image')->getUrl() |
513 |
| - ], |
514 |
| - 'sku' => $product->getSku(), |
515 |
| - 'name' => $product->getName(), |
516 |
| - 'quantity' => $this->getProductStockQty($product), |
517 |
| - 'price' => $price, |
518 |
| - 'options' => $variationOptions, |
519 |
| - 'weight' => $product->getWeight(), |
520 |
| - 'status' => $product->getStatus(), |
521 |
| - '__disableTmpl' => true, |
522 |
| - ]; |
| 449 | + /** @var AbstractAttribute $attribute */ |
| 450 | + $attribute = $attributeComposition['attribute']; |
| 451 | + if (!isset($attributes[$attribute->getAttributeId()])) { |
| 452 | + $attributes[$attribute->getAttributeId()] = $this->buildAttributeDetails($attribute); |
523 | 453 | }
|
| 454 | + $variationOption = [ |
| 455 | + 'attribute_code' => $attribute->getAttributeCode(), |
| 456 | + 'attribute_label' => $attribute->getStoreLabel(0), |
| 457 | + 'id' => $attributeComposition['value_id'], |
| 458 | + 'label' => $this->extractAttributeValueLabel( |
| 459 | + $attribute, |
| 460 | + $attributeComposition['value_id'] |
| 461 | + ), |
| 462 | + 'value' => $attributeComposition['value_id'], |
| 463 | + '__disableTmpl' => true, |
| 464 | + ]; |
| 465 | + $attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption; |
524 | 466 | }
|
| 467 | + $productMatrix[] = $this->buildChildProductDetails($product, $childProductOptions); |
525 | 468 | }
|
| 469 | + |
526 | 470 | $this->productMatrix = $productMatrix;
|
527 | 471 | $this->productAttributes = array_values($attributes);
|
528 | 472 | }
|
529 | 473 |
|
530 |
| - /** |
531 |
| - * Prepare attributes. |
532 |
| - * |
533 |
| - * @param array $attributes |
534 |
| - * @param object $attribute |
535 |
| - * @param array $configurableAttributes |
536 |
| - * @param array $variation |
537 |
| - * @param array $variationOptions |
538 |
| - * @return array |
539 |
| - */ |
540 |
| - private function prepareAttributes( |
541 |
| - array $attributes, |
542 |
| - $attribute, |
543 |
| - array $configurableAttributes, |
544 |
| - array $variation, |
545 |
| - array $variationOptions |
546 |
| - ): array { |
547 |
| - if (!isset($attributes[$attribute->getAttributeId()])) { |
548 |
| - $attributes[$attribute->getAttributeId()] = [ |
549 |
| - 'code' => $attribute->getAttributeCode(), |
550 |
| - 'label' => $attribute->getStoreLabel(), |
551 |
| - 'id' => $attribute->getAttributeId(), |
552 |
| - 'position' => $configurableAttributes[$attribute->getAttributeId()]['position'], |
553 |
| - 'chosen' => [], |
554 |
| - '__disableTmpl' => true |
555 |
| - ]; |
556 |
| - $options = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : []; |
557 |
| - foreach ($options as $option) { |
558 |
| - if (!empty($option['value'])) { |
559 |
| - $attributes[$attribute->getAttributeId()]['options'][] = [ |
560 |
| - 'attribute_code' => $attribute->getAttributeCode(), |
561 |
| - 'attribute_label' => $attribute->getStoreLabel(0), |
562 |
| - 'id' => $option['value'], |
563 |
| - 'label' => $option['label'], |
564 |
| - 'value' => $option['value'], |
565 |
| - '__disableTmpl' => true, |
566 |
| - ]; |
567 |
| - } |
568 |
| - } |
569 |
| - } |
570 |
| - $optionId = $variation[$attribute->getId()]['value']; |
571 |
| - $variationOption = [ |
572 |
| - 'attribute_code' => $attribute->getAttributeCode(), |
573 |
| - 'attribute_label' => $attribute->getStoreLabel(0), |
574 |
| - 'id' => $optionId, |
575 |
| - 'label' => $variation[$attribute->getId()]['label'], |
576 |
| - 'value' => $optionId, |
577 |
| - '__disableTmpl' => true, |
578 |
| - ]; |
579 |
| - $variationOptions[] = $variationOption; |
580 |
| - $attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption; |
581 |
| - |
582 |
| - return [$attributes, $variationOptions]; |
583 |
| - } |
584 |
| - |
585 | 474 | /**
|
586 | 475 | * Create child product details
|
587 | 476 | *
|
|
0 commit comments