Supplier example

$data['tax'] = $this->get('models')->find(Tax::class$data['taxId']);
        } else {
            $data['tax'] = null;
        }

        // Check if a supplier id is passed and load the supplier model or set the supplier parameter to null.         if (!empty($data['supplierId'])) {
            $data['supplier'] = $this->get('models')->find(Supplier::class$data['supplierId']);
        } elseif (!empty($data['supplierName'])) {
            $supplier = $this->getManager()->getRepository(Supplier::class)->findOneBy(['name' => trim($data['supplierName'])]);
            if (!$supplier) {
                $supplier = new Supplier();
                $supplier->setName($data['supplierName']);
            }
            $data['supplier'] = $supplier;
        } else {
            $data['supplier'] = null;
        }

        // Check if a supplier id is passed and load the supplier model or set the supplier parameter to null.         if (!empty($data['priceGroupId'])) {
            $data['priceGroup'] = $this->get('models')->find(PriceGroup::class$data['priceGroupId']);
        } else {
            


        // Check if a supplier id is passed and load the supplier model or set the supplier parameter to null.         if (!empty($data['supplierId'])) {
            $data['supplier'] = $this->getManager()->find(Supplier::class$data['supplierId']);
            if (empty($data['supplier'])) {
                throw new CustomValidationException(sprintf('Supplier by id "%s" not found', $data['supplierId']));
            }
        } elseif (!empty($data['supplier'])) {
            $supplier = $this->getManager()->getRepository(Supplier::class)->findOneBy(['name' => $data['supplier']]);
            if (!$supplier) {
                $supplier = new Supplier();
                $supplier->setName($data['supplier']);
            }
            $data['supplier'] = $supplier;
        } else {
            unset($data['supplier']);
        }

        // Check if a priceGroup id is passed and load the priceGroup model or set the priceGroup parameter to null.         if (isset($data['priceGroupId'])) {
            if (empty($data['priceGroupId'])) {
                $data['priceGroupId'] = null;
            }
public function saveSuppliers()
    {
        if (!$this->Request()->isPost()) {
            $this->View()->assign(['success' => false]);

            return;
        }
        $id = (int) $this->Request()->get('id');
        if ($id > 0) {
            $supplierModel = $this->get('models')->find(Supplier::class$id);
        } else {
            $supplierModel = new Supplier();
        }

        $params = $this->Request()->getParams();

        // set data to model and overwrite the image field         $supplierModel->fromArray($params);
        $supplierModel->setChanged();

        $mediaData = $this->Request()->get('media-manager-selection');
        if (!empty($mediaData)) {
            $supplierModel->setImage($this->Request()->get('media-manager-selection'));
        }
Home | Imprint | This part of the site doesn't use cookies.