Skip to content

Commit

Permalink
add custom size to cart
Browse files Browse the repository at this point in the history
  • Loading branch information
haunv8888 committed Jul 3, 2017
1 parent 5539e94 commit 679c891
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 3 deletions.
71 changes: 71 additions & 0 deletions app/code/PDP/Integration/Api/Data/CustomSizeInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
namespace PDP\Integration\Api\Data;

interface CustomSizeInterface extends \Magento\Framework\Api\ExtensibleDataInterface {

const SIZE_LAYOUT = 'size_layout';
const HEIGHT = 'height';
const WDTH = 'wdth';
const UNIT = 'unit';

/**
* Gets size layout
*
* @return string|null size layout. Otherwise, null.
*/
public function getSizeLayout();

/**
* Sets size layout
*
* @param string $sizeLayout
* @return $this
*/
public function setSizeLayout($sizeLayout);

/**
* Gets size height
*
* @return int|null height. Otherwise, null.
*/
public function getHeight();

/**
* Sets size height
*
* @param int $height
* @return $this
*/
public function setHeight($height);

/**
* Gets size width
*
* @return int|null width. Otherwise, null.
*/
public function getWidth();

/**
* Sets size height
*
* @param int $width
* @return $this
*/
public function setWidth($width);

/**
* Gets size unit
*
* @return string|null size unit. Otherwise, null.
*/
public function getUnit();

/**
* Sets size unit
*
* @param int $unit
* @return $this
*/
public function setUnit($unit);

}
18 changes: 18 additions & 0 deletions app/code/PDP/Integration/Api/Data/PdpItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ interface PdpItemInterface extends \Magento\Framework\Api\ExtensibleDataInterfac

const PDP_PRODUCT_COLOR = 'product_color';

/*
* pdp custom size
*/
const PDP_CUSTOM_SIZE = 'custom_size';

/*
* pdp option.
*/
Expand Down Expand Up @@ -152,6 +157,19 @@ public function getProductColor();
* @return $this
*/
public function setProductColor(\PDP\Integration\Api\Data\ProductColorInterface $productColor);

/**
* Gets the pdp custom size
* @return \PDP\Integration\Api\Data\CustomSizeInterface $customSize|null
*/
public function getCustomSize();

/**
* Sets the custom size
* @param \PDP\Integration\Api\Data\CustomSizeInterface $customSize
* @return $this
*/
public function setCustomSize(\PDP\Integration\Api\Data\CustomSizeInterface $customSize);

/**
* Gets the pdp options.
Expand Down
84 changes: 84 additions & 0 deletions app/code/PDP/Integration/Model/CustomSize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
namespace PDP\Integration\Model;

use Magento\Framework\Api\AbstractExtensibleObject;
use PDP\Integration\Api\Data\CustomSizeInterface;

class CustomSize extends AbstractExtensibleObject implements CustomSizeInterface {

/**
* Gets size layout
*
* @return string|null size layout. Otherwise, null.
*/
public function getSizeLayout() {
return $this->_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);
}
}
18 changes: 18 additions & 0 deletions app/code/PDP/Integration/Model/PdpItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 17 additions & 1 deletion app/code/PDP/Integration/Model/Pdpproduct/PdpItemRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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'])) {
Expand Down
1 change: 1 addition & 0 deletions app/code/PDP/Integration/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<preference for="PDP\Integration\Api\PdpGuestDesignRepositoryInterface" type="PDP\Integration\Model\Pdpproduct\PdpGuestDesignRepository"/>
<preference for="PDP\Integration\Api\Data\PdpDesignItemInterface" type="PDP\Integration\Model\PdpDesignItem"/>
<preference for="PDP\Integration\Api\Data\ProductColorInterface" type="PDP\Integration\Model\ProductColor"/>
<preference for="PDP\Integration\Api\Data\CustomSizeInterface" type="PDP\Integration\Model\CustomSize"/>
<type name="Magento\Sales\Model\Config">
<plugin name="PDP_Integration_Model_Sales_Plugin_Config"
type="PDP\Integration\Model\Sales\Plugin\Config"
Expand Down

0 comments on commit 679c891

Please sign in to comment.