From a2eabeb8d25c9db96a06d1e753e08005cc8e998d Mon Sep 17 00:00:00 2001 From: Anthony Bates Date: Mon, 7 Oct 2024 10:18:56 +0100 Subject: [PATCH] Update Node.php Add Resource Model to __construct so that the connection table name comes through with any prefixes --- Model/ResourceModel/Menu/Node.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Model/ResourceModel/Menu/Node.php b/Model/ResourceModel/Menu/Node.php index 8f0609fd..fdfe8b77 100644 --- a/Model/ResourceModel/Menu/Node.php +++ b/Model/ResourceModel/Menu/Node.php @@ -8,17 +8,21 @@ use Magento\Framework\Model\ResourceModel\Db\AbstractDb; use Magento\Framework\Model\ResourceModel\Db\Context; use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\App\ResourceConnection; class Node extends AbstractDb { protected $serializer; + protected $resource; public function __construct( Context $context, SerializerInterface $serializer, + ResourceConnection $resource, $connectionName = null ) { $this->serializer = $serializer; + $this->resource = $resource; parent::__construct($context, $connectionName); } @@ -29,8 +33,9 @@ protected function _construct() protected function _afterSave(AbstractModel $object) { - $connection = $this->getConnection(); - $connection->delete('snowmenu_customer', ['node_id = ?' => $object->getNodeId()]); + $connection = $this->resource->getConnection(); + $tableName = $this->resource->getTableName('snowmenu_customer'); + $connection->delete($tableName, ['node_id = ?' => $object->getNodeId()]); $nodeCustomerGroups = $object->getData('customer_groups'); if ($nodeCustomerGroups && is_string($nodeCustomerGroups)) { @@ -44,7 +49,7 @@ protected function _afterSave(AbstractModel $object) ]; } if ($nodeCustomerGroups) { - $connection->insertMultiple('snowmenu_customer', $insertData); + $connection->insertMultiple($tableName, $insertData); } return parent::_afterSave($object);