Super product attributes configuration 可配置商品如何设置子商品的库存
来源:互联网 发布:mac word 首选项 编辑:程序博客网 时间:2024/05/20 19:50
web\app\code\core\Mage\Catalog\Block\Product\View\Type\Configurable.php
/** * Composes configuration for js * * @return string */ public function getJsonConfig() { $attributes = array(); $options = array(); $store = $this->getCurrentStore(); $taxHelper = Mage::helper('tax'); $currentProduct = $this->getProduct(); $preconfiguredFlag = $currentProduct->hasPreconfiguredValues(); if ($preconfiguredFlag) { $preconfiguredValues = $currentProduct->getPreconfiguredValues(); $defaultValues = array(); } foreach ($this->getAllowProducts() as $product) { $productId = $product->getId(); foreach ($this->getAllowAttributes() as $attribute) { $productAttribute = $attribute->getProductAttribute(); $productAttributeId = $productAttribute->getId(); $attributeValue = $product->getData($productAttribute->getAttributeCode()); if (!isset($options[$productAttributeId])) { $options[$productAttributeId] = array(); } if (!isset($options[$productAttributeId][$attributeValue])) { $options[$productAttributeId][$attributeValue] = array(); } $options[$productAttributeId][$attributeValue][] = $productId; } } $this->_resPrices = array( $this->_preparePrice($currentProduct->getFinalPrice()) ); foreach ($this->getAllowAttributes() as $attribute) { $productAttribute = $attribute->getProductAttribute(); $attributeId = $productAttribute->getId(); $info = array( 'id' => $productAttribute->getId(), 'code' => $productAttribute->getAttributeCode(), 'label' => $attribute->getLabel(), 'options' => array() ); $optionPrices = array(); $prices = $attribute->getPrices(); if (is_array($prices)) { foreach ($prices as $value) { if(!$this->_validateAttributeValue($attributeId, $value, $options)) { continue; } $currentProduct->setConfigurablePrice( $this->_preparePrice($value['pricing_value'], $value['is_percent']) ); $currentProduct->setParentId(true); Mage::dispatchEvent( 'catalog_product_type_configurable_price', array('product' => $currentProduct) ); $configurablePrice = $currentProduct->getConfigurablePrice(); if (isset($options[$attributeId][$value['value_index']])) { $productsIndex = $options[$attributeId][$value['value_index']]; } else { $productsIndex = array(); }// 增加属性对应的库存数 $_product = Mage::getModel('catalog/product')->load($productsIndex); $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);// echo $stock->getQty();// echo $stock->getMinQty();// echo $stock->getMinSaleQty(); $Qty = sprintf('%d', $stock->getQty()); if($Qty){ $disabled = ""; $Qty = ' (Qty:'.$Qty.')'; }else{ $disabled = "disabled"; $Qty = " (Out of Stock)"; } $info['options'][] = array( 'id' => $value['value_index'], 'label' => $value['label'].$Qty, 'price' => $configurablePrice, 'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']), 'products' => $productsIndex, 'disabled' => $disabled, ); $optionPrices[] = $configurablePrice; } } /** * Prepare formated values for options choose */ foreach ($optionPrices as $optionPrice) { foreach ($optionPrices as $additional) { $this->_preparePrice(abs($additional-$optionPrice)); } } if($this->_validateAttributeInfo($info)) { $attributes[$attributeId] = $info; } // Add attribute default value (if set) if ($preconfiguredFlag) { $configValue = $preconfiguredValues->getData('super_attribute/' . $attributeId); if ($configValue) { $defaultValues[$attributeId] = $configValue; } } } $taxCalculation = Mage::getSingleton('tax/calculation'); if (!$taxCalculation->getCustomer() && Mage::registry('current_customer')) { $taxCalculation->setCustomer(Mage::registry('current_customer')); } $_request = $taxCalculation->getDefaultRateRequest(); $_request->setProductClassId($currentProduct->getTaxClassId()); $defaultTax = $taxCalculation->getRate($_request); $_request = $taxCalculation->getRateRequest(); $_request->setProductClassId($currentProduct->getTaxClassId()); $currentTax = $taxCalculation->getRate($_request); $taxConfig = array( 'includeTax' => $taxHelper->priceIncludesTax(), 'showIncludeTax' => $taxHelper->displayPriceIncludingTax(), 'showBothPrices' => $taxHelper->displayBothPrices(), 'defaultTax' => $defaultTax, 'currentTax' => $currentTax, 'inclTaxTitle' => Mage::helper('catalog')->__('Incl. Tax') ); $config = array( 'attributes' => $attributes, 'template' => str_replace('%s', '#{price}', $store->getCurrentCurrency()->getOutputFormat()), 'basePrice' => $this->_registerJsPrice($this->_convertPrice($currentProduct->getFinalPrice())), 'oldPrice' => $this->_registerJsPrice($this->_convertPrice($currentProduct->getPrice())), 'productId' => $currentProduct->getId(), 'chooseText' => Mage::helper('catalog')->__('Choose an Option...'), 'taxConfig' => $taxConfig ); if ($preconfiguredFlag && !empty($defaultValues)) { $config['defaultValues'] = $defaultValues; } $config = array_merge($config, $this->_getAdditionalConfig()); return Mage::helper('core')->jsonEncode($config); }
jweb\app\design\frontend\smartwave\granada\template\catalog\product\view\type\options\configurable.phtml
\web\js\varien\configurable.js
fillSelect: function(element){ var attributeId = element.id.replace(/[a-z]*/, ''); var options = this.getAttributeOptions(attributeId); this.clearSelect(element); element.options[0] = new Option('', ''); element.options[0].innerHTML = this.config.chooseText; var prevConfig = false; if(element.prevSetting){ prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex]; } if(options) { var index = 1; for(var i=0;i<options.length;i++){ var allowedProducts = []; if(prevConfig) { for(var j=0;j<options[i].products.length;j++){ if(prevConfig.config.allowedProducts && prevConfig.config.allowedProducts.indexOf(options[i].products[j])>-1){ allowedProducts.push(options[i].products[j]); } } } else { allowedProducts = options[i].products.clone(); } if(allowedProducts.size()>0){ options[i].allowedProducts = allowedProducts; element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id); if (typeof options[i].price != 'undefined') { element.options[index].setAttribute('price', options[i].price); } element.options[index].config = options[i]; if(options[i].disabled == 'disabled'){ //element.disabled = true; element.options[index].setAttribute('disabled', true); } console.log(options[i].disabled); index++; } } } },
阅读全文
0 0
- Super product attributes configuration 可配置商品如何设置子商品的库存
- 商品库存的基本概念
- 把库存的商品热销出去----zt
- 商品库存信息管理
- 商品库存管理
- 商品库存管理系统
- 商品库存管理
- 淘宝商品库存数据包
- zen-cart 如何增加一个可下载的商品
- 特定数量的商品如何在高并发下进行库存锁定 ?
- 特定数量的商品如何在高并发下进行库存锁定 ?
- 目录管理之可配置商品
- 购物并发之商品库存
- 实现商品库存信息管理页面
- 利润低的商品是否参与全场打折?如何设置?
- 用C语言编写的商品库存管理系统
- ecshop 点击商品图片弹出带关闭按钮的遮罩层 显示商品库存
- 商品
- python 中Wilcoxon rank-sum 和 R 中的 wilcox.test
- 操作系统页面置换算法之FIFO,LRU
- vrrp原理
- 内存泄露如何调试
- 详解数据挖掘与机器学习的区别与联系
- Super product attributes configuration 可配置商品如何设置子商品的库存
- 课上认真听讲,课后马上忘记怎么办?
- 程序中的this
- 解决IDEA中输入法迟钝、选词框不出现
- Redis集群的配置及使用
- Spring思维导图,让Spring不再难懂(mvc篇)
- arcgis engine 图形操作函数 (面切面)
- MIT《计算机科学数学》Introduction & Chaper01-Proofs
- 玲珑杯1144