Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. protected function _loadPrices()
  2. {
  3. if ($this->count()) {
  4. $pricings = array(
  5. 0 => array()
  6. );
  7.  
  8. if ($this->getHelper()->isPriceGlobal()) {
  9. $websiteId = 0;
  10. } else {
  11. $websiteId = (int)Mage::app()->getStore($this->getStoreId())->getWebsiteId();
  12. $pricing[$websiteId] = array();
  13. }
  14.  
  15. $select = $this->getConnection()->select()
  16. ->from(array('price' => $this->_priceTable))
  17. ->where('price.product_super_attribute_id IN (?)', array_keys($this->_items));
  18.  
  19. if ($websiteId > 0) {
  20. $select->where('price.website_id IN(?)', array(0, $websiteId));
  21. } else {
  22. $select->where('price.website_id = ?', 0);
  23. }
  24.  
  25. $query = $this->getConnection()->query($select);
  26.  
  27. while ($row = $query->fetch()) {
  28. $pricings[(int)$row['website_id']][] = $row;
  29. }
  30.  
  31. $values = array();
  32.  
  33. foreach ($this->_items as $item) {
  34. $productAttribute = $item->getProductAttribute();
  35. if (!($productAttribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract)) {
  36. continue;
  37. }
  38. $options = $productAttribute->getFrontend()->getSelectOptions();
  39.  
  40. $optionsByValue = array();
  41. foreach ($options as $option) {
  42. $optionsByValue[$option['value']] = $option['label'];
  43. }
  44.  
  45. $assProds = $this->getProduct()->getTypeInstance(true)
  46. ->getUsedProducts(array($productAttribute->getAttributeCode()), $this->getProduct());
  47.  
  48. foreach ($assProds
  49. as $associatedProduct) {
  50.  
  51. $optionValue = $associatedProduct->getData($productAttribute->getAttributeCode());
  52.  
  53. if (array_key_exists($optionValue, $optionsByValue)) {
  54. // If option available in associated product
  55. if (!isset($values[$item->getId() . ':' . $optionValue])) {
  56. // If option not added, we will add it.
  57. $values[$item->getId() . ':' . $optionValue] = array(
  58. 'product_super_attribute_id' => $item->getId(),
  59. 'value_index' => $optionValue,
  60. 'label' => $optionsByValue[$optionValue],
  61. 'default_label' => $optionsByValue[$optionValue],
  62. 'store_label' => $optionsByValue[$optionValue],
  63. 'is_percent' => 0,
  64. 'pricing_value' => null,
  65. 'use_default_value' => true
  66. );
  67. }
  68. }
  69. }
  70. }
  71.  
  72. foreach ($pricings[0] as $pricing) {
  73. // Addding pricing to options
  74. $valueKey = $pricing['product_super_attribute_id'] . ':' . $pricing['value_index'];
  75. if (isset($values[$valueKey])) {
  76. $values[$valueKey]['pricing_value'] = $pricing['pricing_value'];
  77. $values[$valueKey]['is_percent'] = $pricing['is_percent'];
  78. $values[$valueKey]['value_id'] = $pricing['value_id'];
  79. $values[$valueKey]['use_default_value'] = true;
  80. }
  81. }
  82.  
  83. if ($websiteId && isset($pricings[$websiteId])) {
  84. foreach ($pricings[$websiteId] as $pricing) {
  85. $valueKey = $pricing['product_super_attribute_id'] . ':' . $pricing['value_index'];
  86. if (isset($values[$valueKey])) {
  87. $values[$valueKey]['pricing_value'] = $pricing['pricing_value'];
  88. $values[$valueKey]['is_percent'] = $pricing['is_percent'];
  89. $values[$valueKey]['value_id'] = $pricing['value_id'];
  90. $values[$valueKey]['use_default_value'] = false;
  91. }
  92. }
  93. }
  94.  
  95. /* foreach ($values as $key => $row) {
  96. $val[$key] = $row['label'];
  97. $i++;
  98. }
  99. array_multisort($val, SORT_ASC, $values);
  100. */
  101.  
  102. $val = array_column($values, 'label');
  103. $val[0] = ""; // fix first row
  104. array_multisort($val, SORT_ASC, $values);
  105.  
  106. foreach ($values as $data) {
  107. $this->getItemById($data['product_super_attribute_id'])->addPrice($data);
  108. }
  109. }
  110. return $this;
  111. }
  112.  
  113. Color
  114. Blue
  115. Black
  116. Green
  117. Orange
  118. Red
  119. Yellow
  120. Size
  121. Large
  122. Small
  123.  
  124. Color
  125. Blue
  126. Black
  127. Green
  128. Orange
  129. Red
  130. Yellow
  131. Size
  132. Small
  133. Large
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement