PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php

https://gitlab.com/LisovyiEvhenii/ismextensions
PHP | 125 lines | 78 code | 13 blank | 34 comment | 5 complexity | 8cc2f695a23a15d167e02635204e5805 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_SalesRule
  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. class Mage_SalesRule_Model_Rule_Condition_Product_Subselect
  27. extends Mage_SalesRule_Model_Rule_Condition_Product_Combine
  28. {
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. $this->setType('salesrule/rule_condition_product_subselect')
  33. ->setValue(null);
  34. }
  35. public function loadArray($arr, $key='conditions')
  36. {
  37. $this->setAttribute($arr['attribute']);
  38. $this->setOperator($arr['operator']);
  39. parent::loadArray($arr, $key);
  40. return $this;
  41. }
  42. public function asXml($containerKey='conditions', $itemKey='condition')
  43. {
  44. $xml = '<attribute>'.$this->getAttribute().'</attribute>'
  45. . '<operator>'.$this->getOperator().'</operator>'
  46. . parent::asXml($containerKey, $itemKey);
  47. return $xml;
  48. }
  49. public function loadAttributeOptions()
  50. {
  51. $this->setAttributeOption(array(
  52. 'qty' => Mage::helper('salesrule')->__('total quantity'),
  53. 'base_row_total' => Mage::helper('salesrule')->__('total amount'),
  54. ));
  55. return $this;
  56. }
  57. public function loadValueOptions()
  58. {
  59. return $this;
  60. }
  61. public function loadOperatorOptions()
  62. {
  63. $this->setOperatorOption(array(
  64. '==' => Mage::helper('rule')->__('is'),
  65. '!=' => Mage::helper('rule')->__('is not'),
  66. '>=' => Mage::helper('rule')->__('equals or greater than'),
  67. '<=' => Mage::helper('rule')->__('equals or less than'),
  68. '>' => Mage::helper('rule')->__('greater than'),
  69. '<' => Mage::helper('rule')->__('less than'),
  70. '()' => Mage::helper('rule')->__('is one of'),
  71. '!()' => Mage::helper('rule')->__('is not one of'),
  72. ));
  73. return $this;
  74. }
  75. public function getValueElementType()
  76. {
  77. return 'text';
  78. }
  79. public function asHtml()
  80. {
  81. $html = $this->getTypeElement()->getHtml().
  82. Mage::helper('salesrule')->__("If %s %s %s for a subselection of items in cart matching %s of these conditions:", $this->getAttributeElement()->getHtml(), $this->getOperatorElement()->getHtml(), $this->getValueElement()->getHtml(), $this->getAggregatorElement()->getHtml());
  83. if ($this->getId() != '1') {
  84. $html .= $this->getRemoveLinkHtml();
  85. }
  86. return $html;
  87. }
  88. /**
  89. * validate
  90. *
  91. * @param Varien_Object $object Quote
  92. * @return boolean
  93. */
  94. public function validate(Varien_Object $object)
  95. {
  96. if (!$this->getConditions()) {
  97. return false;
  98. }
  99. // $value = $this->getValue();
  100. // $aggregatorArr = explode('/', $this->getAggregator());
  101. // $this->setValue((int)$aggregatorArr[0])->setAggregator($aggregatorArr[1]);
  102. $attr = $this->getAttribute();
  103. $total = 0;
  104. foreach ($object->getQuote()->getAllVisibleItems() as $item) {
  105. if (parent::validate($item)) {
  106. $total += $item->getData($attr);
  107. }
  108. }
  109. // $this->setAggregator(join('/', $aggregatorArr))->setValue($value);
  110. return $this->validateAttribute($total);
  111. }
  112. }