Inheritance: extends AppModel
 public function actionUpdate()
 {
     $lid = Yii::app()->request->getParam('id');
     Until::isUpdateValid(array($lid), $this->companyId, $this);
     //0,表示企业任何时候都在云端更新。
     $model = ProductDiscount::model()->find('lid=:lid and dpid=:dpid', array(':lid' => $lid, ':dpid' => $this->companyId));
     $product = Product::model()->find('lid=:lid and dpid=:dpid and delete_flag=0', array(':lid' => $model->product_id, ':dpid' => $this->companyId));
     if (Yii::app()->request->isPostRequest) {
         $model->attributes = Yii::app()->request->getPost('ProductDiscount');
         $model->update_at = date('Y-m-d H:i:s', time());
         if ($model->save()) {
             Yii::app()->user->setFlash('success', yii::t('app', '修改成功'));
             $this->redirect(array('productSales/updatedetail', 'companyId' => $this->companyId, 'id' => $model->product_id));
         }
     }
     $this->render('update', array('model' => $model, 'product' => $product));
 }
 public function validateProductDiscount()
 {
     if (isset($_POST['ProductDiscount'])) {
         $valid = true;
         $this->_productdiscount = array();
         /*Yii::log( "ProductCreateAction: ".CVarDumper::dumpAsString( $_POST['ProductOption'] ),
         			CLogger::LEVEL_ERROR, "product.actions.create" 
         		);*/
         foreach ($_POST['ProductDiscount'] as $i => $pdiscount) {
             if (isset($_POST['ProductDiscount'][$i])) {
                 $discount = new ProductDiscount();
                 $discount->product_id = 0;
                 $discount->attributes = $_POST['ProductDiscount'][$i];
                 $discount->date_start = date('Y-m-d', strtotime($_POST['ProductDiscount'][$i]['date_start']));
                 $discount->date_end = date('Y-m-d', strtotime($_POST['ProductDiscount'][$i]['date_end']));
                 Yii::log("ProductCreateAction: " . $discount->date_start . " " . $discount->date_end, CLogger::LEVEL_ERROR, "product.actions.create");
                 $valid = $discount->validate() && $valid;
                 $this->_productdiscount[] = $discount;
             }
         }
         if (!$valid) {
             return false;
         }
     }
     return true;
 }
Esempio n. 3
0
 public function afterDelete()
 {
     // delete dependencies
     ProductAttribute::model()->deleteAll("product_id={$this->cacheId}");
     ProductDescription::model()->deleteAll("product_id={$this->cacheId}");
     ProductDiscount::model()->deleteAll("product_id={$this->cacheId}");
     ProductFilter::model()->deleteAll("product_id={$this->cacheId}");
     ProductImage::model()->deleteAll("product_id={$this->cacheId}");
     ProductOption::model()->deleteAll("product_id={$this->cacheId}");
     ProductOptionValue::model()->deleteAll("product_id={$this->cacheId}");
     ProductRelated::model()->deleteAll("product_id={$this->cacheId}");
     ProductRelated::model()->deleteAll("related_id={$this->cacheId}");
     ProductReward::model()->deleteAll("product_id={$this->cacheId}");
     ProductSpecial::model()->deleteAll("product_id={$this->cacheId}");
     ProductToCategory::model()->deleteAll("product_id={$this->cacheId}");
     ProductToDownload::model()->deleteAll("product_id={$this->cacheId}");
     ProductToLayout::model()->deleteAll("product_id={$this->cacheId}");
     ProductToStore::model()->deleteAll("product_id={$this->cacheId}");
     Review::model()->deleteAll("product_id={$this->cacheId}");
     UrlAlias::model()->deleteAll("query='product_id={$this->cacheId}'");
     parent::afterDelete();
 }
Esempio n. 4
0
        foreach ($target as $id => &$product) {
            if ($product['id'] == $this->getParameter()) {
                $product['price'] = (int) $this->getModifier()->modify($target[$id]['price']);
                break;
            }
        }
    }
}
$context = [['id' => 1, 'name' => 'foobar', 'qty' => 12, 'price' => 10], ['id' => 2, 'name' => 'bazbat', 'qty' => 9, 'price' => 25]];
// Set up a rule that will give a 50% discount on product 1
// Set up the "has product" rule and point it at product 1
$assertion = new Equal();
$assertion->setTargetValue(1);
$rule = new HasProduct();
$rule->setAssertion($assertion);
// Set up our 50% discount
$result = new ProductDiscount();
$result->setParameter(1);
$modifier = new Percent();
$modifier->setTargetValue(50);
$result->setModifier($modifier);
// Roll them into a rule set
$ruleSet = new RuleSet();
$ruleSet->setRule($rule);
$ruleSet->addResult($result);
// Add to the rule set and run
$processor = new Processor();
$processor->addRuleSet($ruleSet);
$processor->process($context, $context);
// New price for product 1 is now 5
var_dump($context);