Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Resource Connection to __construct so that the connection table name comes through with any prefixes #345

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading