Skip to content

Commit

Permalink
Don't add stock_data attribute if is_in_stock was not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Acker committed Mar 14, 2014
1 parent f400055 commit 04685bd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/MageTest/MagentoExtension/Context/MagentoContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,18 @@ public function theProductsExist(TableNode $table)
$hash = $table->getHash();
$fixtureGenerator = $this->factory->create('product');
foreach ($hash as $row) {
$row['stock_data'] = array();
if (isset($row['is_in_stock'])) {
$row['stock_data']['is_in_stock'] = $row['is_in_stock'];
}
if (isset($row['is_in_stock'])) {
$row['stock_data']['qty'] = $row['qty'];
if (!isset($row['qty'])) {
throw new \InvalidArgumentException('You have specified is_in_stock but not qty, please add value for qty.');
};

$row['stock_data'] = array(
'is_in_stock' => $row['is_in_stock'],
'qty' => $row['qty']
);

unset($row['is_in_stock']);
unset($row['qty']);
}

$fixtureGenerator->create($row);
Expand Down

0 comments on commit 04685bd

Please sign in to comment.