PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php

https://gitlab.com/blingbang2016/shop
PHP | 133 lines | 81 code | 11 blank | 41 comment | 16 complexity | e0a012200dafa6ce8774edec6d90d65f MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_XmlConnect
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Bundle product options xml renderer
  28. *
  29. * @category Mage
  30. * @package Mage_XmlConnect
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_XmlConnect_Block_Catalog_Product_Options_Bundle extends Mage_XmlConnect_Block_Catalog_Product_Options
  34. {
  35. /**
  36. * Generate bundle product options xml
  37. *
  38. * @param Mage_Catalog_Model_Product $product
  39. * @param bool $isObject
  40. * @return string | Mage_XmlConnect_Model_Simplexml_Element
  41. */
  42. public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false)
  43. {
  44. $xmlModel = $this->getProductCustomOptionsXmlObject($product);
  45. $optionsXmlObj = $xmlModel->options;
  46. if (!$product->isSaleable()) {
  47. return $isObject ? $xmlModel : $xmlModel->asNiceXml();
  48. }
  49. if ($product->hasPreconfiguredValues()) {
  50. $optionData = $product->getPreconfiguredValues()->getData('bundle_option');
  51. }
  52. /**
  53. * Bundle options
  54. */
  55. $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product);
  56. $optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
  57. $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
  58. $product->getTypeInstance(true)->getOptionsIds($product), $product
  59. );
  60. $bundleOptions = $optionCollection->appendSelections($selectionCollection, false, false);
  61. if (!sizeof($bundleOptions)) {
  62. return $isObject ? $xmlModel : $xmlModel->asNiceXml();
  63. }
  64. foreach ($bundleOptions as $option) {
  65. $selections = $option->getSelections();
  66. $optionId = $option->getOptionId();
  67. if (empty($selections)) {
  68. continue;
  69. }
  70. $optionNode = $optionsXmlObj->addChild('option');
  71. $type = parent::OPTION_TYPE_SELECT;
  72. if ($option->isMultiSelection()) {
  73. $type = parent::OPTION_TYPE_CHECKBOX;
  74. }
  75. $code = 'bundle_option[' . $option->getId() . ']';
  76. if ($type == parent::OPTION_TYPE_CHECKBOX) {
  77. $code .= '[]';
  78. }
  79. $optionNode->addAttribute('code', $code);
  80. $optionNode->addAttribute('type', $type);
  81. $optionNode->addAttribute('label', $optionsXmlObj->escapeXml($option->getTitle()));
  82. if ($option->getRequired()) {
  83. $optionNode->addAttribute('is_required', 1);
  84. }
  85. foreach ($selections as $selection) {
  86. if (!$selection->isSaleable()) {
  87. continue;
  88. }
  89. $qty = null;
  90. if ($product->hasPreconfiguredValues()) {
  91. $qty = $product->getPreconfiguredValues()->getData("bundle_option_qty/{$optionId}");
  92. }
  93. if (null === $qty) {
  94. $qty = !($selection->getSelectionQty() * 1) ? '1' : $selection->getSelectionQty() * 1;
  95. }
  96. $valueNode = $optionNode->addChild('value');
  97. $valueNode->addAttribute('code', $selection->getSelectionId());
  98. $valueNode->addAttribute('label', $optionsXmlObj->escapeXml($selection->getName()));
  99. if (!$option->isMultiSelection()) {
  100. if ($selection->getSelectionCanChangeQty()) {
  101. $valueNode->addAttribute('is_qty_editable', 1);
  102. }
  103. }
  104. $valueNode->addAttribute('qty', $qty);
  105. $price = $product->getPriceModel()->getSelectionPreFinalPrice($product, $selection);
  106. $price = Mage::helper('xmlconnect')->formatPriceForXml($price);
  107. if ((float)$price != 0.00) {
  108. $valueNode->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml(
  109. Mage::helper('core')->currency($price, false, false)
  110. ));
  111. $valueNode->addAttribute('formated_price', $this->_formatPriceString($price, $product));
  112. }
  113. if ($product->hasPreconfiguredValues()) {
  114. $this->_setCartSelectedValue($valueNode, $type, $this->_getPreconfiguredOption(
  115. $optionData, $optionId, $selection->getSelectionId()
  116. ));
  117. }
  118. }
  119. }
  120. return $isObject ? $xmlModel : $xmlModel->asNiceXml();
  121. }
  122. }