本文整理汇总了PHP中Manufacturer::getNewInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Manufacturer::getNewInstance方法的具体用法?PHP Manufacturer::getNewInstance怎么用?PHP Manufacturer::getNewInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Manufacturer
的用法示例。
在下文中一共展示了Manufacturer::getNewInstance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEavQueue
public function testEavQueue()
{
// set up Manufacturer records
$field = EavField::getNewInstance('Manufacturer', EavField::DATATYPE_TEXT, EavField::TYPE_TEXT_SIMPLE);
$field->save();
$data = array('first', 'second', 'third');
foreach ($data as $value) {
$manufacturer = Manufacturer::getNewInstance($value);
$manufacturer->getSpecification()->setAttributeValueByLang($field, 'en', $value . ' test');
$manufacturer->save();
}
ActiveRecordModel::clearPool();
// fetch them from database
$manufacturers = ActiveRecordModel::getRecordSetArray('Manufacturer', new ARSelectFilter());
foreach ($manufacturers as &$entry) {
ActiveRecordModel::addToEavQueue('Manufacturer', $entry);
}
// duplicate
$manufacturers = array_merge($manufacturers, $manufacturers);
// load EAV data
ActiveRecordModel::loadEav();
foreach ($manufacturers as $man) {
$this->assertEqual($man['name'] . ' test', $man['attributes'][$field->getID()]['value_en']);
}
}
示例2: testIsProductMatching
public function testIsProductMatching()
{
$condition = DiscountCondition::getNewInstance();
$condition->isEnabled->set(true);
$condition->conditionClass->set('RuleConditionContainsProduct');
$condition->save();
$record = DiscountConditionRecord::getNewInstance($condition, $this->product1);
$record->save();
$condition->loadAll();
$ruleCondition = RuleCondition::createFromArray($condition->toArray());
$this->assertFalse($ruleCondition->isProductMatching($this->product2));
$this->assertTrue($ruleCondition->isProductMatching($this->product1));
// check matching by manufacturer
$manufacturer = Manufacturer::getNewInstance('testing');
$manufacturer->save();
$this->product2->manufacturer->set($manufacturer);
$record = DiscountConditionRecord::getNewInstance($condition, $manufacturer);
$record->save();
$condition->loadAll();
$ruleCondition = RuleCondition::createFromArray($condition->toArray());
$this->assertTrue($ruleCondition->isProductMatching($this->product2));
// check matching by category
$newCategory = Category::getNewInstance(Category::getRootNode());
$newCategory->save();
$newSubCategory = Category::getNewInstance($newCategory);
$newSubCategory->save();
$newProduct = Product::getNewInstance($newSubCategory);
$newProduct->save();
$newProduct->reload();
$record = DiscountConditionRecord::getNewInstance($condition, $newCategory);
$record->save();
$this->assertFalse($ruleCondition->isProductMatching($newProduct));
$condition->loadAll();
$ruleCondition = RuleCondition::createFromArray($condition->toArray());
$this->assertTrue($ruleCondition->isProductMatching($newProduct));
// sub-condition
$sub = DiscountCondition::getNewInstance($condition);
$sub->isEnabled->set(true);
$sub->conditionClass->set('RuleConditionContainsProduct');
$sub->save();
$condition->isAllSubconditions->set(true);
$condition->save();
$condition->loadAll();
$manufacturer = Manufacturer::getNewInstance('new one');
$manufacturer->save();
$record = DiscountConditionRecord::getNewInstance($sub, $manufacturer);
$record->save();
$sub->loadAll();
$subCondition = RuleCondition::createFromArray($sub->toArray());
$this->assertFalse($subCondition->isProductMatching($newProduct));
$ruleCondition = RuleCondition::createFromArray($condition->toArray());
$this->assertFalse($ruleCondition->isProductMatching($newProduct));
$newProduct->manufacturer->set($manufacturer);
$newProduct->save();
$this->assertTrue($ruleCondition->isProductMatching($newProduct));
// sub-sub condition
$sub->isAllSubconditions->set(false);
$sub->save();
for ($k = 1; $k <= 2; $k++) {
$subs[$k] = DiscountCondition::getNewInstance($sub);
$subs[$k]->isEnabled->set(true);
$subs[$k]->conditionClass->set('RuleConditionContainsProduct');
}
// false
$subs[1]->save();
$someManufacturer = Manufacturer::getNewInstance('Manufacturer without products');
$someManufacturer->save();
$record = DiscountConditionRecord::getNewInstance($subs[1], $someManufacturer);
$record->save();
$subs[1]->loadAll();
$sub->loadAll();
$condition->loadAll();
$this->assertFalse(RuleCondition::create($subs[1])->isProductMatching($newProduct));
$this->assertFalse(RuleCondition::create($condition)->isProductMatching($newProduct));
// true
$subs[2]->save();
$record = DiscountConditionRecord::getNewInstance($subs[2], $newProduct);
$record->save();
$subs[2]->loadAll();
$sub->loadAll();
$condition->loadAll();
$this->assertTrue(RuleCondition::create($condition)->isProductMatching($newProduct));
}
示例3: testDiscountForManufacturerProducts
public function testDiscountForManufacturerProducts()
{
$manufacturer = Manufacturer::getNewInstance('Discount Test');
$manufacturer->save();
$this->products[0]->manufacturer->set($manufacturer);
$this->products[0]->save();
// order condition
$condition = DiscountCondition::getNewInstance();
$condition->isEnabled->set(true);
$condition->count->set(4);
$condition->comparisonType->set(DiscountCondition::COMPARE_GTEQ);
$condition->conditionClass->set('RuleConditionContainsProduct');
$condition->save();
$record = DiscountConditionRecord::getNewInstance($condition, $manufacturer);
$record->save();
$action = DiscountAction::getNewInstance($condition);
$action->actionCondition->set($condition);
$action->isEnabled->set(true);
$action->type->set(DiscountAction::TYPE_ITEM_DISCOUNT);
$action->amount->set(10);
$action->actionClass->set('RuleActionPercentageDiscount');
$action->save();
$this->order->addProduct($this->products[0], 3);
$this->order->addProduct($this->products[1], 2);
$this->order->save();
$price0 = $this->products[0]->getPrice($this->usd);
$price1 = $this->products[1]->getPrice($this->usd);
$expectedTotal = $price1 * 2 + $price0 * 0.9 * 3;
$normalPrice = $price1 * 2 + $price0 * 3;
$this->assertEquals($normalPrice, $this->order->getTotal(true));
// require only 3 items of this manufacturer
$condition->count->set(3);
$condition->save();
$this->assertEquals(count($this->order->getDiscountActions(true)), 1);
$this->assertEquals($expectedTotal, $this->order->getTotal(true));
}
示例4: create
public function create()
{
return $this->save(Manufacturer::getNewInstance(''));
}