Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top