Ejemplo n.º 1
0
 public function createTaxRule($tax_rate = 8, $apply_date = null)
 {
     $TaxRule = new TaxRule();
     $CalcRule = $this->app['orm.em']->getRepository('Eccube\\Entity\\Master\\Taxrule')->find(1);
     $Member = $this->app['eccube.repository.member']->find(2);
     if (is_null($apply_date)) {
         $apply_date = new \DateTime();
     }
     $TaxRule->setTaxRate($tax_rate)->setApplyDate($apply_date)->setCalcRule($CalcRule)->setTaxAdjust(0)->setCreator($Member)->setDelFlg(0);
     $this->app['orm.em']->persist($TaxRule);
     $this->app['orm.em']->flush();
     return $TaxRule;
 }
Ejemplo n.º 2
0
 /**
  * 個別税率設定のテストケース
  * 個別税率設定を有効にし、商品編集時に更新されることを確認する
  *
  * @see https://github.com/EC-CUBE/ec-cube/issues/1547
  * @param $before 更新前の税率
  * @param $after POST値
  * @param $expected 期待値
  *
  * @dataProvider dataEditProductProvider
  */
 public function testEditWithPostTaxRate($before, $after, $expected)
 {
     // Give
     $BaseInfo = $this->app['eccube.repository.base_info']->get();
     $BaseInfo->setOptionProductTaxRule(Constant::ENABLED);
     $Product = $this->createProduct(null, 0);
     $ProductClasses = $Product->getProductClasses();
     $ProductClass = $ProductClasses[0];
     $formData = $this->createFormData();
     if (!is_null($after)) {
         $formData['class']['tax_rate'] = $after;
     }
     if (!is_null($before)) {
         $DefaultTaxRule = $this->app['eccube.repository.tax_rule']->find(\Eccube\Entity\TaxRule::DEFAULT_TAX_RULE_ID);
         $TaxRule = new TaxRule();
         $TaxRule->setProductClass($ProductClass)->setCreator($Product->getCreator())->setProduct($Product)->setCalcRule($DefaultTaxRule->getCalcRule())->setTaxRate($before)->setTaxAdjust(0)->setApplyDate(new \DateTime())->setDelFlg(Constant::DISABLED);
         $ProductClass->setTaxRule($TaxRule);
         $this->app['orm.em']->persist($TaxRule);
         $this->app['orm.em']->flush();
     }
     // When
     $this->client->request('POST', $this->app->url('admin_product_product_edit', array('id' => $Product->getId())), array('admin_product' => $formData));
     // Then
     $this->assertTrue($this->client->getResponse()->isRedirect($this->app->url('admin_product_product_edit', array('id' => $Product->getId()))));
     $this->expected = $expected;
     $TaxRule = $this->app['eccube.repository.tax_rule']->findOneBy(array('Product' => $Product, 'ProductClass' => $ProductClass));
     if (is_null($TaxRule)) {
         $this->actual = null;
     } else {
         $this->actual = $TaxRule->getTaxRate();
     }
     $this->assertTrue($this->actual === $this->expected);
 }
Ejemplo n.º 3
0
 /**
  * 商品規格を登録
  *
  * @param Application     $app
  * @param Product         $Product
  * @param ArrayCollection $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 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(TaxRule::DEFAULT_TAX_RULE_ID);
         // 初期税率設定の計算方法を設定する
         $CalcRule = $TaxRule->getCalcRule();
         foreach ($ProductClasses as $ProductClass) {
             if ($ProductClass && is_numeric($taxRate = $ProductClass->getTaxRate())) {
                 $TaxRule = new TaxRule();
                 $TaxRule->setProduct($Product);
                 $TaxRule->setProductClass($ProductClass);
                 $TaxRule->setCalcRule($CalcRule);
                 $TaxRule->setTaxRate($taxRate);
                 $TaxRule->setTaxAdjust(0);
                 $TaxRule->setApplyDate(new \DateTime());
                 $TaxRule->setDelFlg(Constant::DISABLED);
                 $app['orm.em']->persist($TaxRule);
             }
         }
     }
 }