<?php
namespace FrontBundle\Services\ServicePortal;
use FrontBundle\Helper\PortalConstantHelper;
use FrontBundle\Services\ServicePortal\UserManagerService;
use Symfony\Component\Security\Http\EntryPoint\RetryAuthenticationEntryPoint;
use Pimcore\Model\DataObject;
use Pimcore\Controller\FrontendController;
use Symfony\Component\Templating\EngineInterface;
class SlipManagerService
{
protected $renderer;
public function __construct(EngineInterface $engineInterface)
{
$this->renderer = $engineInterface;
}
public function createSlip($orderId)
{
$orderObj = \Pimcore\Model\DataObject\ServiceOrder::getById($orderId);
if (empty($orderObj)) {
return false;
}
$packingSlipPdf = $this->createPackingSlipPdf($orderObj);
}
public function createPackingSlipPdf(\Pimcore\Model\DataObject\ServiceOrder $myObject)
{
$itemList = [];
$count = count($myObject->getChildren());
for ($i = 0; $i < $count; $i++) {
$itemList[$i]['orderID'] = $myObject->getId();
$itemList[$i]['prefix'] = $myObject->getChildren()[$i]->getAttachedParts()->getPrefix();
$itemList[$i]['factoryCode'] = $myObject->getChildren()[$i]->getAttachedParts()->getFactoryCode();
$itemList[$i]['description'] = $myObject->getChildren()[$i]->getAttachedParts()->getDescription();
$itemList[$i]['price'] = $myObject->getChildren()[$i]->getAttachedParts()->getPrice();
$itemList[$i]['availableQuantity'] = $myObject->getChildren()[$i]->getAttachedParts()->getAvailableQuantity();
$itemList[$i]['quantity'] = $myObject->getChildren()[$i]->getOrderedQuantity();
$itemList[$i]['postCode'] = $myObject->getPostCode();
$itemList[$i]['city'] = $myObject->getCity();
$itemList[$i]['country'] = $myObject->getCountry();
$itemList[$i]['street'] = $myObject->getStreet();
$itemList[$i]['streetNumber'] = $myObject->getStreetNumber();
$itemList[$i]['phoneNumber'] = $myObject->getPhoneNumber();
$itemList[$i]['mobileNumber'] = $myObject->getMobileNumber();
}
$pdfInstance = (\Pimcore\Web2Print\Processor::getInstance());
$pdfInstance->setOptions("--print-media-type --page-size A3 ");
$html = $this->renderer->render('/service-portal/admin/slipPdf.html.php', ["itemList" => $itemList]);
$pdf = $pdfInstance->getPdfFromString($html);
$asset = new \Pimcore\Model\Asset();
$asset->setFilename('sas' . uniqid() . '.pdf');
$parentFolder = \Pimcore\Model\Asset\Service::createFolderByPath(PortalConstantHelper::PACKING_SLIP_PDF_ASSET_FOLDER);
$asset->setParent($parentFolder);
$asset->setData($pdf);
$asset->save();
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter