Skip to content

Commit 5894b01

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-64547: Bundle Products - The options you selected are not available
1 parent 8f2b576 commit 5894b01

File tree

3 files changed

+41
-59
lines changed

3 files changed

+41
-59
lines changed

lib/internal/Magento/Framework/EntityManager/Operation/Create.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66
namespace Magento\Framework\EntityManager\Operation;
77

8+
use Magento\Framework\App\ObjectManager;
89
use Magento\Framework\DB\Adapter\DuplicateException;
10+
use Magento\Framework\EntityManager\Sequence\SequenceApplier;
911
use Magento\Framework\EntityManager\Operation\Create\CreateMain;
1012
use Magento\Framework\EntityManager\Operation\Create\CreateAttributes;
1113
use Magento\Framework\EntityManager\Operation\Create\CreateExtensions;
@@ -56,6 +58,11 @@ class Create implements CreateInterface
5658
*/
5759
private $createExtensions;
5860

61+
/**
62+
* @var SequenceApplier
63+
*/
64+
private $sequenceApplier;
65+
5966
/**
6067
* @param MetadataPool $metadataPool
6168
* @param TypeResolver $typeResolver
@@ -106,6 +113,8 @@ public function execute($entity, $arguments = [])
106113
);
107114
$this->eventManager->dispatchEntityEvent($entityType, 'save_before', ['entity' => $entity]);
108115

116+
$entity = $this->getSequenceApplier()->apply($entity);
117+
109118
$entity = $this->createMain->execute($entity, $arguments);
110119
$entity = $this->createAttributes->execute($entity, $arguments);
111120
$entity = $this->createExtensions->execute($entity, $arguments);
@@ -127,4 +136,20 @@ public function execute($entity, $arguments = [])
127136
}
128137
return $entity;
129138
}
139+
140+
/**
141+
* @return SequenceApplier
142+
*
143+
* @deprecated
144+
*/
145+
private function getSequenceApplier()
146+
{
147+
if (!$this->sequenceApplier) {
148+
$this->sequenceApplier = ObjectManager::getInstance()->get(
149+
SequenceApplier::class
150+
);
151+
}
152+
153+
return $this->sequenceApplier;
154+
}
130155
}

lib/internal/Magento/Framework/EntityManager/Operation/Create/CreateMain.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
*/
66
namespace Magento\Framework\EntityManager\Operation\Create;
77

8-
use Magento\Framework\App\ObjectManager;
98
use Magento\Framework\EntityManager\TypeResolver;
109
use Magento\Framework\EntityManager\HydratorPool;
1110
use Magento\Framework\EntityManager\Db\CreateRow;
12-
use Magento\Framework\EntityManager\Sequence\SequenceApplier;
1311

1412
/**
1513
* Class CreateMain
@@ -31,27 +29,19 @@ class CreateMain
3129
*/
3230
private $createRow;
3331

34-
/**
35-
* @var SequenceApplier
36-
*/
37-
private $sequenceApplier;
38-
3932
/**
4033
* @param TypeResolver $typeResolver
4134
* @param HydratorPool $hydratorPool
4235
* @param CreateRow $createRow
43-
* @param SequenceApplier $sequenceApplier
4436
*/
4537
public function __construct(
4638
TypeResolver $typeResolver,
4739
HydratorPool $hydratorPool,
48-
CreateRow $createRow,
49-
SequenceApplier $sequenceApplier = null
40+
CreateRow $createRow
5041
) {
5142
$this->typeResolver = $typeResolver;
5243
$this->hydratorPool = $hydratorPool;
5344
$this->createRow = $createRow;
54-
$this->sequenceApplier = $sequenceApplier;
5545
}
5646

5747
/**
@@ -61,28 +51,11 @@ public function __construct(
6151
*/
6252
public function execute($entity, $arguments = [])
6353
{
64-
$entity = $this->getSequenceApplier()->apply($entity);
6554
$entityType = $this->typeResolver->resolve($entity);
6655
$hydrator = $this->hydratorPool->getHydrator($entityType);
6756
$arguments = array_merge($hydrator->extract($entity), $arguments);
6857
$entityData = $this->createRow->execute($entityType, $arguments);
6958
$entity = $hydrator->hydrate($entity, $entityData);
7059
return $entity;
7160
}
72-
73-
/**
74-
* @return SequenceApplier
75-
*
76-
* @deprecated
77-
*/
78-
private function getSequenceApplier()
79-
{
80-
if (!$this->sequenceApplier) {
81-
$this->sequenceApplier = ObjectManager::getInstance()->get(
82-
SequenceApplier::class
83-
);
84-
}
85-
86-
return $this->sequenceApplier;
87-
}
8861
}

lib/internal/Magento/Framework/EntityManager/Sequence/SequenceManager.php

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,39 @@ public function __construct(
5353
}
5454

5555
/**
56-
* Force sequence value creation
56+
* Forces creation of a sequence value.
5757
*
5858
* @param string $entityType
5959
* @param string|int $identifier
60+
*
6061
* @return int
62+
*
6163
* @throws \Exception
6264
*/
6365
public function force($entityType, $identifier)
6466
{
65-
$metadata = $this->metadataPool->getMetadata($entityType);
6667
$sequenceInfo = $this->sequenceRegistry->retrieve($entityType);
6768

6869
if (!isset($sequenceInfo['sequenceTable'])) {
69-
throw new \Exception('TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesnt exists');
70+
throw new \Exception(
71+
'TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesnt exists'
72+
);
7073
}
7174

7275
try {
73-
$connection = $this->appResource->getConnectionByName($metadata->getEntityConnectionName());
74-
$sequenceTable = $this->appResource->getTableName($sequenceInfo['sequenceTable']);
76+
$metadata = $this->metadataPool->getMetadata($entityType);
7577

76-
if (!$this->isIdentifierExists($connection, $sequenceTable, $identifier)) {
77-
return $connection->insert($sequenceTable, ['sequence_value' => $identifier]);
78-
}
78+
$connection = $this->appResource->getConnectionByName(
79+
$metadata->getEntityConnectionName()
80+
);
7981

80-
return $identifier;
82+
return $connection->insert(
83+
$this->appResource->getTableName($sequenceInfo['sequenceTable']),
84+
['sequence_value' => $identifier]
85+
);
8186
} catch (\Exception $e) {
8287
$this->logger->critical($e->getMessage(), $e->getTrace());
88+
8389
throw new \Exception('TODO: use correct Exception class' . PHP_EOL . $e->getMessage());
8490
}
8591
}
@@ -108,26 +114,4 @@ public function delete($entityType, $identifier)
108114
throw new \Exception('TODO: use correct Exception class' . PHP_EOL . $e->getMessage());
109115
}
110116
}
111-
112-
/**
113-
* Checks whether given identifier exists in the corresponding sequence table.
114-
*
115-
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
116-
* @param string $sequenceTable
117-
* @param int $identifier
118-
*
119-
* @return bool
120-
*/
121-
private function isIdentifierExists(
122-
\Magento\Framework\DB\Adapter\AdapterInterface $connection,
123-
$sequenceTable,
124-
$identifier
125-
) {
126-
return (bool) $connection->fetchOne(
127-
$connection->select()
128-
->from($sequenceTable, ['sequence_value'])
129-
->where('sequence_value = ?', $identifier)
130-
->limit(1)
131-
);
132-
}
133117
}

0 commit comments

Comments
 (0)