0

I am trying to call a method from a class, but its not working

namespace Vendor\RetailOps\Service;

/**
 * Shipment class.
 *
 */
abstract class Shipment implements \Vendor\RetailOps\Api\Shipment\ShipmentInterface
{
   /**
     * @param $order
     */
    public function createShipment(\Magento\Sales\Api\Data\OrderInterface $order)
    {
        echo'check'; exit;
    }

    use Magento\Framework\App\Bootstrap;
    require __DIR__ . '/../app/bootstrap.php';
    $bootstrap     = Bootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();
    $state         = $objectManager->get('Magento\Framework\App\State');
    $state->setAreaCode('frontend');
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $orderid = 940;
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $order = $objectManager->create('Magento\Sales\Api\Data\OrderInterface')->load($orderid);
    echo  $objectManager->create('Vendor\RetailOps\Service\Shipment')->createShipment($order);
6
  • is their any thing missing ? Commented Jul 30, 2021 at 10:16
  • Can you explain what you are try to do? Commented Jul 30, 2021 at 10:19
  • Yes, i have created a script, executing the script should call a method from an class (added code above). but it seems like method from a class is not getting executed. Commented Jul 30, 2021 at 10:20
  • echo $objectManager->create('Vendor\RetailOps\Service\Shipment')->createShipment($order); this createShipment method in class not getting executed Commented Jul 30, 2021 at 10:21
  • you class is abstrack, did you think that is working on this way? Commented Jul 30, 2021 at 10:21

1 Answer 1

1

Modify your class like this one.

namespace Vendor\RetailOps\Service;

class Shipment implements \Vendor\RetailOps\Api\Shipment\ShipmentInterface
{
    public function createShipment(\Magento\Sales\Api\Data\OrderInterface $order)
    {
            echo'check'; exit;
    }
}
6
  • I have tried it but its not working. Commented Jul 30, 2021 at 10:24
  • is compile needed ? Commented Jul 30, 2021 at 10:24
  • Just put the log on your function and then check and yes for safer side run all the magento commands one's. Commented Jul 30, 2021 at 10:26
  • ok thanks let me check Commented Jul 30, 2021 at 10:33
  • Thankyou, could you please give some advice why it was not working before & working now ? Commented Jul 30, 2021 at 10:42

Your Answer

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

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