<?php
namespace Customize\Controller\CustomProduct\CustomBreathred;
use Codeception\Lib\Di;
use Codeception\Util\FileSystem as UtilFileSystem;
use Customize\Entity\CustomJewel;
use Customize\Entity\Jewel;
use Customize\Entity\JewelPart;
use Customize\Entity\Breathred;
use Customize\Form\Type\JewelType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Response;
use Eccube\Repository\Master\SaleTypeRepository;
use Customize\Repository\JewelRepository;
use Customize\Repository\CustomProductRepository;
use Customize\Repository\JewelPartRepository;
use Customize\Repository\BreathredRepository;
use Customize\Repository\RepairRepository;
use Doctrine\ORM\Query\Expr\Func;
use Eccube\Controller\AbstractController;
use Eccube\Entity\CartItem;
use Eccube\Util\CacheUtil;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Master\ProductStatus;
use Eccube\Entity\Master\SaleType;
use Eccube\Entity\Product;
use Eccube\Entity\ProductCategory;
use Eccube\Entity\ProductClass;
use Eccube\Entity\ProductImage;
use Eccube\Entity\ProductStock;
use Eccube\Entity\ProductTag;
use Eccube\Entity\TaxRule;
use Eccube\Repository\TaxRuleRepository;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Customize\Service\CartService;
use Eccube\Service\TaxRuleService;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Form\Type\AddCartType;
use Eccube\Form\Type\Admin\ProductType;
use Google\Service\Adsense\Alert;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Eccube\Repository\BaseInfoRepository;
use Symfony\Component\Routing\Annotation\Route;
use Eccube\Repository\Master\ProductStatusRepository;
use Google\Service\HangoutsChat\Resource\Dms;
use Knp\Component\Pager\PaginatorInterface;
use PDO;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use function GuzzleHttp\Promise\each;
class CustomBreathredBaseController extends AbstractController
{
/**
* @var ProductStatusRepository
*/
protected $productStatusRepository;
/**
* @var SaleTypeRepository
*/
protected $saleTypeRepository;
/**
* @var PurchaseFlow
*/
protected $purchaseFlow;
/**
* @var CartService
*/
protected $cartService;
/**
* @var JewelRepository
*/
protected $jewelRepository;
/**
* @var JewelPartRepository
*/
protected $jewelPartRepository;
/**
* @var CustomProductRepository
*/
protected $customProductRepository;
/**
* @var BaseInfo
*/
protected $BaseInfo;
/**
* @var TaxRuleService
*/
protected $taxRuleService;
/**
* @var TaxRuleRepository
*/
protected $taxRuleRepository;
/**
* @var SessionInterface
*/
protected $session;
/**
* @var RepairRepository
*/
protected $repairRepository;
/**
* @var BreathredRepository
*/
protected $breathredRepository;
/**
*
*
* constructor.
*
* @param JewelRepository $jewelRepository
* @param CustomProductRepository $customProductRepository
* @param CartService $cartService
* @param ProductStatusRepository $productStatusRepository
* @param BaseInfoRepository $baseInfoRepository
* @param SaleTypeRepository $saleTypeRepository
* @param PurchaseFlow $cartPurchaseFlow
* @param TaxRuleService $taxRuleService
* @param TaxRuleRepository $taxRuleRepository
* @param SessionInterface $session
* @param JewelPartRepository $jewelPartRepository
* @param RepairRepository $repairRepository
* @param BreathredRepository $breathredRepository
*
*/
public function __construct(
JewelRepository $jewelRepository,
CartService $cartService,
CustomProductRepository $customProductRepository,
ProductStatusRepository $productStatusRepository,
BaseInfoRepository $baseInfoRepository,
SaleTypeRepository $saleTypeRepository,
PurchaseFlow $cartPurchaseFlow,
TaxRuleService $taxRuleService,
TaxRuleRepository $taxRuleRepository,
SessionInterface $session,
JewelPartRepository $jewelPartRepository,
RepairRepository $repairRepository,
BreathredRepository $breathredRepository
) {
$this->jewelRepository = $jewelRepository;
$this->cartService = $cartService;
$this->customProductRepository = $customProductRepository;
$this->productStatusRepository = $productStatusRepository;
$this->BaseInfo = $baseInfoRepository->get();
$this->saleTypeRepository = $saleTypeRepository;
$this->purchaseFlow = $cartPurchaseFlow;
$this->taxRuleService = $taxRuleService;
$this->taxRuleRepository = $taxRuleRepository;
$this->session = $session;
$this->jewelPartRepository = $jewelPartRepository;
$this->repairRepository = $repairRepository;
$this->breathredRepository = $breathredRepository;
}
/**
* //選んだカスタムリングとジュエルのidをsessionにセーブ
* @Route("/custom_breathred_session", name="custom_breathred_session")
*/
public function BreathredSession(Request $request)
{
if ($request->isXmlHttpRequest()) {
$doct = $this->getDoctrine()->getManager();
$session = $request->getSession();
if ($request->request->get('breathred_id') != null) {
$id = intval($request->request->get('breathred_id'));
$session->set('breathred_id', $id);
$breathred = $doct->getRepository(Breathred::class)->find($id);
if ($breathred === null) {
return new JsonResponse(array('status' => 'Error'), 400);
}
$breathred_price = $breathred->getPrice();
$socket = $breathred->getSocket();
$session->set('breathred_price', $breathred_price);
$upload_directory = $this->getParameter('uploads_directory');
$finder = new Finder();
//image
$display_image = 'html/upload/save_image/customRing/breathred/' . $breathred->getBreathredShape() . '/' . $breathred->getBreathredType() . '/main/' . $breathred->getImageName();
$list_image = 'html/upload/save_image/customRing/breathred/' . $breathred->getBreathredShape() . '/' . $breathred->getBreathredType() . '/list/' . $breathred->getImageName();
//vrの画像
$vr = 'VR';
$upload = 'html/upload/save_image/customRing/breathred/' . $breathred->getBreathredShape() . '/' . $breathred->getBreathredType() . '/main/' . $vr . '/';
$finder->in($upload)->directories()->depth("==0");
$path = array();
$vr_image = array();
if ($finder->hasResults()) {
foreach ($finder as $folder) {
$folder = $folder . '/';
array_push($path, $folder);
}
//image path
for ($i = 0; $i < count($path); $i++) {
$images = glob($path[$i] . "*.{jpg,png,jpeg,JPG,JPEG,PNG}", GLOB_BRACE);
$img_temp = explode('save_image/', $images[1]);
$temp = explode('save_image/', $path[$i]);
$path[$i] = $temp[1];
array_push($vr_image, $img_temp[1]);
}
}
return new JsonResponse(array('status' => 'done', 'item_price' => $breathred_price, 'path' => $path, 'image' => $display_image, 'list_image'=> $list_image, 'vr_img' => $vr_image, 'socket' => $socket), 200);
}
}
return new JsonResponse(array('status' => 'Error'), 400);
}
/**
*
* @Method("GET", "POST")
* @Route("/custom_breathred_base", name="custom_breathred_base") #URLを指定
* @Template("CustomProduct/CustomBreathred/custom_base.twig") #ページ遷移先を指定
*
*/
public function CustomBreathredBase(Request $request, PaginatorInterface $paginator)
{
if(!array_key_exists('HTTP_REFERER', $_SERVER)){
return $this->redirectToRoute('homepage');
}
$breathred = $this->breathredRepository->customFindAll();
$session = $request->getSession();
//mypageから移動させられないとカスタマイズのsessionを除去
if(str_contains($_SERVER['HTTP_REFERER'], 'mypage')){
//dd($_SERVER);
}else{
$session->remove('customize_part_id');
$session->remove('customize_part_type');
$session->remove('customize_product_name');
$session->remove('customize_custom_id');
}
$customize_type = $session->get('customize_part_type');
$customize_id = $session->get('customize_part_id');
$customize_jewel = $session->get('customize_jewel');
if($customize_type == 'jewel_part'){
$jewel = $this->jewelRepository->CustomFindWithID($customize_jewel)[0];
$jewel_part = $this->jewelPartRepository->CustomFindWithID($customize_id)[0];
$breathred = $this->breathredRepository->CustomFindWithType($jewel_part->getJewelPartType());
}
else if($customize_type == 'jewel'){
$jewel = $this->jewelRepository->CustomFindWithID($customize_id)[0];
$jewel_part['image_name'] = null;
}
else{
$jewel['image_name'] = null;
$jewel_part['image_name'] = null;
}
return [
'breathreds' => $breathred,
'customize_type' => $customize_type,
'customize_id' => $customize_id,
'customize_jewel' => $customize_jewel,
'jewel' => $jewel,
'jewel_part' => $jewel_part
];
}
}