本文整理汇总了PHP中ProductCategory::getNewInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductCategory::getNewInstance方法的具体用法?PHP ProductCategory::getNewInstance怎么用?PHP ProductCategory::getNewInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductCategory
的用法示例。
在下文中一共展示了ProductCategory::getNewInstance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
Category::recalculateProductsCount();
$this->root = Category::getNewInstance(Category::getRootNode());
$this->root->save();
for ($k = 1; $k <= 2; $k++) {
$cat = Category::getNewInstance($this->root);
$cat->save();
$this->categories[$k] = $cat;
}
$this->product = Product::getNewInstance($this->categories[1]);
$this->product->save();
$this->secondCategory = ProductCategory::getNewInstance($this->product, $this->categories[2]);
$this->secondCategory->save();
}
示例2: importAdditionalCategories
private function importAdditionalCategories(CsvImportProfile $profile, Product $product, array $extraCategories)
{
$product->deleteRelatedRecordSet('ProductCategory');
foreach ($extraCategories as $names) {
ProductCategory::getNewInstance($product, $this->getCategoryByPath($profile, $names))->save();
}
}
示例3: testAdditionalCategories
/**
* @todo: doesn't work
*/
public function testAdditionalCategories()
{
$customCategory = Category::getNewInstance(Category::getRootNode());
$customCategory->save();
$product = $this->product1;
$this->order->addProduct($product, 1, true);
$this->order->save();
$condition = DiscountCondition::getNewInstance();
$condition->isEnabled->set(true);
$condition->conditionClass->set('RuleConditionContainsProduct');
$condition->save();
DiscountConditionRecord::getNewInstance($condition, $customCategory)->save();
$this->assertEquals(0, count($this->order->getDiscountConditions(true)));
ProductCategory::getNewInstance($product, $customCategory)->save();
$condition->loadAll();
//$this->assertEquals(1, count($this->order->getDiscountConditions(true)));
}
示例4: testProductSyncMatchingProductExtraCat
public function testProductSyncMatchingProductExtraCat()
{
for ($k = 0; $k <= 1; $k++) {
$product = Product::getNewInstance($this->categories['1.2.1']);
$product->sku->set($k);
$product->save();
}
ClonedStoreCategory::getNewInstance($this->categories['1.2.2'], $this->stores[0])->save();
ProductCategory::getNewInstance($product, $this->categories['1.2.1'])->save();
$updater = $this->getUpdater();
$updater->syncAll();
$this->assertRecordCount('Product', 1);
}
示例5: testDiscountByAdditionalCategories
public function testDiscountByAdditionalCategories()
{
$product = $this->products[1];
$condition = DiscountCondition::getNewInstance();
$condition->isEnabled->set(true);
$condition->save();
$actionCondition = DiscountCondition::getNewInstance();
$actionCondition->isEnabled->set(true);
$actionCondition->conditionClass->set('RuleConditionContainsProduct');
$actionCondition->save();
$action = DiscountAction::getNewInstance($condition);
$action->actionCondition->set($actionCondition);
$action->isEnabled->set(true);
$action->type->set(DiscountAction::TYPE_ITEM_DISCOUNT);
$action->amount->set(10);
$action->actionClass->set('RuleActionPercentageDiscount');
$action->save();
$randomCategory = Category::getNewInstance(Category::getRootNode());
$randomCategory->save();
DiscountConditionRecord::getNewInstance($actionCondition, $randomCategory)->save();
$this->order->addProduct($product, 1, true);
$this->order->save();
Category::recalculateProductsCount();
$product->reload();
$this->assertFalse(RuleCondition::create($actionCondition)->isProductMatching($product));
$customCategory = Category::getNewInstance(Category::getRootNode());
$customCategory->save();
ProductCategory::getNewInstance($product, $customCategory)->save();
DiscountConditionRecord::getNewInstance($actionCondition, $customCategory)->save();
Category::recalculateProductsCount();
$product->reload();
$actionCondition->loadAll();
$this->assertTrue(RuleCondition::create($actionCondition)->isProductMatching($product));
$this->assertEquals(count($this->order->getDiscountActions(true)), 1);
$this->assertEquals($this->products[1]->getPrice($this->usd) * 0.9, $this->order->getTotal(true));
ActiveRecordModel::clearPool();
$order = CustomerOrder::getInstanceByID($this->order->getID());
$order->loadAll();
$this->assertEquals($this->products[1]->getPrice($this->usd) * 0.9, $this->order->getTotal(true));
}
示例6: importAdditionalCategories
private function importAdditionalCategories(CsvImportProfile $profile, Product $product, $extraCategories)
{
$product->deleteRelatedRecordSet('ProductCategory');
$instances = array();
if (is_array($extraCategories)) {
foreach ($extraCategories as $names) {
$instances[] = $this->getCategoryByPath($profile, $names);
}
} else {
if ($extraCategories instanceof Condition) {
$instances = ActiveRecord::getRecordSet('Category', select($extraCategories));
}
}
foreach ($instances as $cat) {
ProductCategory::getNewInstance($product, $cat)->save();
}
}