Files
ltsecurityinc/app/code/JR/NetSuite/Model/ResourceModel/Location/Collection.php
T

42 lines
1.2 KiB
PHP
Executable File

<?php
namespace JR\NetSuite\Model\ResourceModel\Location;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use JR\NetSuite\Model\Location;
use JR\NetSuite\Model\ResourceModel\Location as LocationResource;
class Collection extends AbstractCollection
{
protected function _construct()
{
$this->_init(Location::class, LocationResource::class);
}
/**
* Insert or update based on UNIQUE combo 'key-processing'
* @param $key
* @param $value
*/
public function insertOrUpdate($item)
{
$connection = $this->getConnection();
try {
// Start a transaction
// $connection->beginTransaction();
// Insert new item or update existing one
$connection->insertOnDuplicate($this->getMainTable(), $item, ['data', 'status']);
// Commit the transaction
// $connection->commit();
} catch (\Exception $e) {
// Rollback the transaction in case of an error
$connection->rollBack();
throw new \Magento\Framework\Exception\LocalizedException(
__('Error in insertOrUpdate: %1', $e->getMessage()),
$e
);
}
}
}