LiamMcArthur

Member Since 1 Year Ago

Experience Points
170
Total
Experience

4,830 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 1
170 XP
Apr
16
3 weeks ago
Activity icon

Replied to How To Combine Values Of Two Arrays Based On Quantity Value Into A Final Array

This is how the two arrays are saved in the database. I'm pulling both arrays and just need a method of creating a third array that contains the calculated versions based on quantities.

Activity icon

Replied to How To Combine Values Of Two Arrays Based On Quantity Value Into A Final Array

This is how the pricing tiers come through against each product so the only complication I have at the minute is determining a method of adding these two array values together based on the quantities between the two.

Activity icon

Replied to How To Combine Values Of Two Arrays Based On Quantity Value Into A Final Array

@abhijeet9920 unfortunately this won't work because I'm not just trying to merge the arrays, but total up the values. The problem is I need to programmatically calculate a final array based on the first two. For example, the 7th array item would end up being:

[
    "qty" => 5000,
    "price" => 2.7125 // 0.2625 + 2.45
]

because it would grab 0.2625 from the 5000 array and then find the tier value from the second array, in this case it would grab it from the 1000 quantity array.

Here's an example of how the 250 array would become:

[
    "qty" => 250,
    "price" => 2.875 // 0.325 + 2.55
]

It needs to understand how to determine the values between the two tiers. The two tiers might not necessarily always contain the exact quantity fields - so the script needs to understand how to determine the value either matches the tier or is between it and the prev or next one depending on the quantity. I hope this makes sense. It's pretty difficult to explain!

Activity icon

Started a new Conversation How To Combine Values Of Two Arrays Based On Quantity Value Into A Final Array

I'm currently working on a tier pricing system in PHP. A product can have a price, but it also has an additional printing tier price attached to it. For example:

Product price:

array:10 [▼
  0 => array:2 [▼
    "qty" => 1
    "price" => 0.5125
  ]
  1 => array:2 [▼
    "qty" => 50
    "price" => 0.4
  ]
  2 => array:2 [▼
    "qty" => 100
    "price" => 0.35
  ]
  3 => array:2 [▼
    "qty" => 250
    "price" => 0.325
  ]
  4 => array:2 [▼
    "qty" => 500
    "price" => 0.3
  ]
  5 => array:2 [▼
    "qty" => 1000
    "price" => 0.275
  ]
  6 => array:2 [▼
    "qty" => 2500
    "price" => 0.2625
  ]
  7 => array:2 [▼
    "qty" => 5000
    "price" => 0.2625
  ]
  8 => array:2 [▼
    "qty" => 10000
    "price" => 0.2625
  ]
  9 => array:2 [▼
    "qty" => 20000
    "price" => 0.25
  ]
]

Products print price:

array:4 [▼
  0 => array:2 [▼
    "qty" => 1
    "price" => 2.625
  ]
  1 => array:2 [▼
    "qty" => 250
    "price" => 2.55
  ]
  2 => array:2 [▼
    "qty" => 500
    "price" => 2.5
  ]
  3 => array:2 [▼
    "qty" => 1000
    "price" => 2.45
  ]
]

How can I go about returning a final array that combines the price values should the quantity from the other array fall in that tier? For example, the final array should contain all 10 array items from the main product array, but should add the prices into each matching one from the print price array if the quantity is between that and its next item.

The final resulting array would be:

array:10 [▼
  0 => array:2 [▼
    "qty" => 1
    "price" => 3.1375
  ]
  1 => array:2 [▼
    "qty" => 50
    "price" => 3.025
  ]
  2 => array:2 [▼
    "qty" => 100
    "price" => 2.975
  ]
  3 => array:2 [▼
    "qty" => 250
    "price" => 2.875
  ]
  4 => array:2 [▼
    "qty" => 500
    "price" => 2.8
  ]
  5 => array:2 [▼
    "qty" => 1000
    "price" => 2.7125
  ]
  6 => array:2 [▼
    "qty" => 2500
    "price" => 2.7125
  ]
  7 => array:2 [▼
    "qty" => 5000
    "price" => 2.7125
  ]
  8 => array:2 [▼
    "qty" => 10000
    "price" => 2.7125

  ]
  9 => array:2 [▼
    "qty" => 20000
    "price" => 2.7
  ]
]

So far, I'm trying to achieve this with a nested loop:

$productPrintTiers = get_price_tiers_by_product($variantPrice, $supplier);
$productTiers = get_price_tiers_by_product($productPrice, $supplier);
$finalTiers = [];
$i = 0;

foreach ($productTiers as $tier) {
    foreach ($productPrintTiers as $printTier) {
        if ($tier['qty'] >= $printTier['qty']) {
            $finalTiers[$i] = [
                'qty' => $tier['qty'],
                'price' => ($tier['price'] + $printTier['price'])
            ];
        }
        $i++;
    }
}

but weirdly, some of the values are calculating correctly and some aren't. I suspect it's something to do with my if statement check, but I'm a little stuck on working out the logic?

Is there a nice way I could achieve this possibly using Laravel collections?

Mar
17
1 month ago
Activity icon

Replied to Laravel Sail Zsh Alias Not Working

I managed to get this working in zshrc by adding the following:

alias sail="bash ./vendor/bin/sail"