Commit 061b7af9 authored by Karamel's avatar Karamel
Browse files

Import compositions from v7 and fix toStruct for them.

parent 2e887343
......@@ -455,7 +455,41 @@ if ($stmt->execute()) {
}
}
// Read compositions
// TODO compositions
$stmt3 = $pdo->prepare('select * from SUBGROUPS where COMPOSITION = :id '
. 'order by DISPORDER asc');
$stmt4 = $pdo->prepare('select * from SUBGROUPS_PROD where SUBGROUP = :id '
. 'order by DISPORDER asc');
foreach ($compositions as $id => $prd) {
$stmt3->bindValue(':id', $id);
if ($stmt3->execute()) {
while ($rowGrp = $stmt3->fetch()) {
$group = new \Pasteque\Server\Model\CompositionGroup();
$group->setLabel($rowGrp['NAME']);
$dispOrder = ($rowGrp['DISPORDER'] === null) ?
0 : $rowGrp['DISPORDER'];
$group->setDispOrder($dispOrder);
$stmt4->bindValue(':id', $rowGrp['ID']);
if ($stmt4->execute()) {
while ($rowPrd = $stmt4->fetch()) {
$grpPrd = new \Pasteque\Server\Model\CompositionProduct();
$dispOrder = ($rowPrd['DISPORDER'] === null) ?
0 : $rowPrd['DISPORDER'];
$grpPrd->setDispOrder($dispOrder);
$grpPrd->setProduct($prdMapping[$rowPrd['PRODUCT']]);
$group->addCompositionProducts($grpPrd);
}
} else {
$err = $stmt4->errorInfo();
die('SUBGROUPS_PROD error ' . $err[2]);
}
$prd->addCompositionGroup($group);
$api->write($prd);
}
} else {
$err = $stmt3->errorInfo();
die('SUBGROUPS error ' . $err[2]);
}
}
} else {
$err = $stmt->errorInfo();
die('PRODUCTS error' . $err[2]);
......
......@@ -312,14 +312,10 @@ class Product extends DoctrineModel
$struct['taxedPrice'] = $this->getTaxedPrice();
$struct['taxValue'] = $this->getTaxValue();
if ($this->isPrepay()) {
// Remove irrelevent fields
unset($struct['compositionGroups']);
// Embed prepay value to be able to apply discounts on it.
$struct['prepayValue'] = $this->getPriceSell();
} elseif ($this->isComposition()) {
// Disable irrelevent fields
unset($struct['prepay']);
} else {
}
if (!$this->isComposition()) {
unset($struct['compositionGroups']);
}
return $struct;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment