How i can Change the behavior of Upsell Products in mageto 2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
All i want to do is i want to show upsells products according to my phtml file
i have already done this for cross sells and its working fine i wrote a view/layout file
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Vendo_ModuleName::css/owl.carousel.css" />
<css src="Vendo_ModuleName::css/owl.theme.default.min.css" />
<css src="Vendo_ModuleName::css/style.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js" ></script>
<script src="Vendo_ModuleName::js/owl.carousel.js" ></script>
</head>
<body>
<referenceBlock name="product.info.options.wrapper">
<block class="VendoModuleNameBlockFrontendCrossSell" name="test.crosssell" template="slider.phtml" after="-">
<arguments>
<argument name="type" xsi:type="string">crosssell</argument>
</arguments>
<block class="MagentoCatalogBlockProductProductListItemContainer" name="crosssell.product.addto" as="addto">
<block class="MagentoCatalogBlockProductProductListItemAddToCompare"
name="crosssell.product.addto.compare" as="compare"
template="Magento_Catalog::product/list/addto/compare.phtml"/>
</block>
</block>
</referenceBlock>
<move element="test.crosssell" destination="content" after="product.info.media"/>
</body>
</page>
now i want to do same for up sell products i already made a block for upsells in
use VendoModuleNameHelperData as ModuleNameHelper;
class UpSells extends MagentoCatalogBlockProductAbstractProduct implements MagentoFrameworkDataObjectIdentityInterface {
protected $_sliderType = 'up-sells';
protected $_itemCollection;
protected $_storeManager;
protected $_sliderfactory;
protected $_helper;
protected $_customerSession;
protected $_customerGroupCollection;
public function __construct(
MagentoCatalogBlockProductContext $context,
MagentoFrameworkStdlibDateTimeDateTime $date,
MagentoCustomerModelSession $customerSession,
MagentoCustomerModelGroup $customerGroupCollection,
MagentoStoreModelStoreManagerInterface $storeManager,
VendoModuleNameModelResourceModelProductSlidersCollectionFactory $slidefactory,
ModuleNameHelper $helper,
array $data =
) {
$this->_sliderfactory = $slidefactory;
$this->date = $date;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->_registry = $context->getRegistry();
$this->_customerGroupCollection = $customerGroupCollection;
$this->_helper=$helper;
parent::__construct(
$context,
$data
);
}
protected function _prepareData()
{
$date = $this->date->gmtDate();
$rules=$this->_sliderfactory->create()
->addStatusFilter()
->addTypeFilter($this->_sliderType)
->addCurrentSlider($date)
->addStoreFilter($this->getStoreId())
->addCostumerGroupFilter($this->_helper->getCustomerGroupId());
$item=$rules->getFirstItem();
$product = $this->_registry->registry('current_product');
$this->_itemCollection = $product->getUpSellProductCollection()->addAttributeToSelect(
$this->_catalogConfig->getProductAttributes()
)->setPositionOrder()->addStoreFilter();
$this->_itemCollection->load();
foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true);
}
return $this;
}
protected function _beforeToHtml()
{
$this->_prepareData();
return parent::_beforeToHtml();
}
public function getItems()
{
return $this->_itemCollection;
}
public function getStoreId()
{
return $this->_storeManager->getStore()->getId();
}
public function getItemCount() {
return count($this->getItems());
}
public function getIdentities()
{
$identities = ;
foreach ($this->getItems() as $item) {
$identities = array_merge($identities, $item->getIdentities());
}
return $identities;
}
}
magento2.2 php-7
add a comment |
All i want to do is i want to show upsells products according to my phtml file
i have already done this for cross sells and its working fine i wrote a view/layout file
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Vendo_ModuleName::css/owl.carousel.css" />
<css src="Vendo_ModuleName::css/owl.theme.default.min.css" />
<css src="Vendo_ModuleName::css/style.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js" ></script>
<script src="Vendo_ModuleName::js/owl.carousel.js" ></script>
</head>
<body>
<referenceBlock name="product.info.options.wrapper">
<block class="VendoModuleNameBlockFrontendCrossSell" name="test.crosssell" template="slider.phtml" after="-">
<arguments>
<argument name="type" xsi:type="string">crosssell</argument>
</arguments>
<block class="MagentoCatalogBlockProductProductListItemContainer" name="crosssell.product.addto" as="addto">
<block class="MagentoCatalogBlockProductProductListItemAddToCompare"
name="crosssell.product.addto.compare" as="compare"
template="Magento_Catalog::product/list/addto/compare.phtml"/>
</block>
</block>
</referenceBlock>
<move element="test.crosssell" destination="content" after="product.info.media"/>
</body>
</page>
now i want to do same for up sell products i already made a block for upsells in
use VendoModuleNameHelperData as ModuleNameHelper;
class UpSells extends MagentoCatalogBlockProductAbstractProduct implements MagentoFrameworkDataObjectIdentityInterface {
protected $_sliderType = 'up-sells';
protected $_itemCollection;
protected $_storeManager;
protected $_sliderfactory;
protected $_helper;
protected $_customerSession;
protected $_customerGroupCollection;
public function __construct(
MagentoCatalogBlockProductContext $context,
MagentoFrameworkStdlibDateTimeDateTime $date,
MagentoCustomerModelSession $customerSession,
MagentoCustomerModelGroup $customerGroupCollection,
MagentoStoreModelStoreManagerInterface $storeManager,
VendoModuleNameModelResourceModelProductSlidersCollectionFactory $slidefactory,
ModuleNameHelper $helper,
array $data =
) {
$this->_sliderfactory = $slidefactory;
$this->date = $date;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->_registry = $context->getRegistry();
$this->_customerGroupCollection = $customerGroupCollection;
$this->_helper=$helper;
parent::__construct(
$context,
$data
);
}
protected function _prepareData()
{
$date = $this->date->gmtDate();
$rules=$this->_sliderfactory->create()
->addStatusFilter()
->addTypeFilter($this->_sliderType)
->addCurrentSlider($date)
->addStoreFilter($this->getStoreId())
->addCostumerGroupFilter($this->_helper->getCustomerGroupId());
$item=$rules->getFirstItem();
$product = $this->_registry->registry('current_product');
$this->_itemCollection = $product->getUpSellProductCollection()->addAttributeToSelect(
$this->_catalogConfig->getProductAttributes()
)->setPositionOrder()->addStoreFilter();
$this->_itemCollection->load();
foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true);
}
return $this;
}
protected function _beforeToHtml()
{
$this->_prepareData();
return parent::_beforeToHtml();
}
public function getItems()
{
return $this->_itemCollection;
}
public function getStoreId()
{
return $this->_storeManager->getStore()->getId();
}
public function getItemCount() {
return count($this->getItems());
}
public function getIdentities()
{
$identities = ;
foreach ($this->getItems() as $item) {
$identities = array_merge($identities, $item->getIdentities());
}
return $identities;
}
}
magento2.2 php-7
add a comment |
All i want to do is i want to show upsells products according to my phtml file
i have already done this for cross sells and its working fine i wrote a view/layout file
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Vendo_ModuleName::css/owl.carousel.css" />
<css src="Vendo_ModuleName::css/owl.theme.default.min.css" />
<css src="Vendo_ModuleName::css/style.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js" ></script>
<script src="Vendo_ModuleName::js/owl.carousel.js" ></script>
</head>
<body>
<referenceBlock name="product.info.options.wrapper">
<block class="VendoModuleNameBlockFrontendCrossSell" name="test.crosssell" template="slider.phtml" after="-">
<arguments>
<argument name="type" xsi:type="string">crosssell</argument>
</arguments>
<block class="MagentoCatalogBlockProductProductListItemContainer" name="crosssell.product.addto" as="addto">
<block class="MagentoCatalogBlockProductProductListItemAddToCompare"
name="crosssell.product.addto.compare" as="compare"
template="Magento_Catalog::product/list/addto/compare.phtml"/>
</block>
</block>
</referenceBlock>
<move element="test.crosssell" destination="content" after="product.info.media"/>
</body>
</page>
now i want to do same for up sell products i already made a block for upsells in
use VendoModuleNameHelperData as ModuleNameHelper;
class UpSells extends MagentoCatalogBlockProductAbstractProduct implements MagentoFrameworkDataObjectIdentityInterface {
protected $_sliderType = 'up-sells';
protected $_itemCollection;
protected $_storeManager;
protected $_sliderfactory;
protected $_helper;
protected $_customerSession;
protected $_customerGroupCollection;
public function __construct(
MagentoCatalogBlockProductContext $context,
MagentoFrameworkStdlibDateTimeDateTime $date,
MagentoCustomerModelSession $customerSession,
MagentoCustomerModelGroup $customerGroupCollection,
MagentoStoreModelStoreManagerInterface $storeManager,
VendoModuleNameModelResourceModelProductSlidersCollectionFactory $slidefactory,
ModuleNameHelper $helper,
array $data =
) {
$this->_sliderfactory = $slidefactory;
$this->date = $date;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->_registry = $context->getRegistry();
$this->_customerGroupCollection = $customerGroupCollection;
$this->_helper=$helper;
parent::__construct(
$context,
$data
);
}
protected function _prepareData()
{
$date = $this->date->gmtDate();
$rules=$this->_sliderfactory->create()
->addStatusFilter()
->addTypeFilter($this->_sliderType)
->addCurrentSlider($date)
->addStoreFilter($this->getStoreId())
->addCostumerGroupFilter($this->_helper->getCustomerGroupId());
$item=$rules->getFirstItem();
$product = $this->_registry->registry('current_product');
$this->_itemCollection = $product->getUpSellProductCollection()->addAttributeToSelect(
$this->_catalogConfig->getProductAttributes()
)->setPositionOrder()->addStoreFilter();
$this->_itemCollection->load();
foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true);
}
return $this;
}
protected function _beforeToHtml()
{
$this->_prepareData();
return parent::_beforeToHtml();
}
public function getItems()
{
return $this->_itemCollection;
}
public function getStoreId()
{
return $this->_storeManager->getStore()->getId();
}
public function getItemCount() {
return count($this->getItems());
}
public function getIdentities()
{
$identities = ;
foreach ($this->getItems() as $item) {
$identities = array_merge($identities, $item->getIdentities());
}
return $identities;
}
}
magento2.2 php-7
All i want to do is i want to show upsells products according to my phtml file
i have already done this for cross sells and its working fine i wrote a view/layout file
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Vendo_ModuleName::css/owl.carousel.css" />
<css src="Vendo_ModuleName::css/owl.theme.default.min.css" />
<css src="Vendo_ModuleName::css/style.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js" ></script>
<script src="Vendo_ModuleName::js/owl.carousel.js" ></script>
</head>
<body>
<referenceBlock name="product.info.options.wrapper">
<block class="VendoModuleNameBlockFrontendCrossSell" name="test.crosssell" template="slider.phtml" after="-">
<arguments>
<argument name="type" xsi:type="string">crosssell</argument>
</arguments>
<block class="MagentoCatalogBlockProductProductListItemContainer" name="crosssell.product.addto" as="addto">
<block class="MagentoCatalogBlockProductProductListItemAddToCompare"
name="crosssell.product.addto.compare" as="compare"
template="Magento_Catalog::product/list/addto/compare.phtml"/>
</block>
</block>
</referenceBlock>
<move element="test.crosssell" destination="content" after="product.info.media"/>
</body>
</page>
now i want to do same for up sell products i already made a block for upsells in
use VendoModuleNameHelperData as ModuleNameHelper;
class UpSells extends MagentoCatalogBlockProductAbstractProduct implements MagentoFrameworkDataObjectIdentityInterface {
protected $_sliderType = 'up-sells';
protected $_itemCollection;
protected $_storeManager;
protected $_sliderfactory;
protected $_helper;
protected $_customerSession;
protected $_customerGroupCollection;
public function __construct(
MagentoCatalogBlockProductContext $context,
MagentoFrameworkStdlibDateTimeDateTime $date,
MagentoCustomerModelSession $customerSession,
MagentoCustomerModelGroup $customerGroupCollection,
MagentoStoreModelStoreManagerInterface $storeManager,
VendoModuleNameModelResourceModelProductSlidersCollectionFactory $slidefactory,
ModuleNameHelper $helper,
array $data =
) {
$this->_sliderfactory = $slidefactory;
$this->date = $date;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->_registry = $context->getRegistry();
$this->_customerGroupCollection = $customerGroupCollection;
$this->_helper=$helper;
parent::__construct(
$context,
$data
);
}
protected function _prepareData()
{
$date = $this->date->gmtDate();
$rules=$this->_sliderfactory->create()
->addStatusFilter()
->addTypeFilter($this->_sliderType)
->addCurrentSlider($date)
->addStoreFilter($this->getStoreId())
->addCostumerGroupFilter($this->_helper->getCustomerGroupId());
$item=$rules->getFirstItem();
$product = $this->_registry->registry('current_product');
$this->_itemCollection = $product->getUpSellProductCollection()->addAttributeToSelect(
$this->_catalogConfig->getProductAttributes()
)->setPositionOrder()->addStoreFilter();
$this->_itemCollection->load();
foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true);
}
return $this;
}
protected function _beforeToHtml()
{
$this->_prepareData();
return parent::_beforeToHtml();
}
public function getItems()
{
return $this->_itemCollection;
}
public function getStoreId()
{
return $this->_storeManager->getStore()->getId();
}
public function getItemCount() {
return count($this->getItems());
}
public function getIdentities()
{
$identities = ;
foreach ($this->getItems() as $item) {
$identities = array_merge($identities, $item->getIdentities());
}
return $identities;
}
}
magento2.2 php-7
magento2.2 php-7
asked 2 mins ago
Waqar AliWaqar Ali
257
257
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272742%2fhow-i-can-change-the-behavior-of-upsell-products-in-mageto-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272742%2fhow-i-can-change-the-behavior-of-upsell-products-in-mageto-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown