#StackBounty: #magento2 #product #cart #quote Magento 2 – New product added to cart has subtotal price value of 0

Bounty: 50

I created a new product programmatically and added it to the cart, but the subtotal value which is showing in the cart is 0.

use MagentoCatalogModelProductFactory;

...

$product = $this->productFactory->create();
$product->setName($data["name"]);
$product->setSku($data["sku"]);
$product->setPrice($data["difference"]);
$product->setTypeId("virtual");
$product->setWeight(0);
$product->setTaxClassId($this->taxClassId);
$product->setVisibility(1);
$product->save();

...

$this->quote->addProduct($product);
$this->quote->save();

price subtotal is 0


Get this bounty!!!

#StackBounty: #magento-1.9 #product #exception #zipcode I want to set exceptions on add_to_cart button

Bounty: 50

I am building E-Commerce website in Magento 1.9. I want to add below functionalities on my add_to_cart button on product page:

  1. Want to keep add_to_cart button disabled always.
  2. I want every user check the zipcode first & if their zipcode is valid then only unfreeze the add_to_cart button, if the zipcode is invalid then keep the add_to_cart button disabled.
  3. Always refresh the product page whenever user checks zipcode & keep add_to_cart button disabled if zipcode is invalid & unfreeze if it is valid.

These exceptions are useful for me because I am running my E-Commerce store in limited area. I have attached the view.phtml, restriczip.phml & product page screenshot. If any more things needed please ask me. Any help will be appreciated.

view.phtml

<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->toHtml() ?></div>
<div class="product-view">
    <div class="product-essential">
        <form action="<?php echo $this->getSubmitUrlCustom($_product, array('_secure' => $this->_isSecure()), false) ?>"
              method="post"
              id="product_addtocart_form"
              <?php if ($_product->getOptions()): ?> enctype="multipart/form-data" <?php endif; ?>>
            <?php echo $this->getBlockHtml('formkey') ?>
            <div class="no-display">
                <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
                <input type="hidden" name="related_product" id="related-products-field" value="" />
            </div>

            <div class="product-img-box">
                <div class="product-name">
                    <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
                </div>
                <?php echo $this->getChildHtml('media') ?>
            </div>

            <div class="product-shop">
                <div class="product-name">
                    <span class="h1"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></span>
                </div>

                <div class="price-info">
                    <?php echo $this->getPriceHtml($_product); ?>
                    <?php echo $this->getChildHtml('bundle_prices') ?>
                    <?php echo $this->getTierPriceHtml() ?>
                </div>

                <div class="extra-info">
                    <?php echo $this->getReviewsSummaryHtml($_product, 'default', false)?>
                    <?php echo $this->getChildHtml('product_type_availability'); ?>
                </div>

                <?php echo $this->getChildHtml('alert_urls') ?>

                <?php if ($_product->getShortDescription()):?>
                    <div class="short-description">
                        <div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
                    </div>
                <?php endif;?>




                <?php echo $this->getChildHtml('other');?>

                <?php if ($_product->isSaleable() && $this->hasOptions()):?>
                    <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
                <?php endif;?>

            </div>

            <div class="add-to-cart-wrapper">
                <?php echo $this->getChildHtml('product_type_data') ?>
                <?php echo $this->getChildHtml('extrahint') ?>

                <?php if (!$this->hasOptions()):?>
                    <div class="add-to-box">
                        <?php if($_product->isSaleable()): ?>
                            <?php echo $this->getChildHtml('addtocart') ?>
                            <?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
                                <span class="or"><?php echo $this->__('OR') ?></span>
                            <?php endif; ?>
                        <?php endif; ?>
                        <?php echo $this->getChildHtml('addto') ?>
                        <?php echo $this->getChildHtml('sharing') ?>
                    </div>
                    <?php echo $this->getChildHtml('extra_buttons') ?>
                <?php elseif (!$_product->isSaleable()): ?>
                    <div class="add-to-box">
                        <?php echo $this->getChildHtml('addto') ?>
                        <?php echo $this->getChildHtml('sharing') ?>
                    </div>
                <?php endif; ?>
            </div>

            <?php echo $this->getChildHtml('related_products') ?>

            <div class="clearer"></div>
            <?php if ($_product->isSaleable() && $this->hasOptions()):?>
                <?php echo $this->getChildChildHtml('container2', '', true, true) ?>
            <?php endif;?>
        </form>
        <script type="text/javascript">
        //<![CDATA[
            var productAddToCartForm = new VarienForm('product_addtocart_form');
            productAddToCartForm.submit = function(button, url) {
                if (this.validator.validate()) {
                    var form = this.form;
                    var oldUrl = form.action;

                    if (url) {
                       form.action = url;
                    }
                    var e = null;
                    try {
                        this.form.submit();
                    } catch (e) {
                    }
                    this.form.action = oldUrl;
                    if (e) {
                        throw e;
                    }

                    if (button && button != 'undefined') {
                        button.disabled = true;
                    }
                }
            }.bind(productAddToCartForm);

            productAddToCartForm.submitLight = function(button, url){
                if(this.validator) {
                    var nv = Validation.methods;
                    delete Validation.methods['required-entry'];
                    delete Validation.methods['validate-one-required'];
                    delete Validation.methods['validate-one-required-by-name'];
                    // Remove custom datetime validators
                    for (var methodName in Validation.methods) {
                        if (methodName.match(/^validate-datetime-.*/i)) {
                            delete Validation.methods[methodName];
                        }
                    }

                    if (this.validator.validate()) {
                        if (url) {
                            this.form.action = url;
                        }
                        this.form.submit();
                    }
                    Object.extend(Validation.methods, nv);
                }
            }.bind(productAddToCartForm);
        //]]>
        </script>
    </div>

    <div class="product-collateral toggle-content tabs">
        <?php if ($detailedInfoGroup = $this->getChildGroup('detailed_info', 'getChildHtml')):?>
            <dl id="collateral-tabs" class="collateral-tabs">
                <?php foreach ($detailedInfoGroup as $alias => $html):?>
                    <dt class="tab"><span><?php echo $this->escapeHtml($this->getChildData($alias, 'title')) ?></span></dt>
                    <dd class="tab-container">
                        <div class="tab-content"><?php echo $html ?></div>
                    </dd>
                <?php endforeach;?>
            </dl>
        <?php endif; ?>
    </div>

    <?php echo $this->getChildHtml('upsell_products') ?>
    <?php echo $this->getChildHtml('product_additional_data') ?>

</div>

restrictzip.phtml

<div id="meetanshi-restrictzip">
    <ul class="messages cod-available">
        <li class="success-msg">
            <ul>
                <li>
                    <span>
                    <?php echo $this->__(Mage::helper('restrictzip')->getSuccessMsg()) ?> 
                    </span>
                </li>
            </ul>
        </li>
    </ul>
    <ul class="messages cod-available">
        <li class="success-msg"   style="display:<?php echo Mage::helper('restrictzip')->isShowDelivery();?>">
            <ul>
                <li><span id="extpected_delivery_time"> </span>
                </li>
            </ul>
        </li>
    </ul>
    <ul class="messages cod-not-available">
        <li class="error-msg">
            <ul>
                <li><span>
                        <?php echo $this->__(Mage::helper('restrictzip')->getErrorMsg()) ?>
                    </span>
                </li>
            </ul>
        </li>
    </ul>
    <ul class="messages cod-validation">
        <li class="error-msg">
            <ul>
                <li><span><?php echo $this->__('Please enter a ZIP code.')?></span></li>
            </ul>
        </li>
    </ul>
    <ul class="messages cod-error">
        <li class="error-msg">
            <ul>
                <li>
                    <span>
                        <?php echo $this->__('There was a problem while checking for COD availability. 
                        Please try again after some time.')?>
                    </span>
                </li>
            </ul>
        </li>
    </ul>
    <h4>
        <?php echo $this->__(Mage::helper('restrictzip')->getTitle())?>
    </h4>
    <label for="meetanshi-zip"><?php echo $this->__('ZIP Code')?></label>
    <input id="meetanshi-zip" type="text" name="zip_code" value="" maxlength="10" class="input-text"/>

    <button class="button check-zip" type="button" class="button"><span><span><?php echo $this->__('Check')?></span></span></button>

    <img src="<?php echo $this->getSkinUrl('meetanshi/loading.gif'); ?>" width="20" height="20"
         alt="" class="loading-spinner"/>
</div>
<script type="text/javascript">
    var meetanshi_restrictzip_ajax_url = '<?php echo $this->getUrl('restrictzip/restrictzip'); ?>';
</script>

<style>
#meetanshi-restrictzip {
    padding: 15px;
    border: 1px solid #CCC;
    margin-bottom: 15px;
}
#meetanshi-restrictzip .input-text {
  height: 38px;
  width: 100px;
}
.button.check-zip {
  height: 38px;
}
#meetanshi-restrictzip .cod-available,
#meetanshi-restrictzip .cod-not-available,
#meetanshi-restrictzip .cod-validation,
#meetanshi-restrictzip .cod-error,
#meetanshi-restrictzip .loading-spinner {
    display: none;
}
</style>


<script>
document.observe( 'dom:loaded', function() {

    $$( '#meetanshi-restrictzip .check-zip' ).invoke( 'observe', 'click', function( e ) {
        var the_zip_code = $( 'meetanshi-zip' ).value;
        if ( the_zip_code == '' ) {
            $$( '#meetanshi-restrictzip .cod-available' ).each( function (e) { e.setStyle({ display: 'none' }); } );
            $$( '#meetanshi-restrictzip .cod-not-available' ).each( function (e) { e.setStyle({ display: 'none' }); } );
            $$( '#meetanshi-restrictzip .cod-validation' ).each( function (e) { e.setStyle({ display: 'block' }); } );
            $$( '#meetanshi-restrictzip .cod-error' ).each( function (e) { e.setStyle({ display: 'none' }); } );

            return;
        }

        $$( '#meetanshi-restrictzip .loading-spinner' ).each( function (e) { e.setStyle({ display: 'inline-block' }); } );
        $$( '#meetanshi-restrictzip .cod-available' ).each( function (e) { e.setStyle({ display: 'none' }); } );
        $$( '#meetanshi-restrictzip .cod-not-available' ).each( function (e) { e.setStyle({ display: 'none' }); } );
        $$( '#meetanshi-restrictzip .cod-validation' ).each( function (e) { e.setStyle({ display: 'none' }); } );
        $$( '#meetanshi-restrictzip .cod-error' ).each( function (e) { e.setStyle({ display: 'none' }); } );

        // Send an AJAX request
        new Ajax.Request( meetanshi_restrictzip_ajax_url, {
            method: 'post',
            parameters: { zip_code: the_zip_code },
            asynchronous: true,
            onSuccess: function( response ) {
                var json_response = response.responseText.evalJSON();
                
                
                if ( json_response.status == 'success' ) {
                    if ( json_response.allowed_zip == true ) {
                        $$( '#meetanshi-restrictzip .cod-available' ).each( function (e) { e.setStyle({ display: 'block' }); } );
                        
                        $$( '#meetanshi-restrictzip .cod-not-available' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                        $$( '#meetanshi-restrictzip .cod-validation' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                        $$( '#meetanshi-restrictzip .cod-error' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                        
                        document.getElementById("extpected_delivery_time").innerHTML = "Estimated Delivery Time : "+json_response.estimate_delivery_time;                       
                    }
                    else {
                        $$( '#meetanshi-restrictzip .cod-available' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                        $$( '#meetanshi-restrictzip .cod-not-available' ).each( function (e) { e.setStyle({ display: 'block' }); } );
                        $$( '#meetanshi-restrictzip .cod-validation' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                        $$( '#meetanshi-restrictzip .cod-error' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                    }
                }
                else {
                    $$( '#meetanshi-restrictzip .cod-available' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                    $$( '#meetanshi-restrictzip .cod-not-available' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                    $$( '#meetanshi-restrictzip .cod-validation' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                    $$( '#meetanshi-restrictzip .cod-error' ).each( function (e) { e.setStyle({ display: 'block' }); } );
                }

                $$( '#meetanshi-restrictzip .loading-spinner' ).each( function (e) { e.setStyle({ display: 'none' }); } );
            },
            onException: function( request, ex ) {
                //alert( ex.toSource() );
            },
            onFailure: function() {
                $$( '#meetanshi-restrictzip .cod-available' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                $$( '#meetanshi-restrictzip .cod-not-available' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                $$( '#meetanshi-restrictzip .cod-validation' ).each( function (e) { e.setStyle({ display: 'none' }); } );
                $$( '#meetanshi-restrictzip .cod-error' ).each( function (e) { e.setStyle({ display: 'block' }); } );

                $$( '#meetanshi-restrictzip .loading-spinner' ).each( function (e) { e.setStyle({ display: 'none' }); } );
            }
        });


        e.stop();
    });

});

</script>

enter image description here


Get this bounty!!!

#StackBounty: #product #magento2.3.4 #product-edit Anyone still facing this issue – After Migrated from magento 1.9 Fatal error – Produ…

Bounty: 50

lib/internal/Magento/Framework/View/Element/UiComponentFactory.php

UiComponentFactory::mergeMetadataElement() must be of the type array,
null given

protected function mergeMetadataElement(array $bundleComponents, $name, array $data, $reverseMerge = false)
{
    if (isset($bundleComponents[$name])) {
        $bundleComponents[$name] = $reverseMerge
            ? array_replace_recursive($data, $bundleComponents[$name])
            : array_replace_recursive($bundleComponents[$name], $data);
        return [$bundleComponents, true];
    } else {
        foreach ($bundleComponents as &$childData) {
            if (isset($childData['attributes']['class'])
                && is_a($childData['attributes']['class'], MagentoUiComponentContainer::class, true)
                && isset($childData['children']) && is_array($childData['children'])
            ) {
                list($childData['children'], $isMerged) = $this->mergeMetadataElement(
                    $childData['children'],
                    $name,
                    $data,
                    $reverseMerge
                );
                if ($isMerged) {
                    return [$bundleComponents, true];
                }
            }
        }
    }
    return [$bundleComponents, false];
}

I am getting following error if i try to edit product from backend,

Fatal error: Uncaught TypeError: Argument 3 passed to
MagentoFrameworkViewElementUiComponentFactory::mergeMetadataElement()
must be of the type array, null given, called in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php
on line 384 and defined in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php:337
Stack trace: #0
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(384):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataElement(Array,
‘configurableExi…’, NULL, false) #1
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(412):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataItem(Array,
Array, false) #2
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(412):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataItem(Array,
Array, false) #3 /var/www/html/test/lib/internal/Magento/Fram in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php
on line 337


Get this bounty!!!

#StackBounty: #product #magento2.3.4 #product-edit Magento 2.3 – After Migrated from magento 1.9 Fatal error: Uncaught TypeError: Argum…

Bounty: 50

lib/internal/Magento/Framework/View/Element/UiComponentFactory.php

UiComponentFactory::mergeMetadataElement() must be of the type array,
null given

protected function mergeMetadataElement(array $bundleComponents, $name, array $data, $reverseMerge = false)
{
    if (isset($bundleComponents[$name])) {
        $bundleComponents[$name] = $reverseMerge
            ? array_replace_recursive($data, $bundleComponents[$name])
            : array_replace_recursive($bundleComponents[$name], $data);
        return [$bundleComponents, true];
    } else {
        foreach ($bundleComponents as &$childData) {
            if (isset($childData['attributes']['class'])
                && is_a($childData['attributes']['class'], MagentoUiComponentContainer::class, true)
                && isset($childData['children']) && is_array($childData['children'])
            ) {
                list($childData['children'], $isMerged) = $this->mergeMetadataElement(
                    $childData['children'],
                    $name,
                    $data,
                    $reverseMerge
                );
                if ($isMerged) {
                    return [$bundleComponents, true];
                }
            }
        }
    }
    return [$bundleComponents, false];
}

I am getting following error if i try to edit product from backend,

Fatal error: Uncaught TypeError: Argument 3 passed to
MagentoFrameworkViewElementUiComponentFactory::mergeMetadataElement()
must be of the type array, null given, called in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php
on line 384 and defined in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php:337
Stack trace: #0
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(384):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataElement(Array,
‘configurableExi…’, NULL, false) #1
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(412):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataItem(Array,
Array, false) #2
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(412):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataItem(Array,
Array, false) #3 /var/www/html/test/lib/internal/Magento/Fram in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php
on line 337


Get this bounty!!!

#StackBounty: #product #magento2.3.4 #product-edit Magento 2.3 – After Migration Fatal error: Uncaught TypeError: Argument 3 passed Err…

Bounty: 50

lib/internal/Magento/Framework/View/Element/UiComponentFactory.php

UiComponentFactory::mergeMetadataElement() must be of the type array,
null given

protected function mergeMetadataElement(array $bundleComponents, $name, array $data, $reverseMerge = false)
{
    if (isset($bundleComponents[$name])) {
        $bundleComponents[$name] = $reverseMerge
            ? array_replace_recursive($data, $bundleComponents[$name])
            : array_replace_recursive($bundleComponents[$name], $data);
        return [$bundleComponents, true];
    } else {
        foreach ($bundleComponents as &$childData) {
            if (isset($childData['attributes']['class'])
                && is_a($childData['attributes']['class'], MagentoUiComponentContainer::class, true)
                && isset($childData['children']) && is_array($childData['children'])
            ) {
                list($childData['children'], $isMerged) = $this->mergeMetadataElement(
                    $childData['children'],
                    $name,
                    $data,
                    $reverseMerge
                );
                if ($isMerged) {
                    return [$bundleComponents, true];
                }
            }
        }
    }
    return [$bundleComponents, false];
}

I am getting following error if i try to edit product from backend,

Fatal error: Uncaught TypeError: Argument 3 passed to
MagentoFrameworkViewElementUiComponentFactory::mergeMetadataElement()
must be of the type array, null given, called in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php
on line 384 and defined in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php:337
Stack trace: #0
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(384):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataElement(Array,
‘configurableExi…’, NULL, false) #1
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(412):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataItem(Array,
Array, false) #2
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(412):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataItem(Array,
Array, false) #3 /var/www/html/test/lib/internal/Magento/Fram in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php
on line 337


Get this bounty!!!

#StackBounty: #product #magento2.3.4 #product-edit Magento 2.3 – Can't able to add new product – Error: Uncaught TypeError: Argumen…

Bounty: 50

I am getting following error if i try to edit product from backend,

Fatal error: Uncaught TypeError: Argument 3 passed to
MagentoFrameworkViewElementUiComponentFactory::mergeMetadataElement()
must be of the type array, null given, called in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php
on line 384 and defined in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php:337
Stack trace: #0
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(384):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataElement(Array,
‘configurableExi…’, NULL, false) #1
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(412):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataItem(Array,
Array, false) #2
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(412):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataItem(Array,
Array, false) #3 /var/www/html/test/lib/internal/Magento/Fram in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php
on line 337

Attribute Set Error:

enter image description here

enter image description here


Get this bounty!!!

#StackBounty: #product #magento2.3.4 #product-edit Magento 2.3 – Can't able to add new product – Error: Uncaught TypeError: Argumen…

Bounty: 50

I am getting following error if i try to edit product from backend,

Fatal error: Uncaught TypeError: Argument 3 passed to
MagentoFrameworkViewElementUiComponentFactory::mergeMetadataElement()
must be of the type array, null given, called in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php
on line 384 and defined in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php:337
Stack trace: #0
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(384):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataElement(Array,
‘configurableExi…’, NULL, false) #1
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(412):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataItem(Array,
Array, false) #2
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(412):
MagentoFrameworkViewElementUiComponentFactory->mergeMetadataItem(Array,
Array, false) #3 /var/www/html/test/lib/internal/Magento/Fram in
/var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php
on line 337


Get this bounty!!!

#StackBounty: #product #programmatically #magento2.3.4 faster way to update attributes/ update product programmtically with stock data …

Bounty: 200

I have this code but Anybody tell me faster way to update products.

This below code takes much time. So any alternative solution for to save product in fast way and Can I also put sleep function at end of the for loop to less consume memory ?
Thank you

  public function updateProducts(){

        foreach($productIds as $productId){
            $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // instance of object manager
            $product = $objectManager->create('MagentoCatalogModelProduct');
            $product->load($productId);
            $product->setSku('my-sku'); // Set your sku here
            $product->setName('Sample Simple Product'); // Name of Product
            $product->setStatus(1); // Status on product enabled/ disabled 1/0
            $product->setWeight(10); // weight of product
            $product->setVisibility(4); 
            $product->setPrice(100); // price of product
            $product->setStockData(
                                    array(
                                        'use_config_manage_stock' => 0,
                                        'manage_stock' => 1,
                                        'is_in_stock' => 1,
                                        'qty' => 14
                                    )
                                );
    $imageUrl = "https://example.com/img1.jpg";
    $tmpDir = $this->getMediaDirTmpDir();
    $newFileName = $tmpDir . baseName($imageUrl);
                        $result = $this->file->read($imageUrl, $newFileName);
                        if ($result) {
                             $_product->addImageToMediaGallery($newFileName,array('small','thumbnail','base'), $imageType, true, false);
                        }
            $product->save();
          unset($product);
        }
}
    protected function getMediaDirTmpDir(){
            return $this->directoryList->getPath(DirectoryList::MEDIA) . DIRECTORY_SEPARATOR . 'tmp';
        }


Get this bounty!!!

#StackBounty: #php #wordpress #woocommerce #product #code-snippets Remove Add do Cart Button for customers and guests for specifics pro…

Bounty: 50

For Woocommerce, I need a PHP snippet that will hide few products ID’s I will select for guests and customers.

My code attempt:

function dma_restrict_product() {

    $user = wp_get_current_user();
    $user_meta = get_userdata($user->ID);
    $user_roles = $user_meta->roles;
    
    global $product;

    if( in_array( 'customer', (array) $user_roles ) && ( is_single('3759') ) ) {
        return true;
        add_filter('woocommerce_is_purchasable', 'woocommerce_cloudways_purchasable');
        
        function woocommerce_cloudways_purchasable($cloudways_purchasable, $product) {
            return ($product->id == 3759 ? false : $cloudways_purchasable);
        }

    } else if( in_array('administrator', (array) $user_roles) ) {
        return true;
    } else {
        return false;
    }
}

But it doesn’t work as I would like.


Get this bounty!!!

#StackBounty: #product #video #product-video HTML video for products

Bounty: 50

Is there a way to add HTML video instead of relying on Youtube, Vimeo, …
It’s kinda unprofessional looking and it’s not kinda hard to have a video tag that links to URL. Seems like this is supported as a Magento Commerce feature from documentation, I should be able to allow my own CDN link to do this kinda stuff. Seems like a very simple feature left out intentionally which looks bad on an open-source project


Get this bounty!!!