public function setUp() { parent::setUp(); $this->specField = SpecField::getNewInstance($this->rootCategory, SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_SELECTOR); $this->specField->save(); $this->specFieldAutoIncrementNumber = $this->specField->getID(); $specFieldValue = SpecFieldValue::getNewInstance($this->specField); $specFieldValue->save(); $this->specFieldValueAutoIncrementNumber = $specFieldValue->getID(); $this->product = Product::getNewInstance($this->rootCategory, 'test'); $this->product->save(); $this->productAutoIncrementNumber = $this->product->getID(); }
public function testDelete() { $category = Category::getNewInstance(Category::getRootNode()); $category->save(); $field = SpecField::getNewInstance($category, SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_SIMPLE); $field->handle->set('randomhandle'); $field->save(); $this->request->set('id', $field->getID()); $response = $this->controller->delete(); $this->assertIsA($response, 'JSONResponse'); $value = $response->getValue(); $this->assertEqual($value['status'], 'success'); // already deleted $response = $this->controller->delete(); $value = $response->getValue(); $this->assertEqual($value['status'], 'failure'); }
public function getNextSpecField() { if (is_null($this->specFieldSql)) { $join = $langs = array(); foreach ($this->languages as $id => $code) { list($join[], $langs[]) = $this->joinAttributeFields($id, $code); } // get all categories $this->specFieldSql = 'SELECT ' . $this->getTablePrefix() . 'extra_fields.* ' . ($langs ? ',' : '') . implode(', ', $langs) . ' FROM ' . $this->getTablePrefix() . 'extra_fields ' . implode(' ', $join) . ' ORDER BY orderby ASC'; } if (!($data = $this->loadRecord($this->specFieldSql))) { return null; } $this->attributes[] = $data; $rec = SpecField::getNewInstance(Category::getRootNode(), SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_SIMPLE); $rec->setID($data['fieldid']); $rec->handle->set($data['service_name']); $rec->setValueByLang('name', $this->defLang, $data['field']); $rec->isDisplayed->set(true); foreach ($this->languages as $code => $id) { $rec->setValueByLang('name', $code, $data['fieldname_' . $code]); } return $rec; }
public function testClone() { $image = ActiveRecordModel::getNewInstance('ProductImage'); $image->product->set($this->product); $image->save(); $this->assertSame($image, $this->product->defaultImage->get()); $numField = SpecField::getNewInstance($this->productCategory, SpecField::DATATYPE_NUMBERS, SpecField::TYPE_NUMBERS_SIMPLE); $numField->save(); $this->product->setAttributeValue($numField, 100); $this->product->save(); $option = ProductOption::getNewInstance($this->product); $option->type->set(ProductOption::TYPE_SELECT); $option->setValueByLang('name', 'en', 'test'); $option->save(); $related = Product::getNewInstance($this->productCategory, 'related'); $related->save(); $relGroup = ProductRelationshipGroup::getNewInstance($this->product, ProductRelationship::TYPE_CROSS); $relGroup->save(); $rel = ProductRelationship::getNewInstance($this->product, $related, $relGroup); $rel->save(); $this->assertEquals(1, $this->product->getRelationships()->size()); $cloned = clone $this->product; $this->assertEquals(100, $cloned->getSpecification()->getAttribute($numField)->value->get()); $cloned->setAttributeValue($numField, 200); $cloned->setPrice($this->usd, 80); $cloned->save(); $this->assertNotEquals($cloned->getID(), $this->product->getID()); ActiveRecordModel::clearPool(); $reloaded = Product::getInstanceByID($cloned->getID(), true); $reloaded->loadPricing(); $this->assertEquals(80, $reloaded->getPrice($this->usd)); $reloaded->loadSpecification(); $this->assertEquals(200, $reloaded->getSpecification()->getAttribute($numField)->value->get()); // related products $rel = $reloaded->getRelationships(); $this->assertEquals(1, $rel->size()); $this->assertSame($reloaded, $rel->get(0)->productRelationshipGroup->get()->product->get()); // options $clonedOpts = ProductOption::getProductOptions($reloaded); $this->assertEquals(1, $clonedOpts->size()); // image $this->assertTrue(is_object($reloaded->defaultImage->get())); $this->assertNotEquals($reloaded->defaultImage->get()->getID(), $this->product->defaultImage->get()->getID()); }
public function testTextRulesSpecField() { $field = SpecField::getNewInstance(Category::getRootNode(), SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_ADVANCED); $field->save(); $product = Product::getNewInstance($this->categories['1.2.1']); $product->sku->set('testing'); $product->save(); $product->setAttributeValueByLang($field, $this->getApplication()->getDefaultLanguageCode(), 'Attribute value'); $product->save(); $rule = ClonedStoreRule::getNewInstance($this->stores[0], ClonedStoreRule::TYPE_TEXT); $rule->field->set('specField.' . $field->getID()); $rule->find->set('value'); $rule->repl->set('replaced'); $rule->save(); $updater = $this->getUpdater(); $updater->syncAll(); $row = ActiveRecord::getDataBySQL('SELECT * FROM ' . $updater->getImportDatabase() . '.SpecificationStringValue WHERE productID=' . $product->getID()); $row = array_shift($row); $name = unserialize($row['value']); $this->assertEqual($name[$this->getApplication()->getDefaultLanguageCode()], 'Attribute replaced'); }
public function getNextSpecField() { if (is_null($this->specFieldSql)) { // get all categories $this->specFieldSql = 'SELECT * FROM ' . $this->getTablePrefix() . 'product_options ORDER BY sort_order ASC'; } if (!($data = $this->loadRecord($this->specFieldSql))) { return null; } $this->attributes[] = $data; $rec = SpecField::getNewInstance(Category::getRootNode(), SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_SIMPLE); $rec->setID($data['optionID']); $rec->handle->set(createHandleString($data['name'])); $rec->setValueByLang('name', $this->defLang, $data['name']); $rec->isDisplayed->set(true); return $rec; }