Ejemplo n.º 1
0
 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']);
     }
 }
Ejemplo n.º 2
0
 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));
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 public function create()
 {
     return $this->save(Manufacturer::getNewInstance(''));
 }