1

I try to create my loyalty program, use this module https://github.com/brjupo/Magento_2.4_E.E._RewardPointsGrid

I copied the code, but I get an error after "bin/magento setup:upgrade" SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.magento_reward' doesn't exist

why i dont have a table magento_reward? How to finish a module? What is the best way to make a table? I will be grateful for help

 <?php

namespace Brjupo\RewardPointsReport\Setup\Patch\Schema;

use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\Framework\Setup\SchemaSetupInterface;


class CreateRewardPointsView implements SchemaPatchInterface
{

private $schemaSetup;


public function __construct(
SchemaSetupInterface $schemaSetup
){
$this->schemaSetup = $schemaSetup;
}


public function getAliases()
{
  return [];
}


public function apply()
{
$this->schemaSetup->startSetup();

$sql = "DROP VIEW IF EXISTS rewardpoints_report;";
$this->schemaSetup->getConnection()->query($sql);

$sql = "CREATE SQL SECURITY INVOKER VIEW rewardpoints_report AS
        (
        SELECT 
          reward_points_delta_expiration.history_id,
          customer_entity.firstname,
          customer_entity.lastname,
          customer_entity.email,
          reward_points_delta_expiration.points_delta,
          reward_points_delta_expiration.expired_at_static
        FROM
          customer_entity
        INNER JOIN
          ( SELECT 
              magento_reward_history.history_id,
              magento_reward.customer_id,
              magento_reward_history.points_delta,
              magento_reward_history.expired_at_static
            FROM
              magento_reward
            INNER JOIN magento_reward_history 
              ON magento_reward.reward_id = magento_reward_history.reward_id
          ) AS reward_points_delta_expiration 
        ON customer_entity.entity_id = reward_points_delta_expiration.customer_id
        ORDER BY reward_points_delta_expiration.history_id DESC
        );";

$this->schemaSetup->getConnection()->query($sql);
$this->schemaSetup->endSetup();


 return $this;
}
public static function getDependencies()
{
  return [];
}
}

1 Answer 1

2

That table is included in the Magento_Reward module which is only available in Adobe Commerce (Enterprise edition), and not available in Magento Open Source.

The module you mentioned depends on the Magento_Reward module to create Reward Points Grid. So you can't use that module to build the Reward Points module as you expected.

The best way to create a new table is using Declarative Schema, you can take a look at the Magento official document: https://developer.adobe.com/commerce/php/development/components/declarative-schema/configuration/

5
  • Patch schema not needed?
    – Miron
    Nov 21, 2022 at 13:54
  • What do you mean? If you run (release) your module for the first time, you should use db_schema.xml to create a table, the link I mentioned in my answer is talking about db_schema.xml file.
    – Tu Van
    Nov 21, 2022 at 13:58
  • If you modify your database table after that to apply a complex modification, then you should use Schema patches developer.adobe.com/commerce/php/development/components/…
    – Tu Van
    Nov 21, 2022 at 14:01
  • 1
    thanks for the explanation
    – Miron
    Nov 21, 2022 at 18:08
  • Glad to help. Cheers!
    – Tu Van
    Nov 21, 2022 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.