public function testAvailability() { $this->config->setRuntime('INVENTORY_TRACKING', 'DISABLE'); $product1 = Product::getNewInstance($this->root); $product1->save(); $product2 = Product::getNewInstance($this->root); $product2->save(); ProductBundle::getNewInstance($this->container, $product1)->save(); ProductBundle::getNewInstance($this->container, $product2)->save(); // bundle container not enabled $this->assertFalse($this->container->isAvailable()); $this->container->isEnabled->set(true); $this->assertTrue($this->container->isAvailable()); // turn on inventory tracking $this->config->setRuntime('INVENTORY_TRACKING', 'ENABLE_AND_HIDE'); $product1->stockCount->set(2); $product1->save(); $product2->stockCount->set(2); $product2->save(); $this->assertTrue($this->container->isAvailable()); // remove inventory for one product $product2->stockCount->set(0); $product2->save(); $this->assertFalse($this->container->isAvailable()); }
public function index() { $productID = (int) $this->request->get('id'); $product = Product::getInstanceByID($productID, ActiveRecord::LOAD_DATA); $response = new ActionResponse(); $response->set('ownerID', $productID); $response->set('categoryID', $product->category->get()->getID()); $response->set('items', ProductBundle::getBundledProductArray($product)); $currency = $this->application->getDefaultCurrency(); $response->set('total', $currency->getFormattedPrice(ProductBundle::getTotalBundlePrice($product, $currency))); return $response; }
public function getBundledProducts() { if (is_null($this->bundledProducts)) { ClassLoader::import('application.model.product.ProductBundle'); $this->bundledProducts = ProductBundle::getBundledProductSet($this); } return $this->bundledProducts; }
$focus->billing_account_id = $row['id']; $focus->name = str_replace('[account name]', $row['name'], $focus->name); $focus->billing_address_street = $row['billing_address_street']; $focus->billing_address_city = $row['billing_address_city']; $focus->billing_address_state = $row['billing_address_state']; $focus->billing_address_country = $row['billing_address_country']; $focus->billing_address_postalcode = $row['billing_address_postalcode']; $focus->shipping_address_street = $row['shipping_address_street']; $focus->shipping_address_city = $row['shipping_address_city']; $focus->shipping_address_state = $row['shipping_address_state']; $focus->shipping_address_country = $row['shipping_address_country']; $focus->shipping_address_postalcode = $row['shipping_address_postalcode']; break; } foreach ($quote['bundle_data'] as $bundle_key => $bundle) { $pb = new ProductBundle(); $pb->team_id = $focus->team_set_id; $pb->team_set_id = $focus->team_set_id; $pb->currency_id = $focus->currency_id; $pb->bundle_stage = $bundle['bundle_stage']; $pb->name = $bundle['bundle_name']; $product_bundle_id = $pb->save(); //Save the products foreach ($bundle['products'] as $product_key => $products) { $sql = 'SELECT * FROM product_templates WHERE name = \'' . $products['name'] . '\''; $result = $GLOBALS['db']->query($sql); while ($row = $GLOBALS['db']->fetchByAssoc($result)) { $product = new Product(); foreach ($product->column_fields as $field) { if (isset($row[$field])) { $product->{$field} = $row[$field];
public function index() { $this->loadLanguageFile('Category'); $product = Product::getInstanceByID($this->request->get('id'), Product::LOAD_DATA, array('ProductImage', 'Manufacturer', 'Category')); $this->product = $product; if (!$product->isEnabled->get() || $product->parent->get()) { throw new ARNotFoundException('Product', $product->getID()); } $product->loadPricing(); $this->category = $product->getCategory(); $this->categoryID = $product->getCategory()->getID(); // get category path for breadcrumb $path = $product->category->get()->getPathNodeArray(); include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php'; include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.productUrl.php'; foreach ($path as $nodeArray) { $url = createCategoryUrl(array('data' => $nodeArray), $this->application); if ($nodeArray['isEnabled']) { $this->addBreadCrumb($nodeArray['name_lang'], $url); } } // add filters to breadcrumb CategoryController::getAppliedFilters(); // for root category products if (!isset($nodeArray)) { $nodeArray = array(); } $params = array('data' => $nodeArray, 'filters' => array()); foreach ($this->filters as $filter) { $f = $filter->toArray(); $params['filters'][] = $f; $url = createCategoryUrl($params, $this->application); $this->addBreadCrumb($f['name_lang'], $url); } $productArray = $product->toArray(); $handle = empty($productArray['URL']) ? $productArray['name_lang'] : $productArray['URL']; $this->redirect301($this->request->get('producthandle'), createHandleString($handle)); //ProductSpecification::loadSpecificationForProductArray($productArray); // filter empty attributes foreach ($productArray['attributes'] as $key => $attr) { if (empty($attr['value']) && empty($attr['values']) && empty($attr['value_lang'])) { unset($productArray['attributes'][$key]); } } // attribute summary $productArray['listAttributes'] = array(); foreach ($productArray['attributes'] as $key => $attr) { if ($attr['SpecField']['isDisplayedInList']) { $productArray['listAttributes'][] = $attr; } if (!$attr['SpecField']['isDisplayed']) { unset($productArray['attributes'][$key]); } } // add product title to breacrumb $this->addBreadCrumb($productArray['name_lang'], createProductUrl(array('product' => $productArray), $this->application)); // manufacturer filter if ($product->manufacturer->get()) { $manFilter = new ManufacturerFilter($product->manufacturer->get()->getID(), $product->manufacturer->get()->name->get()); } // get category page route end($this->breadCrumb); $last = prev($this->breadCrumb); $catRoute = $this->router->getRouteFromUrl($last['url']); $response = new ActionResponse(); $response->set('product', $productArray); $response->set('category', $productArray['Category']); $response->set('quantity', $this->getQuantities($product)); $response->set('currency', $this->request->get('currency', $this->application->getDefaultCurrencyCode())); $response->set('catRoute', $catRoute); // ratings if ($this->config->get('ENABLE_RATINGS')) { if ($product->ratingCount->get() > 0) { // rating summaries ClassLoader::import('application.model.product.ProductRatingSummary'); $response->set('rating', ProductRatingSummary::getProductRatingsArray($product)); } ClassLoader::import('application.model.category.ProductRatingType'); $ratingTypes = ProductRatingType::getProductRatingTypeArray($product); $response->set('ratingTypes', $ratingTypes); $response->set('ratingForm', $this->buildRatingForm($ratingTypes, $product)); $response->set('isRated', $this->isRated($product)); $response->set('isLoginRequiredToRate', $this->isLoginRequiredToRate()); $response->set('isPurchaseRequiredToRate', $this->isPurchaseRequiredToRate($product)); } // add to cart form $response->set('cartForm', $this->buildAddToCartForm($this->getOptions(), $this->getVariations())); // related products $related = $this->getRelatedProducts($product); // items purchased together $together = $product->getProductsPurchasedTogether($this->config->get('NUM_PURCHASED_TOGETHER'), true); $spec = array(); foreach ($related as $key => $group) { foreach ($related[$key] as $i => &$prod) { $spec[] =& $related[$key][$i]; } } foreach ($together as &$prod) { $spec[] =& $prod; } ProductSpecification::loadSpecificationForRecordSetArray($spec); $response->set('related', $related); $response->set('together', $together); if (isset($manFilter)) { $response->set('manufacturerFilter', $manFilter); } $response->set('variations', $this->getVariations()); // reviews if ($this->config->get('ENABLE_REVIEWS') && $product->reviewCount->get() && ($numReviews = $this->config->get('NUM_REVIEWS_IN_PRODUCT_PAGE'))) { $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('ProductReview', 'isEnabled'), true)); $f->setLimit($numReviews); $reviews = $product->getRelatedRecordSetArray('ProductReview', $f); $this->pullRatingDetailsForReviewArray($reviews); $response->set('reviews', $reviews); } // bundled products if ($product->isBundle()) { $bundleData = ProductBundle::getBundledProductArray($product); $bundledProducts = array(); foreach ($bundleData as &$bundled) { $bundledProducts[] =& $bundled['RelatedProduct']; } ProductPrice::loadPricesForRecordSetArray($bundledProducts); $response->set('bundleData', $bundleData); $currency = Currency::getInstanceByID($this->getRequestCurrency()); $total = ProductBundle::getTotalBundlePrice($product, $currency); $response->set('bundleTotal', $currency->getFormattedPrice($total)); $saving = $total - $product->getPrice($currency); $response->set('bundleSavingTotal', $currency->getFormattedPrice($saving)); $response->set('bundleSavingPercent', $total ? round($saving / $total * 100) : 0); } // contact form if ($this->config->get('PRODUCT_INQUIRY_FORM')) { $response->set('contactForm', $this->buildContactForm()); } // display theme if ($theme = CategoryPresentation::getThemeByProduct($product)) { if ($theme->getTheme()) { $this->application->setTheme($theme->getTheme()); } $response->set('presentation', $theme->toFlatArray()); } // product images $images = $product->getImageArray(); if ($theme && $theme->isVariationImages->get()) { if ($variations = $this->getVariations()) { foreach ($variations['products'] as $prod) { if (!empty($prod['DefaultImage']['ID'])) { $images[] = $prod['DefaultImage']; } } } } $response->set('images', $images); // discounted pricing $response->set('quantityPricing', $product->getPricingHandler()->getDiscountPrices($this->user, $this->getRequestCurrency())); $response->set('files', $this->getPublicFiles()); // additional categories $f = new ARSelectFilter(); $f->setOrder(new ARFieldHandle('Category', 'lft')); $f->mergeCondition(new EqualsCond(new ARFieldHandle('Category', 'isEnabled'), true)); $pathC = new OrChainCondition(); $pathF = new ARSelectFilter($pathC); $categories = array(); foreach ($product->getRelatedRecordSetArray('ProductCategory', $f, array('Category')) as $cat) { $categories[] = array($cat['Category']); $cond = new OperatorCond(new ARFieldHandle('Category', 'lft'), $cat['Category']['lft'], "<"); $cond->addAND(new OperatorCond(new ARFieldHandle('Category', 'rgt'), $cat['Category']['rgt'], ">")); $pathC->addAnd($cond); } if ($categories) { $pathF->setOrder(new ARFieldHandle('Category', 'lft'), 'DESC'); $pathF->mergeCondition(new EqualsCond(new ARFieldHandle('Category', 'isEnabled'), true)); foreach (ActiveRecordModel::getRecordSetArray('Category', $pathF, array('Category')) as $parent) { if (!$parent['isEnabled']) { continue; } foreach ($categories as &$cat) { if ($cat[0]['lft'] > $parent['lft'] && $cat[0]['rgt'] < $parent['rgt'] && $parent['ID'] > Category::ROOT_ID) { $cat[] = $parent; } } } foreach ($categories as &$cat) { $cat = array_reverse($cat); } $response->set('additionalCategories', $categories); } $response->set('enlargeProductThumbnailOnMouseOver', $this->config->get('_ENLARGE_PRODUCT_THUMBNAILS_ON') == 'P_THUMB_ENLARGE_MOUSEOVER'); return $response; }
public function countTabsItems() { ClassLoader::import('application.model.product.*'); $product = Product::getInstanceByID((int) $this->request->get('id'), ActiveRecord::LOAD_DATA); return new JSONResponse(array('tabProductBundle' => count(ProductBundle::getBundledProductArray($product)), 'tabProductRelationship' => $product->getRelationships(ProductRelationship::TYPE_CROSS)->getTotalRecordCount(), 'tabProductUpsell' => $product->getRelationships(ProductRelationship::TYPE_UP)->getTotalRecordCount(), 'tabProductFiles' => $product->getFiles(false)->getTotalRecordCount(), 'tabProductImages' => count($product->getImageArray()), 'tabProductOptions' => $product->getOptions()->getTotalRecordCount(), 'tabProductReviews' => $product->getRelatedRecordCount('ProductReview'), 'tabProductCategories' => $product->getRelatedRecordCount('ProductCategory') + 1, 'tabProductVariations' => $product->getRelatedRecordCount('Product', new ARSelectFilter(new EqualsCond(new ARFieldHandle('Product', 'isEnabled'), true))))); }
public function testDownloadableBundle() { $container = Product::getNewInstance(Category::getRootNode()); $container->isEnabled->set(true); $container->type->set(Product::TYPE_BUNDLE); $container->setPrice($this->usd, 100); $container->save(); foreach ($this->products as $product) { $product->type->set(Product::TYPE_DOWNLOADABLE); ProductBundle::getNewInstance($container, $product)->save(); } $order = CustomerOrder::getNewInstance($this->user); $order->addProduct($container, 1); $order->save(); $order->finalize(); $this->assertEqual($order->getShipments()->size(), 1); $this->assertFalse($order->getShipments()->get(0)->isShippable()); }
$focus->name = str_replace('[account name]', $row['name'], $focus->name); $focus->billing_address_street = $row['billing_address_street']; $focus->billing_address_city = $row['billing_address_city']; $focus->billing_address_state = $row['billing_address_state']; $focus->billing_address_country = $row['billing_address_country']; $focus->billing_address_postalcode = $row['billing_address_postalcode']; $focus->shipping_address_street = $row['shipping_address_street']; $focus->shipping_address_city = $row['shipping_address_city']; $focus->shipping_address_state = $row['shipping_address_state']; $focus->shipping_address_country = $row['shipping_address_country']; $focus->shipping_address_postalcode = $row['shipping_address_postalcode']; break; } $focus->save(); foreach ($quote['bundle_data'] as $bundle_key => $bundle) { $pb = new ProductBundle(); $pb->team_id = $focus->team_set_id; $pb->team_set_id = $focus->team_set_id; $pb->currency_id = $focus->currency_id; $pb->base_rate = $focus->base_rate; $pb->bundle_stage = $bundle['bundle_stage']; $pb->name = $bundle['bundle_name']; $pb->shipping = '0.00'; $product_bundle_id = $pb->save(); //Save the products foreach ($bundle['products'] as $product_key => $products) { $sql = 'SELECT * FROM product_templates WHERE name = \'' . $products['name'] . '\''; $result = $GLOBALS['db']->query($sql); while ($row = $GLOBALS['db']->fetchByAssoc($result)) { $product = new Product(); foreach ($product->column_fields as $field) {
private function getTotal(Product $product) { $currency = $this->application->getDefaultCurrency(); return $currency->getFormattedPrice(ProductBundle::getTotalBundlePrice($product, $currency)); }