Skip to content

Commit

Permalink
Merge pull request #720 from magento-jackalopes/MAGETWO-58455-n-MAGET…
Browse files Browse the repository at this point in the history
…WO-58463

Fixed issues:

- MAGETWO-58551 Remove uses of unserialize in Module_Quote
- MAGETWO-58455 Remove uses of unserialize in \Magento\Framework\Model\ ResourceModel\Db\AbstractDb and its child classes and their usages
- MAGETWO-58463 Remove uses of unserialize in Module_Sales
- MAGETWO-61872 Create FieldDataConverter
- MAGETWO-62133 Create QueryModifier to select only options of type file and info_buyRequest
  • Loading branch information
sdwright authored Jan 5, 2017
2 parents 3c0c8c7 + f931b34 commit 159b261
Show file tree
Hide file tree
Showing 107 changed files with 4,400 additions and 875 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,42 @@
namespace Magento\Bundle\Block\Adminhtml\Sales\Order\Items;

use Magento\Catalog\Model\Product\Type\AbstractType;
use Magento\Framework\Serialize\Serializer\Json;

/**
* Adminhtml sales order item renderer
*/
class Renderer extends \Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer
{
/**
* Serializer
*
* @var Json
*/
private $serializer;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
* @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
* @param \Magento\Framework\Registry $registry
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
\Magento\Framework\Registry $registry,
array $data = [],
Json $serializer = null
) {
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(Json::class);

parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $data);
}

/**
* Truncate string
*
Expand Down Expand Up @@ -153,7 +183,7 @@ public function getSelectionAttributes($item)
$options = $item->getOrderItem()->getProductOptions();
}
if (isset($options['bundle_selection_attributes'])) {
return unserialize($options['bundle_selection_attributes']);
return $this->serializer->unserialize($options['bundle_selection_attributes']);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,54 @@
namespace Magento\Bundle\Block\Adminhtml\Sales\Order\View\Items;

use Magento\Catalog\Model\Product\Type\AbstractType;
use Magento\Framework\Serialize\Serializer\Json;

/**
* Adminhtml sales order item renderer
*/
class Renderer extends \Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer
{
/**
* Serializer
*
* @var Json
*/
private $serializer;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
* @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
* @param \Magento\Framework\Registry $registry
* @param \Magento\GiftMessage\Helper\Message $messageHelper
* @param \Magento\Checkout\Helper\Data $checkoutHelper
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
\Magento\Framework\Registry $registry,
\Magento\GiftMessage\Helper\Message $messageHelper,
\Magento\Checkout\Helper\Data $checkoutHelper,
array $data = [],
Json $serializer = null
) {
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(Json::class);

parent::__construct(
$context,
$stockRegistry,
$stockConfiguration,
$registry,
$messageHelper,
$checkoutHelper,
$data
);
}

/**
* Truncate string
*
Expand Down Expand Up @@ -110,7 +152,7 @@ public function getSelectionAttributes($item)
$options = $item->getOrderItem()->getProductOptions();
}
if (isset($options['bundle_selection_attributes'])) {
return unserialize($options['bundle_selection_attributes']);
return $this->serializer->unserialize($options['bundle_selection_attributes']);
}
return null;
}
Expand Down
30 changes: 29 additions & 1 deletion app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Bundle\Block\Sales\Order\Items;

use Magento\Catalog\Model\Product\Type\AbstractType;
use Magento\Framework\Serialize\Serializer\Json;

/**
* Order item render block
Expand All @@ -14,6 +15,33 @@
*/
class Renderer extends \Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer
{
/**
* Serializer
*
* @var Json
*/
private $serializer;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Stdlib\StringUtils $string
* @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Stdlib\StringUtils $string,
\Magento\Catalog\Model\Product\OptionFactory $productOptionFactory,
array $data = [],
Json $serializer = null
) {
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(Json::class);

parent::__construct($context, $string, $productOptionFactory, $data);
}

/**
* @param mixed $item
* @return bool
Expand Down Expand Up @@ -100,7 +128,7 @@ public function getSelectionAttributes($item)
$options = $item->getOrderItem()->getProductOptions();
}
if (isset($options['bundle_selection_attributes'])) {
return unserialize($options['bundle_selection_attributes']);
return $this->serializer->unserialize($options['bundle_selection_attributes']);
}
return null;
}
Expand Down
20 changes: 17 additions & 3 deletions app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,32 @@ class Configuration extends AbstractHelper implements ConfigurationInterface
*/
protected $escaper;

/**
* Serializer interface instance.
*
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Catalog\Helper\Product\Configuration $productConfiguration
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
* @param \Magento\Framework\Escaper $escaper
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Catalog\Helper\Product\Configuration $productConfiguration,
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
\Magento\Framework\Escaper $escaper
\Magento\Framework\Escaper $escaper,
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
$this->productConfiguration = $productConfiguration;
$this->pricingHelper = $pricingHelper;
$this->escaper = $escaper;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
parent::__construct($context);
}

Expand Down Expand Up @@ -113,15 +124,18 @@ public function getBundleOptions(ItemInterface $item)

// get bundle options
$optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
$bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : [];
$bundleOptionsIds = $optionsQuoteItemOption
? $this->serializer->unserialize($optionsQuoteItemOption->getValue())
: [];

if ($bundleOptionsIds) {
/** @var \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection */
$optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);

// get and add bundle selections collection
$selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');

$bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue());
$bundleSelectionIds = $this->serializer->unserialize($selectionsQuoteItemOption->getValue());

if (!empty($bundleSelectionIds)) {
$selectionsCollection = $typeInstance->getSelectionsByIds($bundleSelectionIds, $product);
Expand Down
16 changes: 13 additions & 3 deletions app/code/Magento/Bundle/Model/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price
*/
protected $_catalogData = null;

/**
* Serializer interface instance.
*
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* Price constructor.
*
Expand All @@ -52,7 +59,7 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price
* @param \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
* @param \Magento\Catalog\Helper\Data $catalogData
*
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -65,9 +72,12 @@ public function __construct(
GroupManagementInterface $groupManagement,
\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $config,
\Magento\Catalog\Helper\Data $catalogData
\Magento\Catalog\Helper\Data $catalogData,
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
$this->_catalogData = $catalogData;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
parent::__construct(
$ruleFactory,
$storeManager,
Expand Down Expand Up @@ -154,7 +164,7 @@ protected function getBundleSelectionIds(\Magento\Catalog\Model\Product $product
{
$customOption = $product->getCustomOption('bundle_selection_ids');
if ($customOption) {
$selectionIds = unserialize($customOption->getValue());
$selectionIds = $this->serializer->unserialize($customOption->getValue());
if (!empty($selectionIds) && is_array($selectionIds)) {
return $selectionIds;
}
Expand Down
Loading

0 comments on commit 159b261

Please sign in to comment.