public function products() { $this->setLayout('empty'); set_time_limit(0); $response = new XMLResponse(); $filter = new ARSelectFilter(); $filter->setOrder(f('Product.dateCreated'), ARSelectFilter::ORDER_DESC); $categoryId = $this->getRequest()->get('id'); if (preg_match('/^\\d+$/', $categoryId)) { $this->shouldBeEnabledFeed('CATEGORY_PRODUCTS'); $category = Category::getInstanceById($categoryId, Category::LOAD_DATA); $filter = new ProductFilter($category, $filter); } else { $this->shouldBeEnabledFeed('ALL_PRODUCTS'); $category = Category::getRootNode(true); $filter = new ProductFilter($category, $filter); $filter->includeSubCategories(); } $feed = new ProductFeed($filter); $feed->setFlush(); $feed->setLimit($this->config->get('NUMBER_OF_PRODUCTS_TO_INCLUDE')); $response->set('feed', $feed); $response->set('category', $category->toArray()); return $response; }
public function index() { $category = Category::getInstanceById($this->request->get('id'), ActiveRecord::LOAD_DATA); $f = select(); $f->setOrder(f('CategoryRelationship.position')); $additional = $category->getRelatedRecordSet('CategoryRelationship', $f, array('Category_RelatedCategory')); $categories = array(); foreach ($additional as $cat) { $categories[] = $cat; $cat->relatedCategory->get()->load(); $cat->relatedCategory->get()->getPathNodeSet(); } $response = new ActionResponse('category', $category->toArray()); $response->set('categories', ARSet::buildFromArray($categories)->toArray()); return $response; }
<?php error_reporting(E_ALL); ini_set('display_errors', 'On'); include '../application/Initialize.php'; ClassLoader::import('application.LiveCart'); new LiveCart(); ClassLoader::import('application.model.category.Category'); Category::getInstanceById(1); Category::recalculateProductsCount();
public function getNextProduct() { if (!$this->productSql) { foreach ($this->languages as $code => $id) { list($join[], $langs[]) = $this->joinProductFields($id, $code); } foreach ($this->attributes as $attr) { $join[] = 'LEFT JOIN ' . $this->getTablePrefix() . 'extra_field_values AS extra_' . $attr['fieldid'] . ' ON (extra_' . $attr['fieldid'] . '.productid=' . $this->getTablePrefix() . 'products.productid AND extra_' . $attr['fieldid'] . '.fieldid=' . $attr['fieldid'] . ')'; $langs[] = 'extra_' . $attr['fieldid'] . '.value AS extrafield_' . $attr['fieldid']; } $this->productSql = 'SELECT ' . $this->getTablePrefix() . 'products.*, ' . $this->getTablePrefix() . 'products_categories.categoryid ' . ($langs ? ',' : '') . implode(', ', $langs) . ', (SELECT price FROM ' . $this->getTablePrefix() . 'pricing WHERE ' . $this->getTablePrefix() . 'pricing.productid=' . $this->getTablePrefix() . 'products.productid ORDER BY quantity ASC LIMIT 1) AS price FROM ' . $this->getTablePrefix() . 'products ' . implode(' ', $join) . ' LEFT JOIN ' . $this->getTablePrefix() . 'products_categories ON (' . $this->getTablePrefix() . 'products.productid=' . $this->getTablePrefix() . 'products_categories.productid AND ' . $this->getTablePrefix() . 'products_categories.main="Y")'; } if (!($data = $this->loadRecord($this->productSql))) { return null; } $rec = Product::getNewInstance(Category::getInstanceById($this->getRealId('Category', $data['categoryid']))); $rec->setID($data['productid']); $rec->keywords->set($data['keywords']); $rec->setValueByLang('name', $this->defLang, $data['product']); $rec->setValueByLang('longDescription', $this->defLang, $data['fulldescr']); $rec->setValueByLang('shortDescription', $this->defLang, $data['descr']); foreach ($this->languages as $code => $id) { $rec->setValueByLang('name', $code, $data['name_' . $code]); $rec->setValueByLang('longDescription', $code, $data['fulldescr_' . $code]); $rec->setValueByLang('shortDescription', $code, $data['descr_' . $code]); } foreach ($this->attributes as $attr) { if (!empty($data['extrafield_' . $attr['fieldid']])) { $rec->setAttributeValueByLang(SpecField::getInstanceByID($this->getRealId('SpecField', $attr['fieldid']), SpecField::LOAD_DATA), $this->defLang, $data['extrafield_' . $attr['fieldid']]); } } if ($data['manufacturerid']) { $rec->manufacturer->set(Manufacturer::getInstanceById($this->getRealId('Manufacturer', $data['manufacturerid']))); } foreach (array('sku' => 'productcode', 'shippingWeight' => 'weight', 'stockCount' => 'avail', 'shippingSurchargeAmount' => 'shipping_freight', 'minimumQuantity' => 'min_amount', 'dateCreated' => 'add_date') as $lc => $xc) { $rec->{$lc}->set($data[$xc]); } $rec->isEnabled->set('Y' == $data['forsale']); $rec->setPrice($this->getDefaultCurrency(), $data['price']); //images $images = array_merge($this->getDataBySQL('SELECT * FROM ' . $this->getTablePrefix() . 'images_t WHERE id=' . $data['productid'] . ' ORDER BY orderby ASC'), $this->getDataBySQL('SELECT * FROM ' . $this->getTablePrefix() . 'images_d WHERE id=' . $data['productid'] . ' ORDER BY orderby ASC')); foreach ($images as $image) { $this->importProductImage($rec, $this->path . '/' . $image['image_path']); } $rec->rawData = $data; return $rec; }
protected function boxSearchBlock() { ClassLoader::import('application.model.category.Category'); $category = $this->getCategory(); $search = $this->getCategory()->getPathNodeArray(); $subCategories = $category->getSubCategoryArray(); if ($subCategories) { if ($category->getID() != Category::ROOT_ID) { $search[] = $category->toArray(); } $search = array_merge($search, $subCategories); } if (!$search) { $category = Category::getInstanceById(Category::ROOT_ID, Category::LOAD_DATA); $subCategories = $category->getSubCategorySet(); foreach ($subCategories as $category) { $search[] = $category->toArray(); } } $options = array(1 => $this->translate('_all_products')); foreach ($search as $cat) { if ($cat['isEnabled']) { $options[$cat['ID']] = $cat['name_lang']; } } $form = new Form($this->getValidator("productSearch", $this->request)); $form->enableClientSideValidation(false); $form->set('id', $this->getCategory()->getID()); $form->set('q', $this->request->get('q')); if ($this->filters && is_array($this->filters)) { foreach ($this->filters as $filter) { if ($filter instanceof SearchFilter) { $form->set('q', $filter->getKeywords()); } } } $response = new BlockResponse(); $response->set('categories', $options); $response->set('form', $form); return $response; }
public function setConfig() { if (!$this->buildConfigValidator()->isValid()) { return new ActionRedirectResponse('install', 'config'); } Language::deleteCache(); // site name $this->config->setValueByLang('STORE_NAME', $this->request->get('language'), $this->request->get('name')); $this->config->save(); ClassLoader::import('application.model.Currency'); // create currency if (ActiveRecord::objectExists('Currency', $this->request->get('curr'))) { $currency = Currency::getInstanceByID($this->request->get('curr'), Currency::LOAD_DATA); } else { $currency = ActiveRecord::getNewInstance('Currency'); $currency->setID($this->request->get('curr')); $currency->isEnabled->set(true); $currency->isDefault->set(true); $currency->save(ActiveRecord::PERFORM_INSERT); } ClassLoader::import('application.model.system.Language'); // create language if (ActiveRecord::objectExists('Language', $this->request->get('language'))) { $language = Language::getInstanceByID($this->request->get('language'), Language::LOAD_DATA); } else { $language = ActiveRecord::getNewInstance('Language'); $language->setID($this->request->get('language')); $language->save(ActiveRecord::PERFORM_INSERT); $language->isEnabled->set(true); $language->isDefault->set(true); $language->save(); } // set root category name to "LiveCart" ClassLoader::import('application.model.category.Category'); $root = Category::getInstanceById(Category::ROOT_ID, Category::LOAD_DATA); $root->setValueByLang('name', $language->getID(), 'LiveCart'); $root->save(); // create a default shipping service ClassLoader::import('application.model.delivery.DeliveryZone'); ClassLoader::import('application.model.delivery.ShippingService'); ClassLoader::import('application.model.delivery.ShippingRate'); $service = ShippingService::getNewInstance(DeliveryZone::getDefaultZoneInstance(), 'Default Service', ShippingService::SUBTOTAL_BASED); $service->save(); $rate = ShippingRate::getNewInstance($service, 0, 100000); $rate->flatCharge->set(10); $rate->save(); // create a couple of blank static pages ClassLoader::import('application.model.staticpage.StaticPage'); $page = StaticPage::getNewInstance(); $page->setValueByLang('title', $language->getID(), 'Contact Info'); $page->setValueByLang('text', $language->getID(), 'Enter your contact information here'); $page->menu->set(array('INFORMATION' => true)); $page->save(); $page = StaticPage::getNewInstance(); $page->setValueByLang('title', $language->getID(), 'Shipping Policy'); $page->setValueByLang('text', $language->getID(), 'Enter your shipping rate & policy information here'); $page->menu->set(array('INFORMATION' => true)); $page->save(); // create an example site news post ClassLoader::import('application.model.sitenews.NewsPost'); $news = ActiveRecordModel::getNewInstance('NewsPost'); $news->setValueByLang('title', $language->getID(), 'Our store is open'); $news->setValueByLang('text', $language->getID(), 'Powered by LiveCart software, we have gone live! Of course, we will have to go to <a href="../backend">the backend area</a> and add some categories and products first...'); $news->setValueByLang('moreText', $language->getID(), 'Do not forget to delete this post when you actually go live :)'); $news->isEnabled->set(true); $news->save(); return new ActionRedirectResponse('install', 'finish'); }
public function getNextProduct() { if (!$this->productSql) { foreach ($this->languages as $id => $code) { list($join[], $langs[]) = $this->joinProductFields($id, $code); } $this->productSql = 'SELECT *,' . implode(', ', $langs) . ' FROM ' . $this->getTablePrefix() . 'products ' . implode(' ', $join) . ' LEFT JOIN ' . $this->getTablePrefix() . 'products_to_categories ON ' . $this->getTablePrefix() . 'products.products_id=' . $this->getTablePrefix() . 'products_to_categories.products_id LEFT JOIN ' . $this->getTablePrefix() . 'categories ON ' . $this->getTablePrefix() . 'products_to_categories.categories_id=' . $this->getTablePrefix() . 'categories.categories_id WHERE ' . $this->getTablePrefix() . 'categories.categories_id IS NOT NULL GROUP BY ' . $this->getTablePrefix() . 'products.products_id'; } if (!($data = $this->loadRecord($this->productSql))) { return null; } $rec = Product::getNewInstance(Category::getInstanceById($this->getRealId('Category', $data['categories_id']))); $rec->setID($data['products_id']); foreach ($this->languages as $code) { $rec->setValueByLang('name', $code, $data['name_' . $code]); $rec->setValueByLang('longDescription', $code, $data['descr_' . $code]); // use the first line or paragraph of the long description as the short description $short = array_shift(preg_split("/\n|\\<br/", $data['descr_' . $code])); $rec->setValueByLang('shortDescription', $code, $short); } if ($data['manufacturers_id']) { try { $man = Manufacturer::getInstanceById($this->getRealId('Manufacturer', $data['manufacturers_id']), true); $man->load(); $rec->manufacturer->set($man); } catch (Exception $e) { // orphan data } } $rec->sku->set($data['products_model']); $rec->URL->set($data['products_url']); $rec->isEnabled->set((int) (1 == $data['products_status'])); $rec->shippingWeight->set($data['products_weight']); $rec->stockCount->set($data['products_quantity']); $rec->dateCreated->set($data['products_date_added']); $rec->setPrice($this->getConfigValue('DEFAULT_CURRENCY'), $data['products_price']); //product image if ($data['products_image']) { $this->importProductImage($rec, $this->path . '/images/' . $data['products_image']); } $rec->rawData = $data; return $rec; }
/** * @role mass */ public function processMass() { $filter = $this->getSelectFilter(); $act = $this->request->get('act'); $field = array_pop(explode('_', $act, 2)); if ('move' == $act) { new ActiveGrid($this->application, $filter, $this->getClassName()); $cat = Category::getInstanceById($this->request->get('categoryID'), Category::LOAD_DATA); $update = new ARUpdateFilter(); $update->setCondition($filter->getCondition()); $update->addModifier('Product.categoryID', $cat->getID()); $update->joinTable('ProductPrice', 'Product', 'productID AND (ProductPrice.currencyID = "' . $this->application->getDefaultCurrencyCode() . '")', 'ID'); ActiveRecord::beginTransaction(); ActiveRecord::updateRecordSet('Product', $update, Product::LOAD_REFERENCES); Category::recalculateProductsCount(); ActiveRecord::commit(); return new JSONResponse(array('act' => $this->request->get('act')), 'success', $this->translate('_move_succeeded')); } // remove design themes if ('theme' == $act && !$this->request->get('theme')) { ClassLoader::import('application.model.presentation.CategoryPresentation'); ActiveRecord::deleteRecordSet('CategoryPresentation', new ARDeleteFilter($filter->getCondition()), null, array('Product', 'Category')); return new JSONResponse(array('act' => $this->request->get('act')), 'success', $this->translate('_themes_removed')); } $params = array(); if ('manufacturer' == $act) { $params['manufacturer'] = Manufacturer::getInstanceByName($this->request->get('manufacturer')); } else { if ('price' == $act || 'inc_price' == $act) { $params['baseCurrency'] = $this->application->getDefaultCurrencyCode(); $params['price'] = $this->request->get($act); $params['currencies'] = $this->application->getCurrencySet(); $params['inc_price_value'] = $this->request->get('inc_price_value'); $params['inc_quant_price'] = $this->request->get('inc_quant_price'); } else { if ('addRelated' == $act) { $params['relatedProduct'] = Product::getInstanceBySKU($this->request->get('related')); if (!$params['relatedProduct']) { return new JSONResponse(0); } } else { if ($this->request->get('categoryID')) { $params['category'] = Category::getInstanceById($this->request->get('categoryID'), Category::LOAD_DATA); } else { if ('theme' == $act) { ClassLoader::import('application.model.presentation.CategoryPresentation'); $params['theme'] = $this->request->get('theme'); } else { if ('shippingClass' == $act) { $params['shippingClass'] = $this->request->get('shippingClass'); } else { if ('taxClass' == $act) { $params['taxClass'] = $this->request->get('taxClass'); } } } } } } } $response = parent::processMass($params); if ($this->request->get('categoryID')) { Category::recalculateProductsCount(); } return $response; }
private function getCategory(CsvImportProfile $profile, $record) { $fields = $this->getSortedFields($profile); // detect product category if (isset($fields['Product']['parentID']) && !empty($record[$fields['Product']['parentID']])) { $cat = Product::getInstanceByID($record[$fields['Product']['parentID']], true); } else { if (isset($fields['Parent']['parentSKU']) && !empty($record[$fields['Parent']['parentSKU']])) { $cat = Product::getInstanceBySKU($record[$fields['Parent']['parentSKU']]); } else { if (isset($fields['Category']['ID'])) { try { $cat = Category::getInstanceById($record[$fields['Category']['ID']], Category::LOAD_DATA); } catch (ARNotFoundException $e) { $failed++; continue; } } else { if (isset($fields['Categories']['Categories'])) { $index = $fields['Categories']['Categories']; $categories = explode('; ', $record[$index]); $cat = $this->getCategoryByPath($profile, array_shift($categories)); $extraCategories = $categories; } else { if (isset($fields['Category'])) { $path = array(); foreach ($fields['Category'] as $level => $csvIndex) { if ($record[$csvIndex]) { $path[] = $record[$csvIndex]; } } $cat = $this->getCategoryByPath($profile, $path); } else { return $this->getRoot($profile); } } } } } return $cat; }
protected function getCategory() { if (!$this->category) { $this->category = Category::getInstanceById($this->request->get('id', 1), Category::LOAD_DATA); } return $this->category; }
function testDigitalItemsAddedThroughShipment() { $order = CustomerOrder::getNewInstance($this->user); $price = 400; $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test3'); $product->save(); $product->setPrice('USD', $price); $product->type->set(Product::TYPE_DOWNLOADABLE); $product->isEnabled->set(true); $product->save(); $order->addProduct($product, 1); $item = array_shift($order->getItemsByProduct($product)); $shipment = Shipment::getNewInstance($order); $shipment->addItem($item); $order->save(); $shipment->recalculateAmounts(); $shipment->save(); $order->save(); $order->finalize(); $this->assertEqual($order->getSubTotal($this->usd), $price); ActiveRecord::clearPool(); $loadedOrder = CustomerOrder::getInstanceById($order->getID()); $loadedOrder->loadAll(); $this->assertEqual($loadedOrder->getSubTotal($this->usd), $price); }
public function getNextProduct() { if (!$this->productSql) { $fields = array($this->getTablePrefix() . 'products.*'); $join = array(); foreach ($this->attributes as $attr) { $join[] = 'LEFT JOIN ' . $this->getTablePrefix() . 'product_options_values AS extra_' . $attr['optionID'] . ' ON (extra_' . $attr['optionID'] . '.productID=' . $this->getTablePrefix() . 'products.productID AND extra_' . $attr['optionID'] . '.optionID=' . $attr['optionID'] . ')'; $fields[] = 'extra_' . $attr['optionID'] . '.option_value AS extrafield_' . $attr['optionID']; } $validCats = implode(',', $this->categoryIds); $this->productSql = 'SELECT ' . implode(',', $fields) . ' FROM ' . $this->getTablePrefix() . 'products ' . implode(' ', $join) . ' LEFT JOIN ' . $this->getTablePrefix() . 'categories AS cat ON cat.categoryID=' . $this->getTablePrefix() . 'products.categoryID WHERE cat.categoryID IS NOT NULL AND cat.categoryID IN (' . $validCats . ')'; } if (!($data = $this->loadRecord($this->productSql))) { return null; } $rec = Product::getNewInstance(Category::getInstanceById($this->getRealId('Category', $data['categoryID']))); $rec->setID($data['productID']); $rec->keywords->set($data['meta_keywords']); $rec->setValueByLang('name', $this->defLang, $data['name']); $rec->setValueByLang('longDescription', $this->defLang, $data['description']); $rec->setValueByLang('shortDescription', $this->defLang, $data['brief_description']); foreach ($this->attributes as $attr) { if (!empty($data['extrafield_' . $attr['optionID']])) { $rec->setAttributeValueByLang(SpecField::getInstanceByID($this->getRealId('SpecField', $attr['optionID']), SpecField::LOAD_DATA), $this->defLang, $data['extrafield_' . $attr['optionID']]); } } $data['voteSum'] = round($data['customers_rating'] * $data['customer_votes']); if ($data['product_code']) { $rec->sku->set($data['product_code']); } foreach (array('shippingWeight' => 'weight', 'stockCount' => 'in_stock', 'shippingSurchargeAmount' => 'shipping_freight', 'minimumQuantity' => 'min_order_amount', 'dateCreated' => 'date_added', 'ratingSum' => 'voteSum', 'rating' => 'customers_rating', 'ratingCount' => 'customer_votes') as $lc => $xc) { $rec->{$lc}->set($data[$xc]); } $rec->isEnabled->set(1 == $data['enabled']); $rec->setPrice($this->getDefaultCurrency(), $data['Price']); if ($data['list_price']) { $price = $rec->getPricingHandler()->getPriceByCurrencyCode($this->getDefaultCurrency()); $price->listPrice->set($data['list_price']); } // images foreach ($this->getDataBySQL('SELECT * FROM ' . $this->getTablePrefix() . 'product_pictures WHERE productID=' . $data['productID'] . ' ORDER BY (photoID=' . (int) $data['default_picture'] . '), photoID ASC') as $image) { $file = $image['enlarged'] ? $image['enlarged'] : $image['filename']; $this->importProductImage($rec, $this->path . '/products_pictures/' . $file); } $rec->rawData = $data; return $rec; }
protected function initOrder() { // set up currency $this->setUpCurrency(); $this->usd->decimalCount->set(2); $this->usd->clearRoundingRules(); $this->usd->save(); // initialize order ActiveRecordModel::executeUpdate('DELETE FROM User WHERE email="*****@*****.**"'); $user = User::getNewInstance('*****@*****.**'); $user->save(); $this->user = $user; $address = UserAddress::getNewInstance(); $address->countryID->set('US'); $state = State::getInstanceById(1, State::LOAD_DATA); $address->state->set(State::getInstanceById(1)); $address->postalCode->set(90210); $address->save(); $billing = BillingAddress::getNewInstance($user, $address); $billing->save(); $address = clone $address; $address->save(); $shipping = ShippingAddress::getNewInstance($user, $address); $shipping->save(); $this->order = CustomerOrder::getNewInstance($user); $this->order->shippingAddress->set($shipping->userAddress->get()); $this->order->billingAddress->set($billing->userAddress->get()); // set up products $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test1'); $product->save(); $product->setPrice('USD', 100); $product->stockCount->set(20); $product->isEnabled->set(1); $product->save(); $this->products[] = $product; $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test2'); $product->save(); $product->setPrice('USD', 200); $product->stockCount->set(20); $product->isEnabled->set(1); $product->save(); $this->products[] = $product; $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test3'); $product->save(); $product->setPrice('USD', 400); $product->isSeparateShipment->set(true); $product->stockCount->set(20); $product->isEnabled->set(1); $product->save(); $this->products[] = $product; }