-
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.
MAGETWO-47017: [Github] Add Configurable Product To Cart from Categor…
- Loading branch information
Palamar, Mykola
committed
Oct 17, 2016
1 parent
492f0ca
commit ac363e4
Showing
28 changed files
with
839 additions
and
5 deletions.
There are no files selected for viewing
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
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
30 changes: 30 additions & 0 deletions
30
dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ListProduct.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,30 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Swatches\Test\Block\Product; | ||
|
||
use Magento\Mtf\Client\Locator; | ||
use Magento\Mtf\Fixture\FixtureInterface; | ||
use Magento\Catalog\Test\Block\Product\ListProduct as CatalogListProduct; | ||
|
||
/** | ||
* Product list block. | ||
*/ | ||
class ListProduct extends CatalogListProduct | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getProductItem(FixtureInterface $product) | ||
{ | ||
$locator = sprintf($this->productItem, $product->getName()); | ||
|
||
return $this->blockFactory->create( | ||
\Magento\Swatches\Test\Block\Product\ProductList\ProductItem::class, | ||
['element' => $this->_rootElement->find($locator, Locator::SELECTOR_XPATH)] | ||
); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ests/functional/tests/app/Magento/Swatches/Test/Block/Product/ProductList/ProductItem.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,58 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Swatches\Test\Block\Product\ProductList; | ||
|
||
use Magento\Mtf\Client\Locator; | ||
use Magento\Catalog\Test\Block\Product\ProductList\ProductItem as CatalogProductItem; | ||
|
||
/** | ||
* Product item block on frontend category view. | ||
*/ | ||
class ProductItem extends CatalogProductItem | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $swatchSelector = 'div[option-id="%s"]'; | ||
|
||
/** | ||
* Fill product options on category page | ||
* | ||
* @param $product | ||
*/ | ||
public function fillData($product) { | ||
$checkoutData = $product->getCheckoutData(); | ||
$options = $checkoutData['options']['configurable_options']; | ||
$confAttrData = $product->getDataFieldConfig('configurable_attributes_data'); | ||
$attributes = ($confAttrData['source'])->getAttributes(); | ||
|
||
foreach ($options as $option) { | ||
$availableOptions = $attributes[$option['title']]->getOptions(); | ||
$optionForSelect = $availableOptions[str_replace('option_key_', '', $option['value'])]; | ||
$this->clickOnSwatch($optionForSelect['id']); | ||
} | ||
} | ||
|
||
/** | ||
* Click on swatch | ||
* | ||
* @param $optionId | ||
*/ | ||
private function clickOnSwatch($optionId) { | ||
$selector = sprintf($this->swatchSelector, $optionId); | ||
$this->_rootElement->find($selector, Locator::SELECTOR_CSS)->click(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function clickAddToCart() | ||
{ | ||
$this->_rootElement->hover(); | ||
parent::clickAddToCart(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/Cart/Item.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,17 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Swatches\Test\Fixture\Cart; | ||
|
||
use Magento\ConfigurableProduct\Test\Fixture\Cart\Item as ConfigurableCart; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class Item extends ConfigurableCart | ||
{ | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/ConfigurableProduct.xml
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,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd"> | ||
<fixture | ||
name="configurableProductSwatch" | ||
module="Magento_Swatches" | ||
class="Magento\Swatches\Test\Fixture\ConfigurableProduct" | ||
extends="\Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct" | ||
> | ||
<!-- <field name="configurable_attributes_data" is_required="0" group="variations" source="Magento\Swatches\Test\Fixture\ConfigurableProduct\ConfigurableAttributesData" repository="Magento\ConfigurableProduct\Test\Repository\ConfigurableProduct\ConfigurableAttributesData" />--> | ||
</fixture> | ||
</config> |
18 changes: 18 additions & 0 deletions
18
...ests/app/Magento/Swatches/Test/Fixture/ConfigurableProduct/ConfigurableAttributesData.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,18 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Swatches\Test\Fixture\ConfigurableProduct; | ||
|
||
use Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct\ConfigurableAttributesData as | ||
ConfigurableProductAttributesData; | ||
|
||
/** | ||
* Source configurable attributes data of the configurable products. | ||
*/ | ||
class ConfigurableAttributesData extends ConfigurableProductAttributesData | ||
{ | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/SwatchProductAttribute.xml
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,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd"> | ||
<fixture name="swatchesProductAttribute" | ||
module="Magento_Swatches" | ||
handler_interface="Magento\Swatches\Test\Handler\SwatchProductAttribute\SwatchProductAttributeInterface" | ||
repository_class="Magento\Swatches\Test\Repository\SwatchProductAttribute" | ||
class="Magento\Swatches\Test\Fixture\CatalogProductAttribute" | ||
extends="\Magento\Catalog\Test\Fixture\CatalogProductAttribute"> | ||
</fixture> | ||
</config> |
48 changes: 48 additions & 0 deletions
48
dev/tests/functional/tests/app/Magento/Swatches/Test/Handler/SwatchProductAttribute/Curl.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,48 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Swatches\Test\Handler\SwatchProductAttribute; | ||
|
||
use Magento\Catalog\Test\Handler\CatalogProductAttribute\Curl as CatalogProductAttributeCurl; | ||
use Magento\Mtf\Config\DataInterface; | ||
use Magento\Mtf\System\Event\EventManagerInterface; | ||
|
||
/** | ||
* Class Curl | ||
* Curl handler for creating Swatch Attribute | ||
*/ | ||
class Curl extends CatalogProductAttributeCurl implements SwatchProductAttributeInterface | ||
{ | ||
/** | ||
* Add mapping data related to swatches | ||
* | ||
* @param DataInterface $configuration | ||
* @param EventManagerInterface $eventManager | ||
*/ | ||
public function __construct(DataInterface $configuration, EventManagerInterface $eventManager) | ||
{ | ||
$this->mappingData['frontend_input'] = [ | ||
'Text Swatch' => 'swatch_text', | ||
]; | ||
|
||
parent::__construct($configuration, $eventManager); | ||
} | ||
|
||
/** | ||
* Re-map options from default options structure to swatches structure | ||
* | ||
* @param array $data | ||
* @return array | ||
*/ | ||
protected function changeStructureOfTheData(array $data) { | ||
$data['optiontext'] = $data['option']; | ||
$data['swatchtext'] = [ | ||
'value' => $data['option']['value'] | ||
]; | ||
unset($data['option']); | ||
return $data; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../Magento/Swatches/Test/Handler/SwatchProductAttribute/SwatchProductAttributeInterface.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,16 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Swatches\Test\Handler\SwatchProductAttribute; | ||
|
||
use Magento\Mtf\Handler\HandlerInterface; | ||
|
||
/** | ||
* Interface for swatch specific Curl calls | ||
*/ | ||
interface SwatchProductAttributeInterface extends HandlerInterface | ||
{ | ||
} |
Oops, something went wrong.
ac363e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @palamar ,
Could help me please !!!
I thing take these files to use in my Magento, but , in moment to running magento setup:upgrade , returns error: Autoload error: Module 'Magento_Catalog' from '/var/www/html/app/code/Magento/Catalog' has been already defined in '/var/www/html/vendor/magento/module-catalog'.
What i need is send bundle direct to cart on grid or list page .
I observe than methods references to cited in #2434 , Methods setTypeHasRequiredOptions (false) and setRequiredOptions(false) do not exist !!!
Sorry, I send a message over here !!!
Thanks !!!