<?php
namespace Jabber\GenericBundle\EventListener;
use Carbon\Carbon;
use Pimcore\Event\Model\DataObjectEvent;
use Pimcore\Event\Model\ElementEventInterface;
use Pimcore\Model\DataObject\Product;
class SupplierData {
public function onPreUpdate (ElementEventInterface $e) {
if (!$e->hasArgument('isAutoSave')) {
if ($e instanceof DataObjectEvent) {
// do something with the object
$dataObject = $e->getObject();
if ($dataObject instanceof Product) {
if ($dataObject->getType() == "variant" && $dataObject->getProductLevel() == "STYLE") {
$dataObject = $this->StoreDefaultDate($dataObject, "WholesaleFabricSwatchDue");
$dataObject = $this->StoreDefaultDate($dataObject, "DipsDue");
$dataObject = $this->StoreDefaultDate($dataObject, "DipsApproved");
$dataObject = $this->StoreDefaultDate($dataObject, "TrimDue");
$dataObject = $this->StoreDefaultDate($dataObject, "TrimApproved");
$dataObject = $this->StoreDefaultDate($dataObject, "FabricDue");
$dataObject = $this->StoreDefaultDate($dataObject, "FabricApproved");
$dataObject = $this->StoreDefaultDate($dataObject, "FirstSampleDue");
$dataObject = $this->StoreDefaultDate($dataObject, "FirstSampleFitted");
$dataObject = $this->StoreDefaultDate($dataObject, "SecondSampleDue");
$dataObject = $this->StoreDefaultDate($dataObject, "SecondSampleFitted");
$dataObject = $this->StoreDefaultDate($dataObject, "SealSampleDue");
$dataObject = $this->StoreDefaultDate($dataObject, "SealApproved");
$dataObject = $this->StoreDefaultDate($dataObject, "GradeSampleDue");
$dataObject = $this->StoreDefaultDate($dataObject, "GradeSampleFitted");
$dataObject = $this->StoreDefaultDate($dataObject, "ColourSampleDue");
$dataObject = $this->StoreDefaultDate($dataObject, "CutDate");
$dataObject = $this->StoreDefaultDate($dataObject, "GoldSealDue");
$dataObject = $this->StoreDefaultDate($dataObject, "GoldSealApproved");
$dataObject = $this->StoreDefaultDate($dataObject, "ExpectedFactoryShippingDate");
}
}
}
}
}
private function StoreDefaultDate(Product $dataObject, $fieldName) {
$getterMethod = "get".$fieldName;
$setterMethod = "set".$fieldName;
if (method_exists($dataObject, $getterMethod)) {
if ($dataObject->$getterMethod() == "1970-01-01 00:00:00") {
$dataObject->$setterMethod(new Carbon("1970-01-01 01:00:00"));
} else if ($dataObject->$getterMethod() == "1970-01-00 00:00:00") {
$dataObject->$setterMethod(null);
}
}
return $dataObject;
}
}