ionik Posted March 12, 2009 Share Posted March 12, 2009 Anyone have experience working with Magento, if so I got a few minor questions regarding this monstrosity of a e-commerce application Quote Link to comment https://forums.phpfreaks.com/topic/149167-magento/ Share on other sites More sharing options...
ionik Posted March 13, 2009 Author Share Posted March 13, 2009 Nvm I have figured the beast out If anyone was wondering what I was trying to do and know what Magento is I needed to remove any products from a dropdown menu configured with JSON for configurable products, as this feature is non-existant strangely ?? The solution was as follows, this does involve editing core files but it gets the job done ( nothing like a hack eh? ). In file app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php replace method getJsonConfig() with the following public function getJsonConfig() { $attributes = array(); $options = array(); $store = Mage::app()->getStore(); foreach ($this->getAllowProducts() as $product) { $productId = $product->getId(); $productInfo = Mage::getModel('catalog/product') ->setStoreId(Mage::app()->getStore()->getId()) ->load($productId); $productInfo->stock_item->getData('qty'); if ($productInfo->stock_item->getData('qty') > 5) { foreach ($this->getAllowAttributes() as $attribute) { $productAttribute = $attribute->getProductAttribute(); $attributeValue = $product->getData($productAttribute->getAttributeCode()); if (!isset($options[$productAttribute->getId()])) { $options[$productAttribute->getId()] = array(); } if (!isset($options[$productAttribute->getId()][$attributeValue])) { $options[$productAttribute->getId()][$attributeValue] = array(); } $options[$productAttribute->getId()][$attributeValue][] = $productId; } $this->_resPrices = array( $this->_preparePrice($this->getProduct()->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; } $info['options'][] = array( 'id' => $value['value_index'], 'label' => $value['label'], 'price' => $this->_preparePrice($value['pricing_value'], $value['is_percent']), 'products' => isset($options[$attributeId][$value['value_index']]) ? $options[$attributeId][$value['value_index']] : array(), ); $optionPrices[] = $this->_preparePrice($value['pricing_value'], $value['is_percent']); //$this->_registerAdditionalJsPrice($value['pricing_value'], $value['is_percent']); } } /** * 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; } } } } /*echo '<pre>'; print_r($this->_prices); echo '</pre>';die();*/ $_request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false); $_request->setProductClassId($this->getProduct()->getTaxClassId()); $defaultTax = Mage::getSingleton('tax/calculation')->getRate($_request); $_request = Mage::getSingleton('tax/calculation')->getRateRequest(); $_request->setProductClassId($this->getProduct()->getTaxClassId()); $currentTax = Mage::getSingleton('tax/calculation')->getRate($_request); $taxConfig = array( 'includeTax' => Mage::helper('tax')->priceIncludesTax(), 'showIncludeTax' => Mage::helper('tax')->displayPriceIncludingTax(), 'showBothPrices' => Mage::helper('tax')->displayBothPrices(), 'defaultTax' => $defaultTax, 'currentTax' => $currentTax, 'inclTaxTitle' => Mage::helper('catalog')->__('Incl. Tax'), ); $config = array( 'attributes' => $attributes, 'template' => str_replace('%s', '#{price}', $store->getCurrentCurrency()->getOutputFormat()), // 'prices' => $this->_prices, 'basePrice' => $this->_registerJsPrice($this->_convertPrice($this->getProduct()->getFinalPrice())), 'oldPrice' => $this->_registerJsPrice($this->_convertPrice($this->getProduct()->getPrice())), 'productId' => $this->getProduct()->getId(), 'chooseText' => Mage::helper('catalog')->__('Choose option...'), 'taxConfig' => $taxConfig, ); return Zend_Json::encode($config); } Quote Link to comment https://forums.phpfreaks.com/topic/149167-magento/#findComment-783965 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.