Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace VendorModuleModel;
- use MagentoQuoteModelQuoteAddress;
- use MagentoRuleModelAbstractModel;
- class Rule extends AbstractModel
- {
- /**
- * Prefix of model events names
- *
- * @var string
- */
- protected $_eventPrefix = 'vendor_table';
- protected $_eventObject = 'rule';
- /** @var MagentoSalesRuleModelRuleConditionCombineFactory */
- protected $condCombineFactory;
- /** @var MagentoSalesRuleModelRuleConditionProductCombineFactory */
- protected $condProdCombineF;
- /**
- * Store already validated addresses and validation results
- *
- * @var array
- */
- protected $validatedAddresses = [];
- /**
- * @param MagentoFrameworkModelContext $context
- * @param MagentoFrameworkRegistry $registry
- * @param MagentoFrameworkDataFormFactory $formFactory
- * @param MagentoFrameworkStdlibDateTimeTimezoneInterface $localeDate
- * @param MagentoCatalogWidgetModelRuleConditionCombineFactory $condCombineFactory
- * @param MagentoCatalogWidgetModelRuleConditionProductCombineFactory $condProdCombineF
- * @param MagentoFrameworkModelResourceModelAbstractResource $resource
- * @param MagentoFrameworkDataCollectionAbstractDb $resourceCollection
- * @param array $data
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- */
- public function __construct(
- MagentoFrameworkModelContext $context,
- MagentoFrameworkRegistry $registry,
- MagentoFrameworkDataFormFactory $formFactory,
- MagentoFrameworkStdlibDateTimeTimezoneInterface $localeDate,
- MagentoCatalogWidgetModelRuleConditionCombineFactory $condCombineFactory,
- MagentoCatalogWidgetModelRuleConditionProductFactory $condProdCombineF,
- MagentoFrameworkModelResourceModelAbstractResource $resource = null,
- MagentoFrameworkDataCollectionAbstractDb $resourceCollection = null,
- array $data = []
- ) {
- $this->condCombineFactory = $condCombineFactory;
- $this->condProdCombineF = $condProdCombineF;
- parent::__construct($context, $registry, $formFactory, $localeDate, $resource, $resourceCollection, $data);
- }
- /**
- * Set resource model and Id field name
- *
- * @return void
- */
- protected function _construct()
- {
- parent::_construct();
- $this->_init('VendorModuleModelResourceModelRule');
- $this->setIdFieldName('profile_id');
- }
- /**
- * Get rule condition combine model instance
- *
- * @return MagentoSalesRuleModelRuleConditionCombine
- */
- public function getConditionsInstance()
- {
- return $this->condCombineFactory->create();
- }
- /**
- * Get rule condition product combine model instance
- *
- * @return MagentoSalesRuleModelRuleConditionProductCombine
- */
- public function getActionsInstance()
- {
- return $this->condProdCombineF->create();
- }
- /**
- * Check cached validation result for specific address
- *
- * @param Address $address
- * @return bool
- */
- public function hasIsValidForAddress($address)
- {
- $addressId = $this->_getAddressId($address);
- return isset($this->validatedAddresses[$addressId]) ? true : false;
- }
- /**
- * Set validation result for specific address to results cache
- *
- * @param Address $address
- * @param bool $validationResult
- * @return $this
- */
- public function setIsValidForAddress($address, $validationResult)
- {
- $addressId = $this->_getAddressId($address);
- $this->validatedAddresses[$addressId] = $validationResult;
- return $this;
- }
- /**
- * Get cached validation result for specific address
- *
- * @param Address $address
- * @return bool
- * @SuppressWarnings(PHPMD.BooleanGetMethodName)
- */
- public function getIsValidForAddress($address)
- {
- $addressId = $this->_getAddressId($address);
- return isset($this->validatedAddresses[$addressId]) ? $this->validatedAddresses[$addressId] : false;
- }
- /**
- * Return id for address
- *
- * @param Address $address
- * @return string
- */
- private function _getAddressId($address)
- {
- if ($address instanceof Address) {
- return $address->getId();
- }
- return $address;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement