Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like CsvImportController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CsvImportController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 44 | class CsvImportController |
||
|
|
|||
| 45 | { |
||
| 46 | |||
| 47 | private $errors = array(); |
||
| 48 | |||
| 49 | private $fileName; |
||
| 50 | |||
| 51 | private $em; |
||
| 52 | |||
| 53 | private $productTwig = 'Product/csv_product.twig'; |
||
| 54 | |||
| 55 | private $categoryTwig = 'Product/csv_category.twig'; |
||
| 56 | |||
| 57 | |||
| 58 | /** |
||
| 59 | * 商品登録CSVアップロード |
||
| 60 | */ |
||
| 61 | 3 | public function csvProduct(Application $app, Request $request) |
|
| 408 | |||
| 409 | /** |
||
| 410 | * カテゴリ登録CSVアップロード |
||
| 411 | */ |
||
| 412 | 2 | public function csvCategory(Application $app, Request $request) |
|
| 547 | |||
| 548 | |||
| 549 | /** |
||
| 550 | * アップロード用CSV雛形ファイルダウンロード |
||
| 551 | */ |
||
| 552 | public function csvTemplate(Application $app, Request $request, $type) |
||
| 588 | |||
| 589 | |||
| 590 | /** |
||
| 591 | * 登録、更新時のエラー画面表示 |
||
| 592 | * |
||
| 593 | */ |
||
| 594 | 5 | protected function render($app, $form, $headers, $twig) |
|
| 618 | |||
| 619 | |||
| 620 | /** |
||
| 621 | * アップロードされたCSVファイルの行ごとの処理 |
||
| 622 | * |
||
| 623 | * @param $formFile |
||
| 624 | * @return CsvImportService |
||
| 625 | */ |
||
| 626 | 5 | protected function getImportData($app, $formFile) |
|
| 665 | |||
| 666 | |||
| 667 | /** |
||
| 668 | * 商品画像の削除、登録 |
||
| 669 | */ |
||
| 670 | 3 | protected function createProductImage($row, Product $Product) |
|
| 697 | |||
| 698 | |||
| 699 | /** |
||
| 700 | * 商品カテゴリの削除、登録 |
||
| 701 | */ |
||
| 702 | 3 | protected function createProductCategory($row, Product $Product, $app, $data) |
|
| 703 | { |
||
| 704 | // カテゴリの削除 |
||
| 705 | 3 | $ProductCategories = $Product->getProductCategories(); |
|
| 706 | 3 | foreach ($ProductCategories as $ProductCategory) { |
|
| 707 | 2 | $Product->removeProductCategory($ProductCategory); |
|
| 708 | 2 | $this->em->remove($ProductCategory); |
|
| 709 | 3 | $this->em->flush($ProductCategory); |
|
| 710 | } |
||
| 711 | |||
| 712 | 3 | if ($row['商品カテゴリ(ID)'] == '') { |
|
| 713 | // 入力されていなければ削除のみ |
||
| 714 | return; |
||
| 715 | } |
||
| 716 | |||
| 717 | // カテゴリの登録 |
||
| 718 | 3 | $categories = explode(',', $row['商品カテゴリ(ID)']); |
|
| 719 | 3 | $rank = 1; |
|
| 720 | 3 | $categoriesIdList = array(); |
|
| 721 | foreach ($categories as $category) { |
||
| 722 | 3 | ||
| 723 | 3 | if (preg_match('/^\d+$/', $category)) { |
|
| 724 | 3 | $Category = $app['eccube.repository.category']->find($category); |
|
| 725 | if (!$Category) { |
||
| 726 | $this->addErrors(($data->key() + 1).'行目の商品カテゴリ(ID)「'.$category.'」が存在しません。'); |
||
| 727 | 3 | } else { |
|
| 728 | 3 | View Code Duplication | foreach($Category->getPath() as $ParentCategory){ |
| 729 | 3 | if (!isset($categoriesIdList[$ParentCategory->getId()])){ |
|
| 730 | 3 | $ProductCategory = $this->makeProductCategory($Product, $ParentCategory, $rank); |
|
| 731 | 3 | $app['orm.em']->persist($ProductCategory); |
|
| 732 | 3 | $rank++; |
|
| 733 | 3 | $Product->addProductCategory($ProductCategory); |
|
| 734 | 3 | $categoriesIdList[$ParentCategory->getId()] = true; |
|
| 735 | 3 | } |
|
| 736 | } |
||
| 737 | if (!isset($categoriesIdList[$Category->getId()])){ |
||
| 738 | 3 | $ProductCategory = $this->makeProductCategory($Product, $Category, $rank); |
|
| 739 | $rank++; |
||
| 740 | $this->em->persist($ProductCategory); |
||
| 741 | $Product->addProductCategory($ProductCategory); |
||
| 742 | $categoriesIdList[$Category->getId()] = true; |
||
| 743 | } |
||
| 744 | } |
||
| 745 | } else { |
||
| 746 | $this->addErrors(($data->key() + 1).'行目の商品カテゴリ(ID)「'.$category.'」が存在しません。'); |
||
| 747 | } |
||
| 748 | } |
||
| 749 | |||
| 750 | } |
||
| 751 | |||
| 752 | |||
| 753 | 3 | /** |
|
| 754 | * タグの登録 |
||
| 755 | * |
||
| 756 | 3 | * @param array $row |
|
| 757 | 3 | * @param Product $Product |
|
| 758 | 1 | * @param Application $app |
|
| 759 | 3 | * @param CsvImportService $data |
|
| 760 | */ |
||
| 761 | protected function createProductTag($row, Product $Product, $app, $data) |
||
| 762 | 3 | { |
|
| 763 | // タグの削除 |
||
| 764 | $ProductTags = $Product->getProductTag(); |
||
| 765 | foreach ($ProductTags as $ProductTags) { |
||
| 766 | $Product->removeProductTag($ProductTags); |
||
| 767 | 3 | $this->em->remove($ProductTags); |
|
| 768 | 3 | } |
|
| 769 | 3 | ||
| 770 | 3 | if ($row['タグ(ID)'] == '') { |
|
| 771 | 3 | return; |
|
| 772 | 3 | } |
|
| 773 | 3 | ||
| 774 | // タグの登録 |
||
| 775 | 3 | $tags = explode(',', $row['タグ(ID)']); |
|
| 776 | 3 | foreach ($tags as $tag_id) { |
|
| 777 | $Tag = null; |
||
| 778 | 3 | if (preg_match('/^\d+$/', $tag_id)) { |
|
| 779 | $Tag = $app['eccube.repository.master.tag']->find($tag_id); |
||
| 780 | 3 | if ($Tag) { |
|
| 781 | $ProductTags = new ProductTag(); |
||
| 782 | $ProductTags |
||
| 783 | 3 | ->setProduct($Product) |
|
| 784 | 3 | ->setTag($Tag); |
|
| 785 | |||
| 786 | $Product->addProductTag($ProductTags); |
||
| 787 | |||
| 788 | $this->em->persist($ProductTags); |
||
| 789 | } |
||
| 790 | } |
||
| 791 | if (!$Tag) { |
||
| 792 | $this->addErrors(($data->key() + 1) . '行目のタグ(ID)「' . $tag_id . '」が存在しません。'); |
||
| 793 | 3 | } |
|
| 794 | } |
||
| 795 | } |
||
| 796 | |||
| 797 | 3 | ||
| 798 | 3 | /** |
|
| 799 | * 商品規格分類1、商品規格分類2がnullとなる商品規格情報を作成 |
||
| 800 | */ |
||
| 801 | 3 | protected function createProductClass($row, Product $Product, $app, $data, $ClassCategory1 = null, $ClassCategory2 = null) |
|
| 802 | { |
||
| 803 | // 規格分類1、規格分類2がnullとなる商品を作成 |
||
| 804 | 3 | ||
| 805 | 3 | $ProductClass = new ProductClass(); |
|
| 806 | 3 | $ProductClass->setProduct($Product); |
|
| 807 | |||
| 808 | |||
| 809 | 3 | View Code Duplication | if ($row['商品種別(ID)'] == '') { |
| 810 | $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が設定されていません。'); |
||
| 811 | } else { |
||
| 812 | if (preg_match('/^\d+$/', $row['商品種別(ID)'])) { |
||
| 813 | $ProductType = $app['eccube.repository.master.product_type']->find($row['商品種別(ID)']); |
||
| 814 | if (!$ProductType) { |
||
| 815 | $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が存在しません。'); |
||
| 816 | 3 | } else { |
|
| 817 | 3 | $ProductClass->setProductType($ProductType); |
|
| 818 | } |
||
| 819 | 3 | } else { |
|
| 820 | 2 | $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が存在しません。'); |
|
| 821 | 2 | } |
|
| 822 | 2 | } |
|
| 823 | |||
| 824 | $ProductClass->setClassCategory1($ClassCategory1); |
||
| 825 | 2 | $ProductClass->setClassCategory2($ClassCategory2); |
|
| 826 | |||
| 827 | if ($row['発送日目安(ID)'] != '') { |
||
| 828 | if (preg_match('/^\d+$/', $row['発送日目安(ID)'])) { |
||
| 829 | $DeliveryDate = $app['eccube.repository.delivery_date']->find($row['発送日目安(ID)']); |
||
| 830 | if (!$DeliveryDate) { |
||
| 831 | $this->addErrors(($data->key() + 1) . '行目の発送日目安(ID)が存在しません。'); |
||
| 832 | 3 | } else { |
|
| 833 | 2 | $ProductClass->setDeliveryDate($DeliveryDate); |
|
| 834 | } |
||
| 835 | 1 | } else { |
|
| 836 | $this->addErrors(($data->key() + 1) . '行目の発送日目安(ID)が存在しません。'); |
||
| 837 | } |
||
| 838 | 3 | } |
|
| 839 | |||
| 840 | View Code Duplication | if (Str::isNotBlank($row['商品コード'])) { |
|
| 841 | 3 | $ProductClass->setCode(Str::trimAll($row['商品コード'])); |
|
| 842 | 3 | } else { |
|
| 843 | $ProductClass->setCode(null); |
||
| 844 | 3 | } |
|
| 845 | |||
| 846 | View Code Duplication | if ($row['在庫数無制限フラグ'] == '') { |
|
| 847 | 3 | $this->addErrors(($data->key() + 1) . '行目の在庫数無制限フラグが設定されていません。'); |
|
| 848 | 3 | } else { |
|
| 849 | 3 | if ($row['在庫数無制限フラグ'] == (string) Constant::DISABLED) { |
|
| 850 | $ProductClass->setStockUnlimited(Constant::DISABLED); |
||
| 851 | 3 | // 在庫数が設定されていなければエラー |
|
| 852 | if ($row['在庫数'] == '') { |
||
| 853 | $this->addErrors(($data->key() + 1) . '行目の在庫数が設定されていません。'); |
||
| 854 | } else { |
||
| 855 | $stock = str_replace(',', '', $row['在庫数']); |
||
| 856 | if (preg_match('/^\d+$/', $stock) && $stock >= 0) { |
||
| 857 | $ProductClass->setStock($stock); |
||
| 858 | } else { |
||
| 859 | $this->addErrors(($data->key() + 1) . '行目の在庫数は0以上の数値を設定してください。'); |
||
| 860 | } |
||
| 861 | } |
||
| 862 | |||
| 863 | 3 | } else if ($row['在庫数無制限フラグ'] == (string) Constant::ENABLED) { |
|
| 864 | $ProductClass->setStockUnlimited(Constant::ENABLED); |
||
| 865 | $ProductClass->setStock(null); |
||
| 866 | } else { |
||
| 867 | $this->addErrors(($data->key() + 1) . '行目の在庫数無制限フラグが設定されていません。'); |
||
| 868 | } |
||
| 869 | } |
||
| 870 | |||
| 871 | if ($row['販売制限数'] != '') { |
||
| 872 | 3 | $saleLimit = str_replace(',', '', $row['販売制限数']); |
|
| 873 | 2 | if (preg_match('/^\d+$/', $saleLimit) && $saleLimit >= 0) { |
|
| 874 | 2 | $ProductClass->setSaleLimit($saleLimit); |
|
| 875 | 2 | } else { |
|
| 876 | $this->addErrors(($data->key() + 1) . '行目の販売制限数は0以上の数値を設定してください。'); |
||
| 877 | } |
||
| 878 | } |
||
| 879 | |||
| 880 | if ($row['通常価格'] != '') { |
||
| 881 | 3 | $price01 = str_replace(',', '', $row['通常価格']); |
|
| 882 | if (preg_match('/^\d+$/', $price01) && $price01 >= 0) { |
||
| 883 | $ProductClass->setPrice01($price01); |
||
| 884 | 3 | } else { |
|
| 885 | 3 | $this->addErrors(($data->key() + 1) . '行目の通常価格は0以上の数値を設定してください。'); |
|
| 886 | 3 | } |
|
| 887 | } |
||
| 888 | |||
| 889 | if ($row['販売価格'] == '') { |
||
| 890 | $this->addErrors(($data->key() + 1) . '行目の販売価格が設定されていません。'); |
||
| 891 | } else { |
||
| 892 | 3 | $price02 = str_replace(',', '', $row['販売価格']); |
|
| 893 | 2 | if (preg_match('/^\d+$/', $price02) && $price02 >= 0) { |
|
| 894 | 2 | $ProductClass->setPrice02($price02); |
|
| 895 | 2 | } else { |
|
| 896 | $this->addErrors(($data->key() + 1) . '行目の販売価格は0以上の数値を設定してください。'); |
||
| 897 | } |
||
| 898 | } |
||
| 899 | |||
| 900 | if ($row['送料'] != '') { |
||
| 901 | 3 | $delivery_fee = str_replace(',', '', $row['送料']); |
|
| 902 | if (preg_match('/^\d+$/', $delivery_fee) && $delivery_fee >= 0) { |
||
| 903 | $ProductClass->setDeliveryFee($delivery_fee); |
||
| 904 | 3 | } else { |
|
| 905 | 3 | $this->addErrors(($data->key() + 1) . '行目の送料は0以上の数値を設定してください。'); |
|
| 906 | } |
||
| 907 | } |
||
| 908 | |||
| 909 | View Code Duplication | if ($row['商品規格削除フラグ'] == '') { |
|
| 910 | $ProductClass->setDelFlg(Constant::DISABLED); |
||
| 911 | 3 | } else { |
|
| 912 | 3 | if ($row['商品規格削除フラグ'] == (string) Constant::DISABLED || $row['商品規格削除フラグ'] == (string) Constant::ENABLED) { |
|
| 913 | 3 | $ProductClass->setDelFlg($row['商品規格削除フラグ']); |
|
| 914 | 3 | } else { |
|
| 915 | $this->addErrors(($data->key() + 1) . '行目の商品規格削除フラグが設定されていません。'); |
||
| 916 | 3 | } |
|
| 917 | 3 | } |
|
| 918 | |||
| 919 | $Product->addProductClass($ProductClass); |
||
| 920 | $ProductStock = new ProductStock(); |
||
| 921 | $ProductClass->setProductStock($ProductStock); |
||
| 922 | $ProductStock->setProductClass($ProductClass); |
||
| 923 | 3 | ||
| 924 | 3 | if (!$ProductClass->getStockUnlimited()) { |
|
| 925 | $ProductStock->setStock($ProductClass->getStock()); |
||
| 926 | 3 | } else { |
|
| 927 | // 在庫無制限時はnullを設定 |
||
| 928 | $ProductStock->setStock(null); |
||
| 929 | } |
||
| 930 | |||
| 931 | $this->em->persist($ProductClass); |
||
| 932 | $this->em->persist($ProductStock); |
||
| 933 | |||
| 934 | 1 | return $ProductClass; |
|
| 935 | |||
| 936 | } |
||
| 937 | 1 | ||
| 938 | |||
| 939 | 1 | /** |
|
| 940 | * 商品規格情報を更新 |
||
| 941 | */ |
||
| 942 | 1 | protected function updateProductClass($row, Product $Product, ProductClass $ProductClass, $app, $data) |
|
| 943 | 1 | { |
|
| 944 | 1 | ||
| 945 | $ProductClass->setProduct($Product); |
||
| 946 | |||
| 947 | 1 | View Code Duplication | if ($row['商品種別(ID)'] == '') { |
| 948 | $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が設定されていません。'); |
||
| 949 | } else { |
||
| 950 | if (preg_match('/^\d+$/', $row['商品種別(ID)'])) { |
||
| 951 | $ProductType = $app['eccube.repository.master.product_type']->find($row['商品種別(ID)']); |
||
| 952 | if (!$ProductType) { |
||
| 953 | $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が存在しません。'); |
||
| 954 | } else { |
||
| 955 | 1 | $ProductClass->setProductType($ProductType); |
|
| 956 | 1 | } |
|
| 957 | 1 | } else { |
|
| 958 | 1 | $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が存在しません。'); |
|
| 959 | } |
||
| 960 | } |
||
| 961 | 1 | ||
| 962 | // 規格分類1、2をそれぞれセットし作成 |
||
| 963 | if ($row['規格分類1(ID)'] != '') { |
||
| 964 | if (preg_match('/^\d+$/', $row['規格分類1(ID)'])) { |
||
| 965 | $ClassCategory = $app['eccube.repository.class_category']->find($row['規格分類1(ID)']); |
||
| 966 | if (!$ClassCategory) { |
||
| 967 | $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)が存在しません。'); |
||
| 968 | 1 | } else { |
|
| 969 | 1 | $ProductClass->setClassCategory1($ClassCategory); |
|
| 970 | 1 | } |
|
| 971 | 1 | } else { |
|
| 972 | $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)が存在しません。'); |
||
| 973 | } |
||
| 974 | 1 | } |
|
| 975 | |||
| 976 | if ($row['規格分類2(ID)'] != '') { |
||
| 977 | if (preg_match('/^\d+$/', $row['規格分類2(ID)'])) { |
||
| 978 | $ClassCategory = $app['eccube.repository.class_category']->find($row['規格分類2(ID)']); |
||
| 979 | if (!$ClassCategory) { |
||
| 980 | $this->addErrors(($data->key() + 1) . '行目の規格分類2(ID)が存在しません。'); |
||
| 981 | 1 | } else { |
|
| 982 | $ProductClass->setClassCategory2($ClassCategory); |
||
| 983 | } |
||
| 984 | } else { |
||
| 985 | $this->addErrors(($data->key() + 1) . '行目の規格分類2(ID)が存在しません。'); |
||
| 986 | } |
||
| 987 | } |
||
| 988 | |||
| 989 | if ($row['発送日目安(ID)'] != '') { |
||
| 990 | if (preg_match('/^\d+$/', $row['発送日目安(ID)'])) { |
||
| 991 | $DeliveryDate = $app['eccube.repository.delivery_date']->find($row['発送日目安(ID)']); |
||
| 992 | if (!$DeliveryDate) { |
||
| 993 | $this->addErrors(($data->key() + 1) . '行目の発送日目安(ID)が存在しません。'); |
||
| 994 | 1 | } else { |
|
| 995 | 1 | $ProductClass->setDeliveryDate($DeliveryDate); |
|
| 996 | } |
||
| 997 | } else { |
||
| 998 | $this->addErrors(($data->key() + 1) . '行目の発送日目安(ID)が存在しません。'); |
||
| 999 | } |
||
| 1000 | 1 | } |
|
| 1001 | |||
| 1002 | View Code Duplication | if (Str::isNotBlank($row['商品コード'])) { |
|
| 1003 | 1 | $ProductClass->setCode(Str::trimAll($row['商品コード'])); |
|
| 1004 | 1 | } else { |
|
| 1005 | $ProductClass->setCode(null); |
||
| 1006 | 1 | } |
|
| 1007 | |||
| 1008 | View Code Duplication | if ($row['在庫数無制限フラグ'] == '') { |
|
| 1009 | 1 | $this->addErrors(($data->key() + 1) . '行目の在庫数無制限フラグが設定されていません。'); |
|
| 1010 | 1 | } else { |
|
| 1011 | 1 | if ($row['在庫数無制限フラグ'] == (string) Constant::DISABLED) { |
|
| 1012 | $ProductClass->setStockUnlimited(Constant::DISABLED); |
||
| 1013 | 1 | // 在庫数が設定されていなければエラー |
|
| 1014 | if ($row['在庫数'] == '') { |
||
| 1015 | $this->addErrors(($data->key() + 1) . '行目の在庫数が設定されていません。'); |
||
| 1016 | } else { |
||
| 1017 | 1 | $stock = str_replace(',', '', $row['在庫数']); |
|
| 1018 | 1 | if (preg_match('/^\d+$/', $stock) && $stock >= 0) { |
|
| 1019 | 1 | $ProductClass->setStock($row['在庫数']); |
|
| 1020 | } else { |
||
| 1021 | $this->addErrors(($data->key() + 1) . '行目の在庫数は0以上の数値を設定してください。'); |
||
| 1022 | } |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | 1 | } else if ($row['在庫数無制限フラグ'] == (string) Constant::ENABLED) { |
|
| 1026 | 1 | $ProductClass->setStockUnlimited(Constant::ENABLED); |
|
| 1027 | 1 | $ProductClass->setStock(null); |
|
| 1028 | 1 | } else { |
|
| 1029 | $this->addErrors(($data->key() + 1) . '行目の在庫数無制限フラグが設定されていません。'); |
||
| 1030 | } |
||
| 1031 | } |
||
| 1032 | |||
| 1033 | if ($row['販売制限数'] != '') { |
||
| 1034 | 1 | $saleLimit = str_replace(',', '', $row['販売制限数']); |
|
| 1035 | 1 | if (preg_match('/^\d+$/', $saleLimit) && $saleLimit >= 0) { |
|
| 1036 | 1 | $ProductClass->setSaleLimit($saleLimit); |
|
| 1037 | 1 | } else { |
|
| 1038 | $this->addErrors(($data->key() + 1) . '行目の販売制限数は0以上の数値を設定してください。'); |
||
| 1039 | } |
||
| 1040 | } |
||
| 1041 | |||
| 1042 | if ($row['通常価格'] != '') { |
||
| 1043 | 1 | $price01 = str_replace(',', '', $row['通常価格']); |
|
| 1044 | if (preg_match('/^\d+$/', $price01) && $price01 >= 0) { |
||
| 1045 | $ProductClass->setPrice01($price01); |
||
| 1046 | 1 | } else { |
|
| 1047 | 1 | $this->addErrors(($data->key() + 1) . '行目の通常価格は0以上の数値を設定してください。'); |
|
| 1048 | 1 | } |
|
| 1049 | } |
||
| 1050 | |||
| 1051 | if ($row['販売価格'] == '') { |
||
| 1052 | $this->addErrors(($data->key() + 1) . '行目の販売価格が設定されていません。'); |
||
| 1053 | } else { |
||
| 1054 | 1 | $price02 = str_replace(',', '', $row['販売価格']); |
|
| 1055 | if (preg_match('/^\d+$/', $price02) && $price02 >= 0) { |
||
| 1056 | $ProductClass->setPrice02($price02); |
||
| 1057 | 1 | } else { |
|
| 1058 | 1 | $this->addErrors(($data->key() + 1) . '行目の販売価格は0以上の数値を設定してください。'); |
|
| 1059 | } |
||
| 1060 | } |
||
| 1061 | |||
| 1062 | View Code Duplication | if ($row['商品規格削除フラグ'] == '') { |
|
| 1063 | $ProductClass->setDelFlg(Constant::DISABLED); |
||
| 1064 | 1 | } else { |
|
| 1065 | if ($row['商品規格削除フラグ'] == (string) Constant::DISABLED || $row['商品規格削除フラグ'] == (string) Constant::ENABLED) { |
||
| 1066 | 1 | $ProductClass->setDelFlg($row['商品規格削除フラグ']); |
|
| 1067 | 1 | } else { |
|
| 1068 | $this->addErrors(($data->key() + 1) . '行目の商品規格削除フラグが設定されていません。'); |
||
| 1069 | } |
||
| 1070 | 1 | } |
|
| 1071 | |||
| 1072 | $ProductStock = $ProductClass->getProductStock(); |
||
| 1073 | 1 | ||
| 1074 | if (!$ProductClass->getStockUnlimited()) { |
||
| 1075 | $ProductStock->setStock($ProductClass->getStock()); |
||
| 1076 | } else { |
||
| 1077 | // 在庫無制限時はnullを設定 |
||
| 1078 | $ProductStock->setStock(null); |
||
| 1079 | } |
||
| 1080 | |||
| 1081 | return $ProductClass; |
||
| 1082 | } |
||
| 1083 | |||
| 1084 | /** |
||
| 1085 | * 登録、更新時のエラー画面表示 |
||
| 1086 | * |
||
| 1087 | */ |
||
| 1088 | protected function addErrors($message) |
||
| 1089 | 5 | { |
|
| 1090 | $e = new CsvImportException($message); |
||
| 1091 | 5 | $this->errors[] = $e; |
|
| 1092 | } |
||
| 1093 | |||
| 1094 | /** |
||
| 1095 | * @return array |
||
| 1096 | */ |
||
| 1097 | protected function getErrors() |
||
| 1101 | |||
| 1102 | /** |
||
| 1103 | * |
||
| 1104 | * @return boolean |
||
| 1105 | */ |
||
| 1106 | 3 | protected function hasErrors() |
|
| 1110 | |||
| 1111 | /** |
||
| 1112 | * 商品登録CSVヘッダー定義 |
||
| 1113 | */ |
||
| 1114 | private function getProductCsvHeader() |
||
| 1115 | { |
||
| 1143 | 2 | ||
| 1144 | |||
| 1145 | /** |
||
| 1146 | * カテゴリCSVヘッダー定義 |
||
| 1147 | */ |
||
| 1148 | private function getCategoryCsvHeader() |
||
| 1156 | |||
| 1157 | /** |
||
| 1158 | * ProductCategory作成 |
||
| 1159 | * @param \Eccube\Entity\Product $Product |
||
| 1160 | * @param \Eccube\Entity\Category $Category |
||
| 1161 | * @return ProductCategory |
||
| 1162 | */ |
||
| 1163 | View Code Duplication | private function makeProductCategory($Product, $Category, $rank) |
|
| 1174 | } |
||
| 1175 |