3

We have 3 customer group. When we create a new product at that time we want all 3 groups are selected and it's price set default 0(zero). Anyone help me to set this type of functionality. Find attach image for more clear my requirement.enter image description here

5
  • How you will create your product? Manual OR CSV?
    – Ravi Soni
    Commented Jun 26, 2019 at 5:50
  • @Ravi we create it Manually
    – Anil
    Commented Jun 26, 2019 at 5:51
  • I m suggesting you to create CSV it will easy to meet your requirement.
    – Ravi Soni
    Commented Jun 26, 2019 at 5:53
  • @Ravi I am also know this thing but requirement is different.
    – Anil
    Commented Jun 26, 2019 at 5:56
  • Let me check and update you.
    – Ravi Soni
    Commented Jun 26, 2019 at 6:17

2 Answers 2

1

I have Added another answer. Might First answer will help someone.

So now here you have to override:

/app/design/adminhtml/default/default/template/catalog/product/edit/price/group.phtml

You should update your code from the line number: 55 and use below code with a condition I have added.

    <?php if(empty($this->getValues())): ?>
    <tbody id="group_price_container">
    <tr>
        <td style="display:none">
            <select class=" input-text required-entry" name="product[group_price][0][website_id]" id="group_price_row_0_website">
                <option value="0">All Websites [USD]</option>
            </select>
        </td>
        <td>
            <select class=" input-text custgroup required-entry" name="product[group_price][0][cust_group]" id="group_price_row_0_cust_group">
                <option value="0">NOT LOGGED IN</option>
                <option value="1" selected>General</option>
                <option value="2">Wholesale</option>
                <option value="3">Retailer</option>
            </select>
        </td>
        <td><input class=" input-text required-entry validate-zero-or-greater" type="text" name="product[group_price][0][price]" value="0.00" id="group_price_row_0_price"></td>
        <td class="last"><input type="hidden" name="product[group_price][0][delete]" class="delete" value="" id="group_price_row_0_delete"><button title="Delete Group Price" type="button" class="scalable delete icon-btn delete-product-option" id="group_price_row_0_delete_button" onclick="return groupPriceControl.deleteItem(event);"><span>Delete</span></button></td>
    </tr>
    <tr>
        <td style="display:none">
            <select class=" input-text required-entry" name="product[group_price][1][website_id]" id="group_price_row_1_website">
                <option value="0">All Websites [USD]</option>
            </select>
        </td>
        <td>
            <select class=" input-text custgroup required-entry" name="product[group_price][1][cust_group]" id="group_price_row_1_cust_group">
                <option value="0">NOT LOGGED IN</option>
                <option value="1">General</option>
                <option value="2" selected>Wholesale</option>
                <option value="3">Retailer</option>
            </select>
        </td>
        <td><input class=" input-text required-entry validate-zero-or-greater" type="text" name="product[group_price][1][price]" value="0.00" id="group_price_row_1_price"></td>
        <td class="last"><input type="hidden" name="product[group_price][1][delete]" class="delete" value="" id="group_price_row_1_delete"><button title="Delete Group Price" type="button" class="scalable delete icon-btn delete-product-option" id="group_price_row_1_delete_button" onclick="return groupPriceControl.deleteItem(event);"><span>Delete</span></button></td>
    </tr>
    <tr>
        <td style="display:none">
            <select class=" input-text required-entry" name="product[group_price][2][website_id]" id="group_price_row_2_website">
                <option value="0">All Websites [USD]</option>
            </select>
        </td>
        <td>
            <select class=" input-text custgroup required-entry" name="product[group_price][2][cust_group]" id="group_price_row_2_cust_group">
                <option value="0">NOT LOGGED IN</option>
                <option value="1">General</option>
                <option value="2">Wholesale</option>
                <option value="3" selected>Retailer</option>
            </select>
        </td>
        <td><input class=" input-text required-entry validate-zero-or-greater" type="text" name="product[group_price][2][price]" value="0.00" id="group_price_row_2_price"></td>
        <td class="last"><input type="hidden" name="product[group_price][2][delete]" class="delete" value="" id="group_price_row_2_delete"><button title="Delete Group Price" type="button" class="scalable delete icon-btn delete-product-option" id="group_price_row_2_delete_button" onclick="return groupPriceControl.deleteItem(event);"><span>Delete</span></button></td>
    </tr>
    </tbody>
<?php else: ?>
    <tbody id="<?php echo $_htmlId; ?>_container"></tbody>
<?php endif; ?>

Code look not well but it is the only solution.

2
  • Yes it's working as per my requirement. Thanks a lot.
    – Anil
    Commented Jun 26, 2019 at 10:01
  • Welcome. Thanks for mark as a right answer. :)
    – Ravi Soni
    Commented Jun 26, 2019 at 10:05
1

I got this solution.

For this you have to override below file

/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php

Updated code here:

/**
 * Save product action
 */
public function saveAction()
{
    $storeId        = $this->getRequest()->getParam('store');
    $redirectBack   = $this->getRequest()->getParam('back', false);
    $productId      = $this->getRequest()->getParam('id');
    $isEdit         = (int)($this->getRequest()->getParam('id') != null);

    $data = $this->getRequest()->getPost();
    if ($data) {
        $this->_filterStockData($data['product']['stock_data']);

        $product = $this->_initProductSave();

        try {
            $defaltSetGroupPrice = array(

                array('website_id' => 0, 'cust_group' => 1, 'price' => 0, 'delete' => ''),
                array('website_id' => 0, 'cust_group' => 2, 'price' => 0, 'delete' => ''),
                array('website_id' => 0, 'cust_group' => 3, 'price' => 0, 'delete' => ''),
            );
            $product->setData('group_price', $defaltSetGroupPrice);
            $product->save();
            $productId = $product->getId();

            if (isset($data['copy_to_stores'])) {
                $this->_copyAttributesBetweenStores($data['copy_to_stores'], $product);
            }

            $this->_getSession()->addSuccess($this->__('The product has been saved.'));
        } catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage())
                ->setProductData($data);
            $redirectBack = true;
        } catch (Exception $e) {
            Mage::logException($e);
            $this->_getSession()->addError($e->getMessage());
            $redirectBack = true;
        }
    }

    if ($redirectBack) {
        $this->_redirect('*/*/edit', array(
            'id'    => $productId,
            '_current'=>true
        ));
    } elseif($this->getRequest()->getParam('popup')) {
        $this->_redirect('*/*/created', array(
            '_current'   => true,
            'id'         => $productId,
            'edit'       => $isEdit
        ));
    } else {
        $this->_redirect('*/*/', array('store'=>$storeId));
    }
}

Here in this variable $defaltSetGroupPrice Set your cust_group ID and check.

3
  • Sorry for this code. We want when we create new product at that time this option default selected. For example; when we click on Add new product button at that time product visibility by default show 'Catalog, Search'. Please update code for this functionality.
    – Anil
    Commented Jun 26, 2019 at 8:48
  • Okay, Once you click on Add Product then you have to select a product type. On which product type you want this?
    – Ravi Soni
    Commented Jun 26, 2019 at 8:59
  • Simple product.
    – Anil
    Commented Jun 26, 2019 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.