Esempio n. 1
0
 public function filter($emptyListIsException = false)
 {
     $request = $this->application->getRequest();
     $parser = $this->getParser();
     $apiFieldNames = $parser->getApiFieldNames();
     $parser->loadDataInRequest($request);
     $f = new ARSelectFilter();
     $id = $request->get('ID');
     if (intval($id) > 0) {
         $f->mergeCondition(new EqualsCond(new ARFieldHandle('Category', 'ID'), $id));
     }
     $f->setOrder(MultiLingualObject::getLangOrderHandle(new ARFieldHandle('Category', 'name')));
     $categories = ActiveRecordModel::getRecordSetArray('Category', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if ($emptyListIsException && count($categories) == 0) {
         throw new Exception('Category not found');
     }
     while ($category = array_shift($categories)) {
         $xmlCategory = $response->addChild('category');
         foreach ($category as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $xmlCategory->addChild($k, htmlentities($v));
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
Esempio n. 2
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     // get delivery zone
     if (isset($fields['DeliveryZone']['ID'])) {
         try {
             $zone = DeliveryZone::getInstanceByID($record[$fields['DeliveryZone']['ID']], true);
         } catch (ARNotFoundException $e) {
             $zone = DeliveryZone::getDefaultZoneInstance();
         }
     } else {
         $zone = DeliveryZone::getDefaultZoneInstance();
     }
     // get shipping service
     $f = select(new EqualsCond(MultiLingualObject::getLangSearchHandle(new ARFieldHandle('ShippingService', 'name'), $this->application->getDefaultLanguageCode()), $record[$fields['ShippingService']['name']]));
     if ($zone->isDefault()) {
         $f->mergeCondition(new IsNullCond(f('ShippingService.deliveryZoneID')));
     } else {
         $f->mergeCondition(eq(f('ShippingService.deliveryZoneID'), $zone->getID()));
     }
     $services = ActiveRecordModel::getRecordSet('ShippingService', $f);
     if ($services->get(0)) {
         $service = $services->get(0);
         // temporary
         $service->deleteRelatedRecordSet('ShippingRate');
     } else {
         $service = ShippingService::getNewInstance($zone, '', 0);
         $service->rangeType->set(ShippingService::SUBTOTAL_BASED);
     }
     $this->importInstance($record, $profile, $service);
     $this->setLastImportedRecordName($service->getValueByLang('name'));
     // get rate instance
     $rate = ShippingRate::getNewInstance($service, 0, 1000000);
     $rate->subtotalRangeStart->set(0);
     $rate->subtotalRangeEnd->set(1000000);
     return $rate;
 }
Esempio n. 3
0
 private function getFieldHandle($field, $handleType)
 {
     // aliases
     if (!strpos($field, '.')) {
         return f($field);
     }
     list($schemaName, $fieldName) = explode('.', $field);
     if ($this->getEavTableAlias() == $schemaName) {
         $fieldID = $fieldName;
         $fieldName = 'value';
         $specField = call_user_func(array($this->getEavFieldClass(), 'getInstanceByID'), $fieldID);
         if ($specField->isSelector()) {
             if ($specField->isMultiValue->get()) {
                 return $specField;
             } else {
                 if (self::FILTER_HANDLE == $handleType) {
                     $fieldName = 'ID';
                 }
             }
         }
     }
     $handle = null;
     if ($schemaName) {
         $schema = $this->getSchemaInstance($field);
         if ($field = $schema->getField($fieldName)) {
             $handle = $schema->getHandle($fieldName);
             if ($this->getEavTableAlias() == $schemaName) {
                 $handle->setTable('specField_' . $fieldID . ($schema->getName() == $this->getEavValueClass() ? '_value' : ''));
             }
             // language fields
             if ($field->getDataType() instanceof ARArray) {
                 if (self::SORT_HANDLE == $handleType) {
                     $handle = MultiLingualObject::getLangOrderHandle($handle);
                 } else {
                     $handleres = array();
                     $defLang = $this->application->getDefaultLanguageCode();
                     $locale = $this->application->getLocaleCode();
                     $handleres[] = MultiLingualObject::getLangSearchHandle($handle, $locale);
                     if ($locale != $defLang) {
                         $handleres[] = MultiLingualObject::getLangSearchHandle($handle, $defLang);
                     }
                     $handle = $handleres;
                 }
             }
         }
     } else {
         $handle = new ARExpressionHandle($fieldName);
     }
     return $handle;
 }
Esempio n. 4
0
 public static function findByName($name)
 {
     $f = select(new EqualsCond(MultiLingualObject::getLangSearchHandle(new ARFieldHandle('TaxClass', 'name'), self::getApplication()->getDefaultLanguageCode()), $name));
     return ActiveRecordModel::getRecordSet('TaxClass', $f)->get(0);
 }
 /**
  * Load product specification data for a whole array of products at once
  */
 public static function loadSpecificationForRecordSetArray($class, &$productArray, $fullSpecification = false)
 {
     $ids = array();
     foreach ($productArray as $key => $product) {
         $ids[$product['ID']] = $key;
     }
     $fieldClass = call_user_func(array($class, 'getFieldClass'));
     $groupClass = $fieldClass . 'Group';
     $groupColumn = call_user_func_array(array($fieldClass, 'getGroupIDColumnName'), array($fieldClass));
     $stringClass = call_user_func(array($fieldClass, 'getStringValueClass'));
     $fieldColumn = call_user_func(array($fieldClass, 'getFieldIDColumnName'));
     $objectColumn = call_user_func(array($fieldClass, 'getObjectIDColumnName'));
     $valueItemClass = call_user_func(array($fieldClass, 'getSelectValueClass'));
     $valueColumn = call_user_func(array($valueItemClass, 'getValueIDColumnName'));
     $specificationArray = self::fetchSpecificationData($class, array_flip($ids), $fullSpecification);
     $specFieldSchema = ActiveRecordModel::getSchemaInstance($fieldClass);
     $specStringSchema = ActiveRecordModel::getSchemaInstance($stringClass);
     $specFieldColumns = array_keys($specFieldSchema->getFieldList());
     foreach ($specificationArray as &$spec) {
         if ($spec['isMultiValue']) {
             $value['value'] = $spec['value'];
             $value = MultiLingualObject::transformArray($value, $specStringSchema);
             if (isset($productArray[$ids[$spec[$objectColumn]]]['attributes'][$spec[$fieldColumn]])) {
                 $sp =& $productArray[$ids[$spec[$objectColumn]]]['attributes'][$spec[$fieldColumn]];
                 $sp['valueIDs'][] = $spec['valueID'];
                 $sp['values'][] = $value;
                 continue;
             }
         }
         foreach ($specFieldColumns as $key) {
             $spec[$fieldClass][$key] = $spec[$key];
             unset($spec[$key]);
         }
         // transform for presentation
         $spec[$fieldClass] = MultiLingualObject::transformArray($spec[$fieldClass], $specFieldSchema);
         if ($spec[$fieldClass]['isMultiValue']) {
             $spec['valueIDs'] = array($spec['valueID']);
             $spec['values'] = array($value);
         } else {
             $spec = MultiLingualObject::transformArray($spec, $specStringSchema);
         }
         // groups
         if ($spec[$fieldClass][$groupColumn]) {
             $spec[$fieldClass][$groupClass] = array('ID' => $spec[$fieldClass][$groupColumn], 'name' => $spec['SpecFieldGroupName'], 'position' => $spec['SpecFieldGroupPosition']);
             if (!isset($groupSchema)) {
                 $groupSchema = ActiveRecordModel::getSchemaInstance($groupClass);
             }
             $spec[$fieldClass][$groupClass] = MultiLingualObject::transformArray($spec[$fieldClass][$groupClass], $groupSchema);
         }
         if (!empty($spec['value']) || !empty($spec['values']) || !empty($spec['value_lang'])) {
             // append to product array
             $productArray[$ids[$spec[$objectColumn]]]['attributes'][$spec[$fieldColumn]] = $spec;
             self::sortAttributesByHandle($class, $productArray[$ids[$spec[$objectColumn]]]);
         }
     }
 }
Esempio n. 6
0
 public function autoComplete()
 {
     $f = new ARSelectFilter();
     $f->setLimit(20);
     $resp = array();
     $field = $this->request->get('field');
     if (in_array($field, array('sku', 'URL', 'keywords'))) {
         $c = new LikeCond(new ARFieldHandle('Product', $field), $this->request->get($field) . '%');
         $f->setCondition($c);
         $f->setOrder(new ARFieldHandle('Product', $field), 'ASC');
         $query = new ARSelectQueryBuilder();
         $query->setFilter($f);
         $query->includeTable('Product');
         $query->addField('DISTINCT(Product.' . $field . ')');
         $results = ActiveRecordModel::getDataBySQL($query->createString());
         foreach ($results as $value) {
             $resp[] = $value[$field];
         }
     } else {
         if ('name' == $field) {
             $c = new LikeCond(new ARFieldHandle('Product', $field), '%:"' . $this->request->get($field) . '%');
             $f->setCondition($c);
             $locale = $this->locale->getLocaleCode();
             $langCond = new LikeCond(Product::getLangSearchHandle(new ARFieldHandle('Product', 'name'), $locale), $this->request->get($field) . '%');
             $c->addAND($langCond);
             $f->setOrder(Product::getLangSearchHandle(new ARFieldHandle('Product', 'name'), $locale), 'ASC');
             $results = ActiveRecordModel::getRecordSet('Product', $f);
             foreach ($results as $value) {
                 $resp[$value->getValueByLang('name', $locale, Product::NO_DEFAULT_VALUE)] = true;
             }
             $resp = array_keys($resp);
         } else {
             if ('specField_' == substr($field, 0, 10)) {
                 list($foo, $id) = explode('_', $field);
                 $handle = new ARFieldHandle('SpecificationStringValue', 'value');
                 $locale = $this->locale->getLocaleCode();
                 $searchHandle = MultiLingualObject::getLangSearchHandle($handle, $locale);
                 $f->setCondition(new EqualsCond(new ARFieldHandle('SpecificationStringValue', 'specFieldID'), $id));
                 $f->mergeCondition(new LikeCond($handle, '%:"' . $this->request->get($field) . '%'));
                 $f->mergeCondition(new LikeCond($searchHandle, $this->request->get($field) . '%'));
                 $f->setOrder($searchHandle, 'ASC');
                 $results = ActiveRecordModel::getRecordSet('SpecificationStringValue', $f);
                 foreach ($results as $value) {
                     $resp[$value->getValueByLang('value', $locale, Product::NO_DEFAULT_VALUE)] = true;
                 }
                 $resp = array_keys($resp);
             }
         }
     }
     return new AutoCompleteResponse($resp);
 }
Esempio n. 7
0
 /**
  * Creates array representation
  *
  * @return array
  */
 protected static function transformArray($array, ARSchema $schema)
 {
     $array = MultiLingualObject::transformArray($array, $schema);
     $array['unavailableProductCount'] = $array['totalProductCount'] - $array['availableProductCount'];
     $array['inactiveProductCount'] = $array['totalProductCount'] - $array['activeProductCount'];
     $c = self::getApplication()->getConfig();
     $array['count'] = 'ENABLE_AND_HIDE' == $c->get('INVENTORY_TRACKING') ? $array['availableProductCount'] : $array['activeProductCount'];
     return $array;
 }
Esempio n. 8
0
 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();
 }
Esempio n. 9
0
 /**
  *  Apply selected product sort order to ARSelectFilter instance
  */
 private function applySortOrder(ARSelectFilter $selectFilter, $order)
 {
     $dir = array_pop(explode('_', $order)) == 'asc' ? 'ASC' : 'DESC';
     if (substr($order, 0, 12) == 'product_name') {
         $selectFilter->setOrder(Product::getLangOrderHandle(new ARFieldHandle('Product', 'name')), $dir);
     } else {
         if (substr($order, 0, 5) == 'price') {
             $selectFilter->setOrder(new ARFieldHandle('ProductPrice', 'price'), $dir);
             $selectFilter->joinTable('ProductPrice', 'Product', 'productID AND (ProductPrice.currencyID = "' . $this->application->getDefaultCurrencyCode() . '")', 'ID');
         } else {
             if (substr($order, 0, 3) == 'sku') {
                 $selectFilter->setOrder(new ARFieldHandle('ProductPrice', 'price'), $dir);
                 $selectFilter->joinTable('ProductPrice', 'Product', 'productID AND (ProductPrice.currencyID = "' . $this->application->getDefaultCurrencyCode() . '")', 'ID');
             } else {
                 if ('newest_arrivals' == $order) {
                     $selectFilter->setOrder(new ARFieldHandle('Product', 'dateCreated'), 'DESC');
                 } else {
                     if (in_array($order, array('rating', 'sku'))) {
                         $selectFilter->setOrder(new ARFieldHandle('Product', $order), $dir);
                     } else {
                         if ('sales_rank' == $order) {
                             Product::updateSalesRank();
                             $selectFilter->setOrder(new ARFieldHandle('Product', 'salesRank'), 'DESC');
                         } else {
                             if (is_numeric($fieldID = array_shift(explode('-', $order))) && !SpecField::getInstanceByID($fieldID, true)->isMultiValue->get()) {
                                 $field = SpecField::getInstanceByID($fieldID);
                                 $field->defineJoin($selectFilter);
                                 $f = $field->getJoinAlias() . ($field->isSelector() ? '_value' : '') . '.value';
                                 $selectFilter->setOrder(new ARExpressionHandle($f . ' IS NOT NULL'), 'DESC');
                                 $selectFilter->setOrder(new ARExpressionHandle($f . ' != ""'), 'DESC');
                                 $f = new ARExpressionHandle($f);
                                 if ($field->isSelector()) {
                                     $f = MultiLingualObject::getLangOrderHandle($f);
                                 }
                                 $selectFilter->setOrder($f, array_pop(explode('_', $order)) == 'desc' ? 'DESC' : 'ASC');
                             } else {
                                 $selectFilter->setOrder(new ARFieldHandle('Product', 'isFeatured'), 'DESC');
                                 $selectFilter->setOrder(new ARFieldHandle('Product', 'salesRank'), 'DESC');
                                 $selectFilter->setOrder(new ARFieldHandle('Product', 'position'), 'DESC');
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 public static function transformArray($array, ARSchema $schema)
 {
     unset($array[call_user_func(array($schema->getName(), 'getOwnerClass'))]);
     unset($array[call_user_func(array($schema->getName(), 'getFieldClass'))]);
     return MultiLingualObject::transformArray($array, $schema);
 }
Esempio n. 11
0
 /**
  * Creates array representation
  *
  * @return array
  */
 protected static function transformArray($array, ARSchema $schema)
 {
     if (!empty($array['serializedCondition'])) {
         $array['serializedCondition'] = unserialize($array['serializedCondition']);
     }
     return MultiLingualObject::transformArray($array, $schema);
 }