You need to add your variable as a property, like so:
class myClass
{
private $shippingMethod;
private function getMainDetails($order)
{
//This value is correctly being set from my order details in Magento
$this->shippingMethod = strtolower($order->getShippingDescription());
}
private function estimateDeliveryDate($orderCreatedDate)
{
if ($this->shippingMethod == 'saturday delivery')
{
echo 'Saturday Delivery';
} else {
echo 'Standard Delivery';
}
}
}
EDIT
However, a more solid approach at this would be something along these lines:
class DeliveryHandler
{
private $order;
public function __construct(Order $order)
{
$this->order = $order;
}
private function getDeliveryDateEstimate()
{
if ($this->order->getShippingMethod() == 'saturday delivery') {
return 'Saturday Delivery';
} else {
return 'Standard Delivery';
}
}
}
class Order
{
public function getShippingMethod()
{
return strtolower($this->getShippingDescription());
}
}
Few of things going on in that example.
I moved shippingMethod() into the Order class as it is not the DeliveryHandlers responsibility so it should not have to care about what's going on in that method. The data belongs to and comes from Order.
I made getDeliveryDateEstimate() return a string instead of using echo. This makes your code more reusable - eg what if one day you want to pass this to a template or another variable instead of echoing it. This way you keep your options open.
I'm using dependency injection to pass the Order class into the DeliveryHandler, thus making the public interface of Order available to DeliveryHandler.
If you happen to have a laracast subscription you could check out these courses here, they explain all this stuff in a nice digestible format:
https://laracasts.com/series/object-oriented-bootcamp-in-php
https://laracasts.com/series/solid-principles-in-php
getMainDetails(...)return$shippingMethod, and then pass it as an argument toestimateDeliveryDate(...)estimateDeliverDatemethod doesn't define the$shippingMethodvariable. If you save it to the object, other methods can use it.$this->shippingMethod = strotolower(...);, then inside your other functions do$this->shippingMethod == 'saturday delivery'