public static function getThemeByProduct(Product $product) { $c = eq(__CLASS__ . '.productID', $product->getID()); $c->addOr(self::getCategoryCondition($product->getCategory())); $f = select($c); $f->setOrder(new ARExpressionHandle('CategoryPresentation.productID=' . $product->getID()), 'DESC'); self::setCategoryOrder($product->getCategory(), $f); // check if a theme is defined for this product particularly $set = ActiveRecordModel::getRecordSet(__CLASS__, $f, array('Category')); return self::getInheritedConfig($set); }
public function testCreateNewGroup() { $group = ProductFileGroup::getNewInstance($this->product); $group->setValueByLang('name', 'en', 'TEST_GROUP'); $group->save(); $group->reload(array('Product')); $name = $group->name->get(); $this->assertEqual($name['en'], 'TEST_GROUP'); $this->assertEqual($this->product->getID(), $group->product->get()->getID()); $this->assertTrue($this->product === $group->product->get()); }
public function setUp() { parent::setUp(); // create a product without attributes $this->product = Product::getNewInstance($this->category, 'test'); $this->product->setValueByLang("name", "en", "TEST_PRODUCT"); $this->product->save(); $this->productAutoIncrementNumber = $this->product->getID(); for ($k = 1; $k < 4; $k++) { $currency = Currency::getNewInstance($k . 'zz'); $currency->save(); } }
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(); }
private static function getProductGroupsFilter(Product $product) { $filter = new ARSelectFilter(); $filter->setOrder(new ARFieldHandle(__CLASS__, "position"), 'ASC'); $filter->setCondition(new EqualsCond(new ARFieldHandle(__CLASS__, "productID"), $product->getID())); return $filter; }
public function __construct(Product $product, $prices = null, LiveCart $application) { $this->product = $product; $this->application = $application; if (is_null($prices) && $product->getID()) { $prices = $product->getRelatedRecordSet("ProductPrice", new ARSelectFilter()); } if ($prices instanceof ARSet) { foreach ($prices as $price) { $this->setPrice($price); } } else { if (is_array($prices)) { foreach ($prices as $id => $price) { if (array_key_exists('ID', $price)) { $this->prices[$id] = ProductPrice::getInstance($product, Currency::getInstanceById($id)); } else { $this->prices[$id] = ProductPrice::getNewInstance($product, Currency::getInstanceById($id)); } $this->prices[$id]->price->set($price['price']); $this->prices[$id]->listPrice->set($price['listPrice']); $this->prices[$id]->serializedRules->set(serialize($price['serializedRules'])); $this->prices[$id]->resetModifiedStatus(); } } } }
public function setUp() { parent::setUp(); // Create some product $this->product1 = Product::getNewInstance($this->rootCategory, 'test'); $this->product1->save(); $this->productAutoIncrementNumber = $this->product1->getID(); // Create second product $this->product2 = Product::getNewInstance($this->rootCategory, 'test'); $this->product2->save(); // create new group $this->group = ProductRelationshipGroup::getNewInstance($this->product1, ProductRelationship::TYPE_CROSS); $this->group->position->set(5); $this->group->save(); $this->groupAutoIncrementNumber = $this->group->getID(); }
private static function getProductGroupsFilter(Product $product, $type) { $filter = new ARSelectFilter(); $filter->setOrder(new ARFieldHandle("ProductRelationshipGroup", "position"), 'ASC'); $filter->setCondition(new EqualsCond(new ARFieldHandle("ProductRelationshipGroup", "productID"), $product->getID())); $filter->mergeCondition(new EqualsCond(new ARFieldHandle("ProductRelationshipGroup", "type"), $type)); return $filter; }
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()); }
private function importProductVariationValue(Product $product, $index, $name) { $parent = $product->parent->get(); $type = $this->getVariationTypeByIndex($parent, $index); if (!$type->getID()) { $type = $this->importVariationType($parent, $index, ''); } $f = new ARSelectFilter(); $f->mergeCondition(new EqualsCond(MultiLingualObject::getLangSearchHandle(new ARFieldHandle('ProductVariation', 'name'), $this->application->getDefaultLanguageCode()), $name)); $values = $type->getRelatedRecordSet('ProductVariation', $f); if ($values->size()) { $variation = $values->get(0); } else { $variation = ProductVariation::getNewInstance($type); $variation->setValueByLang('name', null, $name); $variation->save(); } if (!$product->getID()) { $product->save(); } $f = new ARDeleteFilter(new EqualsCond(new ARFieldHandle('ProductVariation', 'typeID'), $type->getID())); $product->deleteRelatedRecordSet('ProductVariationValue', $f, array('ProductVariation')); ProductVariationValue::getNewInstance($product, $variation)->save(); }
private static function getRelatedProductsSetFilter(Product $product, $type) { $filter = new ARSelectFilter(); $filter->joinTable('ProductRelationshipGroup', 'ProductRelationship', 'ID', 'productRelationshipGroupID'); $filter->setOrder(new ARFieldHandle("ProductRelationshipGroup", "position"), 'ASC'); $filter->setOrder(new ARFieldHandle(__CLASS__, "position"), 'ASC'); $filter->setCondition(new EqualsCond(new ARFieldHandle(__CLASS__, "productID"), $product->getID())); $filter->mergeCOndition(new EqualsCond(new ARFieldHandle(__CLASS__, "type"), $type)); return $filter; }
protected function processRecord(Product $product) { $act = $this->getAction(); $field = $this->getField(); if ('manufacturer' == $act) { $product->manufacturer->set($this->params['manufacturer']); } else { if ('price' == $act) { $product->setPrice($this->params['baseCurrency'], $this->params['price']); } else { if (in_array($act, array('inc_price', 'multi_price', 'div_price'))) { $actions = array('inc_price' => 'increasePriceByPercent', 'multi_price' => 'multiplyPrice', 'div_price' => 'dividePrice'); $action = $actions[$act]; $pricing = $product->getPricingHandler(); foreach ($this->params['currencies'] as $currency) { if ($pricing->isPriceSet($currency)) { $p = $pricing->getPrice($currency); $p->{$action}($this->params['inc_price_value'], $this->params['inc_quant_price']); $p->save(); } } } else { if ('inc_stock' == $act) { $product->stockCount->set($product->stockCount->get() + $this->request->get($act)); } else { if ('addRelated' == $act) { $product->addRelatedProduct($this->params['relatedProduct']); } else { if ('copy' == $act) { $cloned = clone $product; $cloned->category->set($this->params['category']); $cloned->save(); } else { if ('addCat' == $act) { // check if the product is not assigned to this category already $relation = ActiveRecordModel::getInstanceByIdIfExists('ProductCategory', array('productID' => $product->getID(), 'categoryID' => $this->params['category']->getID())); if (!$relation->isExistingRecord() && $product->category->get() !== $category) { $relation->save(); } } else { if ('theme' == $act) { $instance = CategoryPresentation::getInstance($product); $instance->theme->set($this->params['theme']); $instance->save(); } else { if ('shippingClass' == $act) { $product->shippingClass->set(ActiveRecordModel::getInstanceByIDIfExists('ShippingClass', $this->params['shippingClass'], false)); } else { if ('taxClass' == $act) { $product->taxClass->set(ActiveRecordModel::getInstanceByIDIfExists('TaxClass', $this->params['taxClass'], false)); } else { if (substr($act, 0, 13) == 'set_specField') { $this->params['request']->remove('manufacturer'); $product->loadRequestData($this->params['request']); } else { if (substr($act, 0, 16) == 'remove_specField') { $this->params['request']->remove('manufacturer'); if ($this->params['field']->isMultiValue->get()) { // remove only selected multi-select options $product->loadRequestData($this->params['request']); } else { $product->removeAttribute($this->params['field']); } } else { parent::processRecord($product); } } } } } } } } } } } } }
public function contains(Product $product) { $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('ProductListItem', 'productID'), $product->getID())); return $this->getRelatedRecordCount('ProductListItem', $f) > 0; }
public static function registerLastViewedProduct(Product $product) { self::registerLastViewed(array('productID' => $product->getID(), 'instance' => $product)); }
public function getItemsByProduct(Product $product) { $items = array(); foreach ($this->orderedItems as $item) { if ($item->getProduct()->getID() == $product->getID()) { $items[] = $item; } } return $items; }
private function isPurchaseRequiredToRate(Product $product) { if ($this->config->get('REQUIRE_PURCHASE_TO_RATE')) { if ($this->user->isAnonymous()) { return true; } if (is_null($this->isPurchaseRequiredToRate)) { ClassLoader::import('application.model.order.CustomerOrder'); $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $this->user->getID())); $f->mergeCondition(new EqualsCond(new ARFieldHandle('OrderedItem', 'productID'), $product->getID())); $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), 1)); $f->setLimit(1); $this->isPurchaseRequiredToRate = ActiveRecordModel::getRecordCount('OrderedItem', $f, array('CustomerOrder')) < 1; } return $this->isPurchaseRequiredToRate; } }
/** * Get product prices filter * * @param Product $product * * @return ARSelectFilter */ private static function getProductPricesFilter(Product $product) { ClassLoader::import("application.model.Currency"); return new ARSelectFilter(new EqualsCond(new ARFieldHandle(__CLASS__, 'productID'), $product->getID())); }
private static function getFilesByProductFilter(Product $product) { $filter = new ARSelectFilter(); $filter->joinTable('ProductFileGroup', 'ProductFile', 'ID', 'productFileGroupID'); $filter->setOrder(new ARFieldHandle("ProductFileGroup", "position"), ARSelectFilter::ORDER_ASC); $filter->setCondition(new EqualsCond(new ARFieldHandle(__CLASS__, 'productID'), $product->getID())); $filter->setOrder(new ARFieldHandle(__CLASS__, 'position'), ARSelectFilter::ORDER_ASC); return $filter; }
protected function processRecord(Product $product) { $act = $this->getAction(); $field = $this->getField(); if ('manufacturer' == $act) { $product->manufacturer->set($this->params['manufacturer']); } else { if ('price' == $act) { $product->setPrice($this->params['baseCurrency'], $this->params['price']); } else { if ('inc_price' == $act) { $pricing = $product->getPricingHandler(); foreach ($this->params['currencies'] as $currency) { if ($pricing->isPriceSet($currency)) { $p = $pricing->getPrice($currency); $p->increasePriceByPercent($this->params['inc_price_value'], $this->params['inc_quant_price']); $p->save(); } } } else { if ('inc_stock' == $act) { $product->stockCount->set($product->stockCount->get() + $this->request->get($act)); } else { if ('addRelated' == $act) { $product->addRelatedProduct($this->params['relatedProduct']); } else { if ('copy' == $act) { $cloned = clone $product; $cloned->category->set($this->params['category']); $cloned->save(); } else { if ('addCat' == $act) { // check if the product is not assigned to this category already $relation = ActiveRecordModel::getInstanceByIdIfExists('ProductCategory', array('productID' => $product->getID(), 'categoryID' => $this->params['category']->getID())); if (!$relation->isExistingRecord() && $product->category->get() !== $category) { $relation->save(); } } else { if ('theme' == $act) { $instance = CategoryPresentation::getInstance($product); $instance->theme->set($this->params['theme']); $instance->save(); } else { if ('shippingClass' == $act) { $product->shippingClass->set(ActiveRecordModel::getInstanceByIDIfExists('ShippingClass', $this->params['shippingClass'], false)); } else { if ('taxClass' == $act) { $product->taxClass->set(ActiveRecordModel::getInstanceByIDIfExists('TaxClass', $this->params['taxClass'], false)); } else { parent::processRecord($product); } } } } } } } } } } }