public function orderFinalize() { $ch = new ConnectionHandler(); $this->actualOrder->setOrderDate(date("Y-m-d h:i:s")); $ch->preparedInsert("megrendelesek", array("u_id", "rend_datum", "szall_cim", "szam_cim", "statusz_id"), array($this->getId(), $this->actualOrder->getOrderDate(), $this->actualOrder->getDeliveryAddress(), $this->actualOrder->getBillAddress(), $this->actualOrder->getStatus())); $ordNum = $ch->preparedQuery("SELECT rend_szam FROM megrendelesek\n ORDER BY rend_szam DESC\n LIMIT 1", array())->fetch(PDO::FETCH_NUM)[0]; foreach ($this->cart->getProducts() as $pid => $prod) { $ch->preparedInsert("rendeles_reszletei", array('rend_szam', 'termek_id', 'mennyiseg', 'osszeg'), array($ordNum, $prod->getId(), $this->cart->getQuantities()[$pid], $this->cart->itemSub($pid))); } array_push($this->orders, $this->actualOrder); $this->actualOrder = null; $this->cart = new Cart(array(), array()); $ch->preparedDelete("kosar", "u_id = ?", array($this->getId())); }
//a szükséges mennyiség nyilvántartása kulcs: termek_id => szükséges mennyiség $kellDb = array(); //ez előtt ellenőrzés történik ,hogy van-e elég termék raktáron, így csak akkor jutunk el ide, ha igen. while ($row = $stmt2->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) { echo $row[0] . " " . $row[1] . " " . $row[2] . " " . $row[3] . " " . $row[4] . " " . $row[5] . " " . $row[6] . "<br>"; $termek_id = $row[2]; //ha nem létezik a termek_id akkor belerakjuk a szükséges mennyiséget if (array_key_exists($row[2], $kellDb) == false) { $kellDb[$termek_id] = $row[4]; } //ha a szükséges mennyiség nagyobb mint nulla az adott termék_id esetén. if ($kellDb[$termek_id] > 0) { $raktaron = $row[3]; //ha több kellene mint amennyi van az adott szállítmányban a termékből, vagy ugyanannyi if ($raktaron - $kellDb[$termek_id] < 0 || $raktaron - $kellDb[$termek_id] == 0) { $kellDb[$termek_id] = $kellDb[$termek_id] - $raktaron; $raktaron = 0; echo "update raktaron:" . $raktaron . " && ennyi kell meg: " . $kellDb[$termek_id] . "<br>"; $conn->preparedDelete("raktar", "termek_id=? and szall_id=? and mennyiseg=? and stat_id", array($termek_id, $row[0], $row[3], $row[5])); } else { $raktaron -= $kellDb[$termek_id]; $kellDb[$termek_id] = 0; echo "update raktaron:" . $raktaron . " ennyi kell meg: " . $kellDb[$termek_id] . "<br>"; $conn->preparedUpdate("raktar", "mennyiseg", array($raktaron), "raktar", "termek_id=? and szall_id=? and mennyiseg=? and stat_id", array($termek_id, $row[0], $row[3], $row[5])); } } } ?> </body> </html>