Skip to content
This repository has been archived by the owner on Apr 30, 2023. It is now read-only.

Name vs Title #22

Closed
ppalmeida opened this issue Feb 26, 2018 · 3 comments
Closed

Name vs Title #22

ppalmeida opened this issue Feb 26, 2018 · 3 comments

Comments

@ppalmeida
Copy link
Contributor

Hi, guys.
I think I found a new small bug:

In HasSubscriptions trait, we're missing the "title" in subscriptions->create method:

return $this->subscriptions()->create([
            'name' => $subscription,
            'plan_id' => $plan->getKey(),
            'trial_ends_at' => $trial->getEndDate(),
            'starts_at' => $period->getStartDate(),
            'ends_at' => $period->getEndDate(),
        ]);

Then it leads to errors in Validation:

#validationErrors: Illuminate\Support\MessageBag {#818
      #messages: array:1 [
        "title" => array:1 [
          0 => "The title field is required."
        ]
      ]
      #format: ":message"
    }

I did not get the difference between "title" and "name". What's de difference in these properties and when should I use each one of those?

So, what I did was just this:

return $this->subscriptions()->create([
            'name' => $subscription,
            'title' => $subscription,
            'plan_id' => $plan->getKey(),
            'trial_ends_at' => $trial->getEndDate(),
            'starts_at' => $period->getStartDate(),
            'ends_at' => $period->getEndDate(),
        ]); 

And the tests are green until now. Could you check if it works well for you too?

Thank you.

@Omranic
Copy link
Member

Omranic commented Feb 27, 2018

Name: acts like the slug
Title: just normal text for object title
Fixed in 063d8b2

@Omranic Omranic closed this as completed Feb 27, 2018
@ppalmeida
Copy link
Contributor Author

ppalmeida commented Feb 28, 2018

Hi, @Omranic

The error with the "expected()" null point still happening. Even with your fix.

There was 1 error:

1) Tests\Feature\SusbscriptionTest::a_user_can_subscribe_to_plan
Error: Call to a member function expired() on null

/Users/pedropauloalmeida/WORK/PROJECTS/WAVEWEB/SPACE-ROCKET/space-rocket/vendor/rinvex/subscriptions/src/Models/PlanSubscription.php:510
/Users/pedropauloalmeida/WORK/PROJECTS/WAVEWEB/SPACE-ROCKET/space-rocket/tests/Feature/SusbscriptionTest.php:34

In PlanSubscription model, about line 499, I changed the method to this:

public function canUseFeature(string $featureName): bool
    {
        $featureValue = $this->getFeatureValue($featureName);

        // Debug: let's check if the plan exists and if it's features name are ok:
        $plan = \Rinvex\Subscriptions\Models\Plan::first();

        $sql = $this->usage()->byFeatureName($featureName)->toSql();
        $usage = $this->usage()->byFeatureName($featureName)->first();
        dd($featureName, $plan->features->pluck('name'), $usage, $sql);
        
        // .... and so on...
    }

The result of the DD is:

"news"
Illuminate\Support\Collection {#34
  #items: array:4 [
    0 => "news"
    1 => "communications"
    2 => "help"
    3 => "library"
  ]
}
null
"select * from `plan_subscription_usage` where `plan_subscription_usage`.`subscription_id` = ? and `plan_subscription_usage`.`subscription_id` is not null and `feature_id` = ?"

So:

  1. The $featureName is correct and exists in $plan->features.
  2. The line $usage is backing as NULL from the relationship. That is the problem!

The $plan is well defined. The $plan->subscriptions returns 1 subscription as expected. And the 4 $plan->features looks good.

But $usage still coming back as NULL.

@Omranic
Copy link
Member

Omranic commented Apr 4, 2018

Since the name and title conventions made some confusions, I've reverted them all to the original state: name for the name as we know it, and slug for the url-safe name identifier. Hope your issue is now fixed, if not feel free to open this or a new issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants