/** * Create product promotion and connect to product * * @param integer $product_id * @param string $title * @param number $value * @param datetime $date_from * @param datetime $date_to * @param string $type * @param integer $count * @param boolean $stackable * @return integer */ public function createProductPromotion($product_id, $title = 'Test Promotion', $value = 10, $type = 'percentageOff', $stackable = true, $date_from = NULL, $date_to = NULL, $count = 1) { // Create promotion $promotion = new rtShopPromotionProduct(); $promotion->setTitle($title); $promotion->setDateFrom($date_from); $promotion->setDateTo($date_to); $promotion->setReductionType($type); $promotion->setReductionValue($value); $promotion->setCount($count); $promotion->setStackable($stackable); $promotion->save(); // Connect promotion to product $promo_product = new rtShopProductToPromotion(); $promo_product->setProductId($product_id); $promo_product->setPromotionId($promotion->getId()); $promo_product->save(); return $promotion->getId(); }
$i3->setReductionType('dollarOff'); $i3->setReductionValue(10); $i3->setMode('Group'); $i3->setCount(100); $i3->save(); $i4 = new rtShopPromotionProduct(); $i4->setTitle('Voucher'); $i4->setCode($code2); $i4->setDateFrom(date('Y-m-d H:i:s', strtotime(sprintf("-%s months", 3)))); $i4->setDateTo(date('Y-m-d H:i:s', strtotime(sprintf("+%s months", 1)))); $i4->setQuantityFrom(10); $i4->setQuantityTo(30); $i4->setReductionType('percentageOff'); $i4->setReductionValue(15); $i4->setMode('Single'); $i4->setCount(1); $i4->save(); $t->pass('->save() on a rtShopPromotionProduct object works'); } catch (Exception $e) { $t->fail('->save() on a rtShopPromotionProduct failed!'); } $o1 = Doctrine::getTable('rtShopPromotionProduct')->find($i3->getId()); $t->isa_ok($o1, 'rtShopPromotionProduct', '->retrieve() rtShopPromotionProduct object was saved to database and retrieved successfully'); $o2 = Doctrine::getTable('rtShopPromotionProduct')->findAvailable(8, NULL); $t->is(count($o2), 1, '::findAvailable() retrieved 1 object successfully'); // Clean up $i3->delete(); $i4->delete(); unset($o1, $o2); $t->diag('***********************'); $t->diag('*** Promotion: Cart ***');