Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/Ecombricks/Inventory/Framework/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/Ecombricks/Inventory/Framework/Model/SourceTrait.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See LICENSE.txt for license details.
 */
namespace Ecombricks\Inventory\Framework\Model;

/**
 * Model source trait
 */
trait SourceTrait
{
    
    /**
     * Set source code
     * 
     * @param string $sourceCode
     * @return $this
     */
    public function setSourceCode($sourceCode)
    {
        if ($this->_getData('source_code') == $sourceCode) {
            return $this;
        }
        $this->beforeSetSourceCode($sourceCode);
        $this->_data['source_code'] = $sourceCode;
        $this->_hasDataChanges = true;
        foreach ($this->getSourceObjects() as $object) {
            $object->setSourceCode($sourceCode);
        }
        $this->afterSetSourceCode($sourceCode);
        return $this;
    }
    
    /**
     * Before set source code
     * 
     * @param string $sourceCode
     * @return $this
     */
    public function beforeSetSourceCode($sourceCode)
    {
        return $this;
    }
    
    /**
     * After set source code
     * 
     * @param string $sourceCode
     * @return $this
     */
    public function afterSetSourceCode($sourceCode)
    {
        $collection = $this->getCollection();
        if (empty($collection)) {
            return $this;
        }
        $collection->setSourceCode($sourceCode);
        return $this;
    }
    
    /**
     * Get source code
     * 
     * @return string
     */
    public function getSourceCode()
    {
        return $this->_getData('source_code');
    }
    
    /**
     * Unset source code
     * 
     * @return $this
     */
    public function unsSourceCode()
    {
        if (array_key_exists('source_code', $this->_data)) {
            unset($this->_data['source_code']);
            $this->_hasDataChanges = true;
        }
        return $this;
    }
    
    /**
     * Get source
     * 
     * @return \Magento\InventoryApi\Api\Data\SourceInterface
     */
    public function getSource()
    {
        if ($this->hasData('source')) {
            return $this->getData('source');
        }
        $sourceCode = $this->getSourceCode();
        if ($sourceCode) {
            $source = $this->sourceManagement->getSource($sourceCode);
        } else {
            $source = null;
        }
        $this->setData('source', $source);
        return $source;
    }
    
    /**
     * Get source name
     * 
     * @return string
     */
    public function getSourceName()
    {
        $source = $this->getSource();
        return ($source) ? $source->getName() : null;
    }
    
    /**
     * Validate source code before save
     * 
     * @return $this
     * @throws \Magento\Framework\Exception\ValidatorException
     */
    public function validateSourceCodeBeforeSave()
    {
        $sourceCode = $this->getSourceCode();
        if (!$sourceCode) {
            return $this;
        }
        if (!$this->sourceManagement->validateSourceCode($sourceCode)) {
            throw new \Magento\Framework\Exception\ValidatorException(__('Invalid source code.'));
        }
        return $this;
    }
    
    /**
     * After load
     * 
     * @return $this
     */
    public function inventoryAfterLoad()
    {
        $this->_getResource()->loadSourceCode($this);
        return $this;
    }
    
    /**
     * Before save
     * 
     * @return $this
     */
    public function inventoryBeforeSave()
    {
        $this->validateSourceCodeBeforeSave();
        return $this;
    }
    
    /**
     * After save
     * 
     * @return $this
     */
    public function inventoryAfterSave()
    {
        $this->_getResource()->saveSourceCode($this);
        return $this;
    }
    
    /**
     * Before delete
     * 
     * @return $this
     */
    public function inventoryBeforeDelete()
    {
        $this->_getResource()->deleteSourceCode($this);
        return $this;
    }
    
}

Spamworldpro Mini