| Conditions | 24 |
| Paths | > 20000 |
| Total Lines | 525 |
| Code Lines | 330 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 148 | protected function _prepareForm() |
||
| 149 | { |
||
| 150 | $subSellerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_SUB_SELLER_ID); |
||
| 151 | |||
| 152 | $subSellerType = (int) $this->_coreRegistry->registry(RegistryConstants::CURRENT_SUB_SELLER_TYPE); |
||
| 153 | |||
| 154 | try { |
||
| 155 | if ($subSellerId) { |
||
| 156 | $subSellerDataObject = $this->_subSellerRepository->get($subSellerId); |
||
| 157 | } |
||
| 158 | // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock |
||
| 159 | } catch (NoSuchEntityException $e) { |
||
| 160 | //sub seller not found// |
||
| 161 | } |
||
| 162 | |||
| 163 | $sessionFormValues = (array) $this->_coreRegistry->registry(RegistryConstants::CURRENT_SUB_SELLER_FORM_DATA); |
||
| 164 | $formData = isset($subSellerDataObject) |
||
| 165 | ? $this->_subSellerConverter->createArrayFromServiceObject($subSellerDataObject) |
||
| 166 | : []; |
||
| 167 | $formData = array_merge($formData, $sessionFormValues); |
||
| 168 | |||
| 169 | /** @var \Magento\Framework\Data\Form $form */ |
||
| 170 | $form = $this->_formFactory->create(); |
||
| 171 | $bankTypeAccount = $this->bankTypeAccount->toOptionArray(); |
||
| 172 | $dateFormat = $this->_localeDate->getDateFormatWithLongYear(); |
||
| 173 | $yesNo = $this->yesNo->toArray(); |
||
| 174 | |||
| 175 | $countries = $this->_country->toOptionArray(false, 'BR'); |
||
| 176 | unset($countries[0]); |
||
| 177 | |||
| 178 | if (!isset($formData['address_country_id'])) { |
||
| 179 | $formData['address_country_id'] = 'BR'; |
||
| 180 | } |
||
| 181 | |||
| 182 | $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter( |
||
| 183 | $formData['address_country_id'] |
||
| 184 | ); |
||
| 185 | |||
| 186 | $regions = $regionCollection->toOptionArray(); |
||
| 187 | |||
| 188 | if (isset($formData['type'])) { |
||
| 189 | $subSellerType = (int) $formData['type']; |
||
| 190 | } |
||
| 191 | |||
| 192 | $legend = $this->getShowLegend() ? __('Sub Seller') : ''; |
||
| 193 | $fieldset = $form->addFieldset( |
||
| 194 | 'base_fieldset', |
||
| 195 | ['legend' => $legend, 'class' => 'admin__scope-old form-inline'] |
||
| 196 | ); |
||
| 197 | |||
| 198 | if (isset($formData['id']) && $formData['id'] > 0) { |
||
| 199 | $fieldset->addField( |
||
| 200 | 'id', |
||
| 201 | 'hidden', |
||
| 202 | ['name' => 'id', 'value' => $formData['id']] |
||
| 203 | ); |
||
| 204 | } |
||
| 205 | |||
| 206 | if (isset($formData['status'])) { |
||
| 207 | if ($formData['status'] !== 1) { |
||
| 208 | $fieldset->addField( |
||
| 209 | 'status', |
||
| 210 | 'label', |
||
| 211 | [ |
||
| 212 | 'name' => 'status', |
||
| 213 | 'label' => __('Status'), |
||
| 214 | 'title' => __('Status'), |
||
| 215 | ] |
||
| 216 | ); |
||
| 217 | } else { |
||
| 218 | $fieldset->addField( |
||
| 219 | 'status', |
||
| 220 | 'hidden', |
||
| 221 | [ |
||
| 222 | 'name' => 'status', |
||
| 223 | 'label' => __('Status'), |
||
| 224 | 'title' => __('Status'), |
||
| 225 | ] |
||
| 226 | ); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | if (isset($formData['status_comment'])) { |
||
| 231 | $fieldset->addField( |
||
| 232 | 'status_comment', |
||
| 233 | 'label', |
||
| 234 | [ |
||
| 235 | 'name' => 'status', |
||
| 236 | 'label' => __('Status Comment'), |
||
| 237 | 'title' => __('Status Comment'), |
||
| 238 | ] |
||
| 239 | ); |
||
| 240 | } |
||
| 241 | |||
| 242 | if (isset($formData['created_at'])) { |
||
| 243 | $fieldset->addField( |
||
| 244 | 'created_at', |
||
| 245 | 'label', |
||
| 246 | [ |
||
| 247 | 'name' => 'created_at', |
||
| 248 | 'label' => __('Created At'), |
||
| 249 | 'title' => __('Status Comment'), |
||
| 250 | ] |
||
| 251 | ); |
||
| 252 | } |
||
| 253 | |||
| 254 | if (isset($formData['updated_at'])) { |
||
| 255 | $fieldset->addField( |
||
| 256 | 'updated_at', |
||
| 257 | 'label', |
||
| 258 | [ |
||
| 259 | 'name' => 'updated_at', |
||
| 260 | 'label' => __('Updated At'), |
||
| 261 | 'title' => __('Updated At'), |
||
| 262 | ] |
||
| 263 | ); |
||
| 264 | } |
||
| 265 | |||
| 266 | if (isset($formData['id_ext'])) { |
||
| 267 | $fieldset->addField( |
||
| 268 | 'id_ext', |
||
| 269 | 'label', |
||
| 270 | [ |
||
| 271 | 'name' => 'id_ext', |
||
| 272 | 'label' => __('Sub Seller Id on Getnet'), |
||
| 273 | 'title' => __('Sub Seller Id on Getnet'), |
||
| 274 | ] |
||
| 275 | ); |
||
| 276 | } |
||
| 277 | |||
| 278 | $fieldset = $form->addFieldset( |
||
| 279 | 'base_fieldset_data', |
||
| 280 | ['legend' => 'Base Data', 'class' => 'admin__scope-old form-inline'] |
||
| 281 | ); |
||
| 282 | |||
| 283 | $fieldset->addField( |
||
| 284 | 'code', |
||
| 285 | 'text', |
||
| 286 | [ |
||
| 287 | 'name' => 'code', |
||
| 288 | 'label' => __('Code'), |
||
| 289 | 'title' => __('Code'), |
||
| 290 | 'class' => 'required-entry', |
||
| 291 | 'required' => true, |
||
| 292 | ] |
||
| 293 | ); |
||
| 294 | |||
| 295 | $fieldset->addField( |
||
| 296 | 'type', |
||
| 297 | 'hidden', |
||
| 298 | [ |
||
| 299 | 'name' => 'type', |
||
| 300 | 'label' => __('Type Persona'), |
||
| 301 | 'title' => __('Type Persona'), |
||
| 302 | 'value' => isset($subSellerType) ? $subSellerType : 0, |
||
| 303 | ] |
||
| 304 | ); |
||
| 305 | |||
| 306 | // validate-email... |
||
| 307 | $fieldset->addField( |
||
| 308 | 'email', |
||
| 309 | 'text', |
||
| 310 | [ |
||
| 311 | 'name' => 'email', |
||
| 312 | 'label' => __('Email'), |
||
| 313 | 'title' => __('Email'), |
||
| 314 | 'class' => 'required-entry', |
||
| 315 | 'required' => true, |
||
| 316 | ] |
||
| 317 | ); |
||
| 318 | |||
| 319 | $fieldset->addField( |
||
| 320 | 'legal_document_number', |
||
| 321 | 'text', |
||
| 322 | [ |
||
| 323 | 'name' => 'legal_document_number', |
||
| 324 | 'label' => __('Legal Document Number'), |
||
| 325 | 'title' => __('Legal Document Number'), |
||
| 326 | 'class' => 'required-entry', |
||
| 327 | 'required' => true, |
||
| 328 | ] |
||
| 329 | ); |
||
| 330 | |||
| 331 | if (!$subSellerType) { |
||
| 332 | $fieldset->addField( |
||
| 333 | 'legal_name', |
||
| 334 | 'text', |
||
| 335 | [ |
||
| 336 | 'name' => 'legal_name', |
||
| 337 | 'label' => __('Legal Name'), |
||
| 338 | 'title' => __('Legal Name'), |
||
| 339 | 'class' => 'required-entry', |
||
| 340 | 'required' => true, |
||
| 341 | ] |
||
| 342 | ); |
||
| 343 | } |
||
| 344 | |||
| 345 | if ($subSellerType) { |
||
| 346 | $fieldset->addField( |
||
| 347 | 'legal_name', |
||
| 348 | 'text', |
||
| 349 | [ |
||
| 350 | 'name' => 'legal_name', |
||
| 351 | 'label' => __('Trade Legal Name'), |
||
| 352 | 'title' => __('Trade Legal Name'), |
||
| 353 | 'class' => 'required-entry', |
||
| 354 | 'required' => true, |
||
| 355 | ] |
||
| 356 | ); |
||
| 357 | } |
||
| 358 | |||
| 359 | $fieldset->addField( |
||
| 360 | 'birth_date', |
||
| 361 | 'date', |
||
| 362 | [ |
||
| 363 | 'name' => 'birth_date', |
||
| 364 | 'label' => $subSellerType ? __('Founding Date') : __('Birth Date'), |
||
| 365 | 'title' => $subSellerType ? __('Founding Date') : __('Birth Date'), |
||
| 366 | 'date_format' => $dateFormat, |
||
| 367 | 'class' => 'required-entry', |
||
| 368 | 'required' => true, |
||
| 369 | ] |
||
| 370 | ); |
||
| 371 | |||
| 372 | $fieldset = $form->addFieldset( |
||
| 373 | 'base_fieldset_addresses', |
||
| 374 | [ |
||
| 375 | 'legend' => $this->getFormLabelsBySellerType($subSellerType, 'base_fieldset_addresses'), |
||
| 376 | ] |
||
| 377 | ); |
||
| 378 | |||
| 379 | $fieldset->addField( |
||
| 380 | 'address_street', |
||
| 381 | 'text', |
||
| 382 | [ |
||
| 383 | 'name' => 'addresses[0][address_street]', |
||
| 384 | 'label' => __('Street'), |
||
| 385 | 'title' => __('Street'), |
||
| 386 | 'class' => 'required-entry', |
||
| 387 | 'required' => true, |
||
| 388 | ] |
||
| 389 | ); |
||
| 390 | |||
| 391 | $fieldset->addField( |
||
| 392 | 'address_street_number', |
||
| 393 | 'text', |
||
| 394 | [ |
||
| 395 | 'name' => 'addresses[0][address_street_number]', |
||
| 396 | 'label' => __('Street Number'), |
||
| 397 | 'title' => __('Street Number'), |
||
| 398 | 'class' => 'required-entry', |
||
| 399 | 'required' => true, |
||
| 400 | ] |
||
| 401 | ); |
||
| 402 | |||
| 403 | $fieldset->addField( |
||
| 404 | 'address_street_district', |
||
| 405 | 'text', |
||
| 406 | [ |
||
| 407 | 'name' => 'addresses[0][address_street_district]', |
||
| 408 | 'label' => __('District'), |
||
| 409 | 'title' => __('District'), |
||
| 410 | 'class' => 'required-entry', |
||
| 411 | 'required' => true, |
||
| 412 | ] |
||
| 413 | ); |
||
| 414 | |||
| 415 | $fieldset->addField( |
||
| 416 | 'address_street_complement', |
||
| 417 | 'text', |
||
| 418 | [ |
||
| 419 | 'name' => 'addresses[0][address_street_complement]', |
||
| 420 | 'label' => __('Complement'), |
||
| 421 | 'title' => __('Complement'), |
||
| 422 | ] |
||
| 423 | ); |
||
| 424 | |||
| 425 | $fieldset->addField( |
||
| 426 | 'address_city', |
||
| 427 | 'text', |
||
| 428 | [ |
||
| 429 | 'name' => 'addresses[0][address_city]', |
||
| 430 | 'label' => __('City'), |
||
| 431 | 'title' => __('City'), |
||
| 432 | 'class' => 'required-entry', |
||
| 433 | 'required' => true, |
||
| 434 | ] |
||
| 435 | ); |
||
| 436 | |||
| 437 | if (isset($formData['address_region'])) { |
||
| 438 | $fieldset->addField( |
||
| 439 | 'address_region', |
||
| 440 | 'hidden', |
||
| 441 | [ |
||
| 442 | 'name' => 'addresses[0][address_region]', |
||
| 443 | 'style' => 'display:none', |
||
| 444 | ] |
||
| 445 | ); |
||
| 446 | } |
||
| 447 | |||
| 448 | $fieldset->addField( |
||
| 449 | 'address_region_id', |
||
| 450 | 'select', |
||
| 451 | [ |
||
| 452 | 'name' => 'addresses[0][address_region_id]', |
||
| 453 | 'label' => __('State'), |
||
| 454 | 'values' => $regions, |
||
| 455 | 'class' => 'required-entry', |
||
| 456 | 'required' => true, |
||
| 457 | ] |
||
| 458 | ); |
||
| 459 | |||
| 460 | $fieldset->addField( |
||
| 461 | 'address_country_id', |
||
| 462 | 'select', |
||
| 463 | [ |
||
| 464 | 'name' => 'addresses[0][address_country_id]', |
||
| 465 | 'label' => __('Country'), |
||
| 466 | 'required' => true, |
||
| 467 | 'values' => $countries, |
||
| 468 | ] |
||
| 469 | ); |
||
| 470 | |||
| 471 | $fieldset->addField( |
||
| 472 | 'address_postcode', |
||
| 473 | 'text', |
||
| 474 | [ |
||
| 475 | 'name' => 'addresses[0][address_postcode]', |
||
| 476 | 'label' => __('Postcode'), |
||
| 477 | 'title' => __('Postcode'), |
||
| 478 | 'class' => 'required-entry validate-zip-br', |
||
| 479 | 'required' => true, |
||
| 480 | ] |
||
| 481 | ); |
||
| 482 | |||
| 483 | $fieldset->addField( |
||
| 484 | 'telephone', |
||
| 485 | 'text', |
||
| 486 | [ |
||
| 487 | 'name' => 'telephone', |
||
| 488 | 'label' => __('Telephone'), |
||
| 489 | 'title' => __('Telephone'), |
||
| 490 | 'class' => 'required-entry', |
||
| 491 | 'required' => true, |
||
| 492 | ] |
||
| 493 | ); |
||
| 494 | |||
| 495 | $fieldset = $form->addFieldset('base_fieldset_bank', ['legend' => __('Bank Account')]); |
||
| 496 | |||
| 497 | $fieldset->addField( |
||
| 498 | 'account_type', |
||
| 499 | 'select', |
||
| 500 | [ |
||
| 501 | 'name' => 'bank_accounts[0][account_type]', |
||
| 502 | 'label' => __('Account Type'), |
||
| 503 | 'title' => __('Account Type'), |
||
| 504 | 'values' => $bankTypeAccount, |
||
| 505 | 'value' => isset($formData['account_type']) ? $formData['account_type'] : 'C', |
||
| 506 | 'class' => 'required-entry', |
||
| 507 | 'required' => true, |
||
| 508 | ] |
||
| 509 | ); |
||
| 510 | |||
| 511 | $fieldset->addField( |
||
| 512 | 'bank', |
||
| 513 | 'text', |
||
| 514 | [ |
||
| 515 | 'name' => 'bank_accounts[0][bank]', |
||
| 516 | 'label' => __('Bank'), |
||
| 517 | 'title' => __('Bank'), |
||
| 518 | 'class' => 'required-entry', |
||
| 519 | 'required' => true, |
||
| 520 | ] |
||
| 521 | ); |
||
| 522 | |||
| 523 | $fieldset->addField( |
||
| 524 | 'agency', |
||
| 525 | 'text', |
||
| 526 | [ |
||
| 527 | 'name' => 'bank_accounts[0][agency]', |
||
| 528 | 'label' => __('Agency'), |
||
| 529 | 'title' => __('Agency'), |
||
| 530 | 'class' => 'required-entry', |
||
| 531 | 'required' => true, |
||
| 532 | ] |
||
| 533 | ); |
||
| 534 | |||
| 535 | $fieldset->addField( |
||
| 536 | 'agency_digit', |
||
| 537 | 'text', |
||
| 538 | [ |
||
| 539 | 'name' => 'bank_accounts[0][agency_digit]', |
||
| 540 | 'label' => __('Agency Digit'), |
||
| 541 | 'title' => __('Agency Digit'), |
||
| 542 | 'class' => 'required-entry', |
||
| 543 | 'required' => true, |
||
| 544 | ] |
||
| 545 | ); |
||
| 546 | |||
| 547 | $fieldset->addField( |
||
| 548 | 'account', |
||
| 549 | 'text', |
||
| 550 | [ |
||
| 551 | 'name' => 'bank_accounts[0][account]', |
||
| 552 | 'label' => __('Account'), |
||
| 553 | 'title' => __('Account'), |
||
| 554 | 'class' => 'required-entry', |
||
| 555 | 'required' => true, |
||
| 556 | ] |
||
| 557 | ); |
||
| 558 | |||
| 559 | $fieldset->addField( |
||
| 560 | 'account_digit', |
||
| 561 | 'text', |
||
| 562 | [ |
||
| 563 | 'name' => 'bank_accounts[0][account_digit]', |
||
| 564 | 'label' => __('Account Digit'), |
||
| 565 | 'title' => __('Account Digit'), |
||
| 566 | 'class' => 'required-entry', |
||
| 567 | 'required' => true, |
||
| 568 | ] |
||
| 569 | ); |
||
| 570 | |||
| 571 | $fieldset = $form->addFieldset('base_fieldset_settings', ['legend' => __('Marketplace Settings')]); |
||
| 572 | |||
| 573 | $fieldset->addField( |
||
| 574 | 'payment_plan', |
||
| 575 | 'text', |
||
| 576 | [ |
||
| 577 | 'name' => 'payment_plan', |
||
| 578 | 'label' => __('Payment Plan'), |
||
| 579 | 'title' => __('Payment Plan'), |
||
| 580 | 'class' => 'required-entry', |
||
| 581 | 'required' => true, |
||
| 582 | ] |
||
| 583 | ); |
||
| 584 | |||
| 585 | $fieldset->addField( |
||
| 586 | 'accepted_contract', |
||
| 587 | 'select', |
||
| 588 | [ |
||
| 589 | 'name' => 'type', |
||
| 590 | 'label' => __('Accepted Contract'), |
||
| 591 | 'title' => __('Accepted Contract'), |
||
| 592 | 'values' => $yesNo, |
||
| 593 | 'value' => isset($formData['accepted_contract']) ? $formData['accepted_contract'] : 1, |
||
| 594 | 'class' => 'required-entry', |
||
| 595 | 'required' => true, |
||
| 596 | ] |
||
| 597 | ); |
||
| 598 | |||
| 599 | $fieldset->addField( |
||
| 600 | 'marketplace_store', |
||
| 601 | 'select', |
||
| 602 | [ |
||
| 603 | 'name' => 'marketplace_store', |
||
| 604 | 'label' => __('Marketplace Store'), |
||
| 605 | 'title' => __('Marketplace Store'), |
||
| 606 | 'values' => $yesNo, |
||
| 607 | 'value' => isset($formData['marketplace_store']) ? $formData['marketplace_store'] : 0, |
||
| 608 | 'class' => 'required-entry', |
||
| 609 | 'required' => true, |
||
| 610 | ] |
||
| 611 | ); |
||
| 612 | |||
| 613 | $fieldset = $form->addFieldset( |
||
| 614 | 'base_fieldset_additional_data', |
||
| 615 | [ |
||
| 616 | 'legend' => $this->getFormLabelsBySellerType($subSellerType, 'base_fieldset_additional_data'), |
||
| 617 | ] |
||
| 618 | ); |
||
| 619 | |||
| 620 | $fieldset->addField( |
||
| 621 | 'occupation', |
||
| 622 | 'text', |
||
| 623 | [ |
||
| 624 | 'name' => 'occupation', |
||
| 625 | 'label' => __('Occupation'), |
||
| 626 | 'title' => __('Occupation'), |
||
| 627 | ] |
||
| 628 | ); |
||
| 629 | |||
| 630 | $fieldset = $form->addFieldset( |
||
| 631 | 'base_fieldset_gross', |
||
| 632 | [ |
||
| 633 | 'legend' => $this->getFormLabelsBySellerType($subSellerType, 'base_fieldset_gross'), |
||
| 634 | ] |
||
| 635 | ); |
||
| 636 | |||
| 637 | $fieldset->addField( |
||
| 638 | 'monthly_gross_income', |
||
| 639 | 'text', |
||
| 640 | [ |
||
| 641 | 'name' => 'monthly_gross_income', |
||
| 642 | 'label' => __('Monthly Gross Income'), |
||
| 643 | 'title' => __('Monthly Gross Income'), |
||
| 644 | ] |
||
| 645 | ); |
||
| 646 | |||
| 647 | $fieldset->addField( |
||
| 648 | 'gross_equity', |
||
| 649 | 'text', |
||
| 650 | [ |
||
| 651 | 'name' => 'gross_equity', |
||
| 652 | 'label' => __('Gross Equity'), |
||
| 653 | 'title' => __('Gross Equity'), |
||
| 654 | ] |
||
| 655 | ); |
||
| 656 | |||
| 657 | $form->setAction($this->getUrl('subseller/subseller/save')); |
||
| 658 | $form->setUseContainer(true); |
||
| 659 | $form->setId(self::FORM_ELEMENT_ID); |
||
| 660 | $form->setMethod('post'); |
||
| 661 | |||
| 662 | $form->setValues($formData); |
||
| 663 | $this->setForm($form); |
||
| 664 | |||
| 665 | $this->setChild( |
||
| 666 | 'form_after', |
||
| 667 | $this->getLayout()->createBlock( |
||
| 668 | \Magento\Framework\View\Element\Template::class |
||
| 669 | )->setTemplate('Getnet_SubSellerMagento::sub_seller/js.phtml') |
||
| 670 | ); |
||
| 671 | |||
| 672 | return parent::_prepareForm(); |
||
| 673 | } |
||
| 708 |