该setIsInProcess($value)
方法是setData('is_in_process', $value)
相应模型的别名。您可以在父类Magento\Framework\Model\AbstractExtensibleModel
或Magento\Framework\Model\AbstractModel
. 魔术方法是在方法的父类(通常针对所有模型)Magento\Framework\DataObject
中实现的__call
:
/**
* Set/Get attribute wrapper
*
* @param string $method
* @param array $args
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function __call($method, $args)
{
switch (substr($method, 0, 3)) {
case 'get':
$key = $this->_underscore(substr($method, 3));
$index = isset($args[0]) ? $args[0] : null;
return $this->getData($key, $index);
case 'set':
$key = $this->_underscore(substr($method, 3));
$value = isset($args[0]) ? $args[0] : null;
return $this->setData($key, $value);
case 'uns':
$key = $this->_underscore(substr($method, 3));
return $this->unsetData($key);
case 'has':
$key = $this->_underscore(substr($method, 3));
return isset($this->_data[$key]);
}
throw new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase('Invalid method %1::%2', [get_class($this), $method])
);
}
在 magento 1 中使用了类似的东西,我建议你阅读Ryan Street 写的这篇文章
PS:它只用在一个地方:Magento\Sales\Model\ResourceModel\Order\Handler\State::check(Order $order)
第41行。我认为这与您的问题有关,因为这里的订单状态和状态正在更改为处理中。