/**
  * @param null $customer
  * @return string|\yii\web\Response
  * @throws \yii\web\ServerErrorHttpException
  */
 public function actionCreate($customer = null)
 {
     $customer = intval($customer) > 0 ? Customer::findOne(['id' => intval($customer)]) : null;
     $contragent = Contragent::createEmptyContragent(null === $customer ? Customer::createEmptyCustomer() : $customer);
     if (true === \Yii::$app->request->isPost) {
         $data = \Yii::$app->request->post();
         if ($contragent->load($data) && $contragent->save()) {
             if (!empty($contragent->getPropertyGroup())) {
                 $contragent->getPropertyGroup()->appendToObjectModel($contragent);
                 $data[$contragent->getAbstractModel()->formName()] = isset($data['ContragentNew']) ? $data['ContragentNew'] : [];
             }
             $contragent->saveModelWithProperties($data);
             $contragent->refresh();
             $deliveryInformation = DeliveryInformation::createNewDeliveryInformation($contragent, false);
             return $this->redirect(Url::toRoute(['edit', 'id' => $contragent->id]));
         }
     }
     return $this->render('create', ['model' => $contragent]);
 }
Exemplo n.º 2
0
 /**
  * @return string|Response
  * @throws \yii\base\Exception
  * @throws \yii\web\ServerErrorHttpException
  */
 public function actionCreate()
 {
     $model = Order::create(false, false, true);
     $model->setScenario('backend');
     if (Yii::$app->request->isPost) {
         $data = Yii::$app->request->post();
         if ($model->load($data) && $model->validate()) {
             if (User::USER_GUEST === intval($model->user_id)) {
                 $model->customer_id = 0;
             } elseif (null === Customer::findOne(['user_id' => intval($model->user_id), 'id' => intval($model->customer_id)])) {
                 $model->customer_id = 0;
             }
             if (0 === intval($model->customer_id)) {
                 $customer = Customer::createEmptyCustomer(intval($model->user_id));
                 if ($customer->load($data) && $customer->save()) {
                     if (!empty($customer->getPropertyGroup())) {
                         $customer->getPropertyGroup()->appendToObjectModel($customer);
                         $data[$customer->getAbstractModel()->formName()] = isset($data['CustomerNew']) ? $data['CustomerNew'] : [];
                     }
                     $customer->saveModelWithProperties($data);
                     $customer->refresh();
                     $model->customer_id = $customer->id;
                 }
             } else {
                 $customer = Customer::findOne(['id' => $model->customer_id]);
             }
             if (0 === $model->contragent_id || null === Contragent::findOne(['id' => $model->contragent_id, 'customer_id' => $model->customer_id])) {
                 $contragent = Contragent::createEmptyContragent($customer);
                 if ($contragent->load($data) && $contragent->save()) {
                     if (!empty($contragent->getPropertyGroup())) {
                         $contragent->getPropertyGroup()->appendToObjectModel($contragent);
                         $data[$contragent->getAbstractModel()->formName()] = isset($data['ContragentNew']) ? $data['ContragentNew'] : [];
                     }
                     $contragent->saveModelWithProperties($data);
                     $contragent->refresh();
                     $model->contragent_id = $contragent->id;
                 }
             } else {
                 $contragent = Contragent::findOne(['id' => $model->contragent_id]);
             }
             if ($model->save()) {
                 OrderDeliveryInformation::createNewOrderDeliveryInformation($model, false);
                 DeliveryInformation::createNewDeliveryInformation($contragent, false);
                 return $this->redirect(Url::toRoute(['view', 'id' => $model->id]));
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
/** @var \app\properties\AbstractModel $abstractModel */
$abstractModel = $model->getAbstractModel();
$abstractModel->setArrayMode(false);
$_tpl = '<tr><th>%s</th><td>%s</td></tr>' . PHP_EOL;
$_html = '';
foreach ($abstractModel->attributes() as $attr) {
    $_html .= sprintf($_tpl, $abstractModel->getAttributeLabel($attr), $abstractModel->getPropertyValueByAttribute($attr));
}
echo $_html;
?>
            <tr><th colspan="2"><?php 
echo Yii::t('app', 'Delivery information');
?>
</th></tr>
            <?php 
$deliveryInformation = !empty($model->deliveryInformation) ? $model->deliveryInformation : ($model->isNewRecord ? \app\modules\shop\models\DeliveryInformation::createNewDeliveryInformation($model) : \app\modules\shop\models\DeliveryInformation::createNewDeliveryInformation($model, false));
?>
            <tr>
                <th><?php 
echo $deliveryInformation->getAttributeLabel('country_id');
?>
</th>
                <td><?php 
echo null !== $deliveryInformation->country ? Html::encode($deliveryInformation->country->name) : '';
?>
</td>
            </tr>
            <tr>
                <th><?php 
echo $deliveryInformation->getAttributeLabel('city_id');
?>
Exemplo n.º 4
0
 public static function handleStageDelivery(OrderStageEvent $event)
 {
     /** @var Order $order */
     $order = $event->eventData()['order'];
     /** @var Contragent $contragent */
     $contragent = $order->contragent;
     /** @var DeliveryInformation $deliveryInformation */
     $deliveryInformation = !empty($contragent->deliveryInformation) ? $contragent->deliveryInformation : DeliveryInformation::createNewDeliveryInformation($contragent);
     /** @var OrderDeliveryInformation $orderDeliveryInformation */
     $orderDeliveryInformation = !empty($order->orderDeliveryInformation) ? $order->orderDeliveryInformation : OrderDeliveryInformation::createNewOrderDeliveryInformation($order);
     $event->addEventData(['deliveryInformation' => $deliveryInformation, 'orderDeliveryInformation' => $orderDeliveryInformation]);
 }