From 679c8914c50e601ec951c9f4639b508a3f83a34a Mon Sep 17 00:00:00 2001 From: haunv8888 Date: Mon, 3 Jul 2017 13:51:36 +0700 Subject: [PATCH] add custom size to cart --- .../Api/Data/CustomSizeInterface.php | 71 ++++++++++++++++ .../Integration/Api/Data/PdpItemInterface.php | 18 ++++ app/code/PDP/Integration/Model/CustomSize.php | 84 +++++++++++++++++++ app/code/PDP/Integration/Model/PdpItem.php | 18 ++++ .../Pdpproduct/PdpGuestDesignRepository.php | 8 +- .../Model/Pdpproduct/PdpItemRepository.php | 18 +++- app/code/PDP/Integration/etc/di.xml | 1 + 7 files changed, 215 insertions(+), 3 deletions(-) create mode 100644 app/code/PDP/Integration/Api/Data/CustomSizeInterface.php create mode 100644 app/code/PDP/Integration/Model/CustomSize.php diff --git a/app/code/PDP/Integration/Api/Data/CustomSizeInterface.php b/app/code/PDP/Integration/Api/Data/CustomSizeInterface.php new file mode 100644 index 0000000..6259707 --- /dev/null +++ b/app/code/PDP/Integration/Api/Data/CustomSizeInterface.php @@ -0,0 +1,71 @@ +_get(self::SIZE_LAYOUT); + } + + /** + * Sets size layout + * + * @param string $sizeLayout + * @return $this + */ + public function setSizeLayout($sizeLayout) { + return $this->setData(self::SIZE_LAYOUT, $sizeLayout); + } + + /** + * Gets size height + * + * @return int|null height. Otherwise, null. + */ + public function getHeight() { + return $this->_get(self::HEIGHT); + } + + /** + * Sets size height + * + * @param int $height + * @return $this + */ + public function setHeight($height) { + return $this->setData(self::HEIGHT, $height); + } + + /** + * Gets size width + * + * @return int|null width. Otherwise, null. + */ + public function getWidth() { + return $this->_get(self::WDTH); + } + + /** + * Sets size height + * + * @param int $width + * @return $this + */ + public function setWidth($width) { + return $this->setData(self::WDTH, $width); + } + + /** + * Gets size unit + * + * @return string|null size unit. Otherwise, null. + */ + public function getUnit() { + return $this->_get(self::UNIT); + } + + /** + * Sets size unit + * + * @param int $unit + * @return $this + */ + public function setUnit($unit) { + return $this->setData(self::UNIT, $unit); + } +} \ No newline at end of file diff --git a/app/code/PDP/Integration/Model/PdpItem.php b/app/code/PDP/Integration/Model/PdpItem.php index 82ed115..84768f9 100644 --- a/app/code/PDP/Integration/Model/PdpItem.php +++ b/app/code/PDP/Integration/Model/PdpItem.php @@ -157,6 +157,24 @@ public function setProductColor(\PDP\Integration\Api\Data\ProductColorInterface return $this->setData(self::PDP_PRODUCT_COLOR, $productColor); } + /** + * Gets the custom size + * + * @return \PDP\Integration\Api\Data\CustomSizeInterface $customSize|null + */ + public function getCustomSize() { + return $this->_get(self::PDP_CUSTOM_SIZE); + } + + /** + * Sets the custom size + * @param \PDP\Integration\Api\Data\CustomSizeInterface $customSize + * @return this + */ + public function setCustomSize(\PDP\Integration\Api\Data\CustomSizeInterface $customSize) { + return $this->setData(self::PDP_CUSTOM_SIZE, $customSize); + } + /** * Gets the pdp options. * diff --git a/app/code/PDP/Integration/Model/Pdpproduct/PdpGuestDesignRepository.php b/app/code/PDP/Integration/Model/Pdpproduct/PdpGuestDesignRepository.php index 370742e..477bdae 100644 --- a/app/code/PDP/Integration/Model/Pdpproduct/PdpGuestDesignRepository.php +++ b/app/code/PDP/Integration/Model/Pdpproduct/PdpGuestDesignRepository.php @@ -83,16 +83,20 @@ public function save(\PDP\Integration\Api\Data\PdpDesignItemInterface $pdpDesign { $reponse = $this->pdpReponseFactory->create(); if($this->_pdpOptions->statusPdpIntegration()) { - if($pdpDesignItem->getDesignId() && $pdpDesignItem->getProductId() && $pdpDesignItem->getProductSku()) { + if($pdpDesignItem->getDesignId() && $pdpDesignItem->getProductSku()) { $product = $this->productRepository->get($pdpDesignItem->getProductSku()); if($product->getTypeId()) { $modelGuestDesign = $this->_pdpGuestDesignFactory->create(); $dataGuestDesign = array(); $itemValue = array( 'product_id' => $product->getEntityId(), - 'pdp_product_id' => $pdpDesignItem->getProductId(), 'design_id' => $pdpDesignItem->getDesignId() ); + if( $pdpDesignItem->getProductId() ) { + $itemValue['pdp_product_id'] = $pdpDesignItem->getProductId(); + } else { + $itemValue['pdp_product_id'] = $product->getEntityId(); + } if($this->_customerSession->isLoggedIn()) { $customerId = $this->_customerSession->getCustomerId(); $pdpGuestDesignId = $this->_pdpIntegrationSession->getPdpDesignId(); diff --git a/app/code/PDP/Integration/Model/Pdpproduct/PdpItemRepository.php b/app/code/PDP/Integration/Model/Pdpproduct/PdpItemRepository.php index fa78ea0..c893f85 100644 --- a/app/code/PDP/Integration/Model/Pdpproduct/PdpItemRepository.php +++ b/app/code/PDP/Integration/Model/Pdpproduct/PdpItemRepository.php @@ -119,7 +119,7 @@ public function save(\PDP\Integration\Api\Data\PdpItemInterface $pdpItem) $postDataArr = $pdpItem->__toArray(); $reponse = $this->pdpReponseFactory->create(); if($this->_pdpOptions->statusPdpIntegration()) { - if($pdpItem->getEntityId() && $pdpItem->getSku()) { + if(($pdpItem->getEntityId() && $pdpItem->getSku()) || ($pdpItem->getSku() && $pdpItem->getCustomSize() != null)) { $product = $this->productRepository->get($pdpItem->getSku()); if($product->getTypeId()) { $dataOpt = array(); @@ -153,6 +153,22 @@ public function save(\PDP\Integration\Api\Data\PdpItemInterface $pdpItem) $infoRequest['design_id'] = $pdpItem->getDesignId(); $additionalOptions[] = array('label' => 'Design Id', 'value' => 'pdp_design_id'.$pdpItem->getDesignId()); } + if($pdpItem->getCustomSize() != null) { + $customSize = $pdpItem->getCustomSize(); + $unit = $customSize->getUnit(); + if($customSize->getHeight()) { + $infoRequest['custom_size_height'] = $customSize->getHeight(); + $additionalOptions[] = array('label' => __('Height'), 'value' => $customSize->getHeight().$unit); + } + if($customSize->getWidth()) { + $infoRequest['custom_size_width'] = $customSize->getWidth(); + $additionalOptions[] = array('label' => __('Width'), 'value' => $customSize->getWidth().$unit); + } + if($customSize->getSizeLayout()) { + $infoRequest['custom_size_layout'] = $customSize->getSizeLayout(); + $additionalOptions[] = array('label' => __('Size layout'), 'value' => $customSize->getSizeLayout()); + } + } if(isset($dataOpt['product_color']['color_price']) && $dataOpt['product_color']['color_price']) { $color_price = $dataOpt['product_color']['color_price']; if(isset($infoRequest['pdp_price'])) { diff --git a/app/code/PDP/Integration/etc/di.xml b/app/code/PDP/Integration/etc/di.xml index 5ff4a96..62b6838 100644 --- a/app/code/PDP/Integration/etc/di.xml +++ b/app/code/PDP/Integration/etc/di.xml @@ -11,6 +11,7 @@ +