当用户将产品添加到购物车时,Magento自定义选项值和选项标题存储

时间:2016-12-29 10:12:07

标签: php html5 magento

我想在会话中存储值,如下所示

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;  
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class Tab2 extends Fragment
{



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState)
{
    setRetainInstance(false);
    final View rootView;
    rootView= inflater.inflate(R.layout.fragment_tab2, container, false);

    text.setText("default");
    return rootView;
}
}

上面的代码是产品选择颜色的选项,RAM是选项及其值的标题,在option_details数组中包含上述选项的id。 选项显示数组值需要显示在前端,选项详细信息数组需要存储在db。

我的代码是

package com.example.nirvan.diary30;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;  
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v7.widget.Toolbar;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity
{
public static int itemPosition;

private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;


@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
    viewPager.setOffscreenPageLimit(0);



}

private void setupViewPager(ViewPager viewPager)
{
    ViewPagerAdapter adapter = new      ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new Tab1(), "ONE");
    adapter.addFragment(new Tab2(), "TWO");
    viewPager.setAdapter(adapter);
}

class ViewPagerAdapter extends FragmentPagerAdapter
{
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }
}
}

如果我选择值,选项详细信息即将出现,但选项显示数组只有选项标题,没有值即将到来,因为我无法在隐藏字段中选择值 我的输出数组是

option => array (
   ['option_display] => array(
        'color' => 'white',
         'RAM'  => '3gb'
         ),
   ['option_details'] => array (
         '5' => '3'
         '6' => '5'
         ) );

当用户选择选项时,如何获取两个数组中的值。

1 个答案:

答案 0 :(得分:0)

您必须在用户选择选项

时更新值
echo '<input type="hidden" name="option_display['.$value->getTitle().']" id="option_display_'.$value->getTitle().'" />';

echo '<input type="hidden" name="option_display['.$value->getTitle().']" id="option_display_'.$value->getTitle().'" value="user_selected_value" />';