-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from magento-goinc/goinc-bugsfixing
[GoInc] bugsfixing
- Loading branch information
Showing
29 changed files
with
563 additions
and
261 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
app/code/Magento/Catalog/Api/Data/ProductWebsiteLinkInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Api\Data; | ||
|
||
/** | ||
* @api | ||
*/ | ||
interface ProductWebsiteLinkInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getSku(); | ||
|
||
/** | ||
* @param string $sku | ||
* @return $this | ||
*/ | ||
public function setSku($sku); | ||
|
||
/** | ||
* Get website ids | ||
* | ||
* @return int | ||
*/ | ||
public function getWebsiteId(); | ||
|
||
/** | ||
* Set website id | ||
* | ||
* @param int $websiteId | ||
* @return $this | ||
*/ | ||
public function setWebsiteId($websiteId); | ||
} |
42 changes: 42 additions & 0 deletions
42
app/code/Magento/Catalog/Api/ProductWebsiteLinkRepositoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Api; | ||
|
||
interface ProductWebsiteLinkRepositoryInterface | ||
{ | ||
/** | ||
* Assign a product to the website | ||
* | ||
* @param \Magento\Catalog\Api\Data\ProductWebsiteLinkInterface $productWebsiteLink | ||
* @return bool will returned True if website successfully assigned to product | ||
* | ||
* @throws \Magento\Framework\Exception\CouldNotSaveException | ||
* @throws \Magento\Framework\Exception\InputException | ||
*/ | ||
public function save(Data\ProductWebsiteLinkInterface $productWebsiteLink); | ||
|
||
/** | ||
* Remove the website assignment from the product | ||
* | ||
* @param \Magento\Catalog\Api\Data\ProductWebsiteLinkInterface $productWebsiteLink | ||
* @return bool will returned True if website successfully unassigned from product | ||
* | ||
* @throws \Magento\Framework\Exception\CouldNotSaveException | ||
*/ | ||
public function delete(Data\ProductWebsiteLinkInterface $productWebsiteLink); | ||
|
||
/** | ||
* Remove the website assignment from the product by product sku | ||
* | ||
* @param string $sku | ||
* @param int $websiteId | ||
* @return bool will returned True if website successfully unassigned from product | ||
* | ||
* @throws \Magento\Framework\Exception\CouldNotSaveException | ||
*/ | ||
public function deleteById($sku, $websiteId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Model; | ||
|
||
class ProductWebsiteLink extends \Magento\Framework\Api\AbstractSimpleObject implements | ||
\Magento\Catalog\Api\Data\ProductWebsiteLinkInterface | ||
{ | ||
/**#@+ | ||
* Field names | ||
*/ | ||
const KEY_SKU = 'sku'; | ||
const WEBSITE_ID = 'website_id'; | ||
/**#@-*/ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getSku() | ||
{ | ||
return $this->_get(self::KEY_SKU); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getWebsiteId() | ||
{ | ||
return $this->_get(self::WEBSITE_ID); | ||
} | ||
|
||
/** | ||
* @param string $sku | ||
* @return $this | ||
*/ | ||
public function setSku($sku) | ||
{ | ||
return $this->setData(self::KEY_SKU, $sku); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setWebsiteId($websiteId) | ||
{ | ||
return $this->setData(self::WEBSITE_ID, $websiteId); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
app/code/Magento/Catalog/Model/ProductWebsiteLinkRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Model; | ||
|
||
use Magento\Framework\Exception\InputException; | ||
use Magento\Framework\Exception\CouldNotSaveException; | ||
use Magento\Catalog\Api\Data\ProductWebsiteLinkInterface; | ||
|
||
class ProductWebsiteLinkRepository implements \Magento\Catalog\Api\ProductWebsiteLinkRepositoryInterface | ||
{ | ||
/** | ||
* @var \Magento\Catalog\Api\ProductRepositoryInterface | ||
*/ | ||
protected $productRepository; | ||
|
||
/** | ||
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository | ||
*/ | ||
public function __construct( | ||
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository | ||
) { | ||
$this->productRepository = $productRepository; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function save(ProductWebsiteLinkInterface $productWebsiteLink) | ||
{ | ||
if (!$productWebsiteLink->getWebsiteId()) { | ||
throw new InputException(__('There are not websites for assign to product')); | ||
} | ||
$product = $this->productRepository->get($productWebsiteLink->getSku()); | ||
$product->setWebsiteIds(array_merge($product->getWebsiteIds(), [$productWebsiteLink->getWebsiteId()])); | ||
try { | ||
$product->save(); | ||
} catch (\Exception $e) { | ||
throw new CouldNotSaveException( | ||
__( | ||
'Could not assign product "%1" to websites "%2"', | ||
$product->getId(), | ||
$productWebsiteLink->getWebsiteId() | ||
), | ||
$e | ||
); | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function delete(ProductWebsiteLinkInterface $productLink) | ||
{ | ||
return $this->deleteById($productLink->getSku(), $productLink->getSku()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function deleteById($sku, $websiteId) | ||
{ | ||
$product = $this->productRepository->get($sku); | ||
$product->setWebsiteIds(array_diff($product->getWebsiteIds(), [$websiteId])); | ||
|
||
try { | ||
$product->save(); | ||
} catch (\Exception $e) { | ||
throw new CouldNotSaveException( | ||
__( | ||
'Could not save product "%1" with websites %2', | ||
$product->getId(), | ||
implode(', ', $product->getWebsiteIds()) | ||
), | ||
$e | ||
); | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.