Skip to content

Commit

Permalink
Merge pull request #1764 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - 2.2-develop
 - MAGETWO-83552: save invoice ID on credit memo when using API method salesRefundInvoiceV1 #11670
 - MAGETWO-82577: [Backport 2.2] Translate order getCreatedAtFormatted() to store locale #11422
 - MAGETWO-84474: 10128: New Orders not being saved to order grid #12241
 - MAGETWO-83783: Shipping method fixtures not compatible with getShippingMethod(true) in OrderCreateTest #12227
 - MAGETWO-83290: Add swatch option: Prevent loosing data and default value if data is not populated via adminhtml #12036
 - MAGETWO-83741: 11740: Sending emails from Admin in Multi-Store Environment defaults to Primary Store #11992
 - MAGETWO-83399: Fix for remove 'product_list_toolbar' block from layout in XML #9413 #11473
  • Loading branch information
ishakhsuvarov authored Nov 25, 2017
2 parents 1865e82 + b8c4068 commit 9c3d257
Show file tree
Hide file tree
Showing 18 changed files with 607 additions and 63 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Dashboard/Orders/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function _prepareCollection()
protected function _afterLoadCollection()
{
foreach ($this->getCollection() as $item) {
$item->getCustomer() ?: $item->setCustomer('Guest');
$item->getCustomer() ?: $item->setCustomer($item->getBillingAddress()->getName());
}
return $this;
}
Expand Down
140 changes: 104 additions & 36 deletions app/code/Magento/Catalog/Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Block\Product\ProductList\Toolbar;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Config;
use Magento\Catalog\Model\Layer;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Eav\Model\Entity\Collection\AbstractCollection;
use Magento\Framework\App\ActionInterface;
use Magento\Framework\App\Config\Element;
use Magento\Framework\Data\Helper\PostHelper;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Pricing\Render;
use Magento\Framework\Url\Helper\Data;

/**
* Product list
Expand All @@ -40,17 +49,17 @@ class ListProduct extends AbstractProduct implements IdentityInterface
/**
* Catalog layer
*
* @var \Magento\Catalog\Model\Layer
* @var Layer
*/
protected $_catalogLayer;

/**
* @var \Magento\Framework\Data\Helper\PostHelper
* @var PostHelper
*/
protected $_postDataHelper;

/**
* @var \Magento\Framework\Url\Helper\Data
* @var Data
*/
protected $urlHelper;

Expand All @@ -61,18 +70,18 @@ class ListProduct extends AbstractProduct implements IdentityInterface

/**
* @param Context $context
* @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
* @param PostHelper $postDataHelper
* @param Resolver $layerResolver
* @param CategoryRepositoryInterface $categoryRepository
* @param \Magento\Framework\Url\Helper\Data $urlHelper
* @param Data $urlHelper
* @param array $data
*/
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Framework\Data\Helper\PostHelper $postDataHelper,
\Magento\Catalog\Model\Layer\Resolver $layerResolver,
Context $context,
PostHelper $postDataHelper,
Resolver $layerResolver,
CategoryRepositoryInterface $categoryRepository,
\Magento\Framework\Url\Helper\Data $urlHelper,
Data $urlHelper,
array $data = []
) {
$this->_catalogLayer = $layerResolver->get();
Expand Down Expand Up @@ -113,7 +122,7 @@ protected function _getProductCollection()
/**
* Get catalog layer model
*
* @return \Magento\Catalog\Model\Layer
* @return Layer
*/
public function getLayer()
{
Expand All @@ -137,7 +146,35 @@ public function getLoadedProductCollection()
*/
public function getMode()
{
return $this->getChildBlock('toolbar')->getCurrentMode();
if ($this->getChildBlock('toolbar')) {
return $this->getChildBlock('toolbar')->getCurrentMode();
}

return $this->getDefaultListingMode();
}

/**
* Get listing mode for products if toolbar is removed from layout.
* Use the general configuration for product list mode from config path catalog/frontend/list_mode as default value
* or mode data from block declaration from layout.
*
* @return string
*/
private function getDefaultListingMode()
{
// default Toolbar when the toolbar layout is not used
$defaultToolbar = $this->getToolbarBlock();
$availableModes = $defaultToolbar->getModes();

// layout config mode
$mode = $this->getData('mode');

if (!$mode || !isset($availableModes[$mode])) {
// default config mode
$mode = $defaultToolbar->getCurrentMode();
}

return $mode;
}

/**
Expand All @@ -148,28 +185,60 @@ public function getMode()
protected function _beforeToHtml()
{
$collection = $this->_getProductCollection();
$this->configureToolbar($this->getToolbarBlock(), $collection);

$this->addToolbarBlock($collection);

$collection->load();

return parent::_beforeToHtml();
}

/**
* Retrieve Toolbar block
* Add toolbar block from product listing layout
*
* @param Collection $collection
*/
private function addToolbarBlock(Collection $collection)
{
$toolbarLayout = $this->getToolbarFromLayout();

if ($toolbarLayout) {
$this->configureToolbar($toolbarLayout, $collection);
}
}

/**
* Retrieve Toolbar block from layout or a default Toolbar
*
* @return Toolbar
*/
public function getToolbarBlock()
{
$block = $this->getToolbarFromLayout();

if (!$block) {
$block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, uniqid(microtime()));
}

return $block;
}

/**
* Get toolbar block from layout
*
* @return bool|Toolbar
*/
private function getToolbarFromLayout()
{
$blockName = $this->getToolbarBlockName();

$toolbarLayout = false;

if ($blockName) {
$block = $this->getLayout()->getBlock($blockName);
if ($block) {
return $block;
}
$toolbarLayout = $this->getLayout()->getBlock($blockName);
}
$block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, uniqid(microtime()));
return $block;

return $toolbarLayout;
}

/**
Expand Down Expand Up @@ -203,7 +272,7 @@ public function setCollection($collection)
}

/**
* @param array|string|integer|\Magento\Framework\App\Config\Element $code
* @param array|string|integer| Element $code
* @return $this
*/
public function addAttribute($code)
Expand All @@ -223,7 +292,7 @@ public function getPriceBlockTemplate()
/**
* Retrieve Catalog Config object
*
* @return \Magento\Catalog\Model\Config
* @return Config
*/
protected function _getConfig()
{
Expand All @@ -233,8 +302,8 @@ protected function _getConfig()
/**
* Prepare Sort By fields from Category Data
*
* @param \Magento\Catalog\Model\Category $category
* @return \Magento\Catalog\Block\Product\ListProduct
* @param Category $category
* @return $this
*/
public function prepareSortableFieldsByCategory($category)
{
Expand Down Expand Up @@ -278,38 +347,38 @@ public function getIdentities()
/**
* Get post parameters
*
* @param \Magento\Catalog\Model\Product $product
* @param Product $product
* @return string
*/
public function getAddToCartPostParams(\Magento\Catalog\Model\Product $product)
public function getAddToCartPostParams(Product $product)
{
$url = $this->getAddToCartUrl($product);
return [
'action' => $url,
'data' => [
'product' => $product->getEntityId(),
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => $this->urlHelper->getEncodedUrl($url),
ActionInterface::PARAM_NAME_URL_ENCODED => $this->urlHelper->getEncodedUrl($url),
]
];
}

/**
* @param \Magento\Catalog\Model\Product $product
* @param Product $product
* @return string
*/
public function getProductPrice(\Magento\Catalog\Model\Product $product)
public function getProductPrice(Product $product)
{
$priceRender = $this->getPriceRender();

$price = '';
if ($priceRender) {
$price = $priceRender->render(
\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
FinalPrice::PRICE_CODE,
$product,
[
'include_container' => true,
'display_minimal_price' => true,
'zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
'zone' => Render::ZONE_ITEM_LIST,
'list_category_page' => true
]
);
Expand All @@ -322,7 +391,7 @@ public function getProductPrice(\Magento\Catalog\Model\Product $product)
* Specifies that price rendering should be done for the list of products
* i.e. rendering happens in the scope of product list, but not single product
*
* @return \Magento\Framework\Pricing\Render
* @return Render
*/
protected function getPriceRender()
{
Expand All @@ -348,7 +417,7 @@ protected function getPriceRender()
private function initializeProductCollection()
{
$layer = $this->getLayer();
/* @var $layer \Magento\Catalog\Model\Layer */
/* @var $layer Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId($this->_storeManager->getStore()->getRootCategoryId());
}
Expand Down Expand Up @@ -386,9 +455,8 @@ private function initializeProductCollection()
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}

$toolbar = $this->getToolbarBlock();
$this->configureToolbar($toolbar, $collection);

$this->addToolbarBlock($collection);

$this->_eventManager->dispatch(
'catalog_block_product_list_collection',
Expand Down
17 changes: 14 additions & 3 deletions app/code/Magento/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

use Magento\Directory\Model\Currency;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderStatusHistoryInterface;
Expand Down Expand Up @@ -267,6 +269,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
*/
protected $timezone;

/**
* @var ResolverInterface
*/
private $localeResolver;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand Down Expand Up @@ -295,7 +302,9 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @param ResolverInterface $localeResolver
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
\Magento\Framework\Model\Context $context,
Expand Down Expand Up @@ -324,7 +333,8 @@ public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productListFactory,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
ResolverInterface $localeResolver = null
) {
$this->_storeManager = $storeManager;
$this->_orderConfig = $orderConfig;
Expand All @@ -335,7 +345,6 @@ public function __construct(
$this->_productVisibility = $productVisibility;
$this->invoiceManagement = $invoiceManagement;
$this->_currencyFactory = $currencyFactory;
$this->_eavConfig = $eavConfig;
$this->_orderHistoryFactory = $orderHistoryFactory;
$this->_addressCollectionFactory = $addressCollectionFactory;
$this->_paymentCollectionFactory = $paymentCollectionFactory;
Expand All @@ -346,6 +355,8 @@ public function __construct(
$this->_trackCollectionFactory = $trackCollectionFactory;
$this->salesOrderCollectionFactory = $salesOrderCollectionFactory;
$this->priceCurrency = $priceCurrency;
$this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(ResolverInterface::class);

parent::__construct(
$context,
$registry,
Expand Down Expand Up @@ -1830,7 +1841,7 @@ public function getCreatedAtFormatted($format)
new \DateTime($this->getCreatedAt()),
$format,
$format,
null,
$this->localeResolver->getDefaultLocale(),
$this->timezone->getConfigTimezone('store', $this->getStore())
);
}
Expand Down
Loading

0 comments on commit 9c3d257

Please sign in to comment.