Skip to content

Commit

Permalink
Update Node.php
Browse files Browse the repository at this point in the history
Add Resource Model to __construct so that the connection table name comes through with any prefixes
  • Loading branch information
antbates91 authored Oct 7, 2024
1 parent 73681cd commit a2eabeb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Model/ResourceModel/Menu/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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)) {
Expand All @@ -44,7 +49,7 @@ protected function _afterSave(AbstractModel $object)
];
}
if ($nodeCustomerGroups) {
$connection->insertMultiple('snowmenu_customer', $insertData);
$connection->insertMultiple($tableName, $insertData);
}

return parent::_afterSave($object);
Expand Down

0 comments on commit a2eabeb

Please sign in to comment.