Skip to content

Commit

Permalink
Remove price when product is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
trecouvr committed Sep 12, 2013
1 parent faf1bc4 commit 06a49f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Payutc/Bom/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public static function getOne($obj_id, $fun_id=null, $removed=0) {
'obj_type' => "product",
'obj_id' => $obj_id,
));

if($fun_id !== null) {
$qb->andWhere('obj.fun_id = :fun_id')
->setParameter('fun_id', $fun_id);
Expand Down Expand Up @@ -267,7 +266,12 @@ public static function delete($id, $fun_id) {
$db->query("UPDATE t_object_obj SET `obj_removed` = '1' WHERE `obj_id` = '%u';",array($id));

// 3. DELETE PRICE
// TODO !!
$qb = Dbal::createQueryBuilder();
$qb->update('t_price_pri', 'pri')
->where('obj_id = :id')
->set('pri_removed', 1)
->setParameter('id', $id);
$qb->execute();

return array("success"=>"ok");
}
Expand Down
28 changes: 28 additions & 0 deletions tests/ProductRwdbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_once 'bootstrap.php';

use \Payutc\Bom\Product;
use \Payutc\Db\Dbal;

class ProductRwdbTest extends DatabaseTest
{
Expand Down Expand Up @@ -72,6 +73,33 @@ public function testAdd() {
$this->assertEquals(1001, $r['categorie_id']);
$this->assertEquals(1, $r['fundation_id']);
}

/**
* @depends testAdd
*/
public function testDelete() {
// create object
$a = Product::add("Chouffe", 1000, 180, 10, 1, null, 1);
$id = $a["success"];
// delete object
Product::delete($id, 1);
// assert we cant get the object now
$r = Product::getOne($id, 1);
$this->assertNull($r);
// but we can get it if we allow deleted objects
$r = Product::getOne($id, 1, 1);
$this->assertNotNull($r);
// check the price has been removed too
$qb = Dbal::createQueryBuilder();
$q = $qb->select('pri_removed')
->from('t_price_pri', 'pri')
->where('obj_id = :id')
->setParameter('id', $id);
$prices = $q->execute()->fetchAll();
foreach($prices as $p) {
$this->assertEquals(1, $p['pri_removed']);
}
}
}


Expand Down

0 comments on commit 06a49f3

Please sign in to comment.