public function newTaxRule()
 {
     $TaxRule = new \Eccube\Entity\TaxRule();
     $CalcRule = $this->getEntityManager()->getRepository('Eccube\\Entity\\Master\\Taxrule')->find(1);
     $TaxRule->setCalcRule($CalcRule);
     $TaxRule->setTaxAdjust(0);
     $TaxRule->setDelFlg(0);
     return $TaxRule;
 }
 /**
  * 商品規格を登録
  *
  * @param $ProductClasses 登録される商品規格
  */
 private function insertProductClass($app, $Product, $ProductClasses)
 {
     $BaseInfo = $app['eccube.repository.base_info']->get();
     // 選択された商品を登録
     foreach ($ProductClasses as $ProductClass) {
         $ProductClass->setDelFlg(Constant::DISABLED);
         $ProductClass->setProduct($Product);
         $app['orm.em']->persist($ProductClass);
         // 在庫情報を作成
         $ProductStock = new \Eccube\Entity\ProductStock();
         $ProductClass->setProductStock($ProductStock);
         $ProductStock->setProductClass($ProductClass);
         if (!$ProductClass->getStockUnlimited()) {
             $ProductStock->setStock($ProductClass->getStock());
         } else {
             // 在庫無制限時はnullを設定
             $ProductStock->setStock(null);
         }
         $app['orm.em']->persist($ProductStock);
     }
     // 商品税率が設定されている場合、商品税率をセット
     if ($BaseInfo->getOptionProductTaxRule() == Constant::ENABLED) {
         // 初期設定の税設定.
         $TaxRule = $app['eccube.repository.tax_rule']->find(\Eccube\Entity\TaxRule::DEFAULT_TAX_RULE_ID);
         // 初期税率設定の計算方法を設定する
         $CalcRule = $TaxRule->getCalcRule();
         foreach ($ProductClasses as $ProductClass) {
             if ($ProductClass->getTaxRate()) {
                 $TaxRule = new \Eccube\Entity\TaxRule();
                 $TaxRule->setProduct($Product);
                 $TaxRule->setProductClass($ProductClass);
                 $TaxRule->setCalcRule($CalcRule);
                 $TaxRule->setTaxRate($ProductClass->getTaxRate());
                 $TaxRule->setTaxAdjust(0);
                 $TaxRule->setApplyDate(new \DateTime());
                 $TaxRule->setDelFlg(Constant::DISABLED);
                 $app['orm.em']->persist($TaxRule);
             }
         }
     }
 }
Пример #3
0
 /**
  * #1739のテストケース
  * @link https://github.com/EC-CUBE/ec-cube/issues/1739
  */
 public function testGetNewOrderDetailForTaxRate()
 {
     $DefaultTaxRule = $this->app['eccube.repository.tax_rule']->find(1);
     $DefaultTaxRule->setApplyDate(new \DateTime('-2 day'));
     $this->app['orm.em']->flush();
     // 個別税率設定を有効化
     $BaseInfo = $this->app['eccube.repository.base_info']->get();
     $BaseInfo->setOptionProductTaxRule(Constant::ENABLED);
     // 個別税率が設定された商品企画を準備
     $Product = $this->createProduct('テスト商品', 1);
     $ProductClassList = $Product->getProductClasses();
     $ProductClass = $ProductClassList[0];
     $CalcRule = $this->app['orm.em']->getRepository('Eccube\\Entity\\Master\\Taxrule')->find(1);
     $TaxRule = new \Eccube\Entity\TaxRule();
     $TaxRule->setProductClass($ProductClass)->setCreator($Product->getCreator())->setProduct($Product)->setCalcRule($CalcRule)->setTaxRate(10)->setTaxAdjust(0)->setApplyDate(new \DateTime('-1 days'))->setDelFlg(Constant::DISABLED);
     $ProductClass->setTaxRule($TaxRule)->setTaxRate($TaxRule->getTaxRate());
     $this->app['orm.em']->persist($TaxRule);
     $this->app['orm.em']->flush();
     // テスト用に税率設定のキャッシュをクリア
     $this->app['eccube.repository.tax_rule']->clearCache();
     // ShoppingServiceにテスト用のEntityManagerを設定
     $ShoppingService = $this->app['eccube.service.shopping'];
     $RefrectionClass = new \ReflectionClass(get_class($ShoppingService));
     $Property = $RefrectionClass->getProperty('em');
     $Property->setAccessible(true);
     $Property->setValue($ShoppingService, $this->app['orm.em']);
     $OrderDetail = $this->app['eccube.service.shopping']->getNewOrderDetail($Product, $ProductClass, 1);
     $this->expected = $TaxRule->getId();
     $this->actual = $OrderDetail->getTaxRule();
     $this->verify('受注詳細の税率が正しく設定されている');
 }